Repository navigation
fix: turns fail after runtime notices on strict chat templates - #167309
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: needs maintainer review before merge. Reviewed October 8, 2026, 3:04 PM ET / 19:04 UTC (Revision 6). ClawSweeper reviewWhat this changesThe shared Chat Completions converter projects runtime notices as developer messages when supported and labeled user messages otherwise, avoiding later system messages. Example: Send a chat turn after a runtime notice on a strict Chat Completions route.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR remains necessary: current main retains the reported failure. The owner-authored final-head coverage resolves the earlier role-contract question, real Gateway proof is sufficient, and no blocking finding remains. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherOpenClaw combines conversation history and internal runtime notices before sending requests to model providers. The shared Chat Completions converter assigns provider-compatible message roles while preserving conversation order. flowchart TD
A[Conversation history] --> C[Chat Completions converter]
B[Marked runtime notices] --> C
C --> D{Developer role supported?}
D -->|Yes| E[Developer notice]
D -->|No| F[Labeled user notice]
E --> G[Provider request]
F --> G
Technical reviewBest possible solution: Keep the bounded repair at the shared provider-projection owner, retaining notice order, transcript bytes, and existing cache policy. Do we have a high-confidence way to reproduce the issue? Yes: current-main source emits a later system message for marked notices on unsupported-developer routes, and the supplied real Gateway negative control records the resulting HTTP 400. This read-only review did not execute the reproduction. Is this the best way to solve the issue? Yes: using the existing resolved role capability repairs the shared request boundary without provider-specific rewrites, history deletion, or new configuration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against dd0ecdd4bd35. Provenance checked
TestingProof path: shipped entry point. Added test files: 2. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests +28, Docs +1. Total +29 across 4 files. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel 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 (5 earlier review cycles)
|
|
Follow-up to the review and CI failure:
The production repair and complete package have passed local build/import-closure checks and are being deployed. Installed Gateway/session verification is still pending; I will report that result separately. |
|
Installed Gateway verification is complete. The existing main session now completes real turns on the unchanged normal PR CI is green on The private integration line includes distinct compaction repairs, which are not part of this PR. No model switch or proxy rewrite was introduced by this change. The capability-based role-contract choice remains explicitly recorded for maintainer confirmation. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Fold the role matrix into the existing prior-prefix and tool-result regression, retaining cache exclusions and transcript immutability. Document capability-based notice projection and remove redundant commentary. Fixes openclaw#167305. Original fix by @jlapenna.
|
Merged via squash.
|
…law#167309) * fix(ai): keep runtime notices out of mid-transcript system messages * test(ai): align proxy runtime notice role with transport contract * test: tighten runtime notice prefix regressions Fold the role matrix into the existing prior-prefix and tool-result regression, retaining cache exclusions and transcript immutability. Document capability-based notice projection and remove redundant commentary. Fixes openclaw#167305. Original fix by @jlapenna. --------- Co-authored-by: Peter Steinberger <[email protected]>
* fix(ai): keep runtime notices out of mid-transcript system messages * test(ai): align proxy runtime notice role with transport contract * test: tighten runtime notice prefix regressions Fold the role matrix into the existing prior-prefix and tool-result regression, retaining cache exclusions and transcript immutability. Document capability-based notice projection and remove redundant commentary. Fixes #167305. Original fix by @jlapenna. --------- Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit 2b51bb8)
…backport) Runtime notices now use developer or user messages according to provider support. The memory fixtures still recognized only system messages, so they selected the notice as the human prompt and returned the wrong reply. Keep the whole-context marker and empty-after-stripping checks unchanged. All four original failures reproduced on main. Actual HTTP captures showed the user-role carrier; all four corrected cases and suppression checks pass, with scoped types, typed lint and independent P2 review. (cherry picked from commit e09e5dd)
…law#167309) * fix(ai): keep runtime notices out of mid-transcript system messages * test(ai): align proxy runtime notice role with transport contract * test: tighten runtime notice prefix regressions Fold the role matrix into the existing prior-prefix and tool-result regression, retaining cache exclusions and transcript immutability. Document capability-based notice projection and remove redundant commentary. Fixes openclaw#167305. Original fix by @jlapenna. --------- Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit 2b51bb8)
The 9.9 -> 10.1 carry, its rulings, the fork tests adapted to 10.1, the generated files, the guards, the openclaw#167309 fix and both bots' deploys.
Fixes #167305
What Problem This Solves
Fixes turns failing after runtime notices on strict Chat Completions templates that allow a
systemmessage only at the beginning, including local Qwen backends.User Impact
Sessions can continue after event, heartbeat, and compaction notices without clearing history, switching models, or rewriting requests in a proxy. No configuration or migration is required.
Why This Change Was Made
The shared Chat Completions converter selects
developerfor runtime notices when the resolved route supports that role, or labeledusercontent otherwise. It retains notice positions, text, transcript bytes, and cache exclusions. The leading prompt is unchanged. This is provider-neutral: reasoning capability does not imply that a template accepts later system messages.ClawSweeper's role-contract question is addressed by the existing runtime-context contract: trusted context is projected at the strongest valid provider authority. Developer support supplies that authority; unsupported routes require the labeled-user representation. The change belongs at that projection owner and introduces no config, protocol, SDK, or storage contract. The earlier managed OpenRouter composition finding is fixed, with its cache assertions retained. No human review findings were present.
Original fix by @jlapenna; maintainer cleanup consolidates the role matrix into the existing prompt-prefix/tool-result regression, preserves legacy-carrier and mixed-media coverage, removes redundant commentary, and documents the notice behavior.
Evidence
Current-main verification:
c786f4d4c4ea27630466a529630e56071845a682still projects notices tosystemunless both reasoning and developer support are enabled. The production-only negative control uses its exact converter blob712cd1c53011cb7990cfba5d621b876804a1359b, while retaining final-head tests.Final head:
132394fc3bb66fea8e0132d820c06c7da430d4d0. Formatting, targeted type-aware lint, andgit diff --checkpassed. Fresh independent Codex autoreview: scoped-clean through P2, with no accepted/actionable findings.All product execution ran on fresh secretless AWS lease
cbx_96f8caf09391(m7i.2xlarge, approximately 30 GiB RAM), bound to this head. The clean-main trusted bootstrap verified the head, IAM no-role boundary, isolated HOME, and pinned toolchain. No hydration or contributor execution on the maintainer host.pnpm test packages/ai/src/openai-completions-messages.test.ts --maxWorkers=1pnpm test src/llm/providers/stream-wrappers/proxy.test.ts --maxWorkers=1pnpm tsgo:corepnpm tsgo:core:test --ci-graphs-json '["core-test-packages","core-test-other"]'The regression adds no process boots, timers, sleeps, or production seams. The existing proxy suite's first case pays its shared runtime import/setup cost; its 18 cases are unchanged apart from the corrected notice-role expectation.
Fresh real Gateway proof with a local strict Chat Completions provider passed (103.60s, including cold startup and CLI clients). A separate Gateway process used isolated
OPENCLAW_STATE_DIR, a synthetic workspace, and ephemeral ports. Through the public API, twosystem-event→chat.send→agent.wait→chat.historyturns returnedTURN_1_OKandTURN_2_OK. Captured request roles weresystem,user,userandsystem,user,assistant,user,user; notices reached the provider as labeled user content. The leading system message stayed byte-identical (SHA-256e8d6b5829f7cd57a7babb286733bd1e645d3f7e5993bde928276523e2c760c32). This is a real Gateway with a synthetic provider, not a new real-Qwen run.Production-only negative control: replacing only the converter with the exact recorded-main blob made three role-matrix cases fail (
systemreceived instead ofuser/developer), with the supported reasoning/developer control passing. Test command:pnpm test packages/ai/src/openai-completions-messages.test.ts --maxWorkers=1 -t 'preserves prior prompt bytes when runtime notices follow tool results'(5.59s wall).The identical real-Gateway negative control also failed (92.18s): captured roles
system,user,system; Gateway outcomestatus: "error",LLM request rejected: System role only accepted at index zero. The mock returned HTTP 400. Final production bytes were restored andgit diff --exit-codepassed. The lease was stopped after proof.Final-head CI run passed with no failed jobs. Its 23 successful Node test jobs total 3215 job-wall seconds, including setup and all selected coverage; this is not the incremental cost of the regression. No CI reruns were requested. The full repository test suite was not run separately.
Nonfatal Crabbox telemetry-upload timeouts occurred; command output was captured locally, both remote runs exited 0, and all proof above was inspected.
Remote execution and live commands
Launched from a clean trusted
origin/mainworktree; both runs supplied the full head and the trusted bootstrap:CRABBOX_ENV_ALLOW=CI crabbox run --provider aws --id cbx_96f8caf09391 \ --fresh-pr openclaw/openclaw#167309 --no-hydrate --timing-json \ --script scripts/crabbox-untrusted-bootstrap.sh -- \ 132394fc3bb66fea8e0132d820c06c7da430d4d0 bash -c '<serial proof commands>'CRABBOX_AWS_INSTANCE_PROFILEwas unset; public network and no Tailscale were verified. Unit/type run:run_a9c59936a2dcca5c8166dbb33b5422f6. Live/control run:run_e90594570c5a4a0d96ccc8790780f8bc.The remote-only harness ran
node "$proof_root/runtime-notice-gateway.mjs", spawning:The sequence repeated for turn 2. The local provider captured every request and returned HTTP 400 whenever
messages.slice(1)containedrole: "system"; otherwise it streamed the expected reply. The negative control ran the same harness and tests unchanged after replacing only production bytes.Diff against the recorded main: production +1/-1 (net 0), tests +78/-50 (net +28; reduced from +58), docs +1/-0. No changelog, tooling, dependency, or CI configuration changes.
packages/ai/src/openai-completions-messages.tspackages/ai/src/openai-completions-messages.test.tssrc/llm/providers/stream-wrappers/proxy.test.tsdocs/concepts/model-providers/custom-providers.md