Skip to content

fix(agents): omit empty none runtime-fact sections from the tail carrier - #150290

Closed
Bartok9 wants to merge 1 commit into
openclaw:mainfrom
Bartok9:bartok9/nightly-hunt-20260916
Closed

Bartok9 wants to merge 1 commit into
openclaw:mainfrom
Bartok9:bartok9/nightly-hunt-20260916

Conversation

@Bartok9

@Bartok9 Bartok9 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Literal none snapshots for idle process / subagent / media / Windows-exec facts made buildRuntimeContextCustomMessage attach on every turn. On local engines whose history entry must match exactly, that trailing carrier moves each request and pins prefix reuse at the system prompt.

Omit information-free sections unless appendOnlyRuntimeContext needs an explicit empty supersede (Anthropic-style append-only).

Fixes #150286

Test plan

  • src/agents/runtime-facts-prompt.test.ts
  • src/agents/embedded-agent-runner/run/attempt-prompt-context.test.ts
  • Local vitest CLI failed to start in this worktree (defineCacheKeyGenerator); same as 2026-09-15 nightly.

Literal none snapshots for idle process/subagent/media/exec facts made
buildRuntimeContextCustomMessage attach on every turn, which pins local
prefix caches at the system prompt. Keep none only when append-only
runtime context needs an explicit empty supersede.

Fixes openclaw#150286
@clawsweeper

clawsweeper Bot commented Sep 16, 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 agents Agent runtime and tooling triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. size: S labels Sep 16, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

The PR omits empty background-work and executable-approval facts from model requests, while retaining explicit empty snapshots when earlier facts remain in conversation history.

Example: A user continues a conversation with process and subagent tools available but idle.

  • Before: Each request receives a trailing context message containing “Active exec sessions: none” and “Active Subagents: none”.
  • After: Those idle sections are omitted unless the route retains context messages and needs an explicit clearing snapshot.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Real runtime measurements support the useful idea, but the original branch misses a retained-session caller and main already contains the complete approach.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The linked repaired descendant exercises the same idle-fact omission through agent --local on isolated instances and records cache reuse improving from 0.0% to 99.7%, with runtimeContextChars dropping from 52 to 0. This supports the producer behavior; the original branch's separate CLI clearing defect remains a functional finding.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: No · Fix scope: Complete
User problem: Continuing an idle conversation repeatedly recomputes its history instead of reusing the model's prompt cache, increasing latency and inference cost.
Reason: The original repair addresses a measured user problem, but landing this branch now adds no distinct value over the merged implementation.

Merge readiness

⛔ Blocked before merge - 3 items remain

Current main already contains the useful change, but this PR has an assigned reviewer and therefore falls under the maintainer-engaged keep-open policy. The previous closure proposal overlooked that guard.

Priority: P2
Reviewed head: e54ca31208360540c870bc4c5220c03985ff8d59
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should this assigned PR be retired in favor of the merged implementation at fix: prevent internal runtime context from appearing in replies #163471?
  • Recommendation: Retire the superseded branch: Confirm closure while preserving the original contribution and runtime measurements through the linked merged work.
  • Why: The useful behavior is present on main, but the active reviewer assignment invokes the maintainer-engaged keep-open policy.

Before merge

  • Preserve empty media snapshots for resumed CLI sessions (P1) - The CLI caller in src/agents/cli-runner/prepare.ts calls this shared producer without includeEmptySnapshots. After a resumed session has received an active image, music, or video fact, a later task-less turn now emits nothing, leaving the earlier active fact in the retained conversation without a clearing snapshot. Pass includeEmptySnapshots: true from that caller and cover the active-to-empty transition. This concern is raised late: the producer is unchanged from the previously reviewed head.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
  • Product: not worth merging - The original repair addresses a measured user problem, but landing this branch now adds no distinct value over the merged implementation.

Findings

  • [P1] Preserve empty media snapshots for resumed CLI sessions — src/agents/runtime-facts-prompt.ts:47

Tests

  • Missing end-to-end proof: The exact reviewed branch has no demonstrated resumed CLI active-media-to-empty transition; the documented runtime runs used the repaired descendant.
Agent review details

How this fits together

OpenClaw assembles current background-work facts alongside each model request. The prompt builder places those facts in a separate context message and decides whether earlier context messages remain in history.

flowchart TD
  A[Current tool capabilities] --> C[Runtime fact producers]
  B[Processes, subagents, media and approvals] --> C
  C --> D{Retain earlier context?}
  D -->|Yes| E[Include explicit empty snapshots]
  D -->|No| F[Omit idle sections]
  E --> G[Model request context]
  F --> G
Loading

Technical review

Best possible solution:

Keep the merged producer-level omission and explicit clearing behavior, with distinct cache-retention work reviewed separately.

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

No current-main failure was reproduced: source now omits the reported idle sections. Historical real-engine runs establish the original trigger and an improved after-fix result; this review executed no target code.

Is this the best way to solve the issue?

Yes, conditional omission at the fact producer is the appropriate repair. The merged implementation also preserves CLI clearing snapshots that this branch misses.

