Repository navigation
Conversation
|
Codex review: needs maintainer review before merge. What this changesThis PR retains synthetic runtime continuations as hidden internal-system input instead of attributing them to a human. Example: An embedded runtime event arrives with no user text.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep this PR open: it repairs a current-main transcript-attribution bug while preserving replay history, with no remaining actionable findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe embedded prompt phase submits user text and runtime context to AgentSession; the session persistence guard records transcript messages that later feed model replay and visible chat history. flowchart LR
A[Runtime event] --> B[Embedded prompt phase]
B --> C[AgentSession]
C --> D[Persistence guard]
D --> E[SQLite transcript]
E --> F[Model replay]
E --> G[Chat history projection]
Technical reviewBest possible solution: Land the focused attribution repair while leaving the linked issue's separate timeout and restart symptoms tracked independently. Do we have a high-confidence way to reproduce the issue? Yes: current-main source deterministically turns empty human text plus runtime fragments into an ordinarily persisted synthetic user message, corroborated by the supplied pre-fix Gateway run; this review executed no target code. Is this the best way to solve the issue? Yes: hidden attribution at the existing persistence guard fixes the violated contract while retaining model-visible history and clearing unused state after preflight failure. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 390f0f0acb98. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +16, Tests +221, Docs +7, Other +1. Total +245 across 15 files. Added test files: 2. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (11 earlier review cycles; latest 8 shown)
Reviewed October 11, 2026, 2:50 AM ET / 06:50 UTC (Revision 12). |
d1f1748 to
6f12149
Compare
6f12149 to
c1acfb2
Compare
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
c1acfb2 to
9f00d50
Compare
|
Rebased onto current main ( |
|
@vincentkoc — coordinating on the transcript-attribution portion of #124244 only. I preserved @LiuwqGit's commit, merged main, consolidated the existing persistence guard API, and added live native Ollama before/after plus early-failure cleanup evidence to the PR body. The timeout/restart symptoms remain outside this PR's claim. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Keep runtime continuation messages replayable with internal-system provenance and hidden display instead of dropping their model-visible prefix. Reuse the existing guard as the one-shot persistence policy owner; reset pending mode after prompt preflight and consume it before write hooks. Preserve append-only history through timestamped cold SQLite replay, test blocked-write and preflight cleanup, and move the replay table to its existing host-owned SQLite test lane. Related: openclaw#124244.
|
Addressed the cold-reopen prefix finding in 9147c30. The existing guard now retains runtime input as hidden internal-system content instead of dropping it. The timestamped serialized-prefix regression fails under the prior suppression behavior and passes after cold SQLite reopen; the new exact-head Ollama/Gateway proof also verifies visible chat history. Details and the prior CI collection limitation are in the updated body. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…sion transcripts (openclaw#137273) Retain runtime-only continuations as hidden internal_system input in the existing persistence guard. Genuine user messages remain visible and correctly attributed, while cold replay preserves the model-visible prefix preceding retained responses and signed thinking. Reset unconsumed runtime mode after early submission failures. Related: openclaw#124244. This fixes only transcript attribution; timeout, duplicate-send, and restart symptoms remain outside this PR's scope. Validated by 143 focused tests, exact-head CI, and an isolated Gateway using native Ollama qwen3:4b: reopened SQLite and chat.history retain genuine user input without showing runtime markers as human-authored text. Cold-reopen prefix and early-failure cleanup regressions pass. Autoreview and the completed ClawSweeper review report no actionable findings. Thanks @LiuwqGit for the original fix. Co-authored-by: LiuwqGit <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
## What Problem This Solves
Fixes: after a provider rate limit (HTTP 429) or another transient failure, the retry and the next turn resend the whole conversation and miss the prompt cache.
## User Impact
User impact: sessions that hit a rate limit keep their prompt cache on the retry and on the following turns, so retries cost fewer uncached input tokens and answer sooner. Internal retry prompts stay hidden from the transcript, as before. There is no configuration, schema or migration change.
## Why This Change Was Made
A transient retry continues the turn with an internal prompt ("Continue the current task…"). That prompt was sent to the model but deliberately not saved. The turn-scoped runtime context sent right after it *was* saved. So the transcript kept the runtime context without the prompt in front of it. The retry and the next run then replayed a different history than the model had already seen: a role change at the old prompt's position. On OpenAI Responses that also drops `previous_response_id` and resends the full input.
Internal prompts now take the same path as runtime-only prompts (#137273): submission saves them as hidden `internal_system` input (`display: false`). Because an internal prompt has no transcript recorder to capture a model-facing projection, it is submitted and saved as the exact text the model receives (`modelPrompt`, or hook prepend + prompt + append). Replay then sends the same bytes. One helper, `resolveModelPromptText`, now owns that text for both normal and internal prompts.
This keeps #122908's guarantee: internal recovery prompts never appear as operator-authored messages.
## Evidence
- **Production pattern (OpenAI Responses Gateway, 4.3 h, logs only):** 227 user-turn `historyRewrite` cache drops. 205 of them were inside a run that had just received `429 rate_limit_exceeded` (tokens per minute). In 215 the model, route and cache key were unchanged, so the cache was lost only because the replayed history changed. Median cached tokens kept after a drop: 12%.
- **Embedded runner, 4 routes** (`src/agents/embedded-agent-runner.prompt-cache.test.ts`, extended with a rate-limited tool continuation and a following turn). It runs through `runEmbeddedAgent` with the durable transcript and byte-level provider prefix checks:
- `main`: **4 failed** (OpenAI Responses, Chat Completions, Anthropic Messages, Anthropic in-history), each `prefix changed … path=$.role` on the turn after the retry.
- This branch: **4 passed**.
- **Real Gateway E2E** (`test/e2e/qa-lab/runtime/gateway-rate-limit-prompt-cache.e2e.test.ts`): `chat.send` runs through a QA-lab Gateway, with the mock OpenAI provider returning one 429 on the tool continuation, then an ordinary second turn.
- `main`: **failed**, `request 4 breaks request 3 prefix at input[4]: was user/message, now assistant/message`.
- This branch: **passed**.
- `gateway-rpc-chat.e2e.test.ts`: 9 of 9 passed.
- Mock provider suite: 189 of 189 passed.
- **Related suites:** 59 files cover submit, LLM boundary, retries, model fallback, settled-turn finalization and the worker runtime. All pass, except one worker background-exec timing test (`worker.runtime.test.ts > stops registered background execs after anchor`, `ENOENT exec.pid`). It failed once under heavy host load and passed 71/71 when its file was rerun alone.
- `pnpm check:changed`: format, typecheck and lint pass for the changed files. Remaining failures (`max-lines suppression ratchet`, `core tsgo graph boundary`, `dead export scan`) are in files this PR does not touch and are already on `main`.
- **Not covered:** the WebSocket Responses transport, Codex-native turns, and a live provider check of `cached_tokens`.
No overlap with Pash/Sarah changes.
**Merge danger:** two-way door. Reverting restores the old behavior. New transcripts gain one hidden `internal_system` user row per internal retry prompt; older builds already read such rows (runtime-only turns write them today). **Blast radius:** embedded runs that retry with an internal prompt (transient provider errors, outer model fallback after dispatch, plugin-runtime refresh, compaction and settled-turn continuations), on all providers. If it is wrong, the model would see an extra hidden continuation prompt in replayed history.
Co-authored-by: Ayaan Zaidi <[email protected]>
## What Problem This Solves
Fixes: after a provider rate limit (HTTP 429) or another transient failure, the retry and the next turn resend the whole conversation and miss the prompt cache.
## User Impact
User impact: sessions that hit a rate limit keep their prompt cache on the retry and on the following turns, so retries cost fewer uncached input tokens and answer sooner. Internal retry prompts stay hidden from the transcript, as before. There is no configuration, schema or migration change.
## Why This Change Was Made
A transient retry continues the turn with an internal prompt ("Continue the current task…"). That prompt was sent to the model but deliberately not saved. The turn-scoped runtime context sent right after it *was* saved. So the transcript kept the runtime context without the prompt in front of it. The retry and the next run then replayed a different history than the model had already seen: a role change at the old prompt's position. On OpenAI Responses that also drops `previous_response_id` and resends the full input.
Internal prompts now take the same path as runtime-only prompts (openclaw#137273): submission saves them as hidden `internal_system` input (`display: false`). Because an internal prompt has no transcript recorder to capture a model-facing projection, it is submitted and saved as the exact text the model receives (`modelPrompt`, or hook prepend + prompt + append). Replay then sends the same bytes. One helper, `resolveModelPromptText`, now owns that text for both normal and internal prompts.
This keeps openclaw#122908's guarantee: internal recovery prompts never appear as operator-authored messages.
## Evidence
- **Production pattern (OpenAI Responses Gateway, 4.3 h, logs only):** 227 user-turn `historyRewrite` cache drops. 205 of them were inside a run that had just received `429 rate_limit_exceeded` (tokens per minute). In 215 the model, route and cache key were unchanged, so the cache was lost only because the replayed history changed. Median cached tokens kept after a drop: 12%.
- **Embedded runner, 4 routes** (`src/agents/embedded-agent-runner.prompt-cache.test.ts`, extended with a rate-limited tool continuation and a following turn). It runs through `runEmbeddedAgent` with the durable transcript and byte-level provider prefix checks:
- `main`: **4 failed** (OpenAI Responses, Chat Completions, Anthropic Messages, Anthropic in-history), each `prefix changed … path=$.role` on the turn after the retry.
- This branch: **4 passed**.
- **Real Gateway E2E** (`test/e2e/qa-lab/runtime/gateway-rate-limit-prompt-cache.e2e.test.ts`): `chat.send` runs through a QA-lab Gateway, with the mock OpenAI provider returning one 429 on the tool continuation, then an ordinary second turn.
- `main`: **failed**, `request 4 breaks request 3 prefix at input[4]: was user/message, now assistant/message`.
- This branch: **passed**.
- `gateway-rpc-chat.e2e.test.ts`: 9 of 9 passed.
- Mock provider suite: 189 of 189 passed.
- **Related suites:** 59 files cover submit, LLM boundary, retries, model fallback, settled-turn finalization and the worker runtime. All pass, except one worker background-exec timing test (`worker.runtime.test.ts > stops registered background execs after anchor`, `ENOENT exec.pid`). It failed once under heavy host load and passed 71/71 when its file was rerun alone.
- `pnpm check:changed`: format, typecheck and lint pass for the changed files. Remaining failures (`max-lines suppression ratchet`, `core tsgo graph boundary`, `dead export scan`) are in files this PR does not touch and are already on `main`.
- **Not covered:** the WebSocket Responses transport, Codex-native turns, and a live provider check of `cached_tokens`.
No overlap with Pash/Sarah changes.
**Merge danger:** two-way door. Reverting restores the old behavior. New transcripts gain one hidden `internal_system` user row per internal retry prompt; older builds already read such rows (runtime-only turns write them today). **Blast radius:** embedded runs that retry with an internal prompt (transient provider errors, outer model fallback after dispatch, plugin-runtime refresh, compaction and settled-turn continuations), on all providers. If it is wrong, the model would see an extra hidden continuation prompt in replayed history.
Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: LiuwqGit <[email protected]> Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: RomneyDa <[email protected]>
Related: #124244
What Problem This Solves
Runtime-only embedded turns can save
Continue the OpenClaw runtime event.as human-authored text even though the user never wrote it.User Impact
Runtime continuations are now hidden internal-system input, while genuine user messages remain visible and correctly attributed. Their original model-visible content stays in history so cold replay preserves the prefix preceding retained responses and signed thinking. Existing transcript rows are unchanged; no configuration or migration is required.
This PR covers only transcript attribution. It does not claim to resolve the issue's other timeout, duplicate-send, or restart symptoms.
Why This Change Was Made
Builds on @LiuwqGit's work in the existing session persistence guard. The guard owns one one-shot persistence policy: normal input, suppressed replay duplicate, or hidden runtime input. Submission selects runtime mode and resets unconsumed mode in
finally; the guard consumes runtime attribution before write hooks so a blocked marker cannot hide later user input. Recovery/replay callers share that setter; the redundant setters are removed.The earlier suppression-only candidate lost model history after a cold reopen. This revision addresses ClawSweeper's finding by retaining the continuation with existing
internal_systemprovenance anddisplay: false. It preserves the append-only replay contract from #136782 and carrier placement/role behavior from #168169 and #168546. Contributor commits remain intact; main was merged, never rebased.Production +34/−18 (net +16); tests/support +358/−138 (net +220); test routing +2/−0; docs +7/−0. The small production increase expresses attribution and replay as valid states in the existing owner. Prompt text/token delta: 0. No new config, schema, dependency, or public SDK export.
Evidence
e5ee13e2d2d460c94dd4694e9df3c7da329db211, isolated Gateway, native Ollamaqwen3:4b. A temporary plugin Gateway method used publicapi.runtime.agent.runEmbeddedAgent()with no user text and explicit runtime context. The model repliedRUNTIME_EVENT_ACK; reopened SQLite attributed the marker to an ordinary user. This establishes the supported plugin-runtime entry point; no built-in channel producer is claimed.AgentSessionreopen across retained, transient, and native-Ollama policies. Switching runtime mode back to suppression fails that prefix comparison because the continuation disappears. Hidden metadata and normal follow-up visibility are also checked.AgentSessionauth preflight rejected before any append; activating the local provider and submitting genuine text producedRECOVERY_ACK. Reopened SQLite retained exactly the normal user input. This is session/submission-owner proof, separate from the Gateway proof.a5d39c5b4c62failed collection of untouchedsrc/gateway/talk/handlers/client-native-actions.test.tsatsrc/cli/cli-process-tree.test-support.ts:4withERR_INVALID_URL_SCHEME(job, 174 CI seconds). The helper/test match baseline main; standalone main passes on Node 26 (90.88 s wall) and Node 24 withCI=1(139.81 s). The Linux/cache-specific cause is unresolved; passing replays are not claimed as a fix.Focused test command
Gateway proof uses
pnpm openclaw --profile runtime-input gateway run --port 19511, a seed viaagent --session-key,gateway call runtime-input-proof.run --expect-final, and a genuine follow-up viaagent. State, workspace, plugin, and transcript reads are isolated synthetic fixtures; the operator Gateway is not used.Final live candidate
9147c3039ffdd5db6b40b090d041291a6263f388: the isolated Gateway/native Ollama run returnedRUNTIME_EVENT_ACKand the genuine follow-up returnedHUMAN_ACK. Reopened SQLite retained one marker withprovenance.kind: internal_systemanddisplay: false; its two human entries contained only the seed and genuine follow-up. The publicchat.historyRPC likewise returned exactly those two visible user messages, with no marker. This preserves replay content while fixing human attribution and chat visibility.Final review/CI:
9147c3039ffdd5db6b40b090d041291a6263f388passed CI, including bothopenclaw/ci-gatesignals. All 32 Node shard jobs passed (3586 aggregate CI job-seconds, including existing selected suites). ClawSweeper reviewed this exact head on 2026-10-11 and reports no findings, no before-merge items, and readiness for maintainer review. Its partial-fix rating reflects the intentionally limited Related scope.