Skip to content

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

Merged
earakely-scale merged 7 commits into
mainfrom
edgararakelyan/fd-6916-y17-atif-compaction
Nov 24, 2026
Merged

earakely-scale merged 7 commits into
mainfrom
edgararakelyan/fd-6916-y17-atif-compaction

Conversation

@earakely-scale

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

Copy link
Copy Markdown
Collaborator

When Claude Code compacts its conversation (/compact, or an auto-compaction), its atif/1 copy has lost two things since copies began:

#890 pinned both gaps in the recorded tests. This PR closes them with a minor version of the atif/1 profile, 1.1. The tests now ask for full parity on every turn, and for the copy's steps to sum to every turn's reported usage.

What changes

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

  • A compaction is the step of the model call that wrote its summary.
    • It's a source: agent step: its message is the summary, and it carries that call's metrics.
    • Its profile's new compaction field names who wrote the summary (written_by: assistant, the agent's own model, or harness) and what set it off (trigger: manual or auto).
    • The builder writes it with turn.compaction(step=..., written_by=..., trigger=...).
  • A message the harness itself put in the conversation is a source: system step of its own, written by turn.system_message(text=...). ATIF's own source says whose it is, so it needs no new field. Nothing wrote system steps before.
  • The validator.
    • It holds a compaction to an agent step that names who wrote its summary (the new compaction rule), and checks both vocabularies.
    • It reads a 1.0 document as its own, and flags only a newer minor or another major: a minor only adds optional fields. A framework on 1.1 therefore takes 1.0 copies from agents on an older SDK, and a 1.0 framework already reads a 1.1 copy in reader mode.
  • Left for a harness that needs them. The rest of an always-on harness's fields wait for a harness that has them, and the profile's "Versions" section says so: what a compaction kept, the purpose of the harness's messages, and the tools a harness provides itself.

Claude Code (agents/claude-code/claude_code_atif.py, a2a_server.py)

  • The adapter's compaction step. The adapter reads the compact_boundary and the summary after it on stdout as the compaction step, written_by: assistant, with the boundary's trigger. The CLI's own messages, such as /compact's <local-command-stdout>Compacted</local-command-stdout>, become system steps.
  • The summary call's tokens. No transcript record counts them: only the turn's tally does, and it arrives when the turn ends.
    • The bridge's turn aux record now carries the turn's token counts beside its cost: uncached input apart from the cache, and the model when there was one.
    • The compaction step takes what the turn reported beyond its other steps, written or still queued.
    • It takes nothing in any of these cases:
      • the turn's counts are a lower bound;
      • the remainder would be negative;
      • the turn holds two summaries, whose calls the tally can't split;
      • another model call of the turn lacks its own counts, whose tokens the remainder would hold.
  • The summary call's model. The turn's tally keys a model by the name it was called as, which a gateway route prefixes (anthropic/claude-sonnet-5-5), while the steps name it as the API answered (claude-sonnet-5-5).
    • Each turn's count records how the model it was called as answered, from the turn's root calls, and the compaction step is named that way.
    • A model none of whose calls has answered yet, after a model change say, is named as called, so a compaction never names another model.
  • Holding the summary. A step a live page has served never changes again, so the summary waits in the adapter's queue until the turn's count arrives, as records already wait for their transcript record. With /compact, nothing else follows in the turn, so live pages lose nothing. With an auto-compaction partway through a turn followed live, the steps after it wait too, and arrive when the turn ends. always_on doesn't follow live.

The judges (judge_utils/turn_events.py, judge_utils/atif_turns.py)

  • atif_turn_events gives a compaction step and a system step as the notes a native Claude Code turn gives. A turn with no closing message ends with "", as the CLI's result gives it.
  • compact_atif_trajectory and transcript_from_atif leave a compaction out of the agent's words and its final response. They already skipped system steps.

Decided with Edgar

  • The scope: compaction and harness messages, with Claude Code as their first producer. The harness-internal-tool flag and the facts of a harness's compaction wait for a harness that has them.
  • A compaction's shape: the agent step of its summary call, carrying that call's metrics, rather than a system step, which can't hold metrics, or two steps.
  • The harness's messages: a system step, with no new field.
  • The summary call's tokens: from the turn's reported usage, the remainder beyond its steps. The summary is held until they arrive, so no served step ever changes.
  • The judges: they match native Claude Code exactly, with plain notes. Making both paths richer, so that a compaction is read as a compaction (who wrote it, and the context-loss question), changes how every compacting Claude Code run is graded, so it's follow-up work, decided on its own.

Choices to review

  • Claude Code's protocol floor stays at 0.1.649 in this PR.
  • A live stall after an auto-compaction. In a prompt-step turn followed live, the steps after an auto-compaction reach live pages only when that turn ends. /compact and always_on are unaffected.
  • No real auto-compaction recorded. I couldn't force one mid-turn: CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=20 didn't trigger it. The adapter's handling of one is unit-tested on records shaped like the recorded manual one, with steps before and after it.
  • Totals when the tokens are unknown. A compaction step whose tokens are unknown carries none. The document's token totals are then left out, since one model step lacks its counts. That's honest, where the old totals were silently short.
  • Every 1.0 copy now reads as version 1.1. That shows in every fixture and in the judge-input golden. The golden's digests moved only because of the version: I checked by diffing what each pin hashes, on main and on this branch.

