Skip to content

fix(agents): store hook prompt context in the append-only runtime carrier - #166590

Closed
ruel225 wants to merge 5 commits into
openclaw:mainfrom
ruel225:fix/before-prompt-context-append-only-166271
Closed

ruel225 wants to merge 5 commits into
openclaw:mainfrom
ruel225:fix/before-prompt-context-append-only-166271

Conversation

@ruel225

@ruel225 ruel225 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Closes #166271. On models that use append-only runtime context (bindsClaudeThinkingPrefix: Opus 5.5, Fable 5.1), prependContext/appendContext returned by a before_prompt_build hook was folded into the active user prompt for one run only and never stored. The next run replayed the earlier user message without the injected block, so the request was no longer an append-only extension of the previous one:

  • every cache entry written during the run sat after that rewritten message, so none of them could be read again — a plugin injecting on every message (memory recall is the common case) restarted the prompt cache on every turn;
  • every replayed thinking block after that message was dropped (replayed thinking dropped ... prefix_binding_mismatch, prefix_mismatch_behavior: "drop_block").

OpenClaw's own per-turn context does not have this problem: it rides the runtime-context carrier, is stored hidden with the turn, and replays byte-identically. Hook context went down the older one-run rewrite path instead.

The Fix

prepareEmbeddedAttemptPromptAssembly gains appendOnlyRuntimeContext. When it is true and the prompt is non-empty, the joined hook prependContext/appendContext is no longer folded into effectivePrompt; prepareEmbeddedAttemptPromptContext instead adds it as a conversation-data runtime-context fragment, so it is stored hidden with the turn and replayed unchanged — the same treatment OpenClaw's own facts get, so plugin text is not raised to instruction level.

One routing decision, published once: review round 2 caught that the routing predicate was re-derived independently at each consumer and keyed on different fields — carrier construction keyed on the transcript prompt, submission on the assembled prompt. A runtime-only turn (non-empty prompt, empty transcriptPrompt) therefore failed both: assembly skipped the fold, carrier construction excluded the hook text, and submission suppressed prependContext/appendContext, so the model never received it. Assembly now publishes routePromptBuildContextThroughRuntimeCarrier in its result, and carrier construction, submission, and the compaction budget all consume that single decision; the runtime-only submission path delivers the stored carrier to the model.

Redaction (review round 7, P1): the carrier bypasses the canonical prompt-projection redaction on both consumption paths — the provider dispatch and the durable custom-message append — so hook text that logging.redactPatterns would have removed from the recorded prompt previously reached both the model and the retained transcript unsanitized. Carrier construction now applies redactTranscriptText (same policy, same config object the canonical capture uses) to the joined hook context before it becomes a fragment, so dispatch and replay see identical sanitized bytes. The legacy fold path is untouched: it still passes through capturePersistedModelPromptProjection, which already sanitizes.

Kept on the legacy path:

  • runs without the append-only contract (all other models): the one-run prompt rewrite, unchanged;
  • context-only turns (blank prompt) on append-only models: the fold, so hook context alone still reaches the model;
  • the transient per-run rewrite is also withheld from submitEmbeddedAttemptPrompt (prependContext/appendContext) and from pendingAdditivePrompt in the compaction request budget, since the carrier now carries those bytes and is counted through pendingContextMessages — no double injection, no double counting.

Trade-off inherited from the issue discussion: stored hook blocks accumulate in history until compaction or reset; the reporter's local patch of this shape estimated 500-850 tokens per injected block, and an explicit one-run opt-out on the hook result remains possible upstream work.

Evidence

Reproduction and regression tests (all offline, no network):

  • attempt-prompt-build.decision.test.ts "prompt assembly hook prompt context": on appendOnlyRuntimeContext: true with a before_prompt_build hook returning prependContext, the assembly keeps effectivePrompt transcript-identical ("Hello", no hook text) while still reporting promptBuildPrependContext for the carrier route; the legacy fold is pinned for append-only-off and for blank-prompt turns.
  • attempt-prompt-context.test.ts: the carrier carries { kind: "conversation-data", text: <hook context> } (prepend and append joined in order), while promptForSession, promptForModel, and llmBoundaryPromptForPrecheck stay bare user bytes; with the append-only contract off, the carrier contains no hook text and the folded model prompt is preserved.
  • Empty-transcript regression (review round 2 finding): attempt-prompt-context.test.ts "routes hook prompt context through the carrier when the transcript prompt is empty" pins the runtime-only turn (effectivePrompt: "Runtime ask", effectiveTranscriptPrompt: "") delivering the hook text through the carrier — promptSubmission.runtimeOnly is true, promptForModel stays bare, and runtimeContextMessageForCurrentTurn carries the hook fragment; attempt-prompt-build.decision.test.ts "publishes one carrier-routing decision for empty-transcript runtime turns" pins the published decision itself.
  • Redaction regression (review round 7 P1): attempt-prompt-context.test.ts "applies the transcript redaction policy to hook context stored in the carrier" — with logging.redactPatterns: ["sk-TEST-HOOK-SECRET-[a-z0-9]+"] and a hook returning a prependContext containing sk-TEST-HOOK-SECRET-9f2, the carrier fragment must not contain the raw secret and must equal redactTranscriptText(hookPrepend, config) byte-for-byte; promptForModel stays clean too.

