Repository navigation
feat(anthropic): opt-in server-side compaction (compact-2026-01-12) - #123402
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 12:18 AM ET / 04:18 UTC. ClawSweeper reviewWhat this changesAdds opt-in Anthropic server-side compaction with request controls, stored compaction-summary replay, usage accounting, documentation, and focused/live tests. Merge readinessKeep open for explicit maintainer review. This is a protected, maintainer-authored feature PR that introduces opt-in provider configuration and persisted session replay behavior; the supplied evidence is promising but local repository inspection could not run. Priority: P2 Review scores
Verification
How this fits togetherAnthropic model requests pass through the bundled Anthropic plugin and shared AI transport, which also stores assistant transcript state for later turns. Compaction summaries become route-fenced replay metadata that changes the next matching Anthropic request while retaining the local transcript. flowchart LR
A[Agent session] --> B[Anthropic plugin]
B --> C[Shared AI transport]
C --> D[Anthropic API]
D --> E[Compaction summary]
E --> F[Assistant transcript]
F --> G[Next request replay]
Decision needed
Why: Automated evidence cannot determine whether this new provider configuration and durable session-state behavior is the intended permanent product boundary. Before merge
Agent review detailsSecurityNone. PR surfaceSource +685, Tests +1144, Docs +63. Total +1892 across 36 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Accept one canonical, route-fenced Anthropic checkpoint format only after the transcript and provider owners confirm its replay, redaction, rewrite, and upgrade behavior on the exact head. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: this is a new opt-in capability. The PR supplies live-provider evidence, but local review could not independently execute or inspect the exact test path. Is this the best way to solve the issue? Unclear: provider-native compaction is a plausible design, but the persisted replay contract needs exact-head owner review before it can be judged the best durable solution. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against 92eed63f584d. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
3eb68a4 to
8f78d14
Compare
Fix the live fixture baseUrl (the SDK appends /v1 itself), fail fast on errored turns instead of silently looping, assert request-side injection before capture, and log per-turn stream outcomes for live debugging.
83a31d3 to
466d1f0
Compare
Keeps captureAnthropicCompaction module-local; knip flags exports whose only consumers are tests.
|
Land-ready proof for exact head
The latest exact-head ClawSweeper review reports no findings. The owner has accepted the opt-in beta API and durable replay boundary. |
|
Merged via squash.
|
…penclaw#123402) * feat(anthropic): add server-side compaction replay * docs(anthropic): document server compaction * test(anthropic): harden compaction live probe Fix the live fixture baseUrl (the SDK appends /v1 itself), fail fast on errored turns instead of silently looping, assert request-side injection before capture, and log per-turn stream outcomes for live debugging. * test(anthropic): keep live settings type module-local * refactor(agents): split transcript replay sanitizers * test(anthropic): move compaction live probe into plugin tree * refactor(anthropic): consolidate compaction replay duplication * test(anthropic): align compaction threshold host coverage * test(anthropic): fabricate checkpoints via capture tracker Keeps captureAnthropicCompaction module-local; knip flags exports whose only consumers are tests.
What Problem This Solves
OpenClaw sends no Anthropic context-management features. Long Anthropic sessions rely entirely on OpenClaw's client-side compaction, which rewrites the prompt prefix (burning warm prompt caches) and has historically produced invalid message sequences under heavy tool use. Anthropic shipped server-side compaction (beta
compact-2026-01-12): the API summarizes earlier context into acompactionblock and drops prior history on later requests, keeping tool_use/tool_result pairing and message sequencing valid by construction.Closes #10213 (design of record: #10213 (comment)). Related: #54041 (broader context-management passthrough, still open), #65287 (cache-preservation motivation).
Why This Change Was Made
Opt-in, mirroring the shipped OpenAI Responses server-compaction feature end to end:
anthropicServerCompaction: true+ optionalanthropicCompactThresholdmodel/providerparams(no schema change; same source-chain resolution asresponsesServerCompaction). Never auto-on while the API is beta. Applies only to direct Anthropic API endpoints with API-key auth; OAuth/subscription, proxies, Bedrock/Vertex/Foundry are excluded.compact-2026-01-12beta header +context_management.editswith aninput_tokenstrigger. Default thresholdmax(50000, floor(contextWindow * 0.7)); configured values clamp to Anthropic's 50K minimum.pause_after_compactionand custominstructionsare v1 non-goals.compactionblock is stored as route-fencedproviderReplaystate (anthropic-compaction) on the owning assistant message — not a new content-union member, so historical-transcript replay and non-Anthropic providers are untouched. The next request re-emits the summary as the first assistant block and slices pre-checkpoint history client-side; the full transcript stays local. Rejection writes a suppression tombstone and the next turn falls back to full history (the Anthropic client has no full-request rebuild retry seam; dispatch sites are single-shot).mapAnthropicStopReasonno longer throws on"compaction"; billed usage sumsusage.iterationswhen a compaction iteration is present (top-level counters exclude it); transcript redaction, rewrite-invalidation, and empty-final-retry paths recognize the new checkpoint type via a sharedstripCompactionReplayCheckpointhelper that also replaces the OpenAI-only one.resolveServerCompactionThreshold(generalized from the OpenAI-only resolver) raises the client-side preflight compaction floor to at least the server threshold, so Anthropic compacts first and OpenClaw's local compaction stays the fallback.User Impact
Off by default; no behavior change unless a model opts in. Opted-in Anthropic sessions get provider-native summarization with valid message sequencing and warm-cache-friendly prefix handling. Docs:
docs/providers/anthropic.md(new "Server-side compaction" accordion) anddocs/gateway/config-agents.md.Evidence
pnpm test:live src/agents/anthropic-compaction.live.test.ts, sonnet-4-6, 50K threshold): beta header sent,context_managementinjected, compaction checkpoint captured on dense turn 2, summary replayed as first block with sliced history on the following request, and a durable marker from pre-compaction context recalled correctly. 1 passed.compactioncontent block +usage.iterations[{type:"compaction",in:58456,out:128},{type:"message",in:229,out:6}], confirming both the wire shape and that top-level usage excludes the compaction iteration (hence the billing fix).git diff --checkclean.node scripts/check-changed.mjsfails on a pre-existing doctor-closure violation fromextensions/llama-cpp/src/llama-server-install.tsthat reproduces on currentorigin/main; unrelated to this branch.