You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(telemetry): instrument compaction events - frequency + tokens re-paid per Machine:Workspace:Harness #89
The 2026-09-11 user mandate asks for fréquence de condensation as a first-class consumption metric. Today nothing measures it: grep -rn compact packages/cli/src finds only handler plumbing (the stream:false buffering path) — no counter, no log line, no capture field.
It matters because the harness block (CLAUDE.md + .claude/rules/ + MEMORY.md, injected at position 0 of the first user message — see #23) is re-paid in full at every compaction, for the whole session lifetime. A ~45k-token harness × N compactions × M sessions is a first-order cost, and it is currently invisible.
What
Detect the compaction call: /compact arrives as stream:false on /v1/messages with the compaction system prompt. Detection must be structural (stream flag + prompt signature), never UA-based.
Measure the re-paid volume: the compaction request's input_tokens is the context being re-read. Read it from the usage block with the known traps (wire-openai lanes may emit a zero usage block first → take MAX).
A window query returns, per Machine:Workspace:Harness: requests, compactions, tokens re-paid by compaction, and the ratio.
A session with no compaction reports zero — ordinary stream:false calls must not be counted.
The counter survives a container restart (segment on the startup banner; reqN restarts at 0).
Notes
/compact with stream:false is the real-world caller whose mishandling used to surface as "API returned an empty or malformed response (HTTP 200)"; the buffering fix lives in ComposedHandler.handle(). This issue adds the measurement, not the plumbing.
Why
The 2026-09-11 user mandate asks for fréquence de condensation as a first-class consumption metric. Today nothing measures it:
grep -rn compact packages/cli/srcfinds only handler plumbing (thestream:falsebuffering path) — no counter, no log line, no capture field.It matters because the harness block (CLAUDE.md +
.claude/rules/+ MEMORY.md, injected at position 0 of the first user message — see #23) is re-paid in full at every compaction, for the whole session lifetime. A ~45k-token harness × N compactions × M sessions is a first-order cost, and it is currently invisible.What
/compactarrives asstream:falseon/v1/messageswith the compaction system prompt. Detection must be structural (stream flag + prompt signature), never UA-based.Machine:Workspace:Harness(Epic: fleet consumption observability — live per-lane table, provider dashboards, cron-to-cost mapping #41's key).input_tokensis the context being re-read. Read it from the usage block with the known traps (wire-openai lanes may emit a zero usage block first → take MAX).compactions/dayandtokens re-paid by compaction, plus the derived multiplier (compaction overhead ÷ fresh-session cost).Acceptance
requests,compactions,tokens re-paid by compaction, and the ratio.stream:falsecalls must not be counted.reqNrestarts at 0).Notes
/compactwithstream:falseis the real-world caller whose mishandling used to surface as"API returned an empty or malformed response (HTTP 200)"; the buffering fix lives inComposedHandler.handle(). This issue adds the measurement, not the plumbing.