Pre-fix red runs (tests only, fix reverted):

  • Routing: empty-transcript regression fails — promptSubmission.runtimeOnly is undefined (no runtime context at all reaches the turn) and the hook fragment is absent from the carrier.
  • Redaction: expect(fragment?.text).not.toContain("sk-TEST-HOOK-SECRET-9f2") fails — the raw secret is present in the carrier fragment, exactly the round-7 P1 path.

Post-fix:

  • attempt-prompt-context.test.ts: 29/29 (28 pre-existing + 1 new redaction test)
  • attempt-prompt-build.decision.test.ts, attempt-prompt-submit.projections.test.ts, attempt-context-advancement.test.ts, interrupted-input-context.integration.test.ts, tool-result-truncation.test.ts: all green on the same tree.

Branch state: rebased onto current main (571040c310), latest head e3dc40b08b: 0949de0b07 (carrier fix carrying the routing-decision and redaction rounds) → 0e62acd2f9 (aliased-import test helper) → merge refreshes onto successive main tips (the net diff vs main was verified byte-identical to the reviewed patch: 8 files, 248+/10-, every changed line matching).

@clawsweeper

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

@ruel225
ruel225 marked this pull request as ready for review October 7, 2026 12:58
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Oct 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR routes sanitized prompt-hook context through retained runtime carriers on append-only model routes.

Example: A hook returns prependContext="Customer prefers email" for the prompt "Hello" on an append-only route.

  • Before: The hook text becomes part of the model-facing user prompt.
  • After: The user prompt remains "Hello" and the hook text is retained separately as conversation data.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation has no verified code finding, but shipped-entry proof, persisted-session compatibility, and routing direction remain unsettled.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: Hook-enriched requests can lose stable replay context, reducing prefix reuse and invalidating retained reasoning.
Reason: Runtime-only replay remains useful work, but changing ordinary hook additions from canonical prompt text into conversation data needs direction from the existing persistence owner.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this PR contains distinct runtime-only replay work, but broader hook-context routing needs an owner decision following the merged prompt-persistence change.

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

Decision needed

  • Question: Should carrier routing cover all append-only turns, including reframing hook text as conversation data, or only runtime-only submissions without canonical projection capture?
  • Recommendation: Limit routing to the uncovered boundary: Preserve ordinary canonical prompt projections and scope carrier routing to runtime-only submissions that lack projection capture.
  • Why: The merged persistence owner already stabilizes ordinary enriched prompts, while the discussion identifies a plugin-semantics change without recorded owner approval.

Before merge

  • Add real behavior proof - Current-head evidence exercises assembly and carrier helpers; xyrolle's synthetic-stream backport supports prefix retention but predates the current redaction change and excludes runtime-only and in-history system-update routes. The contributor should provide redacted CLI or Gateway request/replay output showing hook text delivered once, sanitized, and retained unchanged across turns and reopen on the approved route; remove keys, IPs, phone numbers, and private endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Missing current-change CLI or Gateway request/replay evidence through the approved routing scope, including sanitized single inclusion, runtime-only delivery, reopen, and existing-session compatibility.
Agent review details

How this fits together

The embedded runner combines user input, plugin hooks, and runtime facts into provider requests and records the context needed for subsequent session replay.

flowchart LR
  A[User input] --> C[Prompt assembly]
  B[Plugin hooks] --> C
  C --> D[Runtime carrier]
  C --> E[Prompt submission]
  D --> E
  E --> F[Provider request]
  E --> G[Session transcript]
  G --> C
Loading

Technical review

Best possible solution:

Preserve canonical projection for ordinary recorded turns unless the owner approves broader carrier semantics, and repair the distinct runtime-only replay boundary through the existing owners.

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

Source establishes the runtime-only recorder exclusion; the original ordinary-turn persistence failure is partly addressed by #167938, and no current-main reproduction was executed.

Is this the best way to solve the issue?

The single routing decision and reuse of the existing carrier are focused, but the broad route changes more semantics than the remaining runtime-only persistence gap requires.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Hook context assembly keeps the original intent (29cfd19: Authorized enrichment joins ordinary and post-policy hook context after finalizing callable tools.)
  • Append-only carrier retention keeps the original intent (30837ae: Persist runtime carriers in place to preserve prefix-bound thinking across subsequent requests.)
  • Compaction request accounting keeps the original intent (60adac1: Count system, tools, pending input, and queued context in foreground compaction budgets.)
  • Ordinary enriched user-prompt persistence changes intended behavior with a stated reason (6461c18: Freeze the first model-facing prompt on its canonical user record for stable replay and reopen.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 2d0d99f adds src/agents/embedded-agent-runner/run/attempt-prompt-build.ts:196 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2d0d99fe08d8; files: src/agents/embedded-agent-runner/run/attempt-prompt-build.ts)
  • Josh Avant: Raw commit 29cfd19 adds src/agents/embedded-agent-runner/run/attempt-prompt-build.ts:208 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 29cfd195d19d; files: src/agents/embedded-agent-runner/run/attempt-prompt-build.ts)

PR surface

Source +55, Tests +183. Total +238 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 62 7 +55
Tests 6 186 3 +183
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 248 10 +238

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The remaining work concerns bounded prompt-replay behavior and plugin compatibility, with no demonstrated urgent current-main outage.
  • merge-risk: 🚨 compatibility: Existing plugin prompt additions change capture location and instruction framing on append-only routes.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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 (12 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-09T20:56:39.277Z sha 9ddeb41e6720f510cc2a5488d379ef9f3a22eb65 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-10T16:28:23.966Z sha 3eb7a0bc0080f654eb4dfd94d8bbfc041868c37f :: needs real behavior proof before merge. :: [P1] Preserve hook-text redaction before storing and dispatching the carrier
  • reviewed 2026-10-10T17:06:34.966Z sha 7bdf4e4ae4d647ad7c775fc8cb20187a6bccecce :: needs real behavior proof before merge. :: [P1] Preserve hook-text redaction before storing and dispatching the carrier
  • reviewed 2026-10-10T20:40:02.460Z sha 2c292a66e6c1fdbba22495cca4a897df9e78979f :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-10T20:49:18.309Z sha 2c292a66e6c1fdbba22495cca4a897df9e78979f :: needs real behavior proof before merge. :: [P2] [P2] Handle optional fragments in the redaction regression
  • reviewed 2026-10-10T21:07:56.967Z sha 5224937fcc17f4ea4b750284489b7ec9f081b905 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-11T00:26:57.429Z sha f43600c5c95bf3191bc290c8dc38709b0ec272d2 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-17T17:11:47.988Z sha f43600c5c95bf3191bc290c8dc38709b0ec272d2 :: needs real behavior proof before merge. :: none

Reviewed October 24, 2026, 8:23 AM ET / 12:23 UTC (Revision 13).

@xyrolle

xyrolle commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Two observations from a deployment that needs this together with #164804. They are not the after-fix production trace the review asks for (limits at the end of point 1), but they cover part of it.

1. Active Memory rewrites the previous user message on every eligible turn, not only on recall turns. In escalate mode, Active Memory's before_prompt_build returns prependContext even when it skips recall (the "intentionally skipped deep recall" line). When it does recall, it returns the recalled context. Without this PR that text is folded into the outgoing user message and is not stored, so the next request replays the bare message. We see this in two consecutive request bodies from a hosted config-defined openai-responses route.

Append-only retention alone does not fix it. We ran three turns on 2026.9.6 with appendOnlyRuntimeContext enabled for that provider, Active Memory eligible and a synthetic model stream. For each pair of turns, we counted how many items of one turn's last request reappear unchanged at the start of the next turn's first request:

turn 1 → 2 turn 2 → 3
retention only 1/12 14/16
retention + this PR (head 8de9b32e backported to 2026.9.6) 12/12 16/16

With retention only, the first difference is the previous user message. The 12/12 and 16/16 hold with encrypted-only reasoning. With reasoning summaries requested, they also need #167769; without it, turn 1 → 2 is 3/12. The same run checks that the hook text reached the model once per turn and was stored in the hidden carrier on all three turns.

Limits: this is a backport onto 2026.9.6, not this head on main. The model stream is synthetic. The run does not exercise in-history system updates or the empty-transcript route. We have not measured provider cache reads with the change applied.

2. Instructions that plugins put in prependContext are now framed as data. As the PR body says, hook text is deliberately not raised to instruction level. On append-only routes, prependContext and appendContext reach the model as a quoted Conversation data (data, not instructions) fragment, and that includes injections a plugin queues for the next turn. A plugin that used prependContext for something like "in your reply, confirm X briefly" will have that line framed as data. We moved such rules into appendSystemContext and kept only facts in the queued text. A sentence in the PR or the plugin hook docs would help other plugin authors who rely on the old behaviour.

@ekinnee

ekinnee commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Related implementation comparison: #167938 now records and replays the enriched model-facing user prompt on the canonical transcript. This PR routes hook prepend/append context into the hidden carrier on append-only routes and keeps those additions out of ordinary submission.

Could the author and @steipete confirm the intended capture location for hook context on that shared route, and whether these changes should compose or one replaces that part of the other? The comparison should preserve single inclusion and stable replay, while accounting for the context-only/empty-transcript path and previously stored turns.

The checkpoint alternatives #166667 and #147248 already compare their approaches; this question concerns the upstream persistence boundary.

@ruel225

ruel225 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for flagging the interaction — I checked both persistence boundaries against the merged #167938 (6461c186).

They compose; neither replaces the other. The split is by route, decided at a single point:

Single inclusion and stable replay hold on both routes: hook text reaches the model exactly once per turn — via the frozen canonical projection on the shared route, via the carrier on append-only routes — with the assembly's routing flag as the single source of truth.

I'm updating the branch onto current main next (#167938 only offsets attempt-prompt-phase.ts); after that I'll run the projection submit tests to confirm the three submit-path gates still hold under installModelPromptProjection and note the result here.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Oct 9, 2026
@ruel225

ruel225 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Following up as promised, now that the branch is updated onto main with #167938 included:

Composition verified at the merge head. All four affected suites pass against the updated branch:

  • attempt-prompt-submit.projections.test.ts — 9/9, including the prepend/append-hook serialized-prefix stability cases and the compacted-keyless exclusion
  • attempt-prompt-context.test.ts
  • attempt-prompt-build.decision.test.ts
  • attempt-context-advancement.test.ts

So after the merge, single inclusion and stable replay hold on both routes: the canonical projection freezes the enriched prompt on the shared route, and the carrier fragment carries hook context on append-only routes, with no path where both include it.

Note on the current red CI: the only failing step is build-artifacts › Check bundled plugin generated assets — regenerated extensions/workboard/openclaw.plugin.json bytes differ from the committed control-ui content hash (e7967afe…). This is independent of this PR: the branch diff touches only the 7 agent-runner files, and the same check fails on a fresh install of current main's lockfile (the vite 8.3.2 bump in #167731 — its committed hash doesn't reproduce under that lockfile). It looks like main needs a pnpm plugins:assets:build regeneration; once that lands, updating this branch should pick it up.

@ekinnee

ekinnee commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

@ruel225, thanks for the composition check and updated-branch test results. The Workboard manifest regeneration landed on main after your follow-up: c40ca82. It replaces the e7967afe… control-UI asset pointers with the regenerated eea70db0… pointers.

Your current head remains 9ddeb41. Updating onto main containing that regeneration and rerunning CI looks like the next useful step. I checked the failed build-artifacts log and the regeneration diff; I have not rerun this branch myself or established that all checks will pass after updating.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 10, 2026
@ruel225

ruel225 commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

The new check-test-types-core-1 failure after the update-branch was a one-line fixture gap: main's interrupted-input-context.integration.test.ts now passes a prompt object that predates PromptAssemblyContext.routePromptBuildContextThroughRuntimeCarrier, which this PR makes a required field. Set it to false for this fixture — the turn carries no hook prompt-build context, so the legacy fold is the correct (and behavior-neutral) value here. Local run: 2/2 passed. New head: 7bdf4e4ae4d647ad7c775fc8cb20187a6bccecce.

@ruel225

ruel225 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

@ekinnee The two changes compose: they own disjoint bytes on every route, so single inclusion and stable replay hold with no overlap.

Capture locations, per route:

  • Append-only routes (this PR's surface): assembly stops folding hook prependContext/appendContext into effectivePrompt/promptForModel, so the pendingText that capturePersistedModelPromptProjection records on the canonical user turn (src/sessions/user-turn-transcript-updates.ts) never contains hook bytes. The hidden conversation-data carrier is the single owner of those bytes — stored per turn, replayed byte-identically.
  • Legacy routes (non-append-only models): this PR deliberately keeps the one-run fold. perf(agents): keep enriched user prompt history stable #167938 captures the folded model-facing text once as the immutable projection and now stabilizes its replay — on that route the stored projection is the de-facto replay owner of the folded hook bytes, which is fine because this PR does not change that path.
  • Runtime-only / empty-transcript turns: perf(agents): keep enriched user prompt history stable #167938's projectionRecorder is undefined for input.runtimeOnly turns (the skipPreparedUserTurnMessage || input.runtimeOnly || isBlocked() guard in attempt-prompt-submit.ts), so no canonical capture happens there. That is exactly the path where this PR delivers hook context through the stored carrier, so the two never write the same turn's text.
  • Context-only (blank prompt) turns on append-only models: this PR keeps the fold so hook context still reaches the model alone; the user turn's model-facing text carries no hook bytes, same as main.

Why compose rather than replace: #167938 stabilizes replay of whatever first went to the model, but the #166271 break comes from rewriting the prompt prefix within a run — the folded user text shifts the cache prefix and drops replayed thinking blocks even when later replays are stable. Only moving hook bytes out of the assembled prompt (into the carrier) fixes that; storing the folded text cannot. Conversely, this PR does not give hook context durable, reopen-stable replay on legacy routes — #167938's stored projection does.

Previously stored turns: rows recorded before either change have no projection field, and capture only happens on a turn's first model send (readModelPromptProjection returning undefined). Historical hook folds were never persisted, and this PR's carrier only carries the current turn's hook bytes, so no double inclusion can arise from old rows.

Net: #167938 owns the canonical user-prompt text on every route that has a recorder, this PR owns hook prompt context on append-only routes, and the runtime-only path is carrier-only by construction. Current head f43600c5 is updated past the Workboard manifest regeneration and CI is green.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 17, 2026
@clawsweeper clawsweeper Bot removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 17, 2026
…rier

On append-only runtime-context models, a before_prompt_build hook's
prependContext/appendContext was folded into the active user prompt for
one run only and never stored. The next run replayed the earlier user
message without the injected block, so the request was no longer an
append-only extension of the previous one: every cache entry written
during the run sat after that rewritten message and could never be read
again, and replayed thinking blocks after that message were dropped.

Route the joined hook context through the stored conversation-data
runtime-context fragment instead. Assembly publishes one
routePromptBuildContextThroughRuntimeCarrier decision (append-only
contract and non-empty prompt); carrier construction, submission, and
the compaction budget consume that single decision, and the carrier
bytes are redacted with the tool-payload policy from the attempt
logging config before storage, since the carrier bypasses the
canonical prompt-projection redaction on both consumption paths.

Legacy routes are untouched: non-append-only models keep the one-run
fold; blank-prompt context-only turns keep the fold so hook context
alone still reaches the model.

Closes openclaw#166271
@ruel225
ruel225 force-pushed the fix/before-prompt-context-append-only-166271 branch from f43600c to 0949de0 Compare October 21, 2026 20:14
The carrier hook-context tests were replayed onto a base where this
suite imports prepareEmbeddedAttemptPromptContext as prepareContext,
so calling the original name left six TS2304 diagnostics and one
implicit-any on the fragment lookup, and the vitest shard failed with
ReferenceError before running a single assertion. Use the alias every
other case in the file already uses.
Keep the redaction-policy test import; drop replayed imports the base
removed with the Windows approval-hints test.
@ekinnee

ekinnee commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

@steipete, could you settle the intended hook-context routing scope here so @ruel225 has a clear target for the remaining proof?

Since your #167938 added canonical persistence for enriched user prompts, should this PR preserve that behavior for ordinary recorded turns and limit carrier routing to runtime-only submissions without projection capture, or is the broader append-only routing intended—including framing prependContext / appendContext as conversation data rather than instructions?

@ruel225 has already documented the route-by-route composition and continued integrating upstream changes. The published bot review still targets f43600c5, not the current e3dc40b head, so its old conflict warning is not evidence of a current conflict. It identifies no code findings at its reviewed head, but leaves this semantics decision and shipped-entry/replay compatibility proof outstanding.

Choosing the scope first would let the author focus the CLI/Gateway replay and existing-session compatibility evidence on the behavior we actually intend to ship.

@ruel225

ruel225 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the work here. We're closing this: it doesn't show a real user-facing problem (no report from an affected user and no natural reproduction), and it follows a pattern of small, speculative or duplicate changes split across many PRs. Please open an issue with a reproduction of real harm first; a fix can follow once the problem is confirmed.

@obviyus obviyus closed this Nov 17, 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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

4 participants