Skip to content

feat(compaction): make compaction summary char cap configurable via maxSummaryChars - #196207

Merged
RomneyDa merged 3 commits into
openclaw:mainfrom
aniruddhaadak80:fix/compaction-summary-chars
Nov 10, 2026
Merged

RomneyDa merged 3 commits into
openclaw:mainfrom
aniruddhaadak80:fix/compaction-summary-chars

Conversation

@aniruddhaadak80

@aniruddhaadak80 aniruddhaadak80 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Closes #194408
Related: #195028, #194719; consolidates the now-closed #196347

Contributor and consolidation

Original configurable-cap proposal and commit by @aniruddhaadak80. The follow-up a444bd49a9b4ea743f9fe593460dc9d865510357 directly descends from the contributor's original 6fda397edd35d9b72b191438aac4c0b792bc5d88; their commit and authorship are preserved.

The reviewed compaction-only patch from #196347 is now applied without unrelated working-branch history: 32 files, +807/−162. Its diff against the original contributor base is byte-identical to bd63497962a1..efe7b6dc099c, and every affected base file is identical between those bases. The full repository tree is not identical because unrelated later changes were excluded. Existing focused proof is reused for this unchanged patch; fresh CI is not claimed as passed.

An earlier consolidation mistakenly merged unrelated newer-base commits. That maintainer merge was replaced using an exact-head lease, without rewriting the contributor's original commit. Overlapping cap/settings implementations remain consolidated into one owner.

What Problem This Solves

Long-context agents still lose generated summary content at the fixed 16,000-character ceiling, even after the summary-priority fix in #195028.

User Impact

Operators can set agents.defaults.compaction.maxSummaryChars or override it through agents.entries.<id>.compaction.maxSummaryChars (1,000–200,000). Omission preserves today's 16,000-character default. Larger summaries increase replay cost; this is a ceiling, not a target or a guarantee that previously lost facts return. No automatic default scaling, state-format change, or provider-native compaction change.

Why This Change Was Made

Carry one resolved setting through the existing compaction settings, safeguard sections, token fitting, and persistence owner. Derived section budgets retain the merged summary-priority behavior. Raised limits remain bounded by the foreground request window, including manual RPC compaction with a separately configured larger summarizer and high fixed instruction/tool pressure.

The core cap/fitting helpers are extracted without changing their public exports; existing split-turn formatting and quality-retry helpers move into the existing quality module to satisfy file-size constraints. No new config/runtime manager or cache is introduced.

Evidence

  • Before: new config case rejected the key; runtime global/per-agent cases produced 16,000 instead of 48,000/64,000 characters. Those runtime assertions ran and failed, but the base test wrapper subsequently exited 2 because it detected a concurrent QA fixture edit during cleanup; this is not claimed as a clean baseline invocation.
  • After: 21/21 summary-limit and existing small-context cases pass, covering persisted/replayed defaults and overrides, automatic/manual token fitting, and high fixed pressure. Config/settings/request-budget/safeguard suites, core compaction suites, and 21/21 Gateway compaction tests pass. Prompt-prefix stability: 14/14 pass.
  • Real isolated Gateway, synthetic providers: configurable-limit scenario persists more than 48k and at most 64k characters, retains the final decision, and resumes; the existing 16k summary-priority sibling passes; manual RPC fits a CJK-heavy summary to a 64k foreground window while using a separate 200k summarizer. All three scenarios pass. The original 32k fixture correctly rejected its ~49k fixed instructions/tools before summarization; the fixture now uses a viable foreground window.
  • Package: the full build completed before the mechanical helper relocation (with nonfatal UI bundle-budget warnings). A fresh runtime-only package from 8595de2bc73e6799461a52a85ccd1e895bae12cc passed archive inventory and import-graph integrity; SHA-256 766b30bfed23b2403335b0a05fc01abeddb52983bec7a210e3d7a477820d6252. The publication commit efe7b6dc099c6f9af098c2ed78dec54ead4a22be has an identical source tree. This is runtime/install proof, not release qualification.
  • Checks: targeted core/session typechecking, changed-TypeScript lint, formatting, and git diff --check pass. Fresh independent review and local AutoReview found no remaining P0–P2 issues after repairing both manual-budget findings. A second AutoReview was clean after the helper relocation; affected safeguard/quality tests passed (41 cases), and the final unchanged retry-helper move passed 34/34 safeguard cases plus lint and the line-cap ratchet. Local ClawSweeper could not start because its Git preparation timed out; hosted ClawSweeper acknowledged the PR.
  • Upgrade result — partial, suite failed: isolated published-upgrade-survivor / sqlite-volume, stable [email protected] → the exact candidate tarball, with 8 synthetic sessions, 5 events per session, and 2 scheduled jobs. The updater returned ok, candidate Doctor/config/plugin/recovery/Gateway checks passed, installed-package identity matched, and the migration assertions verified session records and transcript events. The suite then failed with main volume legacy session-store archive changed; later assertions, including the remaining scheduled-job proof, did not run. This is not a passing upgrade suite.
  • Live-model limitation: the isolated QA profile had no route-compatible provider authentication, so live summarization/resumption was not exercised. The deterministic Gateway checks above use synthetic provider responses, not live inference.

The 207-line regression allocation covers the new 184-line session boundary suite, 21 schema lines, and 2 Gateway budget-handoff assertions; existing core/safeguard tests are reused.

Upgrade failure investigation

Run 20261110T002138Z completed the update in 450 seconds and passed installed-package identity verification. It failed at scripts/e2e/lib/upgrade-survivor/sqlite-volume.mjs:540, which requires exactly one retained legacy sessions.json archive.

The captured migration manifest records the main store as classification: imported, reason: verified-index-import, then disposal.state: disposed at 2026-11-10T00:30:24.667Z. The ops store, which includes an intentionally missing-transcript fixture, is classification: protected, reason: incomplete-index-import, and remains retained. The existing Doctor retirement owner (src/commands/doctor-session-sqlite-retirement.ts:643–665) removes verified recovery originals and records this disposal. Both that owner and the failing fixture are unchanged from the PR base; the archive-presence assertion conflicts with that cleanup behavior. No assertion was weakened, no failure was suppressed, and the suite was not rerun merely for green. Remaining uncertainty: assertions after the archive check were not reached; this run is not full upgrade-survivor qualification.

Reproduce the focused boundary proof
pnpm test src/agents/sessions/agent-session-summary-limit.test.ts src/agents/sessions/agent-session-small-context-compaction.test.ts --maxWorkers=1
pnpm openclaw qa suite --provider-mode mock-openai \
  --scenario compaction-summary-limit \
  --scenario compaction-summary-priority \
  --scenario compaction-summary-window --concurrency 1

The Gateway cases exercise the actual RPC, summarization pipeline, database persistence, and replay; only model responses are synthetic. The two summary-limit/default cases passed together, and the corrected window fixture passed in its targeted rerun.

CI fixture correction (2da313ad1ab5)

Addresses the latest ClawSweeper P2 finding and the 19 failures in CI run 42731031733. The shared runner fixture now creates a fresh real SettingsManager.inMemory() both initially and after reset, replacing the incomplete getGlobalSettings-only mock. No production behavior, assertions, or timeouts changed. The follow-up is one file, +5/−6; the full PR is now 33 files, +812/−168.

Validation: all 94 tests in the three CI-failing suites pass (149.07 seconds including runner preparation). All 63 tests in the five other shared-fixture consumer suites pass (261.90 seconds including preparation; durable delegate/queued-successor cases exercise persistence and cancellation). Total: 157/157 tests in eight suites. Targeted lint, agents-other test typechecking, formatting, and diff checks pass. Local AutoReview of the fixture delta found no actionable P0–P2 issues; the final formatter change only wraps one expression. Existing production proof and the documented live-model/upgrade gaps are unchanged. Fresh hosted CI is pending, not claimed green.

…axSummaryChars

Adds agents.defaults.compaction.maxSummaryChars (default 16000, range
1000-200000) so long-context deployments can raise the persisted compaction
summary budget instead of truncating two-thirds of compactions. The
preserved-turn/split-turn budgets derive from the resolved cap and the
foreground token-budget check remains the safety net against overflow.

Closes openclaw#194408
Copilot AI balanced review requested due to automatic review settings November 9, 2026 19:15
@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Nov 9, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 9, 2026
@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR adds global and per-agent summary character limits while preserving the 16,000-character default and foreground-window fitting.

Example: A research agent sets maxSummaryChars to 64000 and generates a 52,000-character summary with sufficient foreground context space.

  • Before: The persisted summary is capped at 16,000 characters.
  • After: The generated summary can survive above 16,000 characters, within the configured ceiling and token budget.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation has useful Gateway-boundary coverage, but required live-model proof is incomplete and an attributable fixture failure still blocks CI.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Long-context operators cannot retain generated summaries above the fixed ceiling even when their foreground model has sufficient space.
Reason: Maintainer adoption supplies direction for the bounded global/per-agent option; the implementation preserves default cost and the merged summary-priority repair, without promising recovery of previously lost facts.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: current main still has the fixed summary ceiling, and this maintainer-adopted feature remains useful; a previously reported runner-fixture defect still breaks exact-head CI.

Priority: P2
Reviewed head: a444bd49a9b4ea743f9fe593460dc9d865510357

Before merge

  • Add real behavior proof - The body records isolated Gateway RPC, persistence, replay, and separate-summarizer window scenarios using synthetic providers, but explicitly reports no live-model summarization or resumption. Root AGENTS.md requires a real agent and model. Supply redacted terminal output or logs showing a raised configured ceiling reaching a persisted summary and a successful resumed turn; remove API keys, IPs, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Update the shared runner settings fixture for manual budgeting (P2) - Every manual runner invocation now calls getCompactionSettings and getCompactionReserveTokens before deciding whether the raised-cap budget is needed. The shared compact.hooks.harness.ts settings mock implements only getGlobalSettings in both its initial and reset constructions, so ordinary manual compaction tests return a failure before reaching their intended behavior. Exact-head CI confirms the missing-method error in compact.hooks and compact.small-context, and compact.sandbox-info uses the same harness. Update both fixture constructions with the real settings contract, preferably using SettingsManager.inMemory, while retaining the existing assertions. This previously reported fixture blocker remains unresolved.

Findings

  • [P2] Update the shared runner settings fixture for manual budgeting — src/agents/embedded-agent-runner/compaction-session-execution.ts:508-510

Tests

  • Missing end-to-end proof: A real-model Gateway run must demonstrate raised-limit persistence and successful resumption; the supplied Gateway scenarios use synthetic model responses.
Agent review details

How this fits together

Agent configuration flows into session compaction settings; core and safeguard producers summarize conversation history, fit the artifact to the foreground budget, and persist it for subsequent requests.

flowchart LR
  A[Global and agent configuration] --> B[Prepared session settings]
  C[Conversation history] --> D[Core or safeguard summarization]
  B --> D
  E[Foreground request budget] --> F[Summary fitting]
  D --> F
  F --> G[Persisted summary and replay]
Loading

Technical review

Best possible solution:

Keep the existing compaction owners and default, with one resolved override bounded by foreground token pressure.

Do we have a high-confidence way to reproduce the issue?

Current-main source still fixes summary fitting and persistence at 16,000 characters without this override; no target code was executed during this review.

Is this the best way to solve the issue?

The existing settings, fitting, safeguard, and persistence owners provide a coherent implementation; helper extraction preserves existing exports, and the added tests cover distinct configuration and window boundaries.

Full review comments:

  • [P2] Update the shared runner settings fixture for manual budgeting — src/agents/embedded-agent-runner/compaction-session-execution.ts:508-510
    Every manual runner invocation now calls getCompactionSettings and getCompactionReserveTokens before deciding whether the raised-cap budget is needed. The shared compact.hooks.harness.ts settings mock implements only getGlobalSettings in both its initial and reset constructions, so ordinary manual compaction tests return a failure before reaching their intended behavior. Exact-head CI confirms the missing-method error in compact.hooks and compact.small-context, and compact.sandbox-info uses the same harness. Update both fixture constructions with the real settings contract, preferably using SettingsManager.inMemory, while retaining the existing assertions. This previously reported fixture blocker remains unresolved.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1ebc46e1a52f.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/agents/embedded-agent-runner/compact.hooks.test.ts src/agents/embedded-agent-runner/compact.small-context.test.ts src/agents/embedded-agent-runner/compact.sandbox-info.test.ts --maxWorkers=1
  • pnpm exec oxfmt --check src/agents/embedded-agent-runner/compact.hooks.harness.ts
  • git diff --check

What I checked:

PR surface

Source +176, Tests +207, Docs +26, Generated 0, Other +236. Total +645 across 32 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 22 335 159 +176
Tests 3 207 0 +207
Docs 2 26 0 +26
Config 0 0 0 0
Generated 2 3 3 0
Other 3 236 0 +236
Total 32 807 162 +645

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Configuration surface One option at two scopes; range 1,000–200,000; default remains 16,000 Global configuration and per-agent precedence add deliberate operator control without automatic default scaling.

Root-cause cluster

Relationship: same_root_cause
Canonical: #194408
Summary: This PR implements the configurable-ceiling request; summary-priority work addresses a related but distinct source of truncation.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.
  • remove merge-risk: 🚨 session-state: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: This is a bounded compaction improvement for long-context operators, with a focused fixture repair remaining.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-09T19:34:39.498Z sha 6fda397 :: needs real behavior proof before merge. :: [P2] Fit manual compaction to the active window before raising its cap | [P2] Update the runner settings fixtures for the new accessor | [P3] Remove the added helper-only test API

Reviewed November 9, 2026, 10:08 PM ET / November 10, 2026, 03:08 UTC (Revision 2).

@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix app: android App: android app: ios App: ios app: web-ui App: web-ui gateway Gateway runtime extensions: memory-lancedb Extension: memory-lancedb cli CLI command changes scripts Repository scripts commands Command implementations extensions: anthropic extensions: qa-lab plugin: mcp-relay labels Nov 10, 2026
RomneyDa added a commit that referenced this pull request Nov 12, 2026
Adapt the reviewed summary-cap change to the canonical release compaction
request-budget, provenance, and streamed-hydration owners. Preserve the
16000-character default and existing 600-character preserved tool excerpts.
Carry global and per-agent limits through normal, manual, CLI, fork and
Gateway RPC paths with foreground-window fitting before persistence.

Keep manual preflight and its zero-retention fallback within the same
request constraints when a raised cap needs a foreground budget.

(cherry picked from commit c7152f3)
(adapted from commit df8e4d101ced84ee5f0678b3570113d5939f9240)

Co-authored-by: Aniruddha Adak <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: qa-lab gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Compaction: make MAX_COMPACTION_SUMMARY_CHARS (16,000) configurable; two-thirds of production compactions hit it

3 participants