Skip to content

fix(cache): invalidate cached responses when .intentrc changes#27

Merged
CoreyRDean merged 1 commit into
mainfrom
fix/projectrc-cache-key
May 11, 2026
Merged

fix(cache): invalidate cached responses when .intentrc changes#27
CoreyRDean merged 1 commit into
mainfrom
fix/projectrc-cache-key

Conversation

@CoreyRDean
Copy link
Copy Markdown
Owner

Non-technical summary

This fixes a correctness bug where intent could reuse a cached response even after a repo's .intentrc directives changed. That mattered because project directives are part of how the model interprets a request, so stale cache reuse could make intent behave as if it were still following old repo-specific rules.

This matters now because the cache is meant to make repeated requests faster without changing what the user asked the tool to do. After this change, editing .intentrc reliably causes intent to compute a fresh response instead of replaying one generated under different project guidance.

Technical summary

  • added ProjectRCFingerprint to cache.KeyInputs
  • added cache.ProjectRCFingerprint so non-empty .intentrc content participates in cache identity
  • trimmed whitespace-only .intentrc content to an empty fingerprint so repos without real directives keep the baseline key behavior
  • updated engine.Run to include the .intentrc fingerprint when computing cache keys
  • added regression coverage in internal/engine/engine_test.go for:
    • cache-key changes when .intentrc directives change
    • distinct keys for distinct .intentrc contents
    • preserved baseline key behavior for blank .intentrc content

Relevant intent being strengthened: deterministic, honest behavior when repo-level directives change, consistent with the spec and with issue #19's acceptance criteria.

Tests:

  • go test ./internal/cache ./internal/engine
  • go test ./...
  • go vet ./...
  • PATH="/opt/homebrew/bin:$PATH" make build

Breaking changes: none intended. Cached entries generated under old .intentrc contents will naturally stop matching once project directives change, which is the desired bug fix.

Additional notes

Trade-off: this widens cache identity slightly, but only for a prompt input that already materially affects model output.

Intentionally deferred:

  • broader cache invalidation or migration policy work
  • other open cache/chaining issues outside .intentrc participation

Remaining gap to the fuller vision: cache correctness still depends on every prompt-shaping input being accounted for, so other future prompt inputs should be reviewed with the same standard.

Closes #19.

@CoreyRDean CoreyRDean marked this pull request as ready for review May 11, 2026 14:40
@CoreyRDean CoreyRDean merged commit 3daae81 into main May 11, 2026
8 checks passed
@CoreyRDean CoreyRDean deleted the fix/projectrc-cache-key branch May 11, 2026 14:40
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e059c2a4a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/cache/cache.go
in.BinariesFingerprint,
in.BackendIdentity,
in.PromptTemplateVersion,
in.ProjectRCFingerprint,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve baseline key when project directives are absent

Adding in.ProjectRCFingerprint to parts unconditionally changes the serialized key payload for every request (an extra field separator is always inserted), so repositories without .intentrc no longer reuse pre-existing cache entries. That defeats the stated goal of keeping baseline behavior unchanged and causes a broad cache miss wave unrelated to directive changes.

Useful? React with 👍 / 👎.

Comment thread internal/cache/cache.go
Comment on lines +60 to +64
trimmed := strings.TrimSpace(contents)
if trimmed == "" {
return ""
}
h := sha256.Sum256([]byte(trimmed))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Hash non-blank .intentrc content without trimming semantics

ProjectRCFingerprint hashes strings.TrimSpace(contents), but the engine injects the original opts.ProjectRC into the system prompt. If .intentrc changes only in leading/trailing whitespace, the prompt text changes while the cache key does not, which can return a cached response generated under different prompt bytes. Only whitespace-only files should collapse to empty; non-blank content should be fingerprinted from the raw bytes.

Useful? React with 👍 / 👎.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

engine: include ProjectRC in cache key

1 participant