Repository navigation
Conversation
recordFor never set PrefixRewritten, so a thread's return after a client compaction or a fork read as a cold cache miss with no other explanation. The keeper's 1-hour probe (resolveOneHourProbe) counted that as a failed grant and switched 1-hour keep-alive off for the route for the life of the process (cortex#2163). Derive it from the same thread.Result keeperKey already reads (resolveThread's AfterCompaction and InheritsFrom), so no new call to the thread tracker is added. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: DAVID BOAZ <DAVIDBO@il.ibm.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
clawgenti
left a comment
There was a problem hiding this comment.
Summary
The mapping matches the context-guru proxy's rule (capture.prefixRewritten: AfterCompaction || InheritsFrom), the new test fails on main and passes here, and go vet / gofmt / go test ./core/plugins/contextguru/... are clean locally. The blocker: in a Claude Code compaction (the flow in the #2163 log), the request that resolves the 1-hour probe is the compaction call itself. This change leaves PrefixRewritten false on that call, so it would not have stopped the 2026-11-27 switch-off, and the issue's acceptance check ("a client compaction right after a 1-hour probe gives 1-hour probe released") still fails. Details are inline.
Author: boazdavid (CONTRIBUTOR association, admin repo permission — maintainer)
Areas reviewed: Go (contextguru plugin keepalive mapping, context-guru v0.7.9 thread + keepalive consumers), tests
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing. I read the check annotations: they are only cache, Node 20, yamllint and hadolint warnings that were already there, and no tests marked "does not block". I could not fetch the Go CI (core) job log from here, so I ran the package tests locally.
Not applicable here: Record is an in-process struct, so no JSON decoder is involved.
| if !ok { | ||
| return false | ||
| } | ||
| if res.AfterCompaction { |
There was a problem hiding this comment.
must-fix: this does not cover the request that resolves the probe in the #2163 scenario.
In context-guru v0.7.9, resolveOneHourProbe runs on the first accepted Record for the probe's key and deletes the probe unconditionally (delete(k.oneHourProbes, key), onehour.go:281). In a Claude Code compaction the requests go:
- the compaction call (
agentCompaction=true):compactionParentkeeps it on the main thread, with the same key as the probe andAfterCompaction=false; - the post-compaction request, which has
AfterCompaction=trueand also the same key.
I checked this with the real tracker (thread.New().ResolveSession) on turn1, turn2, the compaction call and the post-compaction request: all four resolve to thread "", and only #4 has afterCompaction=true. The thread.go comment in this package says the same: "The tracker marks the request that holds the summary, not the compaction request itself."
So #1 resolves and deletes the probe with PrefixRewritten=false, and by the time #2 carries the flag there is nothing left to release. The log in the issue fits this: the return starts at 01:35:16, the WARN fires at 01:35:27 when it finishes, and the 55k post-compaction request comes at 01:35:28, after the decision was made.
The InheritsFrom half does not reach the probe either. Inherits is only set when the thread id is new (th == nil in Resolve), so keeperKey gives that request a key that holds no probe. It is harmless and matches the proxy, but it does not address the issue.
Suggested fix: keep the agentCompaction verdict that resolveThread already computes on reqThread, for example reqThread{res, compactionCall bool}. Do not re-run IsClientCompaction on pctx.Body at finish time, because the engine may have rewritten the body by then. Then treat the compaction call as rewritten too. At worst this releases a probe that would have proved the tier, which is the safe direction. It goes beyond the proxy's rule, so context-guru should get the same change, ideally as the shared library function from point 2 of the issue.
| // main agent's own compaction must carry PrefixRewritten, or the keeper's 1-hour probe | ||
| // (resolveOneHourProbe) reads its cold return as a downgrade and switches the route off for the | ||
| // life of the process. | ||
| func TestRecordForSetsPrefixRewrittenAfterCompaction(t *testing.T) { |
There was a problem hiding this comment.
suggestion: this test builds the thread.Result by hand, so it checks the field mapping but not the scenario from #2163.
- A test that drives the real tracker (
p.threads = thread.New()andresolveThread) and a real keeper would have caught the ordering problem above: a 1-hour probe, then the compaction call, then the post-compaction request, then assert that the route is still on. - The
InheritsFrombranch has no test at all.Result.inheritsis unexported, so it can only be reached through the tracker.
Summary
recordForincore/plugins/contextguru/keepalive.gonever setkeepalive.Record.PrefixRewritten.What changed
prefixRewritten(pctx): true when the resolvedthread.Resultsays this request is the first one after the main agent's own compaction (AfterCompaction), or a thread that took over another thread's content (InheritsFrom).keepalive.Record.PrefixRewrittenfrom it inrecordFor.thread.ResultkeeperKeyalready reads throughrequestThread; no extra call to the thread tracker.Why it matters
resolveOneHourProbetreats a cold return withPrefixRewrittenunset the same as a real downgrade, and switches 1-hour keep-alive off for that provider/route/model for the life of the process.How it was tested
core/plugins/contextguru/keepalive_prefix_rewritten_test.go:TestRecordForSetsPrefixRewrittenAfterCompaction— fails without the fix, passes with it.TestRecordForLeavesPrefixRewrittenFalseOnAnOrdinaryTurn— control case.GOWORK=off go vet ./...andgofmt -l .are both clean.GOWORK=off go test ./core/plugins/contextguru/...passes.Open questions
prefix_rewrittenon the keeper's WARN/INFO lines. Both of those are context-guru-repo changes, out of scope here.Assisted-By: Claude (Anthropic AI) noreply@anthropic.com
Summary by CodeRabbit