Repository navigation
fix(bridge): end the turn on a terminal upstream refusal instead of a retryable incomplete #7152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
nekonade
wants to merge
6
commits into
lidge-jun:dev
from
nekonade:fix/terminal-refusal-response-failed
+849
−19
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f046858
fix(bridge): end the turn on a terminal upstream refusal instead of a…
nekonade 4c23fea
fix(sidecars): end the turn when a refused iteration carries a sideca…
cd76952
test(sidecars): cover refusal stops on every inbound wire
480e29f
docs(bridge): isolate the terminal refusal contract from reason norma…
0ca7a3b
Merge remote-tracking branch 'origin/dev' into HEAD
be71228
Merge remote-tracking branch 'origin/dev' into HEAD
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import type { AdapterEvent } from "../types"; | ||
| import type { OcxErrorPayload } from "../lib/errors"; | ||
| import { redactSecretString } from "../lib/redact"; | ||
|
|
||
| /** | ||
| * The terminal-refusal code Codex ends a turn on. It is a member of `TERMINAL_REFUSAL_CODES` | ||
| * in `src/lib/errors.ts`, and the one that says "this prompt, as sent, is refused" without | ||
| * claiming a specific policy family the upstream never named. | ||
| */ | ||
| const TERMINAL_REFUSAL_FAILED_CODE = "invalid_prompt"; | ||
|
|
||
| interface TerminalRefusalFailure { | ||
| error: OcxErrorPayload; | ||
| last_error: OcxErrorPayload; | ||
| retryable: false; | ||
| } | ||
|
|
||
| /** | ||
| * Client-visible copy: what happened, and that resending the same context cannot help. It points | ||
| * at a new conversation rather than a new turn, because a later turn replays the refused context. | ||
| */ | ||
| function terminalRefusalMessage(detail: string | undefined): string { | ||
| const reason = detail?.trim() ? ` (${redactSecretString(detail.trim())})` : ""; | ||
| return `The upstream model refused this request${reason}. ` | ||
| + "Retrying with the same conversation context will not succeed; change the request or start a new conversation."; | ||
| } | ||
|
|
||
| /** | ||
| * An adapter `incomplete` that is a non-retryable upstream refusal: a content filter carrying an | ||
| * explicit `retryable: false` verdict. A filter without the verdict, an output cap, a stall and an | ||
| * adapter EOF do not qualify. The sidecar loops read this too: a refused iteration ends the turn, | ||
| * so a sidecar call it carried is neither run nor answered with another model request. | ||
| */ | ||
| export function isTerminalRefusalIncomplete(event: AdapterEvent | undefined): boolean { | ||
| return event?.type === "incomplete" && event.reason === "content_filter" && event.retryable === false; | ||
| } | ||
|
|
||
| /** | ||
| * `response.failed` fields for an adapter `incomplete` that is a non-retryable upstream refusal | ||
| * (#4312), or `undefined` when the event is anything else. The Anthropic and Kiro adapters are | ||
| * the ones that emit it today. | ||
| * | ||
| * codex-rs maps every `response.incomplete` to a retryable stream error and never reads | ||
| * `incomplete_details.retryable`, so a refusal delivered that way is re-sent through the whole | ||
| * stream retry budget. It only ends the turn on `response.failed` carrying a terminal-refusal | ||
| * `error.code`. Only an explicit `retryable: false` content filter qualifies: a filter without | ||
| * the verdict, an output cap, a stall and an adapter EOF stay `response.incomplete`. | ||
| */ | ||
| export function terminalRefusalFailure( | ||
| event: Extract<AdapterEvent, { type: "incomplete" }>, | ||
| ): TerminalRefusalFailure | undefined { | ||
| if (!isTerminalRefusalIncomplete(event)) return undefined; | ||
| const error: OcxErrorPayload = { | ||
| type: "invalid_request_error", | ||
| code: TERMINAL_REFUSAL_FAILED_CODE, | ||
| message: terminalRefusalMessage(event.message), | ||
| }; | ||
| return { error, last_error: error, retryable: false }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.