fix: hash the full source spec for the cache key by gangadhar-res · Pull Request #9970 · updatecli/updatecli · GitHub
Skip to content

fix: hash the full source spec for the cache key - #9970

Merged
olblak merged 6 commits into
updatecli:mainfrom
gangadhar-res:fix/cache-key-full-spec
Aug 25, 2026
Merged

olblak merged 6 commits into
updatecli:mainfrom
gangadhar-res:fix/cache-key-full-spec

Conversation

@gangadhar-res

Copy link
Copy Markdown
Contributor

What

The source cache key (pkg/core/cache/source.go) now hashes the full user-provided spec from ResourceConfig instead of resource.ReportConfig().

Why

ReportConfig() exists to redact resource configuration for reports and predates the cache (#4898). Eleven plugins omit result-affecting spec fields from it (e.g. shell omits workdir, yaml omits documentindex), so two distinct sources could silently share a cache entry and the second received the first one's value — no error, no warning, just a wrong value written to the target.

This implements option 2 from the issue discussion: the cache key gets its own complete input, ReportConfig keeps its original reporting purpose, and no per-plugin changes are needed — the whole bug class is removed at the one call site.

Notes:

  • Secret-bearing spec fields are safe to include: only the SHA256 digest is ever stored or logged, so distinct secrets stay distinct without appearing anywhere.
  • Hashing stays deterministic: specs decode via yaml.v3 into map[string]interface{} and encoding/json marshals maps with sorted keys.
  • The resource is still instantiated first, so unknown kinds or malformed specs keep returning the empty-key cache-miss sentinel.

Testing

  • New regression test: two shell sources differing only in workdir (a field ReportConfig omits) get different keys, while identical specs still share one — both as typed specs and as YAML-decoded map specs, plus hash stability across decodes. Both new tests fail on main by construction.
  • go test ./pkg/core/cache/ passes; go build ./..., gofmt, go vet, and golangci-lint introduce no new findings.

Fixes #9849

gangadhar-res and others added 3 commits August 14, 2026 15:47
The source cache key hashed resource.ReportConfig(), which exists to
redact resource configuration for reports and predates the cache.
Eleven plugins omit result-affecting spec fields from ReportConfig
(e.g. shell omits workdir, yaml omits documentindex), so two distinct
sources could silently share a cache entry and the second one received
the first one's value.

Hash the full user-provided spec from ResourceConfig instead, keeping
ReportConfig for its original reporting purpose. Secret-bearing fields
are safe to include since only the SHA256 digest is ever stored or
logged, and the encoding stays deterministic: yaml.v3 decodes specs
into map[string]interface{} and encoding/json sorts map keys. The
resource is still instantiated first so unknown kinds or malformed
specs keep returning the empty-key cache-miss sentinel.

Regression tests cover two shell sources differing only in workdir
(a field ReportConfig omits) both as typed specs and as YAML-decoded
map specs, plus identical specs still sharing a key.

Fixes updatecli#9849

Signed-off-by: Gangadhar Chalapaka <gangadhar@resolve.ai>
@gangadhar-res

Copy link
Copy Markdown
Contributor Author

@olblak

olblak commented Aug 16, 2026

Copy link
Copy Markdown
Member

@olblak Could I have a review on this pr ? thanks

Thanks for the pull request but I can't review it at the moment

Comment thread pkg/core/cache/source.go
Comment thread pkg/core/cache/source.go Outdated
@olblak olblak added bug Something isn't working core All things related to Updatecli core engine labels Aug 24, 2026
@mergify

mergify Bot commented Aug 25, 2026

Copy link
Copy Markdown

@olblak
olblak merged commit c23bfe6 into updatecli:main Aug 25, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working core All things related to Updatecli core engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Source cache key is incomplete for 11 plugins whose ReportConfig omits result-affecting spec fields

2 participants