Repository navigation
feat(thread): detect the client's own compaction for Codex, OpenCode and Pi - #1335
Conversation
9ac9f74 to
ddf36ad
Compare
|
Behavior changes: approved by a human developer, with one condition. @amiddavid approved both on 2026-11-24, in the session that owns this PR:
Condition: the proxy-boundary session (#1309, #1315) must confirm that the design fits the proxy/library split before this PR merges. The PR owner records that confirmation here. |
|
Proxy/library split: confirmed by the proxy-boundary session (#1309, #1315), with 2 changes. At head
Changes the PR owner makes:
Notes from the same review:
|
…and Pi Mark first, phrase second. Codex marks its compaction request in x-codex-turn-metadata (request_kind). The OpenCode and Pi plugins set x-context-guru-request-kind: compaction. A last-turn phrase match is the fallback, now with the verbatim prompt openings of Codex, OpenCode and Pi. The match reads the Responses input as well as messages. Closes #1314 Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…nt layer thread takes a plain hint. agent/codex reads Codex's turn metadata. agent holds our own request-kind header. agent/all combines them for a host. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
agent/all.IsClientCompaction takes headers and body. The proxy only calls it. The agent package doc states the x-context-guru-* strip rule for hosts. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
cc562e8 to
cb736c2
Compare
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.331 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | cb736c2942de |
approve |
Verdict: approve
Findings
None. I found no wrong behavior, no data loss, no broken fail-open path, and no missing test
for the new behavior.
Non-blocking
-
pi-package/extensions/context-guru.ts:431 — the Pi mark can stick to a session.
- The
compactingset is cleared only bysession_compactandsession_compact_failed.
If neither fires (a compaction that hangs, or an event name that differs in a future Pi),
every later request of that session carries the mark. Each is then counted as a
compaction, sets the thread'scompactingflag, feedsclient_compactionto the replay
cap, and gets the 128 MiB body limit.session_shutdowndoes not clear the set either. - Fix: clear the session in
session_shutdowntoo, or store a timestamp and expire it. - The phrase fallback covers the opposite miss (mark never set), and a process restart
clears the set. So this is robustness, not a defect I can trace to a wrong output.
- The
-
opencode-plugin/index.js:1390 — the v1 mark keys on the agent NAME.
input.agent === "compaction"matches any agent namedcompaction, including one a
user defines themselves. Its requests are then marked as the client's compaction.- The v2 hook keys on the reserved
kindfield, which does not have this problem. - Fix (optional): nothing, or document that the name is the built-in agent's.
-
Stale doc pointers name the old detector.
apply/opts.go:38(the host-contract
example),thread/host.go:42, and the comments atproxy/proxy.go:1316and
proxy/proxy.go:1767still tell a host to callthread.IsAgentCompaction. A host that
copies the example gets the phrase match only, not the header mark. Fix: point them at
agent/all.IsClientCompaction. -
One more full-body scan per request.
isClientCompactionnow runs
gjson.GetBytes(body, "client_metadata")on every request before the phrase match, and on
the oversize path the body is scanned several times. gjson is fast, so the cost is small. -
agent/codex.IsCompactiontrusts the Codex header from any client.codex.Identify
refuses callers that do not say they are Codex;IsCompactiondoes not. Any client can
sendx-codex-turn-metadataand mark itself. The effect stays inside that client's own
thread tracking and body limit. The PR names this trust question (open question 4) and a
human approved the limit lift.
What I checked
- The full diff of all 4 commits, and the code around each change.
- The detection flow:
proxy.go:1372andreadGatedBody→agent/all.IsClientCompaction→
agent.PluginMarksCompaction,codex.IsCompaction,thread.IsAgentCompactionHint. The
result feedsthreadFor, the counter, the dashboard row and the body limit, exactly as the
oldthread.IsAgentCompactionresult did.thread.Resolvetreats the flag as before. - The header cannot leak to a provider:
copyHeaders(proxy.go:3222) strips every
x-context-guru-*header on every forward path; the OpenCode fail-open direct path deletes
both headers; Pi routes through the local Go proxy, so its mark is stripped the same way.
The new proxy test asserts this on the wire. - Import graph:
agent/allnow importsagent,agent/codexandthread;threadimports
no context-guru package, so there is no cycle and no library/host boundary break. - The
inputhandling inthread/compaction.go: array items (role must beuser, trailing
system/developer skipped) and the plain-string form. The new phrases contain no character
that JSON escaping would rewrite, as the file's own rule requires. - Tests read in full: thread tables, hint test, codex test, agent/all test, the proxy
counting + no-leak test, the OpenCode v1/v2 tests, and the new Pi mark test. Helpers
(agentCompactionCount,openAIBody,buildHandler) exist in the same package. - Data dependence: the thread-tracker row file and the regenerated page carry the same text;
the text-reading exception is the same one as before, now with the metadata-only mark as
the first choice. The behavior change is named at the top of the PR with a human's yes. - Limits: I could not verify the cited Codex, OpenCode and Pi source lines (external repos,
and live runs are not approved). I took them as the PR states them; the phrase fallback
covers a wrong mark, and the PR itself flags the Pi mark as unproven live. Go tests were
not run.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddaid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.331 | offload-review skill, @amiddaid's session | fresh | 2 of 2 | 1 of 2 | cb736c2942de |
blocking |
Verdict: blocking
Findings
- pi-package/extensions/context-guru.ts:505 — the compaction mark can stay on for the rest of a session
- What fails: Pi fires
session_before_compact, so the session id enterscompacting. If the summary then ends withoutsession_compactorsession_compact_failed, the id never leaves the set. Every later request of that session then carriesx-context-guru-request-kind: compaction. The mark wins over the text check (thread.IsAgentCompactionHint, thread/compaction.go:71). Each such request gets a wrongclient_compactionmark on its dashboard row, a wrongagent_compactioncount, and the 128 MiB body limit instead of 32 MiB. - Proof: the set has exactly two exits —
session_compact_failed(line 508) andsession_compact(line 529).session_shutdown(line 534) clears other per-session state in the same handler (checks.end, line 538) but notcompacting. So a session that shuts down mid-compact keeps its id marked; Pi reuses a session id on/resume, and the extension is not reloaded for that. I could not verify from Pi's source that an aborted summary request always emitssession_compact_failed. The new test covers only the two clean exits (compaction-mark.test.ts:43-56); no test covers a compact that ends any other way. - Fix: delete the id in
session_shutdowntoo, next tochecks.end. Add a test line: emitsession_before_compact, thensession_shutdown, then check the header is absent.
- What fails: Pi fires
Non-blocking
agent/codex/codex.go:69—IsCompactionreadsx-codex-turn-metadatafrom any caller.Identifyin the same package gates the ids on the User-Agent ororiginatorsaying "codex", exactly because any client could send them. The consequence here is small: a client that spoofs the header could already spoof the phrase. Consider gating onIdentifyfor consistency with the package's own rule.agent/codex/codex.go:73— the body path assumesclient_metadatais an object keyed by the header name. If Codex sends it as a JSON string instead,gjson.Result.Geton a string returns nothing and the path silently gives false. The header path still covers HTTP requests. I could not verify the shape against Codex source.opencode-plugin/index.js:1392and:1434— the v1 mark depends oninput.agent === "compaction", the v2 mark onevent.kind. I could not verify these fields against the two hosts. If either is absent, only the mark is lost; the phrase fallback still detects the request. The tests mock the field, so they do not prove the host sends it.apply/opts.go:38— the host example still passesthread.IsAgentCompaction(orig). That is the fallback-only call.agent/all.IsClientCompactionis now "the ONE call for a host" (its own doc). The example contradicts it; an embedding host that copies the example misses the mark path.- Stale comments:
thread/host.go:42anddash/schema.go:80still say the mark comes fromthread.IsAgentCompaction.docs/design.mdstill describesagent/all/as blank-imports only. Comments and the package map, no behavior.
What I checked
- The full diff
98c9a740..cb736c29(4 commits, 20 files) and the code around each change:proxy/proxy.go(chat, readGatedBody),proxy/agentcompaction.go,thread/compaction.goand the tracker's use of the flag (thread/thread.goResolve),agent/requestkind.go,agent/codex,agent/all, both client plugins, and every new or changed test. - Fail-open and header hygiene:
copyHeaders(proxy/proxy.go:3216) strips everyx-context-guru-*header on each forward path, so the new header cannot leak upstream; the proxy test asserts it. The OpenCode fail-opendirect()path deletes the new header too. Pi has no direct fail-open path, so no leak there. - No import cycle:
threadimports noagentpackage;agent/alladdsthreadonly.proxykeeps its library-only imports. - The new phrases keep the no-escaped-characters rule stated in
thread/compaction.go: the Pi cuts land before<, so the match works whether the wire escapes it or not. - Datadep: the thread-tracker row file and the regenerated page match, and the text states the dependence correctly — the mark is metadata only, the phrase match reads the last turn in flight, nothing is stored.
- Commits carry
Signed-off-byandAssisted-By, conventional titles. - I did not read the PR description or any comment on it (round-1 independence). So I did not check that the PR names the behavior change at the top, as RELEASING.md requires.
- I ran no builds or tests (not approved). Statements about tests come from reading them, not running them.
…ointers Review round 1 of #1335. - Pi: clear the mark on session_shutdown and drop it after 10 minutes. - Codex: IsCompaction answers only for a caller that Identify accepts. - OpenCode v1: cite where the compaction agent is named. - Point the host examples and comments at agent/all.IsClientCompaction. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
|
Round 1 fixes are at Reviewer 1
Reviewer 2
Tests
|
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.331 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 4c7c30d3d234 |
approve |
Verdict: approve
Findings
None. Every round-1 finding is fixed or answered with a reason I checked and accept. The fix
commit adds no new defect.
Earlier findings, and their state
Mine (round 1):
- Pi mark can stick — fixed.
session_shutdownnow deletes the session from the map
(context-guru.ts:552). The mark also expires: the set becameMap<string, number>and
isCompactingdrops an entry older than 10 minutes. Two new tests cover the shutdown
mid-compaction and the expiry. The fail direction stays safe: a compaction slower than
10 minutes loses its mark, and the phrase fallback in the proxy then detects the request. - OpenCode v1 keys on the agent name — documented, accepted. The comment now cites
agent.ts(name: "compaction") andsession/compaction.ts(agents.get("compaction"))
and says a user agent with that name is marked too. The effect is small and
self-inflicted, and the phrase fallback covers the opposite miss. The reason is right. - Stale doc pointers — fixed.
apply/opts.go,thread/host.go,dash/schema.go, the
twoproxy/proxy.gocomments and thedocs/design.mdpackage map now name
agent/all.IsClientCompaction. The newapply/opts.goexample passesreq.Header, the
correct call. - Extra body scan — accepted by the author. The reason (small cost) is right; I said the
same in round 1. - Codex header trusted from any client — fixed.
codex.IsCompactionnow returns false
unlesscodex.Identifyaccepts the caller (User-Agent ororiginatorstarting with
"codex"). Three new test cases (nil header, not Codex, originator only) and a proxy test
case with the metadata but no Codex User-Agent, still counted as not-a-compaction.
Reviewer 2 (round 1, posted after mine, so new to me this round):
- Blocking, the Pi mark stays on — fixed. Same fix as my point 1. I checked it myself;
agree it resolves the finding. - Gate on Identify — done. Same as my point 5.
client_metadatashape — checked by the author against Codex source. The new comment
citesOption<HashMap<String, String>>incodex-rs/codex-api/src/common.rs. That shape
matches what the code assumes: one string value that itself holds JSON. I cannot read the
Codex repo here, so I take the citation; the header path covers HTTP requests either way.
Accept.- OpenCode fields not verified live — checked by the author against both hosts' sources.
The phrase fallback covers a miss. Accept. - Stale doc pointers — fixed. Same as my point 3.
The human's condition (comment at 09:24:16Z): the proxy-boundary session recorded its
confirmation at 09:25:20Z, and its two asks are in the code — the one library call
(agent/all.IsClientCompaction, proxy/agentcompaction.go is a thin wrapper) and the
temporary home with the #1312 note in agent/all/all.go. The agent package doc states the
host contract to strip x-context-guru-* headers. The condition is met.
Non-blocking
thread/host.go:42— the new doc sentence reads "agent/all.IsClientCompaction of that same
headers and body". Grammar only; the meaning is clear.
What I checked
- Last review: round 1,
cb736c2942de63380463638d5db09a9a84a3feaa, 2026-11-24T11:09:56Z. - New commits read: 1 (
4c7c30d3fix(compaction): expire the Pi mark, gate the Codex mark,
fix stale pointers). Full diff read, plus the code around each change. - Read in full: 2 reviews, 3 comments, 0 inline comments (from the three saved files).
- New items since my last review: reviewer 2's round-1 review (11:12:07Z), the author's
round-1 reply (11:18:42Z), and the fix commit. Each is addressed above. - The fix commit, line by line: the Pi
Map+isCompactingexpiry and its two tests
(including thenode:testmock.method(Date, "now", …)usage, whose
mock.mockImplementation/mock.restoreAPI is valid); thesession_shutdowndelete next
tochecks.end; the test file's claim logic (a secondcontextGurucall with
shared[LOADED] === PACKAGE_DIRstill registers handlers, so tests 2 and 3 run real
handlers); thecodex.IsCompactiongate onIdentify(nil or non-Codex headers give
false, no panic —Identifycheckslen(h) == 0first); the updated codex, proxy and
design-doc comments. - The gated body path: with the gate, a nil-header host (the bifrost adapter) now gets false
fromcodex.IsCompactionwhere round 1 could have readclient_metadata. That matches the
documented contract ("a host that has no headers passes a nil h and gets false"), and the
proxy always has headers. - Commit carries
Signed-off-byandAssisted-By, conventional title. - Limits: Go and Node tests were not run (not approved). The Codex, OpenCode and Pi source
citations remain external; I take them as the author states them.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddaid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.331 | offload-review skill, @amiddaid's session | resumed | 2 of 2 | 2 of 2 | 4c7c30d3d234 |
approve |
Verdict: approve
Findings
None.
Round-1 findings
-
Pi mark can stay on for a session — fixed.
session_shutdownnow clears the id (context-guru.ts:551), and the mark expires after 10 minutes (isCompacting, context-guru.ts:417). Two new tests cover both exits (compaction-mark.test.ts:53, 61). I also verified the fix is needed, not just hardening: in Pi 1.6.0 (dist/core/agent-session.js), an auto-compaction aborted beforecompaction_startemits neither clearing event, and a successful compaction whose saved-entry lookup misses emits neither either. The expiry bounds both to 10 minutes. -
Non-blocking notes — all resolved.
- Codex gate:
IsCompactionnow answers only whenIdentifyaccepts the caller (codex.go:76). A nil header is handled (Identifyreturns false on an empty header). Tests added for nil, not-Codex, and originator-only. client_metadatashape: the author's citation is right. I confirmed in openai/codex rust-v0.172.0 (codex-rs/codex-api/src/common.rs):Option<HashMap<String, String>>, with the turn metadata as one string value underx-codex-turn-metadata(stated incore/src/responses_metadata.rs, constant incore/src/client.rs). The current read is correct.- OpenCode fields: I confirmed in sst/opencode v1.19.6 that
chat.headersinput hasagent: string, and that compaction runs asagents.get("compaction"). In v2.4.1,SessionHttpRequest.kindis aSessionRequestKindthat includes"compaction". Both marks are wired to real fields. - Stale doc pointers: fixed in
apply/opts.go,thread/host.go,dash/schema.go, bothproxy/proxy.gocomments, anddocs/design.md.
- Codex gate:
-
Reviewer 1's round-1 notes — I checked each myself. All five are addressed by the same commit: the Pi stick (same fix), the OpenCode v1 agent-name note (documented in the comment, with the source citation), the stale pointers (fixed), the extra body scan (accepted, cost is small), and the Codex trust (fixed with the
Identifygate). Agree with the dispositions.
Non-blocking
- The PR description is now slightly stale after the fix commit. Line "Any client can send the plugin header or the Codex metadata" — the Codex metadata path now requires a Codex User-Agent, so only the plugin header stays open. Line "from
session_before_compactuntilsession_compactorsession_compact_failed" — the Pi mark now also expires after 10 minutes and clears on shutdown. Description text only; the code comments are correct.
What I checked
- Last review: round 1, cb736c2, 2026-11-24T11:12:07Z.
- New commits read: 1 —
4c7c30d3fix(compaction): expire the Pi mark, gate the Codex mark, fix stale pointers. - Read in full: 2 reviews, 3 comments, 0 inline comments (from the three saved files), plus the PR body (88 lines), which round-1 independence had kept me from reading.
- New items since my last review: commit
4c7c30d3(full diff and the code around each change); the fix-summary comment at 11:18:42Z (each claim checked against the code); the PR body (behavior-change naming below). I also read reviewer 1's round-1 review and the two earlier comments (the human's behavior-change approval at 09:24:16Z, the proxy-boundary confirmation at 09:25:20Z) now that independence no longer applies. - The fix commit in detail: the
Set→Mapmigration (all five usages updated, no stale.has/.addleft), theisCompactingexpiry logic, theIdentifygate and its effect on the WebSocket body path, the updated proxy test (5 header cases, count still 2, the not-Codex case now ignored), and the test-helper change to a Codex User-Agent. - The LOADED guard does not block the new tests: it returns early only for a different package dir, so tests 2 and 3 register real handlers, and test 2 asserts the mark is present before shutdown (not vacuous).
- Behavior-change rule: the PR description names the change at the top — who, old and new behavior, the paths these clients now reach, the Responses
inputreading, the trust question, and how to turn it off — with the human's yes and the proxy-boundary confirmation linked. Both confirmations match the two comments. The boundary session's two required changes are in the code: one library call (agent/all.IsClientCompaction), and theagent/allhome with the #1312 note. - External source checks, new this round (public upstream files, read only): openai/codex rust-v0.172.0 — the header constant is
x-codex-turn-metadata,request_kindserializes to"compaction",client_metadataisOption<HashMap<String, String>>, and the fallback phrase matchesprompts/templates/compact/prompt.md. sst/opencode v1.19.6 and v2.4.1 — theagentandkindfields as above. Pi 1.6.0 — the three event names and the two no-event paths named in finding 1. - I ran no builds or tests (not approved). The author's test notes (race tests, plugin tests) are taken as reported.
chore(plugins): bump the plugin versions for v0.7.8 - Pi package: 0.1.6 -> 0.1.7 (#1326, #1330, #1335, #1342, #1344). - OpenCode plugin: pinned proxy version v0.7.7 -> v0.7.8. - Unchanged: Claude Code plugin 0.7.8 (test files only changed since v0.7.7), Codex 0.2.14, Bob 0.1.3. Release owner (David Amid, 2026-11-24, integrator session): cut v0.7.8 now. Version bumps are under the owner standing approval. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Behavior change (a human approved it)
Human yes: feat(thread): detect the client's own compaction for Codex, OpenCode and Pi #1335 (comment)
Proxy-boundary confirmation: feat(thread): detect the client's own compaction for Codex, OpenCode and Pi #1335 (comment)
Who: users of Codex, OpenCode and Pi. Claude Code and Bob are unchanged.
Old: the proxy never saw these clients' own compaction. The thread id could change after a compaction.
agent_compactionandAfterCompactionstayed 0.New: the proxy sees the compaction. The compacting thread passes its id to the next request. The counters count it. A compaction body over 32 MiB is now allowed (up to 128 MiB) for these clients, as for Claude Code.
Paths these clients now reach (they reached none before):
agent_compactioncount in/statsand the dashboard row;AfterCompaction, thread id passes on).Phrase match: it now reads the Responses
input(Codex), not onlymessages.Body limit: a marked compaction body may now be up to 128 MiB, not 32 MiB. Any client can send the plugin header, so any client can lift the limit for one request. The Codex metadata counts only from a caller with a Codex User-Agent or
originator. A prompt match already allows the same. A human decides.Turn off: no switch. Remove the OpenCode or Pi plugin to drop the plugin mark. The phrase fallback has no switch either.
Closes #1314
Stacked on #1311 (
feat/codex-session,agent/codex). The diff shows its 2 commits until it merges. I rebase then.Summary
The proxy now detects the client's own compaction for Codex, OpenCode and Pi. A mark is the first choice. A phrase match is the fallback. Bob keeps its current match.
What changed
x-codex-turn-metadata(header, orclient_metadatain the body).request_kind: "compaction"means a compaction. Local and remote compaction both carry it.x-context-guru-request-kind: compaction. v1 useschat.headerswhenagentiscompaction. v2 useshttp.requestwhenkindiscompaction.session_before_compactuntilsession_compactorsession_compact_failed. The mark is also removed onsession_shutdown, and it ends after 10 minutes.input:IsAgentCompactionnow reads the Responsesinput(array or string) when there is nomessages.x-context-guru-*before it forwards. The OpenCode fail-open path also drops the new header.x-codex-turn-metadatarequest_kind=compactioncore/src/responses_metadata.rs(REQUEST_KIND_KEY,CompactionTurnMetadata),core/src/client.rs:173prompts/templates/compact/prompt.md, used bycore/src/compact.rschat.headersagent=="compaction"packages/opencode/src/session/compaction.ts,packages/plugin/src/index.tshttp.requestkind=="compaction"packages/plugin/src/promise/session.ts(SessionRequestKind)packages/core/src/session/compaction.ts(buildPrompt); v1.19.6 imports itsession_before_compact@earendil-works/pi-coding-agent1.6.0dist/core/extensions/types.d.ts,dist/core/agent-session.js<), and the "earlier context" turn-prefix promptdist/core/compaction/compaction.jsData dependence
docs/data-dependence.md(Thread tracker row) is updated. Decided by: the row's owner must confirm before merge.How it was tested
macOS, Go 1.27.4, Node 22.23.
CGO_ENABLED=1 go test -race ./thread/... ./pi-package/... ./components/all/...: pass.CGO_ENABLED=1 go test -race ./proxy/... ./proxyapp/...: pass (run in 4 parts, load average was about 390).node --test opencode-plugin/test/*.test.mjs: 113 pass.node --test pi-package/tests/*.test.ts: 53 pass (newcompaction-mark.test.ts).input; mark cases for header and Codex metadata; a proxy test that counts a marked request and checks that the upstream never sees the header.Open questions
before_provider_headersruns throughtransformHeaderson the same stream function as a turn, so it should reach the summary call. Nobody ran it. The phrase fallback covers a miss./responses/compact. Codex up to 0.140 used this endpoint. It is gone by 0.160. The proxy routes onlyPOST /openai/v1/responses, so no path match was added.client_metadata. The proxy reads that key in the body, but only sees HTTP requests.Where the logic lives
thread.IsAgentCompactionHint(markedByClient, body): generic. It readsmessagesandinput, and the phrases.agent/codex.IsCompaction(h, body): Codex turn metadata, header orclient_metadata.agent.PluginMarksCompaction(h): our ownx-context-guru-request-kindheader.agent/all.MarkedCompaction(h, body): combines both for a host.agent/all.IsClientCompaction(h, body): the one call for a host (mark, thenthread.IsAgentCompactionHint). The proxy only calls it (proxy/agentcompaction.go). It is a temporary home: after refactor(agent): move Claude Code rules into agent/claudecode; add OpenCode and Pi labels #1312,agent.Identifyreturns the mark in the Client.nil, and the phrase match is the fallback.agent/all.IsClientCompaction(pctx.Headers, body). No path is needed. Cortex must strip everyx-context-guru-*header before it forwards, as the proxy does, or the mark leaks to the provider.IsClientCompaction(nil, body).Technical notes
thread.IsAgentCompaction(body)stays.agent.Agentinterface.