feat(operations): introduce SetIdempotencyDisabled flag#1014
feat(operations): introduce SetIdempotencyDisabled flag#1014graham-chainlink wants to merge 1 commit into
Conversation
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.
|
There was a problem hiding this comment.
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/IdempotencyDisabledglobal flag and a helper to decide whether to reuse prior reports. - Updates
ExecuteOperation,ExecuteOperationN, andExecuteSequenceto 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.
| // 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. |
| SetIdempotencyDisabled(true) | ||
| require.True(t, IdempotencyDisabled()) | ||
| t.Cleanup(func() { SetIdempotencyDisabled(false) }) | ||
|
|
| require.Equal(t, 3, handlerCalledTimes, "execution idempotency disabled should force sequence execution") | ||
|
|
| 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. |
|




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.