Skip to content

feat(verifiers): always_on's judge reads a compaction as one, natively and from atif/1, and asks about context loss - #916

Open
earakely-scale wants to merge 8 commits into
mainfrom
edgararakelyan/fd-6942-y19-compaction-reading
Open

earakely-scale wants to merge 8 commits into
mainfrom
edgararakelyan/fd-6942-y19-compaction-reading

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Since #913, a Claude Code compaction reaches always_on's judge the same way natively and from atif/1, but only as two plain notes: the summary and the CLI's "Compacted". The judge isn't told:

  • that a compaction happened;
  • that the agent's own model wrote the summary;
  • how much history it replaced.

It isn't asked whether a failed criterion traces to context the compaction lost. A run whose harness labels its own trace already gets all of this. This PR gives the same reading to any run whose trajectories hold a compaction, natively and from atif/1 alike.

What changes

One compaction note, from both paths (judge_utils/turn_events.py)

  • Native. Claude Code's compact_boundary and the summary after it are one compaction note with its facts:
    • who wrote the summary: assistant, Claude Code's own model;
    • what set it off: manual or auto;
    • the history's tokens before and after it.
  • atif/1. atif_turn_events reads the same facts from the copy's compaction step, so both paths give the judge the same note.
  • The note's words. Every reader builds them the same way (compaction_note). For example: "Compaction summary (written by the assistant's own model…; it replaces the older history the assistant sees; it was set off on request, such as by a command (manual); the history went from 28,634 tokens to 2,839)". It's followed by the summary.
  • A copy's compaction that doesn't say who wrote its summary leaves the run ungraded, as a labelled native trace's does.
  • One place for the facts. compaction_facts builds them for every reader: it takes atif/1's SUMMARY_WRITERS and COMPACTION_TRIGGERS, and it's the one place that refuses an unknown writer, an OTel span's included.
  • The CLI's "Compacted" stays a plain note.

The profile, 1.2 (atif/profile.py, atif/PROFILE.md, atif/validator.py, atif/builder.py)

  • A compaction gets tokens_before and tokens_after: the tokens of the history the agent sees just before and just after it, when the harness counts them.
  • The builder writes them through turn.compaction(..., tokens_before=..., tokens_after=...) and refuses anything that isn't a count of tokens. The validator's compaction rule refuses a count that isn't a whole number or is negative.
  • is_token_count is the one check of a count. The builder, the validator and the judges' reader use it.
  • Claude Code's adapter keeps its own count check and trigger names. It imports only what its protocol floor (0.1.649) has, because its image installs any protocol at or above that floor. It adopts the protocol's with the floor raise.
  • The validator reads 1.0 to 1.2.
  • Claude Code's adapter writes them from the boundary's pre_tokens and post_tokens.

always_on's judge (always_on_agent_verifier.py, always_on_staging.py)

  • Which runs get the reading. A run whose trajectories hold a compaction now gets what a labelled run gets:
    • the lines that say what a harness note is;
    • whose a summary's losses are: an assistant-written summary is the assistant's own, graded normally;
    • with a per-criterion format, the context_loss question, reported next to the score and never changing it.
  • What it doesn't get. The lines only a labelled harness writes are left out: its save turn, its internal tools, its helpers.
  • Unchanged prompts. A labelled run's prompt is byte for byte as before, and a run with neither labels nor a compaction gets none of it.
  • The index's compaction line says whether the compaction came before the wake's turn or partway through it. A harness's save turn isn't the assistant's own turn, so a labelled run's line still says "before".

The recorder (tst/manual/claude_code_atif/record.py) records a turn compacted partway through as its history fills: a small CLAUDE_CODE_AUTO_COMPACT_WINDOW, and a file read in pieces with the Read tool, since Bash cuts a long output short. Its recording is the new autocompacted fixture, the first real auto-compaction the tests hold.

Decided with Edgar

  • Every run, not opt-in. The reading is on for every run whose trajectories hold a compaction, as it is for a labelled run. An assistant-written summary is graded normally, and context loss is reported, never scored.
  • The token counts are in the facts on both paths. The profile gains them as 1.2, rather than leaving them out.
  • Before merge: a replay of a compacting run through its judges, with main's prompt and this branch's, to show the scores hold.

