feat(agent): add explicit context compression tool / 显式上下文压缩工具 - #8000
Merged
SivanCola merged 7 commits intoAug 8, 2026
Conversation
Problem: - V1 sidecars could carry new logical message invariants that previous readers misinterpreted. - Positional compression adapters treated folded anchors and no-op folds as success. Root cause: - Strict-role coalescing moved to outbound requests without a persisted schema boundary. - Compatibility adapters discarded structured no-op results. Fix: - Write schema-v2 projection sidecars while retaining V1 read support. - Surface folded-boundary and no-savings outcomes through the controller notice path. - Add focused compatibility and positional compression regressions. Verification: - go test ./... - go test -race ./internal/agent ./internal/control - go vet ./... - cd desktop && go test ./... - cd desktop/frontend && pnpm typecheck
Problem: - The explicit compression implementation pushed range planning over the complexity and function-size limits. - New positional and boot coverage extended already oversized test files. Fix: - Split range planning, preparation, projection building, and atomic installation into focused helpers. - Reuse the common compaction telemetry constructor. - Move positional compression and allowlist coverage into dedicated test files. - Keep the context compressor binding and UI copy changes line-neutral in baselined files. Verification: - go run ./tools/repolint - go test ./... - go test -race ./internal/agent ./internal/control - go vet ./... - cd desktop && go test ./... - cd desktop/frontend && pnpm typecheck
Use maps.Copy in the positional compression checkpoint regression so the PR passes the repository's modernize lint rules. Verification: - go test ./internal/control -run TestPositionalCompressionPreservesCheckpointLineage -count=1 - golangci-lint run --timeout=5m ./... - go run ./tools/repolint
SivanCola
marked this pull request as ready for review
August 8, 2026 20:42
SivanCola
enabled auto-merge
August 8, 2026 20:47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
compresstool with exact unique user-message anchors andbefore/afterrange semanticsImplementation details
ContextCompressorto each tool execution so child agents operate only on their own session projectioncompresscalls even though the tool is workspace-read-only and Plan Mode safecompressin default and Economy tool surfaces while respecting explicit tool allowlistsCache impact
The system prompt is unchanged. Adding the default tool schema changes the tool-prefix hash once after upgrade. Successful explicit compression reports one
compact_toolprefix change; noop and failed attempts do not report a rewrite. Schema-v2 downgrade fallback may cause one cold canonical-prefix request while preventing an older client from misreading newer projection invariants.Validation
go run ./tools/repolintgo test ./...go test -race ./internal/agent ./internal/controlgo vet ./...cd desktop && go test ./...cd desktop/frontend && pnpm typecheckcd desktop/frontend && pnpm exec tsx src/__tests__/app-chrome-tabs.test.tscd desktop/frontend && pnpm exec tsx src/__tests__/message-reasoning-panel.test.tsxgit diff --checkCache-impact: medium - adds one default tool schema after upgrade; successful compression deliberately replaces the model-visible history prefix, while schema-v2 downgrade fallback may cause one cold canonical-prefix request.
Cache-guard:
go test ./internal/boot ./internal/agent ./internal/control- existing tool-prefix goldens,compact_toolrewrite assertions, and sidecar compatibility tests cover schema and prefix behavior.System-prompt-review: system prompt bytes are unchanged; only the stable tool schema set and explicit projection prefix change.
Documentation-impact: updated - documented the
compresstool and clarified projection-only context compression while retaining visible history.