Repository navigation
fix(agents): fit compacted context and prioritize foreground replies - #139822
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 6, 2026, 2:21 PM ET / 18:21 UTC. ClawSweeper reviewWhat this changesThe PR sizes compaction around the incoming request, isolates memory housekeeping from conversation history, and schedules optional maintenance after foreground replies finish. Merge readiness⛔ Blocked before merge - 2 items remain The PR remains useful: current main still has the old compaction and memory-flush paths. The prior activity-projection finding is addressed, and no new blocking defect was found in the reviewed changes. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw’s agent runtime combines conversation history, instructions, tools, and incoming messages for model inference. Compaction and memory maintenance manage that context while the session owner coordinates delivery, cancellation, and transcript writes. flowchart TD
A[Incoming message] --> B[Foreground session admission]
B --> C[Prepared request budget]
C --> D[Required checkpoint and compaction]
D --> E[Model inference and reply delivery]
E --> F[Optional maintenance owner]
F --> G[Private memory conversation]
F --> H[Canonical history compaction]
A -->|Cancel and settle optional work| F
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep request sizing and transcript replacement with their existing owners, with private memory execution and cancellable optional maintenance after delivery. Do we have a high-confidence way to reproduce the issue? Yes, the current-main source and supplied before/after runs establish concrete compaction-budget and utility-transcript failure paths; this read-only review did not execute them. Is this the best way to solve the issue? Yes, the patch repairs the owning request-budget and maintenance lifecycle boundaries while preserving manual compaction, source policy, and existing configuration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7115aca8246f. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (13 earlier review cycles; latest 8 shown)
|
830c705 to
bbbad8f
Compare
781ea6f to
c82fa76
Compare
|
@clawsweeper re-review The repaired head is c82fa76. Both required and optional memory inference now use private conversation views, preserving prepared model facts and source policy. Real SQLite/inference regressions reproduce the former transcript pollution and confirm exact subsequent human input after the fix; owner cancellation no longer increments memory failure counts. Types, lint, architecture guards, focused tests and independent review pass. The PR body retains the earlier failed evidence and marks exact-head CI plus actual repaired-revision CLI/Tauri validation as pending merge gates. |
Related: #121617, #53008
Problem and behavior
Large incoming requests can remain over budget after automatic compaction when the retained history is sized without the system prompt, tools, pending input and queued context. Background memory work can also delay an already completed reply, appear as ongoing user activity, or leave internal messages that orphan recovery carries into the next human prompt.
Automatic compaction now consumes the prepared foreground request budget, preserves the admitted unprocessed user independently of that budget, and retains complete exchanges. It fits the summary before quality auditing. When fixed text consumes the preferred reserve, it can still reclaim older history, but the replacement must strictly shrink. An intentional automatic no-op returns through its owner instead of becoming a foreground failure; public manual-compaction settlement keeps its result contract.
Memory inference uses a private, detached conversation view. Required checkpoints read the processed prefix before the admitted user; optional checkpoints read the completed conversation. Both preserve the source policy, cache identity and restricted append-only memory tools. Utility messages and private summaries never become source transcript entries or source compaction accounting. Memory success/failure stays on the original session, and actual owner cancellation does not count as a failed memory attempt.
Persistent Gateway sessions start optional maintenance after delivery and foreground-owner settlement. A new human turn cancels it and waits for the real writer to settle. Presentation uses the recorded visibility policy, so a completed reply stays completed while hidden work is active. Its owner remains available for cancellation. One-shot CLI commands finish without leaving post-return maintenance behind. Native runtimes retain their own compaction ownership. Nested maintenance now uses recorded dependencies consistently for execution, reads and foreground admission, avoiding a parent/queued-sibling/child circular wait while preserving independent sibling serialization. Dependency references are released with write ownership.
Compatibility and scope
This changes maintenance timing and internal execution ownership through existing flows. It adds no operator setting, model default, database schema/version/table/column, stored transcript format or migration. The private conversation manager has no persistence target; source memory metadata retains its existing representation. Pending input, manual compaction, source session admission, conversation tool policy, sandbox classification and cache ownership remain explicit contracts.
The preferred reserve is not a new hard provider admission limit. Required preflight occurs before the complete foreground request exists; it preserves the admitted input and may intentionally leave compaction to the later prepared-request boundary. This does not claim to fix every historical issue in the related threads.
Validation
Final candidate:
62a7df7596bc94e1d9b1fbef1e2e3bccd632594d, based on3967d9b6df1f478c32b0c4127bbadf5c51f1878f. The completed full-PR review identified one nested-maintenance dependency cycle. Its regression failed twice on the unchanged code; the repaired coordinator and lifecycle/ownership/queue suites passed 48 tests. Follow-up P0–P2 review is clean. Production types, all 16 selected dependent test-type graphs, typed lint, formatting and diff checks pass.The rebase preserves main's successful no-op plugin-hook contract from #118094; 244 hook/runtime/queue tests passed. CI on the preceding head failed only because main's split release pages exceeded an old docs-test route pattern. Main fixed that separately in #140337. The final refresh carries all eight reviewed commits without patch changes; the full docs-sync test file and coordinator suite pass all 27 cases, including the failed CI assertion. CI for this exact final head passed.
Live-model evidence below uses the clean, fully built
c82fa7647fa634be8053a99c3988926c5096189crevision. The final memory helper/runner and request-budget files are byte-identical to that tested revision, and the native app source tree is identical. The later no-op hook integration and coordinator dependency repair have the focused proof above; the native case exercises a single optional owner and does not claim to reproduce the nested-owner cycle. Dependency versions, lockfile and workspace configuration are unchanged. Earlier memory/command suites and the 123-case prepared-metadata regression pass; counts overlap and are not additive. The earlier CI fixture repair passed the full 103-test delivery file plus ten private-memory/helper tests.Real SQLite/inference regressions reproduce canonical utility pollution after both completed and interrupted memory work on the previous head. They also reproduce a false memory-failure counter from a plain Error cancellation reason. With private execution, the canonical transcript stays byte-for-byte unchanged and the next provider user input equals the normal timestamp prefix plus the exact original human bytes. Required checkpoint tests also exercise real restricted memory-file writes, preserved restart-safe admitted input, and both intentional no-op and committed-compaction paths.
Other retained owner coverage includes full-request/queued/transient context, complete tool-call/result groups, bounded context, private custom-engine rewrites, delivery settlement, cancellation and stale writer rejection. The complete production build passed on
c82fa7647fa6, and the matched real-model measurements below use that exact clean source. Earlier stale-fixture failures remain preserved: incomplete raw transcript rows lacked the current canonical header, while three assertions expected the retired shared execution identity. The fixtures now use canonical writers and distinguish private execution from source policy; thresholds and behavioral assertions stay intact.Measurements and actual native proof
Four matched full-build Metal arms ran once in order main 1 → candidate 1 → main 2 → candidate 2, using the same two original frozen conversations. Both candidates passed exact recall; main's second reply returned the right identifiers in uppercase and remains a strict failure. All twelve prepared user inputs matched the original bytes. Each arm left zero owned processes and preserved configuration, route, and wire settings: Qwen3.5 4B Q4_K_M, Ollama 0.33.3, 32K context, thinking off, automatic tool search, and an unset lean flag.
b52fb52bc82fa764The runtime isolation is directly observed: all three candidate private memory identities left zero session/transcript rows, and each candidate retained exactly the three submitted user turns. Main's first recall request replayed an internal utility user message; the candidate did not. Timing is mixed, and these individual runs do not establish universal speed or model-quality superiority. The repaired-source Linux CPU CLI passed all three original turns: archive 224.617 s, bulk 552.249 s, and recall 235.497 s; the whole case took 1,014.146 s. Actual input tokens were 18,504 / 20,246 / 19,181, compaction counts were 0 / 1 / 1, all replies were exact, and foreground tool calls were zero. Cleanup observed ten owned processes and zero survivors. This is correctness evidence, not a CPU speedup claim. The actual Tauri archive/bulk/recall case also passed all three exact visible replies and exact prepared/native human-input checks. Its UI case took 1,044.687 s; the final maintenance observation took another 90.169 s, for 1,134.856 s within the original 2,100 s bound. Compaction committed after visible recall completion, then the exact final owner settled. This proves background compaction after the replies, not recall from compacted history. Configuration and wire defaults remained unchanged, with 24 observed owned processes and zero survivors after cleanup.
The preceding matched full-build Metal pairs on
902774/bbbad8fdpassed all twelve exact replies, but the candidate was slower overall: 95.190 versus 92.946 seconds and 80.435 versus 71.933 seconds. Earlier CPU measurements also showed a slower whole conversation despite a faster bulk turn. Those negative results remain preserved; this work does not justify changing model defaults or claiming a universal speedup.Earlier native failures remain failures. The viewport-corrected replay displayed all three exact replies, but its aggregate failed because shutdown cancelled post-recall compaction before commit. The optional-interruption replay displayed both exact replies and an idle completed UI, but strict prepared-input validation exposed the utility transcript bug fixed here. The repaired revision repeated the conversation successfully and waited within the original deadline for owner settlement before cleanup. Its optional-interruption attempt remained unexercised: the observer rejected the copied source-header session ID because it incorrectly expected the private execution session ID. Source and raw records confirm these are deliberately separate identities; the detached header preserves cache affinity. That failed attempt remains preserved. The corrected observer requires the exact canonical source-header ID and the exact private run/session key separately. Its actual-record regression reproduces the rejected selection without relabeling the failed attempt. The fresh original interruption case then passed all unchanged input, owner, HTTP, native-task and cleanup checks.
The fresh 640-row native interruption case passed both exact replies and kept the first reply visibly completed while private inference was active. Source preemption was recorded at 17:51:08.884 UTC and owner settlement at 17:51:08.915 UTC: a recorded 31 ms interval. The next foreground stream began at 17:51:09.379 UTC. Conservative timestamp bounds establish that the private HTTP handler was still open when preemption was requested; all three request/body/header/task assignments are unique and complete. The old task's release precedes the next task's processing in the observed backend stream. This is a handler-lifetime and observed-order claim, with the recorded no-clock-step assumption.
The large CPU-only case still took 295.867 s and 275.976 s from pre-click to visible completion, with 21,244 and 20,174 input tokens. Its whole UI case took 582.972 s. Both prepared human inputs and full native histories match, and the physical source transcript contains exactly the two submitted user turns with no utility contamination. Configuration and wire defaults are unchanged; cleanup observed 24 owned processes and zero survivors. The complete 4,824-file private archive is hash-verified, earlier negative evidence is preserved, and the test lease is stopped.
Review context
The full PR has +1,687 net production lines, +4,331 test/support lines, and +32 documentation lines; the assertion baseline is net-neutral and pure test moves are discounted. Growth implements full-request budgeting and separately owned maintenance. The final private-memory repair removes 78 net production lines by deleting source-side utility rotation/accounting. The dependency repair adds 16 net production lines to record the actual wait relation, replacing duplicated sequence-based inference and clearing obsolete edges at release. Inspected synthetic native captures are below. Existing lifecycle-invocation follow-up remains separate; this PR does not redesign the context-engine LLM invocation capability. Release-note context: fit automatic compaction to the complete incoming request, preserve pending input, and isolate memory maintenance so completed replies stay responsive and later human prompts remain clean.
Native captures
Before: a completed ACK is followed by a busy spinner and Stop control during housekeeping. After: the reply stays completed while the independently verified private inference is active.
Exact recall and completed interruption replies