Skip to content

fix(ai): carry the Responses system prompt via instructions, not input[0] - #130206

Merged
Patrick-Erichsen merged 10 commits into
openclaw:mainfrom
hartmark:fix/openai-responses-continuation-instructions-system-prompt
Aug 28, 2026
Merged

Patrick-Erichsen merged 10 commits into
openclaw:mainfrom
hartmark:fix/openai-responses-continuation-instructions-system-prompt

Conversation

@hartmark

@hartmark hartmark commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

HTTP continuation (previous_response_id reuse) for the OpenAI Responses transport was permanently defeated for any non-Codex connection (native OpenAI direct-API-key, xAI, and OmniRoute-style custom Responses endpoints) whenever the system prompt changed between two turns — which happens routinely, since the embedded runner rebuilds the system prompt fresh on every attempt from live runtime state (active background processes, watched sessions, active-memory context, current date).

Why This Change Was Made

convertOpenAIResponsesMessagesForRequest embedded the system prompt as input[0] for every non-Codex Responses request. resolveResponsesContinuationRequest (packages/ai/src/transports/openai-responses-continuation.ts) compares the cached previous request's input byte-for-byte against the current one to decide whether it can reuse previous_response_id; any drift in that first item — including ordinary runtime-state churn that has nothing to do with the actual conversation — forced a history_changed verdict and threw away continuation.

Native Codex/ChatGPT already avoided this by sending the system prompt via the separate instructions field, which sits outside the compared input array (confirmed via isOpenAICodexResponsesModel/resolveOpenAICodexResponsesInstructions). isOpenAICodexResponsesModel is narrowly scoped to the ChatGPT/Codex-OAuth API variant only, so every other Responses route (native OpenAI with an API key, xAI, custom/proxy endpoints) never got this protection.

Fix: broaden instructions to every Responses-API request (previously Codex-only), and exclude instructions from requestWithoutInput's comparison, matching how input is already excluded there. instructions is still sent on the wire every request regardless of continuation status, so no freshness is lost — only the false-positive continuation rejection is removed.

While rolling this out I found and fixed a second, related bug: xAI's server-side /responses/compact endpoint (used for xAI/opted-in compaction, see docs/providers/xai.md) has no instructions field — confirmed live against https://docs.x.ai/developers/advanced-api-usage/context-compaction, which documents the system prompt as required to be the first input message. postOpenAIResponsesCompaction posts only { model, input } built from the same buildOpenAIResponsesParams result the streaming path uses, so once the system prompt moved out of input it would have silently vanished from every compaction request. Fixed by re-embedding it just for that request body via a new buildOpenAIResponsesCompactSystemMessage helper, which reproduces the same developer/system role selection the old inline embedding used.

User Impact

  • OpenAI, xAI, and OmniRoute-style custom Responses connections can now actually engage HTTP continuation across turns, instead of falling back to full-history replay on effectively every request once the runtime has any live state that changes turn-to-turn (which is the common case for persistent/heartbeat sessions).
  • No change to the wire contract seen by operators: instructions was already a valid, already-observed (promptSource: "instructions") prompt-egress state; it's just no longer Codex-exclusive.
  • xAI compaction requests keep receiving the system prompt exactly as before (still embedded in input, since that's xAI's endpoint contract) — this PR prevents what would otherwise have been a silent compaction-quality regression.

Evidence

  • Live external doc check confirming xAI's /responses/compact contract (no instructions field, system prompt must be input[0]): https://docs.x.ai/developers/advanced-api-usage/context-compaction.
  • packages/ai/ full suite: 108 files / 1910 tests passing.
  • Targeted src/agents/ surfaces (openai-transport-stream.*, openai-responses*, openai-thinking-contract, embedded-agent-helpers/openai, prompt-cache-observability, provider-prompt-state, stream-resolution): all passing.
  • src/agents/embedded-agent-runner/run/ (the runner's own consumer of these request-building helpers): 98 files / 1180 tests passing.
  • New packages/ai/src/transports/openai-responses-params-internal.test.ts covering buildOpenAIResponsesCompactSystemMessage's developer/system role selection, since that invariant lost its only other test path once the main streaming builder stopped embedding the role-bearing message in input.
  • pnpm tsgo -p tsconfig.core.json clean.
  • Autoreview: clean, 0 accepted/actionable findings (score 0.97).

This is a companion fix to #130166 (the heartbeat/cron inbound-metadata continuation fix, already merged) — that fix addressed one mechanism defeating continuation on OmniRoute; this addresses a second, broader one affecting the system-prompt path across all non-Codex Responses connections. Marking as draft pending live deployment/verification against a real OmniRoute-backed session, following the same pattern used for #130166.

Live Deployment Verification

Deployed to Ping's real OmniRoute-backed gateway (daemonbitch, ping-deploy-v2 branch, stacked on top of the already-merged #130166 heartbeat/cron fix). Restarted the gateway and inspected OmniRoute's own request-artifact log directly for the first live requests built by the new binary:

  • POST /v1/responses at 2026-08-26T16:13:12.083Z (session agent:main:main, 225 prior input items): requestBody.instructions is present (29,365 chars) and contains the actual system prompt verbatim (Tooling/Runtime/model-identity blocks) — confirmed by reading the full text, not the unrelated <context_handoff> string a different in-flight feature also happens to put in instructions. requestBody.input[0].role is "user", not "system" — the system prompt is no longer embedded in input.
  • Same shape confirmed again on the next heartbeat tick (16:43:00.169Z) and on two further requests in the same session 12s apart (16:43:27.980Z / 16:43:40.053Z).
  • Historical scan of the last ~3 hours of OmniRoute request artifacts (360 requests) shows HTTP continuation (previous_response_id present on the wire) genuinely engaging 4 times prior to this deploy — all attributable to fix(ai): stabilize runtime context across Responses tool rounds #130166 (the heartbeat/cron metadata-stripping fix), confirming the underlying continuation pipeline (idle TTL, connection-identity matching) is healthy in this environment when its one remaining precondition (byte-stable input) holds.
  • I did not catch a fresh previous_response_id-carrying request in the ~40-minute post-deploy observation window. Continuation only engages for same-session follow-ups issued within the ~90-minute idle TTL that are not immediately preceded by a context-compaction turn; both requests I observed in the same session were compaction-boundary turns (the request body opens with The conversation history before this point was compacted into the following summary:), which correctly cannot reuse a previous_response_id regardless of this fix — the input array is intentionally rebuilt from scratch after compaction. This is expected behavior, not a gap in the fix. I'm not blocking on catching a rarer non-compaction same-session follow-up live; the unit-level reproduction (packages/ai/src/transports/openai-responses-continuation.test.ts and the new openai-responses-params-internal.test.ts) already proves the exact byte-comparison behavior deterministically.

Marking ready for review — the fix is confirmed both by full test coverage and by direct inspection of the live request shape it produces.

Update: real native OpenAI continuation proof at current head (7bed52a189d)

Closed the "final-head native OpenAI trace after prompt drift" gap. Added openai-responses-payload-policy.instructions.live.test.ts, gated on OPENCLAW_LIVE_TEST=1 + OPENAI_API_KEY (matching the established openai-responses-client.continuation.live.test.ts pattern), run twice against the real api.openai.com:

  • Turn 1 (real provider: "openai", baseUrl: "https://api.openai.com/v1", no compat override — the exact default-on route this PR targets): the real captured request carries instructions: "You are a terse test assistant." at top level, no input[0] system/developer role, no previous_response_id.
  • Turn 2: the real captured request carries previous_response_id (a real non-empty string returned by the API), instructions still present with the current text, and a single-message trimmed input (no repeated history). The model correctly recalled a secret code that was given only in turn 1's now-omitted history — this is semantic proof, not just structural: a silent full-history fallback would produce the same visible answer with the same request shape claim but a different actual input (full history, secret repeated) — the trimmed-input assertion together with the correct recall rules that out.

Captured via a globalThis.fetch wrapper rather than a forward-proxy, deliberately: a proxy would need to override the model's baseUrl to a loopback address, which would itself fail the exact-origin check supportsNativeOpenAIResponsesEndpoint (continuation eligibility) uses — the same reason a plain custom endpoint never got continuation for free before this PR.

Ran twice (once before, once after an unrelated lint fix); both passed.

check:changed and autoreview both clean.

…t[0]

Every non-Codex OpenAI Responses request embedded the system prompt as
input[0]. HTTP continuation compares input byte-for-byte against the
cached previous request to decide whether it can reuse
previous_response_id, and the embedded runner rebuilds the system
prompt fresh every attempt from live runtime state (active background
processes, watched sessions, active-memory context) -- so ordinary
state churn between two turns permanently defeated continuation.
Native Codex/ChatGPT already avoided this by sending the system prompt
via the separate instructions field; broaden that to every Responses
request (instructions was previously Codex-only) and exclude
instructions from the continuation comparator, matching how input is
already excluded there.

xAI's /responses/compact endpoint has no instructions field (system
prompt must be the first input message, confirmed against
docs.x.ai/developers/advanced-api-usage/context-compaction) and was
about to silently lose the system prompt on every compaction request
once it stopped riding along in input. Re-embed it just for that
request body via a new buildOpenAIResponsesCompactSystemMessage
helper, with its own regression coverage for the developer/system role
selection since that invariant no longer has any other test path.
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Aug 26, 2026
@hartmark
hartmark marked this pull request as ready for review August 26, 2026 16:45
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 27, 2026, 12:02 PM ET / 16:02 UTC.

ClawSweeper review

What this changes

The branch moves eligible OpenAI Responses system prompts to top-level instructions, preserves input-embedded prompts for other routes through a compatibility setting, and re-embeds the prompt for xAI compaction.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open: this is a distinct current-main bug fix with credible live and boundary proof. One P3 correction remains in the new live-test explanation, and the exact head still needs its failed/incomplete CI state resolved before merge.

Priority: P1
Reviewed head: e6ccfa152eeb0882392bd6b552f2a74167912fd4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The core repair has strong layered proof and no blocking functional finding; a small inaccurate live-test explanation and exact-head validation remain.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body records two real native OpenAI runs, and the committed gated live test checks the actual second request, server continuation, trimmed input, and semantic recall after the fix.
Patch quality 🐚 platinum hermit (4/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body records two real native OpenAI runs, and the committed gated live test checks the actual second request, server continuation, trimmed input, and semantic recall after the fix.
Evidence reviewed 7 items Changed request-policy owner: The introduced policy enables instructions only for native OpenAI and native xAI by default, while an explicit compatibility value overrides either direction.
Caller and continuation boundary: The transport builds the request before claiming native HTTP continuation; the continuation resolver retains the current instructions while comparing only stable request state and input history.
Boundary and live coverage: The branch covers changed instructions in the pure continuation resolver, actual loopback HTTP/SSE payloads, and a gated native OpenAI two-turn continuation with trimmed input and semantic recall.
Findings 1 actionable finding [P3] Correct the live-test base-URL explanation
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs packages/ai/src/transports/openai-responses-payload-policy.instructions.integration.test.ts packages/ai/src/transports/openai-responses-continuation.test.ts

Result: PASS (completed)

[test] starting test/vitest/vitest.unit.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130206-CFjBCC/target

 ✓  unit  packages/ai/src/transports/openai-responses-continuation.test.ts (6 tests) 137ms
 ✓  unit  packages/ai/src/transports/openai-responses-payload-policy.instructions.integration.test.ts (2 tests) 91ms

 Test Files  2 passed (2)
      Tests  8 passed (8)
   Start at  16:03:55
   Duration  2.66s (transform 3.19s, setup 2.49s, import 1.34s, tests 228ms, environment 0ms)

[test] passed 1 Vitest shard in 15.44s

Assertions:

  • PASS expect_output: passed

How this fits together

The Responses transport turns agent context into provider requests and may reuse a prior response to avoid replaying history. This change controls where the system prompt is serialized, which affects continuation eligibility and xAI compaction input.

flowchart LR
A[Agent runtime context] --> B[Responses request builder]
B --> C{Verified instructions route?}
C -->|Yes| D[Top-level instructions]
C -->|No| E[System prompt in request input]
D --> F[Continuation or provider request]
E --> F
F --> G[xAI compaction when requested]
Loading

Before merge

  • Correct the live-test base-URL explanation (P3) - The comment says capture leaves the model base URL unset, but the fixture explicitly uses https://api.openai.com/v1 below. Say that the fetch wrapper avoids a proxy while retaining the explicit native URL; that exact URL is material to continuation eligibility. This wording predates the earlier reviewed head.
  • Resolve merge risk (P1) - This changes the default provider wire shape for native OpenAI and xAI; the new per-model compatibility override preserves input-embedded prompts for any route, but the exact head must complete green CI before merge.
  • Resolve merge risk (P1) - Production changes are +127/-20 (net +107); the growth is concentrated in the existing payload-policy, request builder, and config/catalog contract needed to make the compatibility decision explicit.
  • Complete next step (P2) - The remaining code change is a narrow, mechanical correction to a newly introduced test comment; failed CI needs separate exact-head diagnosis if it persists.

Findings

  • [P3] Correct the live-test base-URL explanation — packages/ai/src/transports/openai-responses-payload-policy.instructions.live.test.ts:13-15
Agent review details

Security

None.

PR surface

Source +107, Tests +580, Docs +1. Total +688 across 22 files.

View PR surface stats
Area Files Added Removed Net
Source 10 127 20 +107
Tests 11 632 52 +580
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 22 760 72 +688

Review metrics

Metric Value Why it matters
Production versus test delta production +127/-20 (net +107); tests +632/-52 (net +580); docs +1 The added compatibility policy and config/catalog propagation are substantial for a bug fix and deserve merge-time scrutiny.
Compatibility surface 1 added model compatibility setting Operators can explicitly preserve input-embedded system prompts for endpoints that do not honor instructions.

Stored data model

Persistent data-model change detected: serialized state: src/agents/sessions/model-registry.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Correct the live-test explanation and refresh validation (recommended)
    State that the fetch wrapper avoids a proxy while the fixture retains an explicit native OpenAI base URL, then resolve the failed/incomplete exact-head checks.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Correct the live-test comment to describe the explicit native OpenAI base URL, then run the focused Responses tests and the changed check gate.

Technical review

Best possible solution:

Keep one request-builder policy for prompt placement, correct the stale live-test explanation, and land only once exact-head validation confirms the documented compatibility behavior.

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

Yes, source reproduction is high confidence: fetched main embeds the prompt in input and compares it as continuation history, while the added resolver and live native-API tests define the failing and repaired paths.

Is this the best way to solve the issue?

Yes, after the route narrowing the policy is the right owner boundary: it keeps unverified routes on their existing input format and leaves current instructions on each continued native request.

Full review comments:

  • [P3] Correct the live-test base-URL explanation — packages/ai/src/transports/openai-responses-payload-policy.instructions.live.test.ts:13-15
    The comment says capture leaves the model base URL unset, but the fixture explicitly uses https://api.openai.com/v1 below. Say that the fetch wrapper avoids a proxy while retaining the explicit native URL; that exact URL is material to continuation eligibility. This wording predates the earlier reviewed head.
    Confidence: 0.99
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is correct
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8e4075371039.

Labels

Label justifications:

  • P1: The existing supported Responses continuation path can repeatedly fall back to full-history replay when routine system-prompt state changes.
  • merge-risk: 🚨 compatibility: Native OpenAI and xAI requests change prompt placement, while the new configuration key controls the compatibility fallback.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body records two real native OpenAI runs, and the committed gated live test checks the actual second request, server continuation, trimmed input, and semantic recall after the fix.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records two real native OpenAI runs, and the committed gated live test checks the actual second request, server continuation, trimmed input, and semantic recall after the fix.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs packages/ai/src/transports/openai-responses-payload-policy.instructions.integration.test.ts packages/ai/src/transports/openai-responses-continuation.test.ts.
  • [P1] node scripts/check-changed.mjs -- packages/ai/src/transports/openai-responses-payload-policy.instructions.live.test.ts.

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored the xAI compaction feature and has the largest visible history share across the payload-policy, client, and continuation files. (role: recent owner of Responses payload and xAI compaction work; confidence: high; commits: c3887db7c174, 575467aa5834; files: packages/ai/src/transports/openai-responses-client.ts, packages/ai/src/transports/openai-responses-payload-policy.ts)
  • hartmark: Markus Hartung authored the stateful SSE continuation feature and the current request-policy repair. (role: continuation feature owner; confidence: high; commits: 4e12d0556b10, e6ccfa152eeb; files: packages/ai/src/transports/openai-responses-continuation.ts, packages/ai/src/transports/openai-responses-params-internal.ts)
  • vincentkoc: Vincent Koc authored the existing native provider prompt-egress observation work updated by this branch. (role: prompt-observability contributor; confidence: medium; commits: a54bec799cdc; files: packages/ai/src/transports/openai-responses-prompt-observer.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Correct the stale live-test comment.
  • Resolve the failed and incomplete exact-head checks before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-27T01:00:32.912Z sha aff2874 :: needs real behavior proof before merge. :: [P1] Preserve input prompts on unverified Responses routes | [P2] Update xAI replay coverage for the new prompt location | [P2] Document the new compatibility opt-out
  • reviewed 2026-08-27T06:43:16.787Z sha 882228c :: needs real behavior proof before merge. :: [P1] Default instructions off for unverified named providers
  • reviewed 2026-08-27T06:51:57.154Z sha 882228c :: needs real behavior proof before merge. :: [P1] Preserve prompts for unverified named endpoints
  • reviewed 2026-08-27T07:58:30.049Z sha 3ec479d :: needs real behavior proof before merge. :: [P2] Cover changed instructions in the continuation regression | [P2] Correct the documented supportsInstructions default
  • reviewed 2026-08-27T11:40:06.834Z sha fb2a263 :: needs real behavior proof before merge. :: [P3] Correct the public supportsInstructions default
  • reviewed 2026-08-27T13:06:13.746Z sha 7bed52a :: needs changes before merge. :: [P1] Keep Azure out of the verified instructions default
  • reviewed 2026-08-27T13:55:24.371Z sha 9bbac5e :: needs changes before merge. :: [P3] Correct the public supportsInstructions default
  • reviewed 2026-08-27T15:14:03.208Z sha e6ccfa1 :: needs maintainer review before merge. :: none

@Yigtwxx Yigtwxx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Measured this against c02ac37d1224 (the base ClawSweeper reviewed) at head 2f27a12e5ab. Two things: the continuation proof the bot asked for, which I could produce deterministically, and one finding about the field's reach.

The proof ClawSweeper asked for

The bot's blocker is that the body shows the request shape but never the recovered continuation. That outcome is reachable without a live provider, because resolveResponsesContinuationRequest is a pure function over the exact bodies buildOpenAIResponsesParams emits.

Two turns on a proxy-like route (api: "openai-responses", configured non-native baseUrl), with only the runtime-state half of the system prompt churning between them and the conversation a clean append:

arm turn-1 input roles turn-2 input roles continuationStatus
main c02ac37d1224 developer, user developer, user, assistant, user history_changed
this branch 2f27a12e5ab user user, assistant, user continued

Same model, same context objects, same probe — only the two checked-out revisions of packages/ai/src/transports/ differ. That is the claim in the PR title, reproduced end to end: the system-prompt churn is what defeated continuation on main, and moving it to instructions recovers it.

Finding: instructions reaches every route with no capability gate

buildOpenAIResponsesParams calls applyOpenAIResponsesPayloadPolicy at the end (line 369), and that policy exists specifically because non-native Responses routes do not accept everything the native one does. On a configured non-native baseUrl it currently gates or strips five things: store, prompt_cache_key + prompt_cache_retention, disabled-reasoning payload, service_tier, and input-item status — the last one carrying the comment "Strict OpenAI-compatible Responses endpoints reject output-only fields such as status on replayed input items. Strip them for non-native routes."

instructions now joins that payload for every Responses route and is the only one of those fields with no gate. Same probe, same proxy-like model:

arm instructions carries system prompt system prompt present in input
main c02ac37d1224 no yes (input[0].role = "developer")
this branch 2f27a12e5ab yes no

So on a route that accepts the request but ignores instructions, the system prompt stops arriving and the call still returns 200. Nothing in the transport notices — this is a silent quality regression, not an error, which is what makes it worth a gate rather than a note.

The reason I do not think this is hypothetical is in this PR itself: xAI's /responses/compact is exactly such an endpoint, and you found it and hand-wrote buildOpenAIResponsesCompactSystemMessage for it. That is one confirmed counter-example to "every Responses endpoint honors instructions", handled by a special case. A second counter-example — some proxy in the custom endpoint class — would not get a special case; it would just quietly lose its system prompt.

The narrow shape that keeps your win intact: reuse the pattern already in the same module, a compat.supportsInstructions boolean read through readCompatPayloadBoolean and defaulting to on, falling back to the input embedding when an operator sets it false. That leaves the default path — including the OmniRoute routes this PR targets — exactly as you have it, and gives a broken proxy an opt-out instead of an unexplained personality change. supportsStore and supportsPromptCacheKey are already carried that way.

One hypothesis I tested and dropped

I expected the system-prompt-only turn to double up, since ensureOpenAIResponsesNonEmptyInput now runs for every model rather than Codex only. It does not: the placeholder it pushes is a single space, so that turn sends instructions plus [{role: "user", text: " "}] and the prompt text appears once. No finding there — recording it so the negative is on the record.

Environment

Probes ran on Windows under node --import tsx, calling buildOpenAIResponsesParams and resolveResponsesContinuationRequest directly; no mocks and no network. This machine is on Node 22.20, whose embedded SQLite trips OpenClaw's WAL-reset guard during module import, so a local shim fakes only the sqlite_version() string — every other runtime behaviour is the real implementation. No provider credentials were involved.

…Instructions

A proxy-compatible Responses endpoint that silently ignores `instructions`
(confirmed for at least xAI's compact endpoint, plausible for other
custom/proxy routes with no established contract) would drop the system
prompt with no error -- the request still returns 200. Add a
compat.supportsInstructions escape hatch, defaulting to on, mirroring
the existing supportsStore/supportsPromptCacheKey pattern: when an
operator sets it false, the system prompt goes back to being embedded
in `input[0]` (the pre-instructions behavior) instead of `instructions`.

Addresses the maintainer review finding on openclaw#130206.
@hartmark

Copy link
Copy Markdown
Contributor Author

Thanks for this — the resolveResponsesContinuationRequest pure-function proof is exactly right and a better demonstration than a live trace would have been (deterministic, no provider flakiness). Confirms the core claim precisely.

The instructions capability-gate finding is correct and I've implemented essentially what you suggested: compat.supportsInstructions (default on), read through readCompatPayloadBoolean alongside the existing supportsStore/supportsPromptCacheKey pattern in openai-responses-payload-policy.ts. When an operator sets it false for a route, buildOpenAIResponsesParams goes back to embedding the system prompt in input[0] and omits instructions entirely — the exact pre-fix behavior, scoped to that one model.

Also produced my own live proof for the "does continuation actually recover" question in the meantime: ran two isolated agent exec turns against the real OmniRoute connection (tool-call chain, so two real HTTP requests in the same session) — confirmed via OmniRoute's own request log that the wire shape is correct (instructions present, input[0].role no longer system). I have not yet caught a live previous_response_id recovery on this specific connection even under ideal conditions (fresh session, no compaction, tight timing) — still investigating whether something else is gating it for this particular OmniRoute route, separate from what this PR fixes. Your pure-function proof is the stronger evidence for the PR's actual claim regardless, since it isolates exactly the change under test.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 26, 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:

@Yigtwxx Yigtwxx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — I measured c0d6d3737f4 and the gate behaves exactly as described. Same deterministic harness as before (buildOpenAIResponsesParams called directly, proxy-style model, sentinel system prompt), with the default and an unrelated compat key as control arms:

compat on the model instructions sent input roles system prompt inside input
absent (default) yes ["user"] no
supportsInstructions: true yes ["user"] no
supportsInstructions: false no ["developer","user"] yes
supportsStore: false (control) yes ["user"] no

So the opt-out reproduces the pre-instructions shape precisely, and no other compat key leaks into the decision.

On the live previous_response_id recovery you could not catch

I think that is gated before your change ever runs, and it is worth confirming so you do not keep chasing it against this PR. HTTP continuation is only ever claimed under openai-responses-client.ts:369-397:

const httpContinuationEligible =
  config.httpContinuation &&
  !websocketMode &&
  !getAiTransportHost().requiresManagedTransport(model) &&
  supportsNativeOpenAIResponsesEndpoint({ provider: model.provider, api: model.api, baseUrl: model.baseUrl });
if (httpContinuationEligible && sessionId && params.store === true && !params.previous_response_id) {

supportsNativeOpenAIResponsesEndpoint (openai-responses-websocket.ts:74-84) requires all three: provider === "openai", api === "openai-responses", and a base URL whose origin is exactly https://api.openai.com with path /v1, no credentials, no query, no fragment. Measured:

route continuation eligible
openai + https://api.openai.com/v1 true
openai + https://api.openai.com/v1/ true
openai + https://api.openai.com/v1?beta=1 false
openai + https://my-gw.openai.azure.com/v1 false
openai + proxy base URL false
non-openai provider + proxy base URL false

If your OmniRoute connection points anywhere other than the official base URL — which is the point of a router — claimOpenAIResponsesHttpContinuation is never called, so no request on that route can carry previous_response_id regardless of what input looks like. The second gate, params.store === true, would independently disqualify any route that runs with store stripped.

That makes the missing live recovery orthogonal to this PR rather than evidence against it: your change fixes what continuation compares (input no longer carries a per-turn-rebuilt system prompt), while route eligibility decides whether the comparison is ever reached. On a native api.openai.com connection your fix is what makes the comparison succeed; on a proxied route it was never going to run either way.

Nothing here asks for a change to the patch — this is the answer to the open question, so the missing trace does not read as an unproven claim during review.

…acts

usesInstructionsField already read compat.supportsInstructions at
request-build time, but strict config and catalog normalization dropped
the key, so no configured model could actually set it. A proxy that
silently ignores top-level instructions had no supported way to opt out.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6
@hartmark

Copy link
Copy Markdown
Contributor Author

Pushed aff287435b6: wires supportsInstructions through the strict config schema (ModelCompatSchema), the model-registry.ts TypeBox schema, and the catalog compat type + normalizer allowlist — same pattern as the sibling supportsStore/supportsTemperature keys. Two new regression tests: zod-schema.models.test.ts proves a real openclaw.json-shaped config with compat: { supportsInstructions: false } parses under the .strict() schema, and model-registry.test.ts proves it survives the full plugin-catalog → ModelRegistry.find() pipeline (fails before this commit, since normalizeModelCatalogCompat silently dropped the field). pnpm check:changed clean on the full branch diff.

Also fixed the pre-existing assertion SAFETY comment ratchet gate failure this branch already had (unrelated to my change, but broken on this head) — added the missing // SAFETY: comment for the model as OpenAIModeModel cast in the new buildOpenAIResponsesCompactSystemMessage.

On the second rank-up move ("add a redacted provider trace showing an eligible continuation request carrying previous_response_id"): explicitly skipping it. Yigtwxx's second review already answered the underlying question with source-level proof (the native-endpoint eligibility gate in openai-responses-websocket.ts requires base URL exactly https://api.openai.com/v1, which no proxy route — including OmniRoute — ever satisfies), and I don't have a native api.openai.com-eligible credential provisioned in this environment to produce a fresh live trace beyond that. Not blocking merge per the review's own classification (rank-up, not a Before merge item).

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 27, 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 rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 27, 2026
…proxy routes

usesInstructionsField defaulted true for any api:"openai-responses" model
regardless of endpoint, including arbitrary custom/local proxies OpenClaw
has no bundled knowledge of. HTTP continuation only ever engages on the
exact native api.openai.com route, so an unverified proxy got nothing in
return for the risk of silently losing its system prompt if it doesn't
honor `instructions`. Default now follows the same known-endpoint
classification the file already uses for reasoning/input-status payload
shaping; xAI's already-verified main route is unaffected since it's a
named endpoint class, not "custom"/"local".

Also updates the one stale test this flips (xAI compact-endpoint replay
no longer embeds the system prompt in input[0], matching what the
original PR's instructions-field change already does for that route) and
documents supportsInstructions in the custom-provider compat table.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: xai labels Aug 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 27, 2026
@hartmark

Copy link
Copy Markdown
Contributor Author

Pushed 882228ca3a2 addressing the P1 from the latest review (usesInstructionsField defaulted true for any openai-responses route, including arbitrary custom/local proxies with no bundled verification — real risk of silently dropping the system prompt on upgrade, with nothing gained since HTTP continuation only ever engages on the exact native api.openai.com route anyway).

Fix: default now follows the same known-endpoint classification (resolveBundledOpenAIResponsesEndpointClass) this file already uses elsewhere in the same function for reasoning/input-status payload shaping — usesUnverifiedProxyEndpoint = endpointClass === "custom" || endpointClass === "local". Named/bundled classes (openai, azure-openai, xai-native, etc.) still default on; an unrecognized custom or local base URL defaults off; compat.supportsInstructions still overrides explicitly in either direction. xAI's already-verified main route is a named class, not "custom", so it's unaffected — confirmed by the existing passing test.

Also fixed the two things this exposed:

  • extensions/xai/server-compaction.test.ts's replay assertion was stale relative to this PR's own change (still expected input[0].role === "system" on xAI's main route, which the original PR's instructions-field change had already made incorrect independent of my fix) — updated to assert instructions instead.
  • Documented supportsInstructions in the custom-provider compat table (docs/gateway/config-tools.md).

Two new regression tests: an unverified custom-proxy route with no explicit compat now defaults to embedding the prompt in input (old behavior, fails pre-fix), and an explicit supportsInstructions: true opt-in on that same route now correctly uses instructions.

check:changed and autoreview both clean on the full branch diff.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 27, 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 P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. labels Aug 27, 2026
@clawsweeper clawsweeper Bot added the rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. label Aug 27, 2026
The comparator already strips instructions before comparing requests
(requestWithoutInput), matching how it already strips input -- but no
fixture actually varied instructions between turns, so nothing proved
continuation still engages when the rebuilt-per-turn instructions text
legitimately differs, or that the current turn's instructions (not a
stale copy) reaches the outgoing request.

Also fixes a stale doc: the custom-provider compat table said
supportsInstructions defaults true for "bundled/catalog-known routes",
which was accurate for an earlier iteration of this branch but not the
current, narrower default (native OpenAI and xAI's main route only).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6
@hartmark

Copy link
Copy Markdown
Contributor Author

Pushed fb2a26394e3, addressing both findings:

Cover changed instructions in the continuation regression — requestWithoutInput already stripped instructions from the comparator (existing behavior, matching how input is already stripped), but no fixture varied instructions between turns, so nothing proved continuation still engages when the per-turn-rebuilt instructions text legitimately differs, or that the current turn's instructions (not a stale copy) reaches the wire. Added that case directly to openai-responses-continuation.test.ts.

Correct the documented supportsInstructions default — my own docs edit from the previous fix was already stale by the time it landed (written for the intermediate, broader default before the OpenCode/GitHub-Copilot fix narrowed it). Now states the real default set precisely: native OpenAI and xAI's main route only.

check:changed and autoreview both clean.

Still explicitly skipping the native previous_response_id trace on a real api.openai.com route — no eligible credential available in this environment; unchanged from the prior explanation.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 27, 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 rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 27, 2026
…ation

Committed, rerunnable proof of the actual open question -- does a real
native OpenAI Responses request carry the system prompt via top-level
instructions, and does HTTP continuation still correctly reuse
previous_response_id once the prompt moved out of input. Follows the
established openai-responses-client.continuation.live.test.ts pattern
(gated on OPENCLAW_LIVE_TEST=1 + OPENAI_API_KEY, skipped otherwise).

Captures the literal request bytes via a globalThis.fetch wrapper
rather than a forward-proxy: proxying would require overriding the
model's baseUrl to a loopback address, which would itself defeat the
native-route classification under test (the continuation eligibility
check in openai-responses-websocket.ts requires an exact
https://api.openai.com/v1 origin/path match and treats any other
baseUrl, including a proxy's loopback address, as non-native).

Uses the same secret-recall semantic proof as the reference continuation
live test: turn 2 can only produce the secret given in turn 1 if the
real API actually resolved server-side state through
previous_response_id, since the trimmed turn-2 request never repeats it
-- structural proof (previous_response_id present) alone can't rule out
a silent full-history fallback producing the same visible answer.

Verified: run against the real API twice (once before, once after an
unrelated lint fix) -- both passed, confirming turn 1 carries
instructions with no previous_response_id, turn 2 carries
previous_response_id plus the correctly-recalled secret with a
single-message trimmed input.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6
@hartmark

Copy link
Copy Markdown
Contributor Author

Added real, current-head, live proof against api.openai.com (PR body updated above) — closes the outstanding 'final-head native OpenAI trace' item: real request carries instructions, real continuation via previous_response_id, semantic secret-recall proof ruling out a silent full-history fallback. Committed as a gated live test (OPENCLAW_LIVE_TEST=1 + OPENAI_API_KEY), not a throwaway script.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 27, 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 P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed P2 Normal backlog priority with limited blast radius. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 27, 2026
…fault

usesVerifiedInstructionsEndpoint reused usesKnownNativeOpenAIRoute, which
also covers azure-openai -- a boolean this file already uses elsewhere
for reasoning/service-tier/input-status policy, where treating Azure as
"native-like" is fine. Reusing it for the instructions default silently
contradicted the PR's own stated evidence boundary (native OpenAI and
xAI's main route only): Azure was never actually verified to honor
`instructions`, unlike those two.

Introduces a narrower usesVerifiedNativeOpenAIRoute specific to this
decision, explicitly excluding azure-openai. Two pre-existing tests that
happened to use an Azure model fixture to test unrelated message-item
serialization structure now opt in explicitly via
compat.supportsInstructions -- their actual intent (structure once
instructions is in play) is unchanged. Left the shared
createAzureResponsesModel() helper itself untouched since ~30 other call
sites across sibling test files use it for unrelated behavior.

New regression test proves Azure specifically defaults to input-embedded,
unlike native OpenAI.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6
@hartmark

Copy link
Copy Markdown
Contributor Author

Pushed 9bbac5ee5b4, addressing the P1: usesVerifiedInstructionsEndpoint reused usesKnownNativeOpenAIRoute, which also covers azure-openai — a boolean this file already uses elsewhere (reasoning/service-tier/input-status policy) where treating Azure as native-like is fine. Reusing it for the instructions default silently contradicted the PR's own stated evidence boundary (native OpenAI and xAI's main route only, per every prior review comment on this PR) — Azure was never actually verified.

Introduced a narrower usesVerifiedNativeOpenAIRoute specific to this decision that explicitly excludes azure-openai. Two pre-existing tests happened to use an Azure fixture to test unrelated message-serialization structure — updated them to opt in explicitly via compat.supportsInstructions, preserving their actual intent. Left the shared createAzureResponsesModel() helper itself untouched (~30 other call sites across sibling test files use it for unrelated behavior — confirmed unaffected by running all of them). New regression test proves Azure specifically defaults to input-embedded, unlike native OpenAI.

check:changed and autoreview both clean.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 27, 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 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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 27, 2026

@Yigtwxx Yigtwxx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI at head 9bbac5ee5b4 is red in three jobs. One is caused by this push; the other two do not reproduce against the diff.

The real one: checks-node-compact-small-34, core-unit-support shard

packages/ai/src/transports/openai-responses-prompt-observer.test.ts:326 > "observes Azure Responses egress":

AssertionError: expected { egress: 'responses-sdk', ... } to match object { ... }
-   "promptSource": "instructions",
+   "promptSource": "input.developer",

The cause is inside this PR's own diff. That line was flipped back when supportsInstructions still defaulted on for every non-Codex Responses route:

   it("observes Azure Responses egress", async () => {
     ...
-      promptSource: "input.developer",
+      promptSource: "instructions",

9bbac5ee5b4 then narrowed usesVerifiedInstructionsEndpoint to openai-public | openai | xai-native, so the azure-openai fixture correctly falls back to the input-embedded prompt again, while the assertion still encodes the pre-narrowing universal default. The runtime behavior after 9bbac5e is the intended one; only the expectation is stale, so reverting that single line to "input.developer" clears the shard.

Same family as the remaining P3, with a third instance

The open finding is the supportsInstructions comment at packages/llm-core/src/types.ts:535 ("Default: true"). The header comment this PR adds in the same test file, lines 283-288, makes the same overreach:

Every non-Codex Responses request now carries the system prompt via instructions, not an input.developer/input.system message

True for the earlier design, not after 9bbac5e - and the Azure case forty lines below is the counter-example in the same file. Correcting these two alongside the type comment leaves the exported contract, the type doc, and the test's own documentation stating one selective default instead of three different ones.

The other two reds

  • checks-node-compact-small-11: src/gateway/server.chat.gateway-server-chat.test.ts:2741 > "agent.wait ignores lifecycle completion while same-runId chat.send is active", failing on "Gateway did not publish settled run ownership after chat.send cleanup". A timing assertion in a file this PR does not touch and that no Responses transport path reaches.
  • build-artifacts / startup-memory: plugins list --json median 407.7 MB against an effective ceiling of 401 MB, samples 407.7 / 422.5 / 399.1 MB. The sample spread straddles the ceiling on its own, and the diff adds no import to the plugins command path.

Neither of those failed at fb2a26394e3 or 3ec479d0fe3, both of which were fully green - which is also where the Azure assertion still passed. The unit-support red is confined to the last push.

The Azure narrowing in 9bbac5e (usesVerifiedInstructionsEndpoint ->
openai-public | openai | xai-native) correctly moved Azure back to
embedding the prompt in input, but left one test assertion and two
comments describing the pre-narrowing universal default.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6
@hartmark

Copy link
Copy Markdown
Contributor Author

Fixed in e6ccfa152ee — thanks for catching this, and for narrowing it down to the exact stale-comment cluster.

  • openai-responses-prompt-observer.test.ts: "observes Azure Responses egress" now expects promptSource: "input.developer" — Azure isn't a verified instructions-field route (usesVerifiedInstructionsEndpoint in openai-responses-payload-policy.ts only covers native OpenAI + xAI since 9bbac5ee5b4), so it correctly falls back to embedding the prompt in input.
  • Same file: the block comment above the reasoning it.each table claimed every non-Codex Responses request carries the prompt via instructions — corrected to describe the actual route-specific default, pointing at the Azure test as the counter-example.
  • packages/llm-core/src/types.ts: supportsInstructions's JSDoc no longer says "Default: true" unconditionally — now states it defaults true only for verified native OpenAI/xAI routes.

Reran the full file (17/17 pass) plus the payload-policy, continuation, and transport-stream suites it touches (149 tests total) — no other fallout. check:changed and autoreview both clean on this commit.

Also checked the two other red jobs from the earlier run: checks-node-compact-small-11 passed on this fresh CI run (flake, not a real regression), and build-artifacts/startup-memory is still in progress — will follow up if it comes back red.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 27, 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:

@Patrick-Erichsen
Patrick-Erichsen merged commit e1a2f77 into openclaw:main Aug 28, 2026
251 checks passed
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
…t[0] (openclaw#130206)

* fix(ai): carry the Responses system prompt via instructions, not input[0]

Every non-Codex OpenAI Responses request embedded the system prompt as
input[0]. HTTP continuation compares input byte-for-byte against the
cached previous request to decide whether it can reuse
previous_response_id, and the embedded runner rebuilds the system
prompt fresh every attempt from live runtime state (active background
processes, watched sessions, active-memory context) -- so ordinary
state churn between two turns permanently defeated continuation.
Native Codex/ChatGPT already avoided this by sending the system prompt
via the separate instructions field; broaden that to every Responses
request (instructions was previously Codex-only) and exclude
instructions from the continuation comparator, matching how input is
already excluded there.

xAI's /responses/compact endpoint has no instructions field (system
prompt must be the first input message, confirmed against
docs.x.ai/developers/advanced-api-usage/context-compaction) and was
about to silently lose the system prompt on every compaction request
once it stopped riding along in input. Re-embed it just for that
request body via a new buildOpenAIResponsesCompactSystemMessage
helper, with its own regression coverage for the developer/system role
selection since that invariant no longer has any other test path.

* fix(ai): gate the Responses instructions field behind compat.supportsInstructions

A proxy-compatible Responses endpoint that silently ignores `instructions`
(confirmed for at least xAI's compact endpoint, plausible for other
custom/proxy routes with no established contract) would drop the system
prompt with no error -- the request still returns 200. Add a
compat.supportsInstructions escape hatch, defaulting to on, mirroring
the existing supportsStore/supportsPromptCacheKey pattern: when an
operator sets it false, the system prompt goes back to being embedded
in `input[0]` (the pre-instructions behavior) instead of `instructions`.

Addresses the maintainer review finding on openclaw#130206.

* fix(ai): expose supportsInstructions through config and catalog contracts

usesInstructionsField already read compat.supportsInstructions at
request-build time, but strict config and catalog normalization dropped
the key, so no configured model could actually set it. A proxy that
silently ignores top-level instructions had no supported way to opt out.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6

* fix(ai): default the Responses instructions field off for unverified proxy routes

usesInstructionsField defaulted true for any api:"openai-responses" model
regardless of endpoint, including arbitrary custom/local proxies OpenClaw
has no bundled knowledge of. HTTP continuation only ever engages on the
exact native api.openai.com route, so an unverified proxy got nothing in
return for the risk of silently losing its system prompt if it doesn't
honor `instructions`. Default now follows the same known-endpoint
classification the file already uses for reasoning/input-status payload
shaping; xAI's already-verified main route is unaffected since it's a
named endpoint class, not "custom"/"local".

Also updates the one stale test this flips (xAI compact-endpoint replay
no longer embeds the system prompt in input[0], matching what the
original PR's instructions-field change already does for that route) and
documents supportsInstructions in the custom-provider compat table.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6

* fix(ai): narrow the instructions-field default to only confirmed-verified routes

usesVerifiedInstructionsEndpoint (formerly usesUnverifiedProxyEndpoint's
inverse) treated every named endpointClass except custom/local as
verified -- but recognizing a hostname (for SSRF/base-URL matching) is
not the same as having confirmed that host's Responses API honors
`instructions`. Bundled classes like OpenCode and GitHub Copilot have no
such confirmation, so their existing users could silently lose their
system prompt on upgrade. Narrowed the default-on set to exactly the two
routes actually verified: native OpenAI (definitionally) and xAI's main
route (confirmed by direct testing, per the existing compact-endpoint
carve-out). Every other route, named or not, now defaults to the
pre-existing input-embedded behavior unless compat.supportsInstructions
opts it in explicitly.

Also lands a permanent committed integration test
(openai-responses-payload-policy.instructions.integration.test.ts) over
a real loopback HTTP+SSE server -- no SDK mocking -- asserting the
literal wire request for both the unverified-default-off and
explicit-opt-in cases, following the same pattern as
openai-responses-client.continuation.integration.test.ts.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6

* test(ai): cover continuation across a changed instructions value

The comparator already strips instructions before comparing requests
(requestWithoutInput), matching how it already strips input -- but no
fixture actually varied instructions between turns, so nothing proved
continuation still engages when the rebuilt-per-turn instructions text
legitimately differs, or that the current turn's instructions (not a
stale copy) reaches the outgoing request.

Also fixes a stale doc: the custom-provider compat table said
supportsInstructions defaults true for "bundled/catalog-known routes",
which was accurate for an earlier iteration of this branch but not the
current, narrower default (native OpenAI and xAI's main route only).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6

* test(ai): add gated live proof for the instructions default + continuation

Committed, rerunnable proof of the actual open question -- does a real
native OpenAI Responses request carry the system prompt via top-level
instructions, and does HTTP continuation still correctly reuse
previous_response_id once the prompt moved out of input. Follows the
established openai-responses-client.continuation.live.test.ts pattern
(gated on OPENCLAW_LIVE_TEST=1 + OPENAI_API_KEY, skipped otherwise).

Captures the literal request bytes via a globalThis.fetch wrapper
rather than a forward-proxy: proxying would require overriding the
model's baseUrl to a loopback address, which would itself defeat the
native-route classification under test (the continuation eligibility
check in openai-responses-websocket.ts requires an exact
https://api.openai.com/v1 origin/path match and treats any other
baseUrl, including a proxy's loopback address, as non-native).

Uses the same secret-recall semantic proof as the reference continuation
live test: turn 2 can only produce the secret given in turn 1 if the
real API actually resolved server-side state through
previous_response_id, since the trimmed turn-2 request never repeats it
-- structural proof (previous_response_id present) alone can't rule out
a silent full-history fallback producing the same visible answer.

Verified: run against the real API twice (once before, once after an
unrelated lint fix) -- both passed, confirming turn 1 carries
instructions with no previous_response_id, turn 2 carries
previous_response_id plus the correctly-recalled secret with a
single-message trimmed input.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6

* fix(ai): exclude Azure OpenAI from the verified instructions-field default

usesVerifiedInstructionsEndpoint reused usesKnownNativeOpenAIRoute, which
also covers azure-openai -- a boolean this file already uses elsewhere
for reasoning/service-tier/input-status policy, where treating Azure as
"native-like" is fine. Reusing it for the instructions default silently
contradicted the PR's own stated evidence boundary (native OpenAI and
xAI's main route only): Azure was never actually verified to honor
`instructions`, unlike those two.

Introduces a narrower usesVerifiedNativeOpenAIRoute specific to this
decision, explicitly excluding azure-openai. Two pre-existing tests that
happened to use an Azure model fixture to test unrelated message-item
serialization structure now opt in explicitly via
compat.supportsInstructions -- their actual intent (structure once
instructions is in play) is unchanged. Left the shared
createAzureResponsesModel() helper itself untouched since ~30 other call
sites across sibling test files use it for unrelated behavior.

New regression test proves Azure specifically defaults to input-embedded,
unlike native OpenAI.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6

* fix(ai): correct stale instructions-field defaults in Azure test and doc

The Azure narrowing in 9bbac5e (usesVerifiedInstructionsEndpoint ->
openai-public | openai | xai-native) correctly moved Azure back to
embedding the prompt in input, but left one test assertion and two
comments describing the pre-narrowing universal default.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6

* test(ai): correct native base URL explanation

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
Co-authored-by: Patrick Erichsen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: xai gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

3 participants