Skip to content

fix(agents): direct commands skip proactive compaction - #130863

Merged
steipete merged 1 commit into
mainfrom
steipete/friendly-clarke-c0ad78
Aug 27, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/friendly-clarke-c0ad78

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #130716

What Problem This Solves

Fixes an issue where users running repeated built-in agent --local commands would keep sending an oversized conversation without proactive compaction when using safeguard mode, including with memory flush disabled. A persisted contextBudgetStatus could correctly report pressure while the next command still sent unreduced history.

Why This Change Was Made

The pressure estimate is intentionally diagnostic, not a compaction command. Normal replies already have a usage-based maintenance owner, but direct commands did not invoke it. This change shares that owner: replies keep pre-turn maintenance, while successful built-in commands compact after transcript persistence and protection of pending final delivery. This prepares reduced context for the next command without rebinding an already-admitted turn.

Maintenance uses the actual completed harness, model, and privately observed auth profile. Native harnesses retain their own compaction; the narrow profile observer does not enable native runtime-artifact capture. Accounting revalidates the caller lifecycle and expected session generation, adopts an owned successor, and clears stale pressure diagnostics. Original provider usage remains separate from subsequent compaction metadata. The old reply-only helper name is removed without an alias; there is no second threshold or compactor.

Ordinary post-turn compaction failures retain the completed local reply only after reloading the authoritative session and checking its identity/revision and the caller's abort/lifecycle state. Canceled, restarted, replaced, or stale work remains fenced. Generic CLI-backend failure behavior is unchanged.

User Impact

Long-running direct built-in sessions now receive usage-based proactive maintenance, including safeguard mode with memory flush disabled. Explicit compaction.enabled: false remains an opt-out. Heartbeats, hidden/raw/model-only runs, incomplete or rebound runs, and turns that already compacted do not receive a second pass. Near the threshold, successful commands can take longer because they now perform the missing summary work; their completed answer is preserved on an ordinary summarization failure.

No new configuration, dependency, SQLite schema, or protocol surface is introduced. Native Codex setup and compaction are unchanged. Documentation: https://docs.openclaw.ai/concepts/compaction and https://docs.openclaw.ai/reference/session-management-compaction.

Evidence

Real command and Gateway flows

Fresh isolated HOME/state/config/workspace, actual built CLI and SQLite, public openai/gpt-5.6-luna fixture, loopback HTTP mock provider, safeguard, 64,000 active context budget, 128,000 model window, disabled memory flush, and tools.deny: ["*"]. All runs recorded zero tool calls. Provider usage and summary text were scripted: this proves execution, persistence, and next-request context, not real model reasoning or server limits.

Scenario Compactions after 45,000-token turn Next request input bytes Old prefix copies in next request Completed reply
Baseline 0 206,876 850 Returned
Repaired 1 84,168 0 Returned
Explicitly disabled 0 206,890 850 Returned
Summary HTTP 503 0 206,876 850 Returned with warning

The repaired run recorded 15,686 tokens after compaction, a persisted summary containing the original fact, and a valid retained-history cut point. It cleared the previous pressure diagnostic without rewriting the completed request's 45,000 prompt-token usage. The injected failure retained original history rather than claiming a compaction occurred.

A separate real Gateway agent RPC flow passed the same boundary checks, with the next request reduced to 72,835 bytes. Its 30-second Control UI video shows usage progressing from 12k to 24k and then one auto-threshold checkpoint at 45,000 → 15,686 tokens. Paired screenshots show baseline zero checkpoints versus repaired one checkpoint. Every image and decoded video frame set was inspected; all data is synthetic. Only task-owned isolated servers were started, and they have been stopped.

Baseline source: 036e635c71cba06cae81722a803b3e61276d3ab3. The full build and behavior runs preceded only a behavior-neutral retry-message deduplication and test-suite organization/fixture cleanup; those final changes receive focused tests, static checks, and independent review below. Production configuration, state, credentials, native setup, and running services were never changed.

Regression, ownership, and validation

The command-boundary regression failed against unchanged production code: expected one shared maintenance invocation, observed zero. Validation also reproduced and fixed loss of an already-successful local reply on ordinary housekeeping failure. The focused owner/sibling suite passed 445 tests across 13 files; subsequent auth/maintenance checks passed 124 tests, and the expanded command boundary passed all 46 cases before being split around one shared fixture.

Coverage includes the 897,999 / 898,000 / 904,869 threshold boundary under a 922,000 active budget, disabled memory flush, actual built-in execution despite configured native runtime, selected/ambient auth, successor adoption, pending-final preservation, abort/restart/revision fencing, and diagnostic invalidation. Existing tests still prove heuristic pressure does not short-circuit provider submission.

The full pnpm build passed, including declarations, SDK export/bootstrap guards, and matching Control UI assets; zero ineffective dynamic-import warnings. Earlier test typing and max-lines failures were repaired rather than suppressed or worked around. The test split preserves all 46 command cases and shares one mock/setup owner; owned one-shot mock queues are reset between cases.

Final local verification passed:

OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/agents/agent-command.compaction-rotation.test.ts src/agents/agent-command.embedded-maintenance.test.ts src/agents/agent-command.live-model-switch.test.ts

All 172 tests passed in the canonical agents-core shared worker. The routing/config tests (test/scripts/test-projects.test.ts and test/vitest-unit-fast-config.test.ts) also passed all 299 cases. Their regressions keep both split suites in the runtime-owning lane; no broader metadata mocks or forced test config were used.

node scripts/check-changed.mjs

The full changed-scope check passed, including core/script/test types, full core/scripts lint, schema/legacy-store guards, and zero runtime import cycles. The final fixture-binding adjustment was followed by another successful pnpm tsgo:core:test, focused lint on all three fixture/suite files, and the 172-test run above. Final isolated Codex autoreview reported no actionable findings at its configured P0 threshold.

The actual command exercised by the local replay was node dist/index.js agent --local --session-key agent:main:compaction-proof --message-file <synthetic-turn-file> --thinking off --json; the Gateway replay used the same CLI without --local. Inspected before/after screenshots and the Gateway flow video are attached below. The screenshots inspect the recorded state after the tiny follow-up turn; the checkpoint records the preceding threshold-crossing turn. Exact-head hosted CI is required before landing.

Native ownership was personally checked against upstream Codex commit d47e5cc0e2bbd35774dff15c83570519735d2ac4, codex-rs/core/src/session/context_window.rs:23–90 and codex-rs/core/src/compact.rs:64–171. The native artifact-capture coupling was checked in extensions/codex/src/app-server/run-attempt-connection.ts:77–82 and extensions/codex/src/app-server/shared-client.ts:769–782. Stable v2026.7.1-2 was compared at source level, not replayed as a binary. Provenance (made visible): #110297 — avoid synthetic overflow in tool-heavy sessions, authored and merged by @joshavant on 2026-07-20, intentionally removed heuristic synthetic overflow. This repair preserves that policy instead of reverting it.

Size/ownership: production net +154 lines (+224/-70 after discounting a 17-line relocation). Growth implements the previously missing command-maintenance capability, private winning-auth transfer, lifecycle/delivery fences, and result accounting; existing followup context and settlement paths are reused. Tests/support: +1,345/-605 (net +740), including the relocated shared fixture and two suites; test-routing configuration adds 4 lines, separately from runtime production. Configuration surface: added 0, removed 0; the existing direct-command default behavior is repaired, with its explicit opt-out preserved.

Separate follow-up recorded: Align reply context-pressure diagnostics. Ordinary reply accounting does not forward the fresh diagnostic like direct-command accounting; this telemetry gap is not the cause of the compaction defect and is not turned into a runtime trigger here. A second named tooling follow-up, Run explicitly requested untracked tests, covers disagreement between fast-lane on-demand classification and tracked-only discovery. The empty fast-lane attempt was not counted as proof; both split suites now run through their existing scoped-runtime ownership contract.

Before: no compaction checkpoint after the local command sequence

After: one auto-threshold checkpoint with the preserved summary

gateway-compaction-flow.mp4

Share usage-based maintenance with successful built-in command turns while
preserving diagnostic-only pressure estimates and native compaction ownership.
Carry the winning auth profile privately, fence session accounting, and retain
completed local replies when ordinary post-turn summarization fails.

Cover threshold, delivery, cancellation, successor, and routing boundaries;
clarify the documented scheduling behavior without adding configuration.

Closes #130716
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 27, 2026 09:37
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready verification for 834fe988ed136f2753a3c957d9d61966a8f67bbf.

Exact-head CI run 33059383762 completed successfully; the required openclaw/ci-gate is SUCCESS. Native main/PR-head review guards and evidence artifacts validated. Fresh isolated Codex autoreview reported no actionable findings at its configured P0 threshold.

Local validation included the full build and changed-scope gates:

pnpm build
node scripts/check-changed.mjs

The final command/lifecycle proof passed all 172 cases in one canonical agents-core worker:

OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/agents/agent-command.compaction-rotation.test.ts src/agents/agent-command.embedded-maintenance.test.ts src/agents/agent-command.live-model-switch.test.ts

The 299 routing/config tests passed in the tooling shard, and final fixture bindings also passed pnpm tsgo:core:test plus focused lint. Earlier fixture typing, file-size, routing, and import-hoisting failures were repaired at their owners; no empty test run, broader metadata mock, or suppression was counted as proof.

Real isolated CLI before/after/disabled/HTTP-503 controls passed. The repaired next request dropped from baseline 206,876 input bytes to 84,168, retained the summary fact, and recorded one checkpoint with 15,686 tokens after compaction. The 503 control retained history and returned the completed reply with a warning. A separate real Gateway agent RPC flow passed, including the inspected 30-second video and paired screenshots attached to the PR.

The latest ClawSweeper comment is still its review-start placeholder; no findings or Rank-up moves have been published. No duplicate review request was sent. I will recheck it before the native merge step rather than treat the publisher as a merge gate.

Proof limits remain explicit: provider usage and summaries were scripted, so this is execution/persistence/context proof, not a model-quality or capacity claim. Native OAuth/production setup, configuration, state, and running services were not changed. No release or package publication is included.

@steipete
steipete merged commit 52750a2 into main Aug 27, 2026
270 checks passed
@steipete
steipete deleted the steipete/friendly-clarke-c0ad78 branch August 27, 2026 10:28
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
…0863)

Share usage-based maintenance with successful built-in command turns while
preserving diagnostic-only pressure estimates and native compaction ownership.
Carry the winning auth profile privately, fence session accounting, and retain
completed local replies when ordinary post-turn summarization fails.

Cover threshold, delivery, cancellation, successor, and routing boundaries;
clarify the documented scheduling behavior without adding configuration.

Closes openclaw#130716
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 maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Direct embedded command sessions skip proactive safeguard compaction

1 participant