Full review comments:

  • [P1] Preserve empty media snapshots for resumed CLI sessions — src/agents/runtime-facts-prompt.ts:47
    The CLI caller in src/agents/cli-runner/prepare.ts calls this shared producer without includeEmptySnapshots. After a resumed session has received an active image, music, or video fact, a later task-less turn now emits nothing, leaving the earlier active fact in the retained conversation without a clearing snapshot. Pass includeEmptySnapshots: true from that caller and cover the active-to-empty transition. This concern is raised late: the producer is unchanged from the previously reviewed head.
    Confidence: 0.98
    Late finding: first raised on code an earlier review cycle already covered.

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 e39552c18106; fix evidence: commit cd9913f1b110, main fix timestamp 2026-10-03T20:09:13Z.

Provenance checked

  • src/agents/runtime-facts-prompt.ts: process, subagent, and media snapshots changes intended behavior with a stated reason (f0cc57d: Explicit empty snapshots prevent retained older work state from appearing current while moving changing facts outside the stable prompt prefix.)
  • src/agents/runtime-facts-prompt.ts: Windows executable hints changes intended behavior with a stated reason (b5d66d8: Current approval hints moved out of tool descriptions to preserve prompt caches; empty and unavailable snapshots supersede earlier hints.)
  • src/agents/embedded-agent-runner/run/attempt-prompt-build.ts: runtime-fact carrier keeps the original intent (f0cc57d: Current work facts use the existing append-only or transient carrier rather than rewriting stable prompt context.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +24, Tests +4. Total +28 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 48 24 +24
Tests 2 13 9 +4
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 61 33 +28

Review metrics

Metric Value Why it matters
Production versus test LOC Production +48/-24; tests +13/-9 The conditional snapshot logic serves the measured cache problem, although current main already supplies it.

Root-cause cluster

Relationship: superseded
Canonical: #163471
Summary: The merged carrier work explicitly adopted the idle-snapshot omission direction; the repaired replacement was subsequently closed unmerged.

Members:

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

Labels

Label changes:

  • add merge-risk: 🚨 session-state: The branch changes the shared media producer's default without preserving clearing snapshots for resumed CLI conversations.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: The original defect increases inference latency and cost, with a bounded repair already present on main.
  • merge-risk: 🚨 session-state: The branch changes the shared media producer's default without preserving clearing snapshots for resumed CLI conversations.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 9, 2026, 8:24 PM ET / October 10, 2026, 00:24 UTC.

@fuller-stack-dev fuller-stack-dev self-assigned this Sep 18, 2026
@davidberardozzi

Copy link
Copy Markdown

Hi @Bartok9. The four blockers listed in the ClawSweeper review are addressed on a branch built on top of your commit. Your commit e54ca31208 stays the first commit of the branch, rebased onto main 7eaaeafdc1 with you as its author, so authorship of the fix stays yours.

The branch is at https://github.com/Scee-Tech-Studio/openclaw/tree/pr150290-envoi

What sits on top of your commit:

  • Rebase onto main 7eaaeafdc1, one conflict resolved: improve(agents): reduce media prompt preparation work #153656 moved buildMediaTaskRuntimeContext after this PR was opened, so the media constructor change is carried into media-generation-task-status.ts and now covers music_generate as well.
  • The CLI caller the review asked for: includeEmptySnapshots: true in buildCliTurnAppendContext (that caller moved out of prepare.ts since the review), plus a transition test for an active media task followed by none.
  • The three test files the change broke, repaired without weakening what each one protects: 14 expect added, none dropped without a replacement.
  • A real before/after run: two runtime-only builds, two isolated instances with byte-identical configs, five turns each, tools process and sessions_spawn available and at rest.

Mean of turns 2 to 5: main 0.0% cache reuse at 2.1 s TTFT, the fix 99.7% at 123 ms. The engine started lines show one message more per turn on main than on the fix, which is the carrier. djl11's replay on #150286 points the same way on OpenAI's own endpoint.

Two things worth knowing before a merge: the test scope is targeted (7 files), not the full suite; and for check:changed, guards, typecheck and lint pass; the import-cycles step was not run locally (machine memory constraint); CI runs it.

Take any or all of this into #150290, whichever shape suits you. Happy to rework the commit split, the wording or the proof if you want it differently.

@fuller-stack-dev, since you are assigned here: the branch works as it stands, pulled into this PR or opened as a separate PR crediting Bartok9, whichever is least work on your side. If main moves before review, we can rebase it again.

@davidberardozzi

Copy link
Copy Markdown

Opened #160174 with the branch described above, rebased onto current main. Two more upstream changes were absorbed on the way: #159179 replaced the media task lookup, so the includeEmptySnapshots logic is grafted onto listMediaGenerationOperations, and #159481 touched the imports of one test file. Following ClawSweeper's review, the PR also updates docs/concepts/system-prompt.md and records seconds and RSS before/after; ClawSweeper now marks it ready for maintainer review. The 7 targeted test files pass (240 tests), and "Allow edits by maintainers" is enabled. Bartok9 stays the author of the first commit.

The only red check is preflight, which hits the Node matrix cap (131 jobs for a limit of 130), the same failure as #149631.

@fuller-stack-dev, if landing this through #150290 is simpler for you, the three commits apply as they are and we will close #160174. Thanks

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 6, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for this fix and the clear write-up in #150286. The same behavior was fixed on main by #163471 (cd9913f, first released in v2026.10.1-beta.1): empty subagent/media snapshot sections are now only emitted when a caller explicitly requests empty snapshots, so the literal none sections no longer force the tail runtime-context carrier onto every request. We verified it while working on local-engine prefix caching, so this PR is superseded and I'm closing it. If you find a remaining case where an empty section still attaches the carrier, please open an issue with a request capture and we'll take it from there.

@steipete steipete closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

4 participants