Choices to review

  • Claude Code's protocol floor stays at 0.1.649. The adapter now needs the protocol this PR ships (profile 1.2). Like feat(protocol): atif/1 profile 1.1 gives a compaction its step and a harness's own messages, which Claude Code's copy writes #913's, the floor is raised after the release that puts it on PyPI.
  • The judge may leave context_loss unsaid.
    • The fields are optional in the row schema, as for a labelled run.
    • In the real run below, the judge left them out for its one failed criterion in every sample, and the entry counts that as not_said.
    • A planted loss didn't change that: with the support-chat rule cut from the summary before the failed criterion's message, the judge still left them out, three times of three, as it did on the copy as stored.
    • Requiring them would change the row schema of every run that's asked, a labelled run's too, so it's left for a decision of its own.
  • Real runs compact late. Claude Code on Sonnet 5.5 has a 1M-token window, so a run compacts only once its history fills that, or when a smaller window is set (CLAUDE_CODE_AUTO_COMPACT_WINDOW).
  • Every 1.1 copy now reads as version 1.2. That shows in every fixture and in the judge-input golden. The golden's digests moved only because of the version: I diffed what each pin hashes, on main and on this branch.

Testing

  • Unit, protocol.
    • The builder writes a compaction's token counts and refuses one that isn't a count.
    • The validator refuses a count that isn't a whole number or is negative: "-1", -1.0, "300" and True are compaction findings, and the profile model refuses 2.5 itself.
    • It reads 1.0 to 1.2 and flags 1.3 and 2.0.
    • The fixtures are rewritten at 1.2.
  • Unit, Claude Code.
    • The adapter writes the boundary's counts.
    • A summary in several text blocks is one compaction step in the copy, as native reads it, and no system step.
    • Both recorded compactions reach the judge as one note with its facts, the same natively and from the copy: /compact between turns, and the new auto-compaction partway through a turn.
    • A copy's compaction that doesn't say who wrote its summary is refused, as native is.
    • The two readers stay equal. 200 seeded conversations that compact are played through the adapter and the native reader, and both give a judge the same events and facts. That's about a second, and it covers 390 compactions, 130 of them with summaries in several blocks. It fails on the adapter before the fix of a summary in several blocks.
  • Unit, always_on.
    • A Claude Code run that compacts gets the compaction reading and the context-loss question, without the lines only a labelled harness writes.
    • A labelled run's prompt is unchanged: the existing tests pass as they were.
    • The index line says "partway through" for Claude Code and still "before" for a labelled run.
  • The judge-input golden moved only by the profile version. I dumped what each pin hashes on main and on this branch: the nine atif/1 cases differ only in "version".
  • Related unit folders: task_step, agents, a2a_agent and the protocol suite pass (8,251), apart from this Mac's known failures. CI is green.
  • The recorded auto-compaction, through Claude Code's image built from this branch on a test host, about $0.40:
    • the boundary says auto, 58,741 tokens before and 32,484 after;
    • the compaction step holds its summary call's 30,640 prompt and 1,077 completion tokens;
    • the copy's steps sum to the turn's reported usage, and its reply step follows the compaction.
  • The final commit, recorded again (ab06266), about $0.70: both compaction scenarios through Claude Code's image built from it, /compact and an auto-compaction.
    • Each fresh copy validates and gives the judge the native turn's events on every turn.
    • Each compaction note's facts are the assistant's, with its trigger: 28,634 to 2,843 tokens, and 69,998 to 43,805.
    • The recorded tests pass on the fresh recordings but for the one that pins the committed recordings' token counts, which a new recording changes.
  • A real always_on run on a test host, about $1:
    • Setup: an always_on task with a user simulator and two agent-judged, per-criterion verifiers. Claude Code (Sonnet) was the solver, atif/1 was prescribed, and a 90k auto-compact window was set on the solver alone (its deploy step's env_vars).
    • The solver compacted twice partway through the run.
    • Both verifiers read its 12 turns from their atif/1 copies and staged the two assistant-written compaction notes. Their prompts carried the harness-note lines and the assistant-written rule, and asked about context loss.
  • The replay, on that same run held up (--keep), with the same judge model, about $1:
    • What ran: each verifier's verify(), three times with main and three times with this branch, alternating.
    • Scores: every criterion scored the same in all three branch samples and in two of the three main samples. main's third sample of one verifier passed a criterion the other five failed, which is judge noise on the unchanged side. The overall score was 0.0 in all twelve, as in the run itself.
    • Prompts: only the branch's prompts carried the compaction reading and the context-loss question.
  • Parity chaos (kept outside the repo).
    • What it does: random Claude Code conversations with compactions, their boundaries' triggers and counts drawn from good and bad values, and summaries as a string or one to three text blocks. Some turns hold two compactions or the CLI's "Compacted". The turn record's counts are right, short or missing.
    • Invariants:
      • the adapter's document validates under the live rule;
      • each turn's native events equal its copy's;
      • each compaction's facts are what its boundary gives.
    • Results: clean over 23,486 seeds locally (49,226 compactions). It catches three planted bugs at once: the counts swapped, the trigger forced to manual, and the counts passed on unchecked. The adapter before the fix of a summary in several blocks fails it within 11 seeds. For 30 minutes on a test host, at 4d6223a, it was clean over 386,322 seeds (810,558 compactions).

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

Summary

Gives native and ATIF compactions the same judge-facing note, including the writer, trigger, and available token counts.

  • Claude Code compactions reach judges as one note with their facts.
  • Always-on judges get compaction context and can report context loss.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Native[Claude Code boundary and summary] --> Facts[Compaction facts and note]
  Native --> Adapter[ATIF adapter]
  Adapter --> Copy[ATIF compaction step]
  Copy --> Facts
  Facts --> Staging[Wake files and index]
  Staging --> Judge[Judge gets compaction guidance]
  Judge --> Result[Score with optional context-loss report]
Loading

Reviews (7) · Last reviewed commit: "Merge main into fd-6942-y19" · Reviewed by Greptile

earakely-scale and others added 4 commits November 24, 2026 10:55
…y and from atif/1, and is asked about context loss

A Claude Code compaction reached always_on's judge as two plain notes. Its compact_boundary and the summary after it
are now one compaction note with its facts (who wrote the summary, its trigger, and the history's tokens before and
after), the same from native stdout and from an atif/1 copy, whose profile 1.2 adds the compaction's tokens_before
and tokens_after, written by Claude Code's adapter. A run whose trajectories hold a compaction gets the harness
reading a labelled run gets: the harness-note lines, whose its summary's losses are, and, with a per-criterion format,
the context-loss question, reported next to the score. A labelled run's prompt is unchanged, and a run without either
gets none of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s its history fills

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ces, which Bash's output cut doesn't

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… as one note with its facts from both paths

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale marked this pull request as ready for review November 24, 2026 19:35
@earakely-scale
earakely-scale requested a review from a team as a code owner November 24, 2026 19:35
earakely-scale and others added 4 commits November 24, 2026 11:45
… the copy, and a count must be a whole number

The adapter made only a summary's first text block the compaction and wrote the rest as system steps, where native
reads them as one note; it now joins them. The validator read a count's raw value only when it was already an int, so
a string or a float the profile model takes passed; a count is now a whole number that isn't negative.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d atif/1's vocabularies, and a seeded test keeps them equal

- The protocol exports is_token_count, which the builder, the validator, Claude Code's adapter and the judges'
  reader use in place of four copies of the check.
- The judges' reader takes SUMMARY_WRITERS and COMPACTION_TRIGGERS from atif/1 rather than its own copies, and the
  OTel span's compaction checks who wrote its summary through compaction_facts, the one place that refuses an
  unknown writer.
- The adapter holds a boundary it hasn't seen the summary of as one _Boundary, in place of three attributes and the
  entry's trigger and tokens.
- test_claude_code_atif.py plays 200 seeded conversations that compact through the adapter and the native reader,
  and asserts both give a judge the same events and facts; it fails on the adapter before the multi-block fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…or has

Its image installs any protocol at or above the floor, and the released protocol has no is_token_count, so importing
it made the adapter fail to import and every Claude Code install built from the checkout fail. The adapter keeps its
own count check and trigger names until its floor is raised.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The conflict was in always_on's context-loss gate: main holds it in a _ContextLoss each run sets (#905), and this
branch asks a run whose trajectories hold a compaction too; the gate is main's holder, asked through _harness_read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant