Repository navigation
fix: distinguish inbound messages from runtime context - #140859
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 7, 2026, 4:13 AM ET / 08:13 UTC. ClawSweeper reviewWhat this changesSeparates inbound text from Gateway-generated runtime context, escapes delimiter mentions for new sessions, and preserves existing sessions’ prompt projections through repair, branching, and replay. Merge readiness⛔ Blocked before merge - 1 item remains This remains useful work absent from current main. The earlier Doctor and resumed-context findings are addressed, and the documented persisted-state compatibility evidence resolves the previous upgrade-proof request. No blocking introduced defect was identified. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway assembles user messages, background events, and conversation metadata before sending them to a model. This change keeps their origins separate while preserving stored transcripts and selecting model-facing formatting through the session header. flowchart TD
A[Inbound user text] --> D[Gateway prompt assembly]
B[Runtime events and conversation data] --> D
C[Stored session version] --> E[Model projection]
D --> F[Preserved transcript]
D --> E
E --> G[Model request]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -1, Tests -259, Docs +20, Other -2. Total -242 across 75 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep producer-owned context separate at the Gateway boundary, retain existing session projections, and complete cloud-worker parity through the already-tracked follow-up. Do we have a high-confidence way to reproduce the issue? Yes for the structural ambiguity: current main extracts runtime context from inbound delimiter text, and the branch contains focused regression cases. The reported live provider refusal was not reproduced. Is this the best way to solve the issue? Yes for the approved Gateway scope: carrying producer facts to one projection boundary removes text-based classification while preserving transcript bytes and existing session policies. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 240b8b158988. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
|
Addressed the two actionable findings in 9e4bde1d909224ecf154f2e6791e66d33f8dcd85. Doctor now repairs canonical headerless legacy history with version 3. Regression coverage preserves raw event JSON and leaves existing versions 3, 4, and 99 untouched. The same audit found session adoption could append a new-version header to retained history; adoption now uses the existing initializer only for physically empty transcripts, rechecked inside the queued write after preparation. A shared append operation now updates full text, resumable text, and producer-typed fragments together. Both reply-prelude additions and MCP App snapshots use it. Regressions failed before the corrections for missing resumed context and incorrect enrollment; the corrected context, adoption, retry, Doctor, and migration suites pass. Queue selection, exclusions, MCP consumption, and transcript-byte assertions remain covered. The final full changed-file check and independent review are clean; hosted CI is running on this new head. Live provider-refusal verification remains a stated proof gap. The maintainer-approved scope is deterministic Gateway prompt hardening, with cloud-worker launch-contract hardening tracked separately in #140666. |
9e4bde1 to
a182ce8
Compare
|
Upgrade compatibility proof for the remaining data-model review item is covered by deterministic persisted-state tests, using synthetic sessions:
No SQLite schema migration or new policy field is used. The maintainer approved selecting new-session projection through the existing transcript header; existing prefixes retain their policy. This is upgrade compatibility proof, not a claim that the reported provider refusal was reproduced live. Cloud-worker launch-contract hardening remains explicitly tracked in #140666. The final head |
Carry producer-owned context through Gateway prompt assembly and escape inbound delimiters only in the model projection. Preserve raw transcripts and select the new projection through the existing per-session header. Keep existing provider roles and legacy session prefixes. Cloud-worker launch-contract hardening remains tracked separately in #140666. Related: #140404
Keep legacy headerless history on its existing projection during Doctor repair, and initialize adopted transcripts only when physically empty. Append new context to full and resumable prompts through one shared owner. Preserve event selection, MCP consumption, retry context, and raw transcript bytes in the compatibility tests.
2bc8619 to
0d0e6ec
Compare
|
The final review identifies no introduced blocking defect. Its remaining live-refusal checklist item is retained as an explicit proof limitation under the maintainer-approved scope: this landing hardens Gateway prompt structure and provenance while preserving provider roles and existing session prefixes. The PR body states that the reported provider refusal was not reproduced live and makes no claim that model behavior is guaranteed. Deterministic assembly, lifecycle, and persisted-state regressions establish the structural repair; final-head hosted CI is green. Cloud-worker launch parity remains #140666. |
|
Merged via squash.
|
|
Related follow-up: #141544 merged on September 8, 2026. It sanitizes outward reasoning previews at the shared dispatch boundary; it does not change model input or runtime-context carrier placement. This is complementary downstream output hardening, not a replacement for the inbound/runtime-context distinction implemented here. #141544 leaves versioned model-input projection and raw replay data unchanged, and does not complete the cloud-worker follow-up in #140666. |
* fix(agents): distinguish inbound text from runtime context Carry producer-owned context through Gateway prompt assembly and escape inbound delimiters only in the model projection. Preserve raw transcripts and select the new projection through the existing per-session header. Keep existing provider roles and legacy session prefixes. Cloud-worker launch-contract hardening remains tracked separately in openclaw#140666. Related: openclaw#140404 * fix(agents): preserve projection during repair and resumed turns Keep legacy headerless history on its existing projection during Doctor repair, and initialize adopted transcripts only when physically empty. Append new context to full and resumable prompts through one shared owner. Preserve event selection, MCP consumption, retry context, and raw transcript bytes in the compatibility tests. * test(agents): align projection lifecycle fixtures with producers * fix(agents): retain runtime events in legacy sessions
* fix(agents): distinguish inbound text from runtime context Carry producer-owned context through Gateway prompt assembly and escape inbound delimiters only in the model projection. Preserve raw transcripts and select the new projection through the existing per-session header. Keep existing provider roles and legacy session prefixes. Cloud-worker launch-contract hardening remains tracked separately in openclaw#140666. Related: openclaw#140404 * fix(agents): preserve projection during repair and resumed turns Keep legacy headerless history on its existing projection during Doctor repair, and initialize adopted transcripts only when physically empty. Append new context to full and resumable prompts through one shared owner. Preserve event selection, MCP consumption, retry context, and raw transcript bytes in the compatibility tests. * test(agents): align projection lifecycle fixtures with producers * fix(agents): retain runtime events in legacy sessions (cherry picked from commit 2d0d99f)
배치 A 체리픽이 이 포크에 없는 중간 리팩터링에 걸린 지점을 포크 코드에 맞춰 정리했다. - 문자열 이스케이프 복구: attempt-prompt-build.ts, attempt-prompt-context.test.ts - openclaw#140859: session-accessor.entry-mutation.ts 의 transcript 헤더 import 복원 - openclaw#141247: runs.ts 에서 포크에 없는 projectSessionActive 조건 제거 - openclaw#141471: execute-plugin.test-support.js 가 없어 native-bash 테스트 파일 제거 - openclaw#141960: quickjs-wasi 3.6.0 의 MAX_STACK_SIZE 를 쓸 수 없어 되돌림(포크는 3.5.0 핀) - openclaw#142130: agents.ts 의 assertCurrent 호출 제거, cleanup-utils 는 선택 인자로 유지 - openclaw#142158: manifest-planner.ts 의 remoteModelIds·manifestModelsById 복원 - openclaw#143308: simple-completion-runtime.ts 에 acquireSimpleCompletionModelForAgent 래퍼 추가 - openclaw#143899: src/infra/file-descriptor.ts 의 fingerprint 비교 헬퍼 이식, backup-shared 의 configCapture 참조 제거 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Related: #140404. Cloud-worker follow-up: #140666.
What Problem This Solves
Fixes an issue where inbound message text could be mistaken for OpenClaw-generated runtime context during Gateway-owned prompt assembly. This addresses the structural ambiguity behind @fstrasz's report of legitimate runtime events being refused or described back to the operator.
Why This Change Was Made
Runtime instructions, conversation data, and heartbeat outcomes retain their producer-owned provenance through
prompt-prelude.ts,internal-events.ts, and the single Gateway owner inattempt-prompt-build.ts:473. The model boundary inattempt-llm-boundary.ts:71neutralizes internal-context delimiter mentions and quotes data. The old text-based context classifier is removed; matching message text does not grant runtime provenance. Existing provider message roles stay unchanged because retained thinking can bind to the preceding message prefix.The existing transcript header selects the projection: genuinely new sessions use version 4, while existing version 3 sessions remain readable and unmigrated. Branching, reset boundaries, compaction, restoration, and replay preserve the source policy. This avoids a new custom policy entry; bounded replay already loads the header, and the header is persisted before the first provider request. Doctor repairs canonical headerless legacy history with version 3 and preserves existing headers, including unknown versions. Creation/adoption initializes a header only when the transcript is physically empty, rechecked inside the queued write. Unknown projection versions fail rather than silently reinterpreting an existing prefix.
Shared command preparation preserves completion content for CLI and worker dispatch. Legacy sessions retain their existing event and MCP App escaping. The Gateway-only producer/projection changes preserve raw user transcript bytes. One append owner keeps full and resumable inbound context aligned, so resumed room CLI turns retain new thread notes, system events, and MCP App snapshots.
Cloud-worker prompt assembly still needs the same hardening through its launch contract. It bypasses the Gateway projection owner; that explicitly deferred work, including worker restart and Gateway/worker transition proof, is tracked in #140666.
User Impact
This is prompt hardening, not an authorization boundary or a guarantee against prompt injection. New Gateway-assembled sessions distinguish user text from runtime-owned instructions and context data. Start a genuinely new session to select the escaped projection; existing sessions retain their policy across replay so earlier provider prefixes are not rewritten. No configuration option, SQL schema, dependency, provider-role migration, or worker protocol change is introduced.
Evidence
Reviewed head:
99c7be243bc5081bda8221c06b08f9f9f4977df9.git diff --checkpasses. The production candidate and final test-only adjustments passed their changed-file checks. A second conflict resolution preserves main’s relocation of cache observation; all 64 affected tests and its full changed-file check passed. Exact-head hosted CI is green: run 34098328672, includingopenclaw/ci-gateand Windows.Production: +626 / -627 (net -1). Tests and support: +858 / -1119 (net -261). Documentation: +20. Counts exclude test fixtures and the Docker proof client from production.
Independent Codex review: scoped-clean at P0–P2 for the staged final candidate. The full compatibility gate and first post-rebase changed check passed. The final candidate has a fresh clean P0–P2 review; both the full second-rebase check and the final correction’s changed-file check passed.
The initial focused proof covered 470 tests across 21 files. After CI exposed compatibility gaps, the Doctor/import suites passed 244 tests, cron passed 26, and prompt-prelude passed 11. The final context/adoption/retry run passed 246 tests across five files; the extracted MCP suite passed all three tests and the remaining lifecycle suite passed 31. These runs retain event selection, exclusion, queue state, MCP consumption, and raw transcript assertions.
Upgrade-compatibility evidence is detailed in the review response: existing 3/4/99 headers and raw event bytes survive repair/adoption; imports below 3 stop at 3; branching reopens versions 3 and 4 unchanged.
New regressions failed before their corrections: resumed source additions and MCP snapshots were missing; Doctor selected version 4 for retained headerless history; and adoption appended a new header to retained history. Corrected tests preserve existing versions 3, 4, and 99, and verify raw event bytes remain unchanged. The first-head CI failures are repaired; the final exact-head hosted run passes the landing gate. The necessary rebase preserved main’s new active process/subagent/media facts and routes them as typed conversation data, including on runtime-only turns; all 99 overlap tests pass. The local install was refreshed to the frozen lockfile after main’s dependency changes. Final empty-reset and restart-sentinel suites pass all 98 tests; the ACP suite passes all 131 tests with a real producer-generated completion fixture. These test-only updates retain the existing exact ownership, delivery, and transcript assertions. A final review found explicit runtime fragments were discarded for version 3 runtime-only turns; removing that conditional preserves producer context under both policies while escaping remains version-selected. The version 3 regression failed before the correction; all 65 related context/submission/cache-stability tests now pass.
Two harmless literal-marker regression cases fail against the original normalizer because it leaves the markers unescaped; both pass with the new projection, with unchanged transcript input objects and consistent current/history projection.
Exact benign assembled prompt before:
After, for a genuinely new session:
The stored carrier body remains raw; only its model projection changes. The deterministic assembly test asserts this exact output.
Validation commands
The broad focused run used the existing Testbox lease. The corrected helper, explicitly selected support suites, and final changed check ran locally. The remote full changed check was stopped after a known local dead-export finding made its frozen tree obsolete; it is not reported as passing proof.
The reported provider refusal was not reproduced live. Validation covers prompt assembly, transcript preservation, provenance, and replay policy through deterministic tests.
Reported by @fstrasz in #140404. No contributor PR was replaced.