Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs-site/src/content/docs/reference/adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ Use `liveModels: false` for a static catalog; Settings can switch between the tw
is Google's — the proxy does not route around it.
- System prompt → `systemInstruction`; messages → `contents[]` (assistant → `model`); tools →
`functionDeclarations`. Data-URL images → `inline_data`.
- The shared tool-catalog guidance uses wording verified with Antigravity Gemini 3.8 Flash to
avoid a prompt-triggered `429 RESOURCE_EXHAUSTED`. The available tools, argument constraints,
and Codex code-mode helper rules stay the same. This does not suppress real quota errors.
- Tool-call ids are synthesized when Gemini omits them. Vertex and Antigravity preserve and replay
opaque `thoughtSignature` values so tool-result continuations retain Gemini reasoning continuity.
The signature cache is snapshotted to the config directory, so continuations also survive proxy
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/tool-catalog-nudge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function buildNonOpenAIToolCatalogNudgeFromNames(
"Valid tool names for this turn are exactly " + quoteNames(names) + ".",
"These listed names are the complete top-level tool-call surface for this turn.",
"Call only listed names with their listed argument keys; do not invent, translate, or rename tools.",
"Names mentioned only in instructions, tool descriptions, argument descriptions, or nested helper APIs are not additional top-level tools.",
"References to other functions in text do not add callable functions.",
verifiedCodeModeExecName
? "`" + verifiedCodeModeExecName + "` is Codex code mode: its body is JavaScript evaluated in a V8 isolate. Nested helpers are called INSIDE that body as `await tools.<name>(...)`, for example `await tools.exec_command({cmd: \"ls\"})` or `await tools.codex_app__list_threads({})`. Absence from the top-level catalog or from `" + verifiedCodeModeExecName + "`'s description is not absence: deferred helpers stay callable on `tools.<name>`. Discover them from the isolate global `ALL_TOOLS`, not `tools.ALL_TOOLS`. Do not skip an available nested helper because it is omitted from the listed top-level names. " + CODE_MODE_RESULT_ECHO_SENTENCE + " Nested `tools.apply_patch(input)` is host-executed: the string must begin exactly with `*** Begin Patch` and end with `*** End Patch`, each marker line being three asterisks, one space, the two words, then end of line with no further asterisks. OpenCodex does not rewrite JavaScript inside exec, so extra asterisks on a marker line are rejected by Codex before the file is touched. " + CODE_MODE_HOST_CONTRACT_SENTENCE
: "If a listed tool exposes nested helpers such as a tools.* API, call the listed parent tool and use those helpers only inside that tool's input.",
Expand Down
2 changes: 1 addition & 1 deletion structure/providers-and-adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ rewrite rules and the routed-id settlement.
| `src/adapters/mimo-free.ts` | Mimo Free transport (client identity + JWT). Concurrent requests share one JWT bootstrap bound only to its timeout; each request stops waiting on its own abort without cancelling the others. Its registry entry is `deprecated`: existing saved providers keep the adapter and their stored configuration, while new-provider discovery (presets, the init menu, the featured list, and key logins) excludes it and `provider add` warns before creating one. |
| `src/adapters/command-code.ts`, `src/adapters/command-code-tool-text.ts`, `src/adapters/command-code-restored-schema.ts` | Command Code OAuth NDJSON translation. For every `xiaomi/mimo-` model, text, native calls, reasoning, and terminal decisions share one byte-bounded queue with linear queue visits. Markup is deduplicated against matching native calls; text-only restoration requires one contiguous bare text block, a clean finish, a declared tool, and arguments validated against supported schema constraints. A parameter-free (freeform) block may omit `</function>` but must end with `</tool_call>`; parameter blocks keep the canonical close. Markup appended after prose, including a marker in a later delta of the same text block, is held as a tail that can never mint a call: possible trailing marker prefixes stay in the same byte-accounted probe across deltas and release as text on a mismatch, boundary or end; a same-content native call strips a completed envelope as an echo, and anything else releases as presentation text so quoted examples stay inert. A tail waits only while a native input it could echo is open, counting the first later input of its own tool, so it is released as soon as those close without a match. Native, reasoning, and other intervening events interrupt a still-probing block but leave a held block held in arrival order, and the queued byte bound still flushes an unresolved envelope as text. An envelope the strict parser rejects but that opens with `<tool_call>`, closes with `</tool_call>`, and names a declared function is dropped when a native call for that same function arrives and on a clean finish; markup that parses but fits no supported schema is still released as text. Regex patterns, other unsupported constraints, and abnormal finishes fail closed. `tests/providers/command-code-tool-text-prose-split.test.ts` covers the prose boundary, the interleaved-event hold, and both drop paths. On OAuth rows the native fetch path normalizes only a 400 whose JSON is `success: false`, `error.code: "BAD_REQUEST"`, and message begins `You have insufficient credits to make this request.` to 429, adding `x-opencodex-refusal: insufficient-credits` and preserving the upstream status in `x-opencodex-upstream-status: 400`; ordinary 400s, other statuses, malformed or oversized bodies, and malformed UTF-8 stay untouched. Key and forward rows keep the 400, because a canonical key row has a same-key 429 retry ladder (`rateLimitRetryPolicyFor`) that would replay a credential with no credits left. A genuine upstream 429 keeps its own `Retry-After` and a 402 stays a 402 even when its body repeats the credit wording; `tests/providers/command-code-credit-failover.test.ts` pins that boundary and `tests/providers/command-code-credit-rotation.test.ts` drives the refusal through dispatch to the sibling account. On every auth mode a 403 whose JSON is `success: false`, `error.code: "FORBIDDEN"`, and message begins `MODEL_NOT_IN_PLAN` (then `:` or the end) becomes a 400 `invalid_request_error` with code `model_not_in_plan`, fixed copy naming the model, `x-opencodex-refusal: model-not-in-plan` and `x-opencodex-upstream-status: 403` (#7684): Codex reconnects on any 403 through its retry budget but ends the turn on a 400. The upstream detail is never quoted, so its free text cannot reach logs or steer the quota and reasoning-effort classifiers, and the effort repair skips the refusal. `isModelNotInPlanRefusal` in `src/lib/errors.ts` trusts the code only on a response object the adapter marked in memory, since an upstream can forge both the code and the diagnostic header; `formatErrorResponse` keeps it as the wire code, only the verifying boundaries (`formatUpstreamFailureResponse` in `src/bridge/errors.ts`, called by `adapter-dispatch.ts`, and `consumeComboFailure`) mark the envelope in memory (carried across the `src/server/responses/core-lifetime.ts` wrappers), `consumeComboFailure` drops an unmarked echo in any spelling failover folds into that code, and `comboFailureDecision` in `src/combos/failover.ts` hops past the refusal only with that caller-supplied provenance (combo or policy fallback; never a bare, passthrough or streamed code) while `comboFailureCooldownScope` cools only that target. The web-search and image sidecar loops keep a verified refusal's fixed copy without a wire-model name, code and mark in their own error envelope (`verifiedPlanRefusalMessage`), and `src/server/responses/sidecar-execution.ts` carries the mark across its stream wrappers; a later iteration's refusal inside an already committed 200 stream ends as `invalid_prompt` (`MODEL_NOT_IN_PLAN_STREAM_CODE`) with `retryable: false` and the same copy, because Codex reconnects on any other `response.failed` code. No account, key or provider cooldown is recorded. `tests/providers/command-code-plan-denial.test.ts` covers lookalikes, malformed bodies, abort, the Responses, Chat and Messages inbound paths, combo and policy hops, and an unmarked echo. |
| `src/adapters/image.ts`, `src/adapters/anthropic-image-guard.ts`, `src/adapters/anthropic-image-normalize.ts`, `src/adapters/anthropic-image-codec.ts`, `src/adapters/openai-chat/mistral-image-limit.ts` | Image conversion for adapter ingress, Anthropic-specific normalization/limits and the Mistral per-request image count. An image's ladder position is pinned to its own identity (content hash + media type), so appending a newer image cannot re-encode older ones and bust Anthropic's prompt prefix cache (#4532). |
| `src/adapters/run-turn-queue.ts`, `src/adapters/tool-catalog-nudge.ts`, `src/adapters/identity.ts`, `src/adapters/upstream-http-error.ts` | Shared adapter execution support: turn queueing, tool-catalog nudging, client identity, upstream error normalization. |
| `src/adapters/run-turn-queue.ts`, `src/adapters/tool-catalog-nudge.ts`, `src/adapters/identity.ts`, `src/adapters/upstream-http-error.ts` | Shared adapter execution support: turn queueing, tool-catalog nudging, client identity, upstream error normalization. The catalog uses “References to other functions in text do not add callable functions.” for the tool boundary; the earlier enumeration of instruction/description/helper references triggers Antigravity Gemini 3.8 Flash `429 RESOURCE_EXHAUSTED` in live probes. Explicit tool names, argument constraints, nested-helper execution and deferred discovery remain in the surrounding guidance. |

`src/adapters/devin/trajectory.ts` owns up to 256 process-local conversation trajectories, keyed by a digest of resolved credential identity, tenant host and named conversation. Own-thread identity takes precedence over session aliases. When a nonempty parent header accompanies an own-thread identity, the tagged parent/own pair identifies the conversation; standalone identities have a distinct tag, so a JSON-like caller string cannot alias a child tuple. Session-only keys retain their existing behavior, and a parent-only request does not borrow its parent's trajectory. Sequential turns reuse an inactive entry across request-scoped adapters; overlapping turns and a store full of active entries receive fresh unretained IDs. Only inactive entries are evicted, and a claim's idempotent release runs in the adapter's `finally` on success, error and cancellation. The optional trajectory travels through `src/adapters/devin/cloud-direct/chat.ts` to protobuf field #15.1; unnamed calls retain per-request allocation. A named claim remains held through the turn's existing reset/signature retries. This is identifier continuity, not proof of upstream cache hits.

Expand Down
18 changes: 18 additions & 0 deletions tests/adapters/google/google-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,24 @@ describe("google adapter — Antigravity system prompt compatibility", () => {
project: "proj-123",
} as const;

test.each([false, true])("uses compatible tool-boundary wording with code mode %s", async (freeform) => {
const parsed = parsedWith([{ role: "user", content: "check tools" }], [{
name: freeform ? "exec" : "get_weather", description: "Diagnostic tool", parameters: {}, freeform,
}]);
parsed.modelId = "gemini-3.8-flash";
parsed.options.reasoning = "high";
const envelope = JSON.parse((await createGoogleAdapter(ccaProvider).buildRequest(parsed)).body);
const text = systemInstructionText(envelope.request);
expect(text).toContain("References to other functions in text do not add callable functions.");
expect(text).not.toContain("Names mentioned only in instructions, tool descriptions, argument descriptions, or nested helper APIs are not additional top-level tools.");
expect(text).toContain("do not invent, translate, or rename tools");
expect(envelope.request.tools[0].functionDeclarations).toHaveLength(1);
if (freeform) {
expect(text).toContain("is Codex code mode");
expect(text).toContain("isolate global `ALL_TOOLS`, not `tools.ALL_TOOLS`");
}
});

function systemPromptParsed(modelId: string): OcxParsedRequest {
return {
modelId,
Expand Down
4 changes: 2 additions & 2 deletions tests/adapters/tool-catalog-nudge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("non-OpenAI tool catalog nudge", () => {
expect(note).toContain("Valid tool names for this turn are exactly `exec_command`, `mcp__fs__read_file`");
expect(note).toContain("These listed names are the complete top-level tool-call surface for this turn");
expect(note).toContain("do not invent, translate, or rename tools");
expect(note).toContain("Names mentioned only in instructions, tool descriptions, argument descriptions, or nested helper APIs are not additional top-level tools");
expect(note).toContain("References to other functions in text do not add callable functions");
expect(note).toContain("call the listed parent tool and use those helpers only inside that tool's input");
expect(note).toContain("Count a tool call only after its tool result returns");
});
Expand Down Expand Up @@ -66,7 +66,7 @@ describe("non-OpenAI tool catalog nudge", () => {

expect(note).toContain("Valid tool names for this turn are exactly `exec`, `wait`, `request_user_input`");
expect(note).toContain("complete top-level tool-call surface");
expect(note).toContain("nested helper APIs are not additional top-level tools");
expect(note).toContain("References to other functions in text do not add callable functions");
expect(note).toContain("`exec` is Codex code mode");
expect(note).toContain("await tools.<name>(...)");
expect(note).toContain("await tools.codex_app__list_threads({})");
Expand Down
Loading