Testing

  • Unit, protocol:
    • the builder writes a compaction step and a system step, and refuses a writer or trigger outside the vocabularies;
    • the validator's new rule, the vocabularies, and the 1.0, 1.1, 1.2 and 2.0 versions;
    • the fixtures rewritten at 1.1.
  • Unit, Claude Code (test_claude_code_atif.py):
    • an auto-compaction is its summary call's step, holding what the turn counted beyond its steps;
    • no live page before the turn's count serves it, and the test fails with the hold removed;
    • a turn that counted less than its steps leaves the compaction without usage;
    • a turn that never reports still writes it when the task ends;
    • two compactions in one turn get no counts, and neither does a compaction whose turn has a call without its own; both tests fail on the commit before their fix;
    • the compaction step names its model as that model's calls answered, mid-turn and in a /compact-only turn, and as called after a model change or when no call has answered; the test fails on both earlier versions of the fix.
  • Unit, the bridge (test_usage.py): the turn record's counts apart from the cache, the model when there's one, and nothing for a lower bound.
  • The recorded compacted scenario, re-recorded through the image with the new bridge, about $0.30:
  • The judge-input golden moves only by the profile version.
  • Related unit folders: task_step, agents, a2a_agent and the protocol suite pass. The failures are this Mac's known ones.
  • SDK chaos (feat(protocol): a live atif/1 read names the header it holds and how far it holds each sub-agent #903's, kept outside the repo), its turns now also writing compactions and the harness's own messages: clean over 414 seeds, with 602 compaction steps and 586 system steps. Every task's document passes the validator, and it still catches its three planted bugs.
  • A real run with Claude Code (Sonnet) on a test host, about $0.11.
    • Setup: a three-turn conversation in one A2A context: some work, then /compact, then a turn that reads what the summary kept. Each turn was a prompt step followed live with atif/1 prescribed, on the checkout's image with the branch's protocol.
    • The task passed: the agent recalled the line after the compaction.
    • The stored copy is profile 1.1 and passes the validator.
      • Its one compaction step is manual, with the summary call's tokens: 30,621 prompt (28,502 cached) and 856 completion.
      • The system step holds "Compacted", and the copy's token totals are present.
    • Live: each turn's pages were atif/1, with every live step equal to the copy's.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge with its documented rollout choices.

Summary

Adds ATIF profile 1.1 support for compaction summaries, their usage, and messages written by the harness. Judges receive summaries and harness messages as notes.

  • ATIF copies can mark compactions and harness-written messages.
  • Claude Code copies compaction summaries with their available usage.
  • ATIF judges read compaction summaries as notes, not agent speech.

Reviews (6) · Last reviewed commit: "fix(agents): a compaction after a model ..." · Reviewed by Greptile

earakely-scale and others added 4 commits November 24, 2026 08:13
…rness's own messages

A compaction is the source: agent step of the model call that wrote its summary, carrying that call's metrics, its
profile's compaction naming who wrote the summary (assistant or harness) and what set it off (manual or auto); a
message the harness itself put in the conversation is a source: system step. The builder writes both
(turn.compaction, turn.system_message), the validator holds a compaction to an agent step and a named writer, and
reads a 1.0 document from an agent on an older SDK as its own: a minor only adds optional fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd the CLI's own messages system steps

A compact_boundary and the summary after it are the step of the call that wrote the summary, profile compaction
(assistant, its trigger), holding what the turn reported beyond its other steps, which the bridge's turn record now
counts; the summary waits for that count, so a live reader never sees the step change. The CLI's own messages, a
command's output say, are system steps. always_on's judge reads both as the notes a native turn gives, the judges'
other atif/1 readers as the harness's rather than the agent's words, and a turn with no closing message ends "".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…unts, and its copy matches native and its usage

The compacted scenario re-recorded through the bridge's counted turn record: its copy's compaction step holds the
summary call's tokens, so every turn's steps sum to its reported usage, and always_on's judge gets native's events on
every turn; both pins come out. The adapter's held summary, a turn that counted less than its steps and one that never
reported are unit-tested, and so is the bridge's turn record. A copy newer than the worker is now profile 1.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mpaction's step

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale requested a review from a team as a code owner November 24, 2026 16:34
earakely-scale and others added 2 commits November 24, 2026 08:40
…he one summary and every other call was counted

Two compactions in one turn each took the whole remainder, so the copy's totals exceeded the turn's; and a call whose
transcript record never came counted as nothing, so its tokens went to the summary. A compaction now takes the remainder
only when it's the turn's one held summary and every other model call of the turn has its counts, and none otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nt's own calls do

The turn's tally keys a model by the name it was called as, which a gateway route prefixes, while every other step
names it as the API answered. The compaction step now takes the root agent's latest model, and the turn's only when
no root call named one.

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

The compaction took the root agent's last model across turns, so a /compact-only turn after a model change named the
one before. Each turn's count now records how the model it was called as answered, and a compaction is named that way,
or as called when no call of that model has answered yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale merged commit 6c598a3 into main Nov 24, 2026
37 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/fd-6916-y17-atif-compaction branch November 24, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant