Skip to content

fix(agents): elevated-exec guidance churn invalidates cached prompt prefix - #150099

Closed
LiuwqGit wants to merge 3 commits into
openclaw:mainfrom
LiuwqGit:feat/issue-150081-elevated-guidance-stable-prefix
Closed

LiuwqGit wants to merge 3 commits into
openclaw:mainfrom
LiuwqGit:feat/issue-150081-elevated-guidance-stable-prefix

Conversation

@LiuwqGit

@LiuwqGit LiuwqGit commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

AI-assisted: yes

Related: #150081

What Problem This Solves

Normal parent turns include elevated-exec availability facts that are absent on the subagent-completion announce turn. Rendering those facts above the stable system-prompt boundary invalidates literal prefix caches on both transitions.

Move the existing elevated-exec guidance into the existing volatile system-prompt suffix in src/agents/system-prompt.ts. No new module, permission policy, config, or instruction authority is introduced. The sandbox restriction remains in the stable prefix. The availability statements and warnings remain system/developer instructions with their existing conditions and wording.

User-visible change: delegation no longer invalidates the stable prompt prefix merely because elevated-exec facts differ between normal and announce runs. This is a bounded fix, not a claim that every source of the reporter's Ollama cache churn is fixed.

Thanks to @Eragim for reporting and @LiuwqGit for the fix. No overlap with Pash/Sarah changes was found in the three changed files.

Evidence

Built current main e5606888f0a503dba456c7fb6905e67440d6877b and merged candidate 861f22474ec9d3c27466c757f2f2f8cd4b6163dd in a secretless Node 24.16 Docker container. An isolated Gateway used the shipped OpenAI Responses provider against a capturing loopback endpoint (no real API key). A real SSH sandbox on container loopback exercised elevated-exec-enabled sessions without mounting the host Docker socket.

Through Gateway chat.send: normal parent turn → actual sessions_spawn → actual sessions_yield → child completion → parent announce → next parent turn. Both versions completed the sequence. Hashes below are SHA-256 of the captured provider instruction's stable region, through the text preceding <!-- /openclaw:attempt:STABLE --> (the transport's representation of the cache boundary).

Build / parent turn Stable bytes SHA-256
Main normal and yield 29,166 2348ece76bd1c971ac3d724ff4cc1be67bc263b80a0133af81efae535d141af6
Main announce 29,016 861223b9c8cedf146f6598c61def9d9e72aa5134d6550047f4e9475fa72c2af1
Main next normal 29,166 2348ece76bd1c971ac3d724ff4cc1be67bc263b80a0133af81efae535d141af6
Merged candidate normal, yield, announce, next normal 29,016 96c8871b26aecedfec639681eab8eecb0461663fe7bba1759682074893cd87a8

Paths are isolated per build, so compare equality within each build, not base hashes against candidate hashes. The base stable-region diff contains exactly these three removed lines; candidate keeps them in the dynamic system/developer region on normal turns:

Elevated exec is available for this session.
User can toggle with /elevated on|off|ask|full.
You may also send /elevated on|off|ask|full when needed.

Every captured parent and child turn on both builds retains this system/developer-authority restriction:

Subagents stay sandboxed without elevated/host access; host read/write depends on this session's tools and permissions.

As before, the announce run has no elevated availability fact; the next normal turn restores that fact. No warning was demoted to user content. This proves prompt bytes and instruction presence, not an Ollama latency measurement.

The merged base includes #170282 (Code Mode schema-directory guidance moved into the dynamic region) and #168169 (date/time moved into runtime context). Neither moves elevated-exec availability out of main's stable Sandbox section. The candidate preserves both upstream changes and moves the elevated block below the same boundary. The full spawn/yield/announce comparison above was rerun after merging them; the defect still reproduces on current main and is absent on the merged candidate.

Focused checks and simplification

  • Changed-file Oxfmt and Oxlint: passed, zero warnings/errors.
  • After merging current main, node scripts/run-vitest.mjs src/agents/system-prompt.test.ts src/agents/system-prompt.cache-prefix.test.ts: 60 tests passed; 48.59 seconds wall time across two selected shards.
  • Earlier negative control against base 2dd42a977aa9: the two new regressions fail on the intended prefix/placement assertions (8 existing tests pass). The refreshed current-main Gateway proof above independently reproduces the defect.
  • Keep one availability-transition equality regression and one elevated-guidance preservation regression. Existing unavailable-full-access coverage remains; remove duplicate level-transition coverage and narration comments.
  • Merge-base delta: production +17/-17 (net 0); tests +36/-25 (net +11). Hosted CI timing is reported by its jobs, not inferred from the local run.

Risk and reversibility

Two-way door: reverting restores the previous rendering positions; no persisted state or public API changes. Blast radius is agent system-prompt rendering for elevated-exec sandbox sessions; a mistake could reduce cache reuse or omit permission guidance.

@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 size: S labels Sep 16, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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: needs maintainer review before merge.

What this changes

Moves per-turn elevated-exec guidance below the stable system-prompt cache boundary.

Example: A sandboxed parent delegates through sessions_spawn and sessions_yield, then receives a child-completion announcement.

  • Before: The supplied Gateway capture shows the stable region changing from 29,166 bytes on normal turns to 29,016 bytes on announcement turns.
  • After: The reviewed candidate retains one identical 29,016-byte stable region across normal, yield, announcement, and subsequent normal turns.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong scoped Gateway proof and a correct, focused patch; overall scope remains partial against the broader linked report.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The reviewed head is exercised through Gateway chat.send in an isolated Docker environment with a real SSH sandbox and the shipped Responses transport: actual spawn/yield/completion turns retain identical stable instruction bytes and preserve permission guidance; Ollama latency improvements are expressly not claimed.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Delegation can change the otherwise stable prompt prefix and force local models to reprocess substantial context.
Reason: The supplied production-entry-point comparison establishes a concrete, narrowly repaired contributor; the Related linkage correctly avoids claiming the entire cache report is resolved.

Merge readiness

✅ Ready for maintainer review

This PR fixes a demonstrated prompt-prefix defect still present on current main, preserves permission guidance, and has no actionable review findings.

Priority: P2
Reviewed head: 861f22474ec9d3c27466c757f2f2f8cd4b6163dd

Before merge

None.

Findings

None.

Agent review details

How this fits together

The agent prompt renderer receives prepared sandbox permissions and workspace instructions, then emits stable and dynamic system instructions for provider request preparation.

flowchart LR
  A[Gateway parent turn] --> B[Sandbox permission preparation]
  B --> C[Agent prompt renderer]
  C --> D[Stable workspace prefix]
  C --> E[Dynamic elevated guidance]
  D --> F[Provider request]
  E --> F
Loading

Technical review

Best possible solution:

Land this bounded guidance relocation and retain the linked issue for remaining cache-churn contributors.

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

Current-main source shows per-turn elevated availability above the stable boundary, and the supplied Gateway trace confirms the normal-to-announcement prefix change; no target code was executed during this review.

Is this the best way to solve the issue?

Relocating the existing instructions within the existing renderer fixes their cache placement without adding another owner or changing permission enforcement.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b36ed3195cb4.

Provenance checked

  • Elevated availability and full-access warnings keeps the original intent (aed57c9: Keep elevated-full guidance truthful to effective runtime and host policy.)
  • Stable versus dynamic elevated guidance placement changes intended behavior with a stated reason (f0cc57d: Preserve cached history by moving changing elevated-level text below the boundary while retaining stable behavioral instructions.)
  • Existing level-transition regression keeps the original intent (834900c: Consolidate overlapping tests while retaining distinct prompt contracts.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified introduced change: The pinned introduction diff relocates the existing elevated guidance without changing its conditions or wording, adds focused prefix and guidance regressions, and removes the previous overlapping level-transition case. (src/agents/system-prompt.ts:832, 861f22474ec9)
  • Current main still needs the fix: Fetched main retains elevated availability and toggle guidance in the stable Sandbox section before SYSTEM_PROMPT_CACHE_BOUNDARY. (src/agents/system-prompt.ts:798, b36ed3195cb4)
  • Shipped-entry-point proof: The full PR body records an isolated Gateway chat.send comparison against base and the reviewed head, using actual spawn/yield/completion turns, the shipped Responses transport, and an SSH sandbox. Captured instructions have alternating stable hashes before and one stable hash afterward; sandbox restrictions and elevated guidance retain system/developer authority. (861f22474ec9)
  • Existing permission owner: buildEmbeddedSandboxInfo returns no sandbox information for unsandboxed runs and derives elevated guidance from the existing permission policy; the PR changes neither this producer nor execution authorization. (src/agents/embedded-agent-runner/sandbox-info.ts:79, 861f22474ec9)
  • Prompt-cache provenance: The earlier merged cache repair moved current elevated level below the boundary to preserve cached history but retained availability guidance above it; this PR addresses that remaining contributor. (src/agents/system-prompt.ts, f0cc57d6b468)
  • Complementary merged work: fix(agents): subagent completions discard cached conversation context #167898 is merged and explicitly identifies elevated-exec guidance as a separate remaining cache contributor; it complements rather than supersedes this PR. (999bf5ecc5c0)

Likely related people:

  • Peter Steinberger: Raw commit f0cc57d adds src/agents/system-prompt.ts:1437 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f0cc57d6b468; files: src/agents/system-prompt.ts)
  • Eva: Raw commit aed57c9 adds src/agents/system-prompt.ts:342 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: aed57c95ec69; files: src/agents/system-prompt.ts)

PR surface

Source 0, Tests +11. Total +11 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 17 17 0
Tests 2 36 25 +11
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 53 42 +11

Review metrics

Metric Value Why it matters
Production versus test LOC Production +17/-17; tests +36/-25 Production is a line-neutral relocation; net test growth protects availability-transition prefix equality and retained permission guidance.

Root-cause cluster

Relationship: partial_overlap
Canonical: #150081
Summary: This PR addresses elevated-guidance prefix churn within a broader report containing additional prompt and tool-cache contributors.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A focused performance fix for sandboxed delegation workflows with a demonstrated current-source failure and limited blast radius.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • 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 execution lanes are retired.

History

Review history (11 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-16T15:42:55.368Z sha 9b044959b6ad02f494160c6b214bd123d7b6be49 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-17T03:22:46.399Z sha d674a7437c2c1d29b65e7d911c60fb5ca7b10257 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-25T01:56:22.981Z sha d674a7437c2c1d29b65e7d911c60fb5ca7b10257 :: blocked before merge. :: none
  • reviewed 2026-10-06T02:45:54.645Z sha d674a7437c2c1d29b65e7d911c60fb5ca7b10257 :: blocked before merge. :: none
  • reviewed 2026-10-09T12:11:43.026Z sha cac373f3d634effdac72dc765c864dad0fb6a4fa :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T12:49:49.439Z sha 0e3d395 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-13T01:43:04.159Z sha ca1fdfe :: needs maintainer review before merge. :: none
  • reviewed 2026-10-13T01:52:53.073Z sha ca1fdfe :: needs maintainer review before merge. :: none

Reviewed October 12, 2026, 10:13 PM ET / October 13, 2026, 02:13 UTC (Revision 12).

@LiuwqGit
LiuwqGit force-pushed the feat/issue-150081-elevated-guidance-stable-prefix branch from d35195f to 9b04495 Compare September 16, 2026 14:54
@LiuwqGit

Copy link
Copy Markdown
Contributor Author

Follow-up on the ClawSweeper review: CI failures fixed and the proof gap closed with a run through the production turn-preparation chain. Head is now 9b044959b6a.

1. CI failures on the previous head (d35195f2d30)

Both were caused by this PR and are fixed:

  • check-lint-core-2 — typescript(no-unnecessary-boolean-literal-compare) at src/agents/system-prompt.ts:1447. Inside the elevated narrowing the field is boolean, so === false was flagged. Gone with the relocation below.
  • checks-fast-baseline-ratchets — check-line-cap-ratchet rejected growth of two already-over-cap files (system-prompt.ts 1488 → 1490, system-prompt.test.ts 2450 → 2487). Per the ratchet's own instruction ("extract a coherent sibling module; never trim coverage or disable max-lines"):
    • the elevated guidance block moved into a new sibling module src/agents/system-prompt-elevated-guidance.ts (buildElevatedGuidanceLines, plus the now module-private formatFullAccessBlockedReason). Pure relocation — same conditions, same text; system-prompt.ts is now smaller than base.
    • the new regression coverage moved to the topical sibling src/agents/system-prompt.cache-prefix.test.ts (split into a placement test and a guidance-retention test). No assertion was dropped; system-prompt.test.ts is back to its base line count.

Re-run locally and green: scripts/check-line-cap-ratchet.mts → Line-cap ratchet OK: 4 changed source files; no new violations or over-cap growth.; scripts/check-max-lines-ratchet.mts → max-lines ratchet OK: 824 grandfathered suppressions.; validate.sh (oxfmt + oxlint + tests + pnpm tsgo:core) all green.

2. Proof through the runtime preparation path

The previous evidence called the renderer directly with constructed elevated inputs. That gap is closed: the new proof drives the production turn-preparation chain for a normal → sessions_yield/announce → normal parent-turn sequence, with no test double standing in for any code under test:

resolveElevatedPermissions (src/auto-reply/reply/reply-elevated.ts) → resolvedElevatedLevel (rule from get-reply-directives.ts:414) → resolveEmbeddedFullAccessState → bashElevated (shape from get-reply-run-execute.ts:524) → resolveEmbeddedSandboxInfoExecPolicy + buildEmbeddedSandboxInfo (the calls made by run/attempt-system-prompt-prepare.ts:66) → buildEmbeddedSystemPrompt → buildConfiguredAgentSystemPrompt → buildAgentSystemPrompt.

Only run-shape inputs are supplied (config, inbound MsgContext, session entry, resolved sandbox context). The elevated facts are derived, and they genuinely change across the transition — allowed: true → false, defaultLevel: "ask" → "off", fullAccessAvailable: true → false (blockedReason: "host-policy"), with resolveElevatedPermissions reporting the real gate failures for the announce shape.

After the patch the stable prefix digest is constant across all three turns:

normal main turn #1                     prefixBytes 6088  prefixDigest a3a58a3cd5e57b7383e91467f34cd03fc651a19ff7c0aa2d1ddb4aa8564de103
sessions_yield/announce parent re-entry prefixBytes 6088  prefixDigest a3a58a3cd5e57b7383e91467f34cd03fc651a19ff7c0aa2d1ddb4aa8564de103
normal main turn #2                     prefixBytes 6088  prefixDigest a3a58a3cd5e57b7383e91467f34cd03fc651a19ff7c0aa2d1ddb4aa8564de103
verdict: elevatedAllowedDiffersAcrossTurns=true  elevatedLevelDiffersAcrossTurns=true
         prefixStableAcrossTransition=true  prefixStableOnReturn=true  guidanceStillRenderedPerTurn=true

Before evidence — the same script with only src/agents/system-prompt.ts reverted to origin/main fails, and reproduces the reporter's alternating-digest symptom:

normal main turn #1                     prefixBytes 6238  prefixDigest f81a05dd8be81aafe4729acf682c219f379298163d8926c0d64dedb063d5b886
sessions_yield/announce parent re-entry prefixBytes 6265  prefixDigest 46fd6ea91ea2d513106bd18d945f639860b2a38a7336b580c222508c6232873b
normal main turn #2                     prefixBytes 6238  prefixDigest f81a05dd8be81aafe4729acf682c219f379298163d8926c0d64dedb063d5b886
verdict: prefixStableAcrossTransition=false
  normal:   - Elevated exec is available for this session.
            - User can toggle with /elevated on|off|ask|full.
            - You may also send /elevated on|off|ask|full when needed.
  announce: + Elevated exec is unavailable for this session.
            + Auto-approved /elevated full is unavailable here (host policy).
            + Do not tell the user to switch to /elevated full in this session.

The relocated regression tests are RED on unpatched origin/main (2 failed | 5 passed: prefix Object.is mismatch, and the guidance lines found above the boundary instead of in the suffix) and GREEN after: system-prompt.cache-prefix.test.ts 7/7, system-prompt.test.ts 177/177, embedded-agent-runner/system-prompt.test.ts 26/26.

3. Scope of the P1 merge-risk item

Stated plainly in the PR body rather than over-claimed: Ollama prompt_eval_cached_count / prompt_eval_duration were not re-measured — that needs the reporter's local-model host and model, which are not available here. What is established is the precondition: with elevated facts changing across the transition, the byte prefix handed to the provider is now identical, so the elevated-guidance contributor to the reporter's prefix invalidation is removed.

The issue's capture lists further system-message differences at the same transition (Authorized Senders, channel-specific Conversation Context, Silent Replies / completion-event guidance). Those are separate prefix contributors and are intentionally out of scope for this bounded fix, so full recovery of the reporter's ~25.4k cached-token figure is not expected from this change alone.

4. One remaining red check is unrelated

checks-node-changed-extensions-bundle-14 fails on extensions/codex/src/app-server/run-attempt.generation-finalization.test.ts > preserves successor continuity after agent_end outlives the recovered generation with Error: Codex turn settled before agent_end held finalization. That assertion is a Promise.race scheduling gate in the Codex test harness; this PR touches only src/agents/system-prompt*. The exact test passes locally on this head on repeated runs (3 passed (3), ~4.4s for that case — timing sensitive). I have no rerun permission on this repo (Must have admin rights to Repository), so a maintainer re-run of that job should clear it.

@LiuwqGit

Copy link
Copy Markdown
Contributor Author

Rank-up move from the last review ("evidence from an actual normal → yield/announce → normal run showing outgoing prefix stability and cache/prefill observations, with before/after seconds and RSS") is now in the PR body. Head is d674a7437c2, rebased onto origin/main (13c6d9e16c1).

1. Real gateway run, measured on the wire

The qa-lab e2e harness now boots the real thing instead of calling the renderer:

  • real gateway child process (node dist/index.js, qa-lab owner harness, pid 262069)
  • real channel plugin carrying the inbound/outbound messages
  • real Docker sandbox (agents.defaults.sandbox.mode = all)
  • local OpenAI-Responses endpoint that captures every outgoing request body

Turn sequence driven through it: inbound message → sessions_spawn → sessions_yield → child-completion announce re-entry → second inbound message (5 wire requests captured: 4 parent, 1 child). The system message each parent turn hands the provider is analysed as captured, split at SYSTEM_PROMPT_CACHE_BOUNDARY.

Both runs use the same harness, config and turn sequence; the only difference is src/agents/system-prompt.ts (patched vs. reverted to origin/main), with dist/ rebuilt (build-all.mts qaRuntime, OPENCLAW_BUILD_PRIVATE_QA=1) between them:

run     turn                          system B   stable B  stable sha256[:16]   LCP w/ prev   elevated lines in stable
BEFORE  normal main turn #1              28180      23095   384af9116c5501df          -                 3
        sessions_yield/announce          26606      22945   b321bc982f2abf00      12901                 0
        normal main turn #2              28180      23095   384af9116c5501df      28180 (full)          3
AFTER   normal main turn #1              28180      22945   69b4a50abb8c0b61          -                 0
        sessions_yield/announce          26606      22945   69b4a50abb8c0b61      24722                 0
        normal main turn #2              28180      22945   69b4a50abb8c0b61      28180 (full)          0
  • Cache/prefill observation: at the announce transition the part of the outgoing system message a literal-prefix cache cannot reuse drops from 26606 − 12901 = 13705 bytes to 26606 − 24722 = 1884 bytes (−86.3 %), and the 22945-byte stable section collapses from two alternating digests to one identical digest across all three turns. The three lines that churned before the patch are exactly the relocated guidance (Elevated exec is available for this session., User can toggle with /elevated on|off|ask|full., You may also send /elevated on|off|ask|full when needed.).
  • Guidance not lost: on both normal turns all four elevated markers still render below the boundary; the announce re-entry's run shape carries no elevated availability, which is why the pre-patch prefix churned.
  • Seconds / RSS (gateway process tree): before turn1 3.39 s / announce 1.54 s / turn2 0.87 s, RSS 993.0 → 1006.7 → 1022.1 MB; after turn1 3.50 s / announce 1.58 s / turn2 0.71 s, RSS 835.7 (ready) → 991.1 → 1005.9 → 1016.9 MB. These show the relocation costs nothing; the model-side prefill win is not claimed, because the endpoint is local — Ollama prompt_eval_cached_count / prompt_eval_duration still need the reporter's host and model.
  • The harness is an evidence-only qa-lab e2e file (needs real Docker + the private QA plugin surface) and is deliberately not part of this diff. Happy to commit it as a permanent wire-level regression if maintainers want it in-tree.

2. Rebased, so CI is fresh

The two red jobs on 9b044959b6a were both unrelated to this diff and are re-running on the new head:

  • checks-node-changed-extensions-bundle-14 — extensions/codex/.../run-attempt.generation-finalization.test.ts > preserves successor continuity after agent_end outlives the recovered generation, a Promise.race scheduling gate in the Codex harness; this PR touches only src/agents/system-prompt*.
  • checks-node-compact-small-34 — test/scripts/plugin-prerelease-telegram-shards.test.ts (Test timed out in 120000ms) and test/scripts/telegram-e2e-userbot-skill.test.ts; the same shard also logged [oxlint:timeout-test] failed (exit 124) and [oxlint:timeout-group-test] failed (exit 124), i.e. a starved runner, and neither test is reachable from this diff.

I have no rerun permission on this repo, hence the rebase to get a fresh run.

3. Local verification on the new head

  • src/agents/system-prompt.cache-prefix.test.ts 7/7, src/agents/system-prompt.test.ts 177/177, src/agents/embedded-agent-runner/system-prompt.test.ts 26/26
  • validate.sh (oxfmt + oxlint + same-directory tests + pnpm tsgo:core) all green
  • scripts/check-line-cap-ratchet.mts → Line-cap ratchet OK: 4 changed source files; no new violations or over-cap growth.; scripts/check-max-lines-ratchet.mts → max-lines ratchet OK: 822 grandfathered suppressions.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 17, 2026
@LiuwqGit

Copy link
Copy Markdown
Contributor Author

CI on d674a7437c2: 167 checks green, one red — checks-node-changed-extensions-bundle-11, and it is a timing flake in an unrelated extension test, reproduced locally on this head:

FAIL  extension-providers  extensions/qwen/video-generation-provider.test.ts > qwen video generation provider > submits as…
AssertionError: expected 119999 to be 120000 // Object.is equality
  ❯ expectPostJsonRequest extensions/qwen/video-generation-provider.test.ts:74:29
     74|   expect(request.timeoutMs).toBe(120_000);

Two consecutive local runs of that single file on this exact head:

--- run 1 ---  Test Files 1 passed (1)   Tests 27 passed (27)
--- run 2 ---  Test Files 1 failed (1)   Tests 1 failed | 26 passed (27)   + 119999

So the assertion is a 1 ms wall-clock race in how the shared provider-HTTP owner derives the remaining request budget — it passes or fails depending on how much of the budget was consumed before the request record was captured. This PR touches only src/agents/system-prompt.ts, src/agents/system-prompt-elevated-guidance.ts and their two test files; extensions/qwen/video-generation-provider.ts is built from openclaw/plugin-sdk/video-generation and shares no code with the prompt renderer. The other 1295 tests in that shard passed.

I have no rerun permission on this repo (Must have admin rights to Repository), so a maintainer re-run of that job should clear it. Everything else — including checks-fast-baseline-ratchets, check-lint-core-2 and the two jobs that were red on the previous head — is green.

@LiuwqGit

LiuwqGit commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (cac373f3d63, parent 4938f90b94a) and re-applied the change against the refactored system-prompt.ts.

The previous red checks-node-changed-extensions-bundle-11 was an unrelated upstream flake in extensions/qwen/video-generation-provider.test.ts (strict expect(timeoutMs).toBe(120_000) racing clock ticks) — fixed on main in #150523 a few minutes after this branch's original base was cut. The rebase picks that fix up.

Re-verification on the new head:

  • RED: new cache-prefix regression tests fail with src/agents/system-prompt.ts reverted to origin/main (2 failed: prefix differs across elevated-availability changes; guidance lines found above the boundary).
  • GREEN: src/agents/system-prompt.cache-prefix.test.ts 10/10 (incl. 2 new), src/agents/system-prompt.test.ts 48/48, src/agents/embedded-agent-runner/system-prompt.test.ts 24/24, plus validate.sh (oxfmt + oxlint + tsgo:core) all green.
  • The adapted elevated-level changes expectation in system-prompt.test.ts now places the toggle guidance in the suffix alongside Current elevated level:.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 9, 2026
…refix

Elevated-exec availability and toggle guidance rendered above the system
prompt cache boundary, so a parent turn whose elevated permissions differ
from the previous turn (normal vs sessions_yield/announce re-entry) produced
a different stable prefix and defeated provider-side literal prefix caching.

Move the guidance below the boundary, next to the existing per-turn
"Current elevated level:" line, and cover prefix stability across
elevated-availability changes.

Fixes openclaw#150081
@LiuwqGit
LiuwqGit force-pushed the feat/issue-150081-elevated-guidance-stable-prefix branch from cac373f to 0e3d395 Compare October 9, 2026 12:42
@LiuwqGit

LiuwqGit commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Slimmed to 0e3d3957c75: the guidance move is now a pure in-file relocation (7 entries moved verbatim below the boundary, next to Current elevated level:), dropping the 86-line sibling module — src/agents/system-prompt.ts is well under the line cap after the upstream refactor, so extraction was no longer needed. Diff is now 3 files, +84/−24.

Re-verified: RED on unpatched system-prompt.ts (2 cache-prefix tests fail), GREEN after (cache-prefix 10/10, system-prompt 48/48, embedded-agent-runner 24/24), oxlint + tsgo:core green.

@obviyus

obviyus commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Oct 13, 2026
@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Oct 13, 2026
@obviyus

obviyus commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks @LiuwqGit. We proved this on a built Gateway: the stable prefix hash changed on every spawn/yield/announce transition on main and stayed fixed with your change. While it was in final checks, #170516 (0e6eb69) landed on main and moved the whole Sandbox section, including all the elevated-exec lines, below the cache boundary. That supersedes this PR's relocation, and the PR now conflicts, so I'm closing it as superseded. Your report and proof in #150081 helped show the gap.

@obviyus obviyus closed this Oct 13, 2026
sectrgt added a commit to sectrgt/openclaw that referenced this pull request Nov 7, 2026
…e/yield turns

Fixes openclaw#150081: Ollama prompt_eval_cached_count drops from ~25k to ~14k
tokens when transitioning between normal main turns and sessions_yield/
announce turns, causing prompt evaluation time to increase from ~11s to
~123-203s.

Changes:
- system-prompt.ts: Always render Silent Replies section; always use
  standard output directives variant; always render Control UI Embed
  when message tool available
- system-prompt-messaging.ts: Always use same completion-event guidance
  wording referencing SILENT_REPLY_TOKEN
- get-reply-run-execute.ts: Fall back to resolveConfiguredCommandOwners
  when command.ownerList is empty (announce turns with no sender)
- system-prompt-cache-stability.test.ts: Regression tests

Prior partial fixes (all merged):
- openclaw#167898: Conversation Context stabilization
- openclaw#175309: Tool definition stabilization
- openclaw#170516: Sandbox/elevated section moved below boundary

Related: openclaw#98261, openclaw#150099
sectrgt added a commit to sectrgt/openclaw that referenced this pull request Nov 16, 2026
…e/yield turns

Fixes openclaw#150081: Ollama prompt_eval_cached_count drops from ~25k to ~14k
tokens when transitioning between normal main turns and sessions_yield/
announce turns, causing prompt evaluation time to increase from ~11s to
~123-203s.

Changes:
- system-prompt.ts: Always render Silent Replies section; always use
  standard output directives variant; always render Control UI Embed
  when message tool available
- system-prompt-messaging.ts: Always use same completion-event guidance
  wording referencing SILENT_REPLY_TOKEN
- get-reply-run-execute.ts: Fall back to resolveConfiguredCommandOwners
  when command.ownerList is empty (announce turns with no sender)
- system-prompt-cache-stability.test.ts: Regression tests

Prior partial fixes (all merged):
- openclaw#167898: Conversation Context stabilization
- openclaw#175309: Tool definition stabilization
- openclaw#170516: Sandbox/elevated section moved below boundary

Related: openclaw#98261, openclaw#150099
sectrgt added a commit to sectrgt/openclaw that referenced this pull request Nov 17, 2026
…e/yield turns

Fixes openclaw#150081: Ollama prompt_eval_cached_count drops from ~25k to ~14k
tokens when transitioning between normal main turns and sessions_yield/
announce turns, causing prompt evaluation time to increase from ~11s to
~123-203s.

Changes:
- system-prompt.ts: Always render Silent Replies section; always use
  standard output directives variant; always render Control UI Embed
  when message tool available
- system-prompt-messaging.ts: Always use same completion-event guidance
  wording referencing SILENT_REPLY_TOKEN
- get-reply-run-execute.ts: Fall back to resolveConfiguredCommandOwners
  when command.ownerList is empty (announce turns with no sender)
- system-prompt-cache-stability.test.ts: Regression tests

Prior partial fixes (all merged):
- openclaw#167898: Conversation Context stabilization
- openclaw#175309: Tool definition stabilization
- openclaw#170516: Sandbox/elevated section moved below boundary

Related: openclaw#98261, openclaw#150099
sectrgt added a commit to sectrgt/openclaw that referenced this pull request Nov 18, 2026
…e/yield turns

Fixes openclaw#150081: Ollama prompt_eval_cached_count drops from ~25k to ~14k
tokens when transitioning between normal main turns and sessions_yield/
announce turns, causing prompt evaluation time to increase from ~11s to
~123-203s.

Changes:
- system-prompt.ts: Always render Silent Replies section; always use
  standard output directives variant; always render Control UI Embed
  when message tool available
- system-prompt-messaging.ts: Always use same completion-event guidance
  wording referencing SILENT_REPLY_TOKEN
- get-reply-run-execute.ts: Fall back to resolveConfiguredCommandOwners
  when command.ownerList is empty (announce turns with no sender)
- system-prompt-cache-stability.test.ts: Regression tests

Prior partial fixes (all merged):
- openclaw#167898: Conversation Context stabilization
- openclaw#175309: Tool definition stabilization
- openclaw#170516: Sandbox/elevated section moved below boundary

Related: openclaw#98261, openclaw#150099
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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: 👀 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.

2 participants