Skip to content

fix/batch-changes: ignore per-job env vars in cache key#1326

Merged
taras-yemets merged 3 commits into
mainfrom
ty/batch-changes-codingagent-cache-parity
May 29, 2026
Merged

fix/batch-changes: ignore per-job env vars in cache key#1326
taras-yemets merged 3 commits into
mainfrom
ty/batch-changes-codingagent-cache-parity

Conversation

@taras-yemets
Copy link
Copy Markdown
Contributor

@taras-yemets taras-yemets commented May 29, 2026

With sourcegraph/sourcegraph#12503, Sourcegraph desugars v3 codingAgent steps server-side and declares per-job env-var forwards on step.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 token
  • SRC_EXECUTOR_JOB_ID — numeric job ID
  • SRC_EXECUTOR_NAME — dequeueing executor's hostname

The 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.

@taras-yemets taras-yemets force-pushed the ty/batch-changes-codingagent-cache-parity branch from f6a51e6 to 2a38987 Compare May 29, 2026 10:48
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.
@taras-yemets taras-yemets force-pushed the ty/batch-changes-codingagent-cache-parity branch from 2a38987 to f9ae28e Compare May 29, 2026 10:54
…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).
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{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for docstring!

@bobheadxi
Copy link
Copy Markdown
Member

Linking for ref: could also tidy up https://github.com/sourcegraph/sourcegraph/pull/12640 to resolve

@bobheadxi
Copy link
Copy Markdown
Member

@taras-yemets how do we pull this into the src-cli version used by executor? Do we need a release?

@taras-yemets
Copy link
Copy Markdown
Contributor Author

@taras-yemets how do we pull this into the src-cli version used by executor? Do we need a release?

I think we need a release first, then set the minimum expected src-cli version in the Sourcegraph repo.

@taras-yemets taras-yemets marked this pull request as ready for review May 29, 2026 17:57
@taras-yemets taras-yemets merged commit e3e7712 into main May 29, 2026
8 checks passed
@taras-yemets taras-yemets deleted the ty/batch-changes-codingagent-cache-parity branch May 29, 2026 18:23
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