Skip to content

fix(agents): preserve cached history when background work changes - #140799

Merged
steipete merged 2 commits into
mainfrom
kv/runtime-facts-in-runtime-context
Sep 7, 2026
Merged

steipete merged 2 commits into
mainfrom
kv/runtime-facts-in-runtime-context

Conversation

@steipete

@steipete steipete commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor
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/run-vitest.mjs \
  src/agents/embedded-agent-runner/run/attempt.tool-search-run-plan.test.ts \
  src/agents/embedded-agent-runner/run/attempt.subagent-runtime-facts.test.ts \
  src/agents/cli-runner/prepare.test.ts \
  src/agents/media-generation-task-status-shared.test.ts \
  src/agents/media-generation-task-status.test.ts
  • 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.
  • Codex autoreview, high reasoning, P0/P1 scope: both the feature and final CI-fixture follow-up were scoped-clean, with zero accepted/actionable findings.
  • CI follow-up: all four required/optional memory integration cases pass. Synthetic models now distinguish whole runtime-only carriers from actual user text; exact input/timestamp, checkpoint, compaction, and transcript-isolation assertions remain, with new carrier count/order checks. No timeout or budget changed.
  • 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 updated: docs/concepts/system-prompt.md, docs/reference/prompt-caching.md.
  • Production diff: +236/−234 lines (net +2). Validation measures prompt bytes and runtime behavior; no live-provider cache billing claim.

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 API sendMessage is observed. This path submits no model request and prepares only ask_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.

@clawsweeper

clawsweeper Bot commented Sep 7, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Sep 7, 2026
@steipete
steipete marked this pull request as ready for review September 7, 2026 04:41
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 2:37 AM ET / 06:37 UTC.

ClawSweeper review

What this changes

Moves 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
Reviewed head: 2f56b180c7462414c92cb2d0d04ca29d6bb1ab66

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent owner-level repair with meaningful regression coverage and no supported blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied MEMBER association exempts this PR from external-contributor proof requirements; inspected assembly and replay tests support the changed runner path, but do not establish live-provider cache savings.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied MEMBER association exempts this PR from external-contributor proof requirements; inspected assembly and replay tests support the changed runner path, but do not establish live-provider cache savings.
Evidence reviewed 8 items Pinned change ownership: Reviewed the merge-base-to-head changes. Raw test-merge parents match the pinned base followed by the exact PR head; unrelated endpoint drift was excluded.
Problem remains on inspected main: Current-main prompt assembly still obtains mediaTaskSystemPromptAddition and inserts it into the system prompt. The requested relocation remains necessary; no verified merged replacement was established.
Latest supplied release check: The v2026.9.2 source also retains the media system-prompt addition; this review does not identify a released fix.
Findings None None.
Security None None.

How this fits together

OpenClaw’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
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +2, Tests +506, Docs +1. Total +509 across 35 files.

View PR surface stats
Area Files Added Removed Net
Source 15 236 234 +2
Tests 18 835 329 +506
Docs 2 4 3 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 35 1075 566 +509

Review metrics

Metric Value Why it matters
Production versus test growth Production +236/−234; tests and fixtures +835/−329 Production remains nearly size-neutral while added coverage protects prompt bytes, replay, and transcript isolation.

Technical review

Best 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.

Labels

Label justifications:

  • P2: Repairs avoidable cache churn during ongoing conversations without evidence of an urgent availability or delivery regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied MEMBER association exempts this PR from external-contributor proof requirements; inspected assembly and replay tests support the changed runner path, but do not establish live-provider cache savings.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-07T04:47:27.097Z sha 656f2dd :: needs maintainer review before merge. :: none
  • reviewed 2026-09-07T05:23:36.004Z sha b99b79d :: needs maintainer review before merge. :: none
  • reviewed 2026-09-07T05:41:40.373Z sha b99b79d :: needs maintainer review before merge. :: none

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.
@steipete
steipete force-pushed the kv/runtime-facts-in-runtime-context branch from b99b79d to 2f56b18 Compare September 7, 2026 06:31
@steipete
steipete merged commit f0cc57d into main Sep 7, 2026
174 checks passed
@steipete
steipete deleted the kv/runtime-facts-in-runtime-context branch September 7, 2026 06:53
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 8, 2026
…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
shreyanshjain05 added a commit to shreyanshjain05/openclaw that referenced this pull request Sep 17, 2026
…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").
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 P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant