Repository navigation
fix(agents): preserve cached history when background work changes - #140799
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: needs maintainer review before merge. Reviewed September 7, 2026, 2:37 AM ET / 06:37 UTC. ClawSweeper reviewWhat this changesMoves background process, subagent, and media progress into current-turn context, relocates variable guidance below stable instructions, and updates regression coverage and documentation. Merge readiness✅ Ready for maintainer review This remains a useful fix: inspected main and release sources still place changing background state ahead of conversation history. No actionable introduced defect was found, and the maintainer-authored PR is protected from automatic closure. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s agent runner combines instructions, conversation history, available tools, and background-work status into model requests. Their placement determines how much earlier request content providers can reuse from cache. flowchart TD
A[Background work registries] --> B[Capability and session filtering]
B --> C[Bounded current snapshots]
C --> D[Current-turn runtime context]
E[Stable instructions] --> G[Model request]
F[Conversation history] --> G
D --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +2, Tests +506, Docs +1. Total +509 across 35 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep stable capability guidance in instructions and deliver changing session facts through the existing bounded runtime-context lifecycle. Do we have a high-confidence way to reproduce the issue? Yes, from source: changing active media state changes the system-prompt addition on inspected main, ahead of conversation history. Runtime reproduction was not executed in this read-only review. Is this the best way to solve the issue? Yes. Reusing the existing runtime carrier addresses the owning placement error while preserving replay policy, transcript isolation, and execution allowlists. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a2770e4592fe. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
Move bounded exec, subagent, and media snapshots into current-turn runtime context, retaining capability-based instructions in the stable system prompt. Explicit empty snapshots supersede old retained facts. Preserve cataloged native capabilities without expanding execution allowlists. Keep Project Memory facts and contextual ACP, Ultra, and elevated-level text below the system cache boundary. Preserve runtime-only event system context, existing carrier retention, and structured process data for compaction hooks.
b99b79d to
2f56b18
Compare
|
Merged via squash.
|
…enclaw#140799) * fix(agents): preserve cached history when background work changes Move bounded exec, subagent, and media snapshots into current-turn runtime context, retaining capability-based instructions in the stable system prompt. Explicit empty snapshots supersede old retained facts. Preserve cataloged native capabilities without expanding execution allowlists. Keep Project Memory facts and contextual ACP, Ultra, and elevated-level text below the system cache boundary. Preserve runtime-only event system context, existing carrier retention, and structured process data for compaction hooks. * test(agents): distinguish runtime carriers in memory turn fixtures
…ier assertions - Add src/agents/model-provider-local.ts to scripts/pr-lib/wrapper-components.txt (sorted between model-extra-params.ts and model-ref-profile.ts). The file was imported by internal-runtime-context.ts in openclaw#149585 but not added to the anchored-copy inventory; fixture copies lacked the module, causing ERR_MODULE_NOT_FOUND in shards 23/25/36/40/42. - Sync wrapper-components.txt with current main (includes entries added since the branch's last merge). - Remove 'test-provider' from CLOUD_PROVIDER_ID_PREFIXES in internal-runtime-context.ts. The entry existed to keep two integration suites green after openclaw#140799 added the findIndex(carrier) > userIndex assertion, but 'test-provider' is a fixture name leaking into production and prefix-matches any user config named test-provider-*. - Update agent-runner-memory.private-transcript.test.ts:317 and agent-runner-required-maintenance.pending-input.test.ts:409 to assert toBeLessThan(userIndex): the test fixtures use openai-completions on http://127.0.0.1:<port>/v1, which isLocalProviderBaseUrl classifies as a local/self-hosted endpoint, so shouldRelocateRuntimeContextCarrierToTail returns false and the carrier stays in chronological position before the steering user. This matches the documented behaviour in attempt-session-boundary-carrier.test.ts ("does not relocate carrier to tail for custom provider with loopback baseUrl").
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers can help update the branch when needed.
What Problem This Solves
Fixes an issue where users continuing long conversations would lose cached conversation-history reuse whenever a background exec session, subagent status, or media-generation progress changed. Project Memory facts, channel-specific ACP routing, Ultra orchestration, and elevated-level changes could also rewrite the stable workspace/system prefix.
Why This Change Was Made
Compact, sorted, bounded exec/subagent/media snapshots now travel in the existing current-turn runtime carrier, with explicit empty snapshots so retained older state cannot appear current. Their instructions stay in the stable system prompt and follow available capabilities. Registered native catalog tools also remain capabilities through Code Mode; execution allowlists and foreign/client-tool exclusion are unchanged.
Project Memory facts and the specified contextual instructions move below the system cache boundary. Runtime-only event text stays in system context, while its facts use the existing append-only/transient installer. CLI media facts use current-turn append context, including inline current-user text for native transports. Structured process data remains available to compaction/context-engine hooks. No configuration, schema, persisted store, temporal-section, or Codex-harness changes.
User Impact
Background-state updates preserve the complete system prompt ahead of conversation history. Memory, channel, Ultra, and elevated-level changes preserve the stable system/workspace prefix. Agents still receive current work status, including explicit empty state, without retaining large Project Memory blocks per turn.
Evidence
Original-code regressions failed for the intended reasons: seven failures across real exec/system assembly, media assembly, full subagent attempts, and both runtime-only carrier policies; the catalog-capability regression also failed before its producer fix. The five memory/ACP/Ultra/elevated boundary cases failed before relocation.
All 23 affected test files are green across scoped runs: 671 passing tests. The five-file feature follow-up passed 195 tests (catalog capabilities 13, full subagent attempts 2, CLI preparation 159, media status 21):
node scripts/check-changed.mjs: passed (exit 0; all selected typecheck, lint, and guard steps). The scoped three-file CI-fixture follow-up also passed.scoped-clean, with zero accepted/actionable findings.pnpm prompt:snapshots:gen: seven files regenerated, byte-identical. The generator covers the unchanged Codex layers; all 17 prompt-snapshot tests passed. Embedded boundaries are exercised by the assembly regressions.docs/concepts/system-prompt.md,docs/reference/prompt-caching.md.Current CI blocker: checks-node-compact-small-33 fails the unchanged
test/loopback-ask-user-telegram-channel.test.ts:308: the direct MCP question registers, but no Telegram Bot APIsendMessageis observed. This path submits no model request and prepares onlyask_user, so the new media facts path is inactive. The two runtime-carrier-related CI jobs now pass. Stopping at this unrelated transport blocker for coordinator triage; no merge attempted.