mirror of
https://github.com/bitbaum/openclaw.git
synced 2026-12-06 05:38:21 +01:00
* 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 #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 <noreply@anthropic.com> 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 <noreply@anthropic.com> 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 <noreply@anthropic.com> 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 <noreply@anthropic.com> 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 <noreply@anthropic.com> 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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6 * fix(ai): correct stale instructions-field defaults in Azure test and doc The Azure narrowing in 9bbac5ee5b4 (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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6 * test(ai): correct native base URL explanation --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>