Skip to content

feat(operations): introduce SetIdempotencyDisabled flag#1014

Draft
graham-chainlink wants to merge 1 commit into
mainfrom
ggoh/disable-operatons-cache
Draft

feat(operations): introduce SetIdempotencyDisabled flag#1014
graham-chainlink wants to merge 1 commit into
mainfrom
ggoh/disable-operatons-cache

Conversation

@graham-chainlink
Copy link
Copy Markdown
Collaborator

Allow users to configure the idempotency behaviour of the Operations API.

We have seen cases where user prefer to not have the caching enable, such as making the same call to retrieve on chain data multiple times that can be updated or running operations where inputs are the same but dependencies eg chain client is a different object. I am not completely convinced in all cases, but I believe it is good to give them the option and let them decide themselves.

This is the master switch , however i will have another PR to enhance the operations API to allow extra cache key so user can be more precise in their caching keys.

Allow users to configure the idempotency behaviour of the Operations API.

We have seen use cases where user prefer to not have the caching enable, this config allow user to disable the caching behaviour if they want to.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 27, 2026

⚠️ No Changeset found

Latest commit: e0d9c30

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a global switch to disable Operations API idempotent behavior (reusing prior successful reports), allowing callers to force fresh executions even when prior matching reports exist.

Changes:

  • Introduces SetIdempotencyDisabled / IdempotencyDisabled global flag and a helper to decide whether to reuse prior reports.
  • Updates ExecuteOperation, ExecuteOperationN, and ExecuteSequence to respect the global “no reuse” setting.
  • Adds documentation/test coverage for the new configuration option.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
operations/config.go Adds global atomic flag + helper for reuse decisions.
operations/execute.go Gates report reuse logic behind the new global flag (and WithForceExecute for single ops).
operations/execute_test.go Adds a test covering behavior when idempotency is disabled.
operations/doc.go Updates package docs to describe disabling reuse globally.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread operations/execute.go
Comment thread operations/execute.go
// ExecuteOperation executes an operation with the given input and dependencies.
// Execution will return the previous successful execution result and skip execution if there was a
// previous successful run found in the Reports.
// previous successful run found in the Reports, unless IdempotencyDisabled or WithForceExecute is set.
Comment on lines +269 to +272
SetIdempotencyDisabled(true)
require.True(t, IdempotencyDisabled())
t.Cleanup(func() { SetIdempotencyDisabled(false) })

Comment on lines +279 to +280
require.Equal(t, 3, handlerCalledTimes, "execution idempotency disabled should force sequence execution")

Comment thread operations/config.go
Comment on lines +5 to +14
var disableIdempotency atomic.Bool

// SetIdempotencyDisabled configures whether execution idempotency (report reuse) is disabled.
// When true, ExecuteOperation, ExecuteOperationN, and ExecuteSequence always run
// fresh regardless of prior successful reports.
func SetIdempotencyDisabled(disabled bool) {
disableIdempotency.Store(disabled)
}

// IdempotencyDisabled reports whether execution idempotency is disabled.
@cl-sonarqube-production
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants