fix/batch-changes: ignore per-job env vars in cache key#1326
Merged
Conversation
f6a51e6 to
2a38987
Compare
The two SRC_BATCHES_* env vars declared by codingAgent steps (see sourcegraph/sourcegraph#12503) resolve to different values on every dequeue. Strip them from cache-key inputs so the key stays stable across runs.
2a38987 to
f9ae28e
Compare
…p SRC_EXECUTOR_NAME The per-job env vars declared by codingAgent steps were renamed in sourcegraph/sourcegraph#12503 (review feedback) from SRC_BATCHES_* to SRC_EXECUTOR_*, and a third var SRC_EXECUTOR_NAME was added so the in-sandbox coding-agent CLI can pass X-Sourcegraph-Executor-Name to the model-provider proxy (lets the server reuse jobAuthMiddleware instead of a bespoke auth path). Mirror those changes in src-cli's cache-key stripping list so cached runs aren't invalidated by the per-dequeue token/ID/executor-name values that get injected onto step.Env.
One of the three stripped env vars (SRC_EXECUTOR_NAME) is per-executor, not per-job, so the perJob name is technically wrong. Renaming to perRunEnvVars accurately captures that all three change on every dequeue (job-token + job-ID per job, executor-name per executor).
bobheadxi
approved these changes
May 29, 2026
Comment on lines
+50
to
+53
| // perRunEnvVars resolve to per-job or per-executor values that change on | ||
| // every dequeue and must be stripped from cache keys. Mirrored in | ||
| // sourcegraph/sourcegraph/lib/batches/execution/cache/cache.go. | ||
| var perRunEnvVars = []string{ |
Member
|
Linking for ref: could also tidy up https://github.com/sourcegraph/sourcegraph/pull/12640 to resolve |
Member
|
@taras-yemets how do we pull this into the src-cli version used by executor? Do we need a release? |
Contributor
Author
I think we need a release first, then set the minimum expected src-cli version in the Sourcegraph repo. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With sourcegraph/sourcegraph#12503, Sourcegraph desugars v3
codingAgentsteps server-side and declares per-job env-var forwards onstep.Env. Their resolved values change every dequeue, so including them in cache-key inputs would invalidate the cache on every run.Strip them before hashing:
SRC_EXECUTOR_JOB_TOKEN— per-job bearer tokenSRC_EXECUTOR_JOB_ID— numeric job IDSRC_EXECUTOR_NAME— dequeueing executor's hostnameThe bare-string declarations still influence the key via the serialized
step.Env, so spec-change invalidation still works. The list is mirrored in sourcegraph/sourcegraph; a comment on each side points at the other.End-to-end test plan: see sourcegraph/sourcegraph#12503.