Skip to content

feat(telemetry): instrument compaction events - frequency + tokens re-paid per Machine:Workspace:Harness #89

Description

@jsboige

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/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

  1. 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.
  2. Count compactions per day, per Machine:Workspace:Harness (Epic: fleet consumption observability — live per-lane table, provider dashboards, cron-to-cost mapping #41's key).
  3. 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).
  4. Expose it as two columns in the consumption rollup (Epic: fleet consumption observability — live per-lane table, provider dashboards, cron-to-cost mapping #41) and the recurring report (Epic: Fleet traffic & consumption analytics — recurring markdown report #60): compactions/day and tokens re-paid by compaction, plus the derived multiplier (compaction overhead ÷ fresh-session cost).

Acceptance

  • 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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions