384 Commits

Author SHA1 Message Date
Luis Pater
14144df573 fix(openai): route duplex quota errors through replay guard after response.created
- Exclude known credential quota and cooldown errors from recoverable duplex error preservation in forwardResponsesWebsocket so opts.suppressError and terminal error handling still apply after response.created.
- Add regression tests verifying usage_limit_reached and model_cooldown consult the replay guard while request and client rate-limit errors stay on the duplex path.

Closes: #7586
2026-11-16 10:43:08 +08:00
Luis Pater
508f8708d0 chore: replace standard JSON package with moego JSON throughout the project 2026-11-16 09:58:12 +08:00
Luis Pater
b4fdfdece3 chore: replace standard regexp with moego regexp throughout the project 2026-11-16 03:02:43 +08:00
Luis Pater
a8c9c8a4a4 fix(openai): fail over pre-commit responses websocket create errors
- Unpin and exclude the failed credential when a full response.create on a persistent Responses WebSocket fails with a pre-commit quota or auth error.
- Propagate excluded auth IDs through handler metadata into mixed and Home stream selection while blocking replay once any downstream frame is committed.
- Add regression tests for pre-commit 429 failover, post-commit non-replay, and Home repeated excluded-auth rejection.

Closes: #7585
2026-11-16 01:59:04 +08:00
Luis Pater
7e82d0d1ca fix(executor): skip credential cooldown on Gemini zero-output 502 errors
- Tag Gemini-family zero-output HTTP 502 errors and translated Claude MALFORMED_FUNCTION_CALL error payloads with ErrorCodeTransientTransport across Antigravity, Gemini, Vertex, and AI Studio executors so Conductor skips credential cooldown while preserving per-request rotation and cross-provider failover.
- Update existing Claude MALFORMED_FUNCTION_CALL conductor tests to assert failed execution results and failed usage metrics without placing credentials into cooldown.
- Add unit and HTTP handler regression tests verifying uncooled rotation, cross-provider failover, and groundingChunks-only Claude fallback paths across Gemini-family executors.

Closes: #7571
2026-11-15 22:00:34 +08:00
Luis Pater
4da9f68527 fix(auth): carry the pool cooldown reset on the terminal 429
- Wrap the final 429 in a poolCooldownTerminalError at the Execute/ExecuteCount/ExecuteStream boundaries when every candidate credential for the model is blocked and at least one is in a timed cooldown, preserving the upstream error body and status while marking IsModelCooldown so the Claude handler appends the reset time.
- Compute the Retry-After from the earliest auto-recovery across all blocked candidates (including non-cooldown timed blocks) so the client sees the pool's real recovery instead of the last attempt's hint.
- Add regression coverage for both cooldown variants across the three execution paths, the available-candidate guard, mixed-block earliest deadlines, the sub-floor hint clamp, and the Claude handler end-to-end.

Closes: #7521
2026-11-14 03:53:47 +08:00
Luis Pater
100f2de1a5 fix(handlers): forward caller identity metadata to model-directory response interceptors
- Build interceptor metadata in WriteModelListResponse from the authenticated gin context (caller_scope, access_provider, frontend_auth_metadata) instead of always passing nil.
- Reuse requestCallerScope so model-list requests share the same irreversible caller handle as execution paths, enabling per-key catalog filtering including ?key= credentials.
- Forward the same metadata to the request lifecycle tracker and add regression tests for identity forwarding, metadata isolation, and unauthenticated nil metadata.

Closes: #7524
2026-11-14 03:38:08 +08:00
Luis Pater
cf07c78abd fix(gemini/antigravity): fail zero-output abnormal terminations before HTTP 200 commit
- Detect MALFORMED_FUNCTION_CALL, UNEXPECTED_TOOL_CALL, and MALFORMED_RESPONSE with zero visible output before bootstrap commit, reasoning replay caching, or usage finalization across Antigravity, Gemini, Vertex, and AI Studio executors.
- Withhold only contentless leading shell frames while keeping thought chunks unbuffered for TTFT, and align Claude response error handling and stream completion flags while preserving valid partial outputs.
- Add unit, executor, bootstrap failover, and cross-module HTTP regression tests covering credential rotation and HTTP 502 exhaustion.

Closes: #7513
Co-authored-by: Dylan <1990016@gmail.com>
Co-authored-by: lzt404 <2596933790@qq.com>
2026-11-14 00:50:21 +08:00
Luis Pater
6acfb76b54 feat(sdk): keep caller-provided interceptor host and executor wrappers across config apply
- Add Builder.WithPluginInterceptorHost so embedders can install a custom PluginInterceptorHost that survives startup and reload; the server wraps it to keep plugin model routing, executor dispatch, lifecycle, and websocket observers delegated to the internal plugin host.
- Add Hooks.OnConfigApplied invoked after each successful config apply so embedders can reinstall executor wrappers and other caller-owned runtime state.
- Cover the delegated interceptor host with nil-safety, skip-forwarding, capability-detection, and real execute-chain regression tests.

Closes: #7499
Co-authored-by: Dylan <1990016@gmail.com>
Co-authored-by: lzt404 <2596933790@qq.com>
2026-11-13 07:53:46 +08:00
Luis Pater
ece3f52a41 fix(logging): preserve bounded upstream responses in error logs
- Capture bounded per-attempt upstream status, masked headers, response chunks, and transport or stream errors when request-log is false.
- Bind synchronized deferred capture to the HTTP request context and preserve partial HTTP bodies and WebSocket dial or reconnect failures.
- Mask Cookie headers alongside Set-Cookie so forced error logs do not expose session credentials.

Closes: #7420
Co-authored-by: Dylan <1990016@gmail.com>
Co-authored-by: lzt404 <2596933790@qq.com>
2026-11-11 03:31:39 +08:00
Luis Pater
cb70eacfa5 fix(claude): emit anthropic-ratelimit-unified headers on local cooldown 429s
- Retain and persist rejected Claude unified quota signals alongside active cooldown deadlines so out-of-order completions, restarts, and dual-layer quota wraps keep accurate window metadata.
- Populate anthropic-ratelimit-unified-* headers on Claude quota modelCooldownError responses aligned with Retry-After while keeping SafeResponseHeaders restricted to trusted retry headers.
- Exclude non-Claude, Cloudflare challenge, and ordinary per-minute rate-limit cooldowns from unified subscription quota header synthesis across selector and scheduler paths.

Closes: #7417
Co-authored-by: Dylan <1990016@gmail.com>
Co-authored-by: lzt404 <2596933790@qq.com>
2026-11-11 01:20:48 +08:00
sususu98
61f1ad5e3e fix(codex): support local compaction for compatible Responses endpoints
Handle compaction triggers and capsule replay locally for is-compat models while preserving native Codex behavior. Harden duplex cancellation, event ordering, response ownership, settings inheritance, model aliases, and credential failure classification.

Add HTTP, streaming, duplex, handler, usage, and deterministic concurrency regression coverage.

Fixes #7406
2026-11-10 19:22:38 +08:00
Luis Pater
46d48eb5af fix(openai): start responses websocket keepalive after upgrade
- Start a connection-scoped downstream Ping keepalive loop immediately after upgrading the Responses WebSocket connection instead of waiting for stream forwarding to begin.
- Guard background Ping writes with non-blocking mutex acquisition so active data writes are not contended while blocked Ping writes are still interrupted on terminal close.
- Preserve the socket cancellation cause in response forwarding and add regression coverage for post-upgrade, upstream-bootstrap, and blocked-Ping close paths.

Closes: #7407
Co-authored-by: Dylan <1990016@gmail.com>
Co-authored-by: lzt404 <2596933790@qq.com>
2026-11-10 17:36:17 +08:00
Luis Pater
23e31fe288 fix(executor): stabilize Codex refresh and websocket tests under CPU contention
- Hijack mock CONNECT proxy connections before writing 200 OK and forward buffered client bytes so TLS ClientHello records are not truncated under CPU contention, while isolating Codex refresh test journals.
- Wait for client request payloads and test completion before closing mock websocket connections in Codex keepalive upload tests.
- Cancel the in-flight HTTP upstream context before writing response.incomplete downstream during local websocket interrupts.

Closes: #7379
Co-authored-by: Dylan <1990016@gmail.com>
2026-11-09 22:44:41 +08:00
Luis Pater
05e668cf2d fix(responses): sanitize orphan tool outputs lacking call_id
- Rewrite standalone function_call_output and custom_tool_call_output items without call_id into user messages while preserving paired tool outputs and multimodal content parts.
- Apply orphan tool output sanitization in both Codex Responses request translation and the Responses HTTP/compact handlers while keeping codex_app delegation compatibility intact.
- Add regression tests covering orphan Companion Page outputs, multimodal array outputs, paired tool calls, and HTTP/compact endpoints.

Closes: #7341
2026-11-08 14:46:03 +08:00
Luis Pater
91e0dee827 fix(openai): prevent SSE keep-alive injection mid-line during image streaming
- Track SSE event newline boundaries across streamed image chunks and suppress keep-alive comments while inside an incomplete SSE event.
- Reset streaming keep-alive tickers when downstream bytes are written and ensure terminal error events start on a clean SSE boundary.

Closes: #7330
2026-11-08 02:02:31 +08:00
Luis Pater
f4d3f0618d fix(openai): replace responses websocket transcript when pending tool calls are unanswered
- Treat subsequent responses websocket requests without previous_response_id that leave pending tool calls unanswered as transcript replacements regardless of incremental upstream mode.
- Add regression tests covering both unanswered and answered pending tool calls when incremental previous_response_id injection is disabled.

Closes: #7320
2026-11-07 17:09:50 +08:00
Luis Pater
e458999bb3 fix(claude): show cooldown retry time in error messages
- Include the trusted retry delay in Claude cooldown errors.
- Verify response headers and stream messages across cooldown cases.

Closes: #7285
2026-11-06 10:25:22 +08:00
Luis Pater
8fb60326f4 fix(codex): handle Responses-Lite hosted image_generation compatibility
- Skip auto-injecting hosted image_generation tools on Responses-Lite models and strip unsupported complexity fields from declared image_generation tools on ChatGPT Codex /responses requests.
- Route forced hosted image_generation turns on Responses-Lite models to the compatible GPT-Image-2 base model (default gpt-5.4-mini) with normalized reasoning configuration.
- Map upstream image_generation_user_error terminal events to HTTP 400 Bad Request with actionable remediation guidance for unsupported complexity errors.

Closes: #7270
2026-11-05 18:28:39 +08:00
Luis Pater
b5e6027ce4 fix(openai): expose terminal 429 error frames on responses websocket
- Forward terminal 429 quota and model-cooldown errors with trusted Retry-After headers when websocket credential failover is exhausted.
- Suppress 1012 HTTP replay on pinned continuation 429 failures when no alternative local or Home credential is eligible.
- Add regression tests covering multi-credential rotation, single-credential exhaustion, expired alternatives, and Home failover.

Closes: #7256
2026-11-05 10:38:56 +08:00
sususu98
6897eebd50 Merge pull request #7242 from sususu98/fix/cyber-block-request-fault-and-error-log
fix(clienterror,logging): classify mid-stream cyber blocks as 400 and persist error logs
2026-11-05 09:53:35 +08:00
sususu98
be69162478 fix(executor,logging): preserve Antigravity usage evidence, sparse Claude refusal identity, and Home stream error logs 2026-11-05 09:51:14 +08:00
赵铕杭
7a7d37ecb5 feat(codex): add support for gpt-image-2.6 models 2026-11-05 08:59:25 +08:00
Luis Pater
f208c90824 fix(handlers): record TTFT for direct plugin executor routes
- Start TTFT timing before invoking direct plugin executors in both non-streaming and streaming handler paths.
- Record first-packet arrival for non-streaming responses and observe protocol-aware stream chunk TTFT events before publishing usage.

Closes: #7253
2026-11-05 07:21:50 +08:00
sususu98
508ac2bce0 fix(executor,handlers): require stream-level evidence for Gemini filter blocks and pre-log terminal chunk errors 2026-11-04 19:16:14 +08:00
sususu98
69a032dea3 perf,fix(logging,websocket): avoid 200 OK body buffering and synchronize ws disconnect error logging 2026-11-04 18:48:02 +08:00
sususu98
c3938b72bd fix(logging,clienterror): classify mid-stream cyber blocks as 400 and persist error logs
- Unify Gemini filter blocks and Claude policy/cyber stop_details refusals under internal/clienterror as HTTP 400 request faults so single-prompt triggers do not cool down credentials.
- Detect Gemini mid-stream filter blocks across Antigravity, Gemini, and Gemini Vertex executors and Claude cyber policy refusals in Claude streaming diagnostics.
- Record LoggingAPIResponseError across streaming/WebSocket terminal error paths even when request-log is disabled.
- Override streaming response log status with actionable API_RESPONSE_ERROR status and prefix error-*.log files in both request-log modes.
2026-11-04 18:14:30 +08:00
Luis Pater
6e6afab99a refactor: migrate gjson, sjson, and base64 to MoeForge/moego
- Replace tidwall/gjson and tidwall/sjson with github.com/MoeForge/moego/ojson
  and encoding/base64 with github.com/MoeForge/moego/base64 across the main
  module and examples
- Introduce cross-method *ojson.Doc request rewriting pipelines across
  thinking, signature, client/codex, runtime/executor/helps, pluginhost, and
  all provider executors with FinalizePayloadDoc as the final semantic barrier
- Convert all consecutive JSON mutations (>= 2 Set/SetRaw/Delete operations)
  to batch edits on ojson.Doc
- Upgrade read-only byte paths to ojson.GetBytesNoCopy,
  ojson.GetManyBytesNoCopy, and util.ParseGJSONBytesNoCopy with explicit
  strings.Clone ownership protection across streaming and persistent state
- Use base64.StdEncoding.ValidateString for zero-allocation signature checks
  and base64.EncodeDataURL for single-allocation data URL construction
2026-11-03 03:05:04 +08:00
Luis Pater
7cad1cb7df Merge pull request #7142 from gabrielrinaldi/fix/grok-video-1.5-lite
fix(xai): support Grok Imagine Video 1.5 Lite
2026-11-02 01:07:10 +08:00
Luis Pater
9037d5430d fix(openai): drop output-only content_token_count from replayed responses websocket items
- Sanitize only upstream-originated replay copies (transcript merge and tool-call repair cache entries) so another credential cannot reject them as unknown input.
- Match passthrough members by decoded key name across duplicates and escaped spellings, drop objects emptied by removal, and leave client input, downstream payloads, and invalid JSON unchanged.

Closes: #7146
2026-11-01 15:27:05 +08:00
Gabriel Rinaldi
c69cdd933d fix(xai): preserve Lite resolution and catalog fallback 2026-10-31 13:36:33 -06:00
Gabriel Rinaldi
f0ddc38f29 fix(xai): support Grok Imagine Video 1.5 Lite 2026-10-31 12:39:19 -06:00
Dylan
4cb98e3ccd fix(logging): prevent deferred request retention on Responses WebSockets
Keep the error-only upstream request capture policy on the connection
context, before model routing and upstream execution begin. Check it before
accessing pooled Gin state so delayed plugin callbacks retain the policy
even after cancellation or Gin context reuse.

Preserve ordinary HTTP error capture, failed upgrade handling, and full
request logging. Cover large repeated requests, late callbacks, real
WebSocket logging, and Codex duplex routing with regression tests.

Related: #6960
2026-10-29 23:25:54 +08:00
sususu98
56efc81fa5 Merge pull request #7092 from sususu98/fix/slow-test-disconnect
Fix WebSocket disconnect test and Devin diagnostics
2026-10-29 09:58:15 +08:00
sususu
fa42f390c1 test(openai): assert websocket disconnect error event 2026-10-29 09:36:31 +08:00
Luis Pater
0fe38224e5 feat(pluginhost): support raw request body byte-range patching
Existing request interceptors wrap the full request body in a JSON RPC envelope with Base64 encoding and skip subsequent duplex WebSocket business frames, causing ~3.33x memory and CPU amplification when rewriting small fields such as Codex `<timezone>` and `<current_date>` in large contexts.

- Add schema v8 raw request body patch methods (`request.patch_body_before` and `request.patch_body_after`) and capabilities (`request_interceptor_patch_body_before/after`, `request_body_patcher_before/after`) that pass raw `Body []byte` directly across the C ABI without JSON/Base64 request wrapping
- Add `RequestBodyEdit`, `RequestBodyPatchResponse`, and `RequestBodyPatcher` in `sdk/pluginapi` with single-pass host splicing, bounds/overlap validation, `json.Valid` verification, no-op original body reuse, and sequential multi-plugin chaining
- Eliminate redundant full-body slice clones in handler/conductor request interceptor application paths
- Run before-auth and after-auth request interceptors on subsequent duplex WebSocket `response.create`, `response.append`, and `response.steer` messages

Closes: #7072
2026-10-28 21:38:42 +08:00
Luis Pater
9717e325ba fix(responses): reject late websocket interrupts after terminal events
- Track the running response identity in the Codex websocket session and reject interrupts that do not target it, so an interrupt after response.completed is never forwarded upstream while turn teardown is pending.
- Gate the handler's local interrupt path by explicit turn ownership and close it before terminal payloads are written downstream, preventing fabricated response.incomplete events and silently dropped claimed frames.
- Add deterministic regression tests covering late and unknown interrupts across completion, failure, queued rejection, upstream loss, and HTTP fallback turns.

Closes: #7065
2026-10-28 18:33:51 +08:00
Luis Pater
ae65e26df2 feat(api): filter private metadata in OpenAI responses and improve SSE framing recovery
- Filter out internal metadata events such as moderation data for standard clients in OpenAI responses API and websocket streams.
- Enhance `responsesSSEFramer` and frame accumulator to robustly handle fragmented JSON payloads, empty data fields, and recovery of split SSE fields.
- Add comprehensive unit tests covering SSE metadata filtering, fragmented frame recovery, and websocket message handling.
2026-10-28 16:33:13 +08:00
Luis Pater
f7342c3838 Merge pull request #6970 from soulmachine/responses-drop-metadata-non-codex 2026-10-28 11:36:03 +08:00
Luis Pater
65889d39f0 test: update tests for default template changes and environment compatibility
Closes: #7059
2026-10-28 02:34:39 +08:00
Luis Pater
b74422180e fix(auth,usage): snapshot request state to avoid reading reused gin.Context (#7056) 2026-10-27 21:22:46 +08:00
Luis Pater
86a1aabf01 fix(codex): retry another credential on early websocket 429 without closing downstream
When an upstream Codex WebSocket returns an early 429 usage_limit_reached (via an error or response.failed frame) before any downstream payload chunk is emitted, notifying UpstreamDisconnectChan caused the Responses WebSocket handler to close the client connection and cancel the request context before the conductor could fail over to another eligible credential.

Suppress downstream disconnect notification on pre-output upstream WebSocket errors and treat bootstrap usage-limit terminal failures as failover-eligible while bootstrap buffering is active, allowing the conductor to retry another credential on the same downstream WebSocket connection.

Fixes #7051
2026-10-27 18:35:03 +08:00
Luis Pater
826bb16780 fix(images): apply payload default rules to xAI image endpoints
- Build un-defaulted original request payloads for xAI image generation and edit handlers and propagate them via execution context so payload default rules can distinguish omitted client fields from built-in defaults.
- Pass normalized original requests into the xAI image executor payload finalizer and report finalized response_format values back to handlers via metadata callbacks across streaming and non-streaming responses.
- Add unit and handler regression tests covering payload default, default-raw, and override rules for xAI image endpoints.

Closes: #7048
2026-10-27 17:27:20 +08:00
Luis Pater
f73e66ac2a fix(responses-ws): keep downstream websocket open on upstream Codex disconnect
Keep the client's /v1/responses websocket open when an upstream Codex websocket drops during or between turns, report correlated non-closing error frames without replaying in-flight turns, fence pre-loss queued input across handler and executor boundaries, and preserve pinned credential affinity across Home turn releases.

Closes: #7028
2026-10-27 15:32:41 +08:00
Luis Pater
9a35fa12b2 fix(codex): treat turn_rate_limit_exceeded as transient capacity with retry hint
- Classify Codex turn-rate and model-capacity 429s as transient per-model rate limits via a new executor contract, honour upstream Retry-After headers behind quota resets, and cool only the reporting model without quota labelling or exponential backoff.
- Carry the trusted retry deadline to terminal clients and retry scheduling across direct, streaming, bootstrap, and Home paths, keeping Home aggregated deadlines authoritative over per-attempt hints.

Closes: #7017
2026-10-27 04:29:38 +08:00
Luis Pater
064e008b07 feat(codex): add full-chain compression for Codex upstream and downstream traffic
- Compress finalized Codex OAuth request bodies with zstd on the verified ChatGPT backend path, with size/benefit gating, header-body alignment, and one uncompressed retry on 400/415 rejection.
- Negotiate downstream HTTP response compression under server.response-compression (zstd/gzip with q-values, SSE-safe flushing, commit-time Vary merging) and enable negotiated permessage-deflate on Codex and downstream WebSockets.
- Advertise Accept-Encoding to Codex upstreams and decode gzip/deflate/br/zstd upstream responses through a shared decoder before parsing or relaying.

Closes: #6905
2026-10-26 10:09:56 +08:00
Luis Pater
712e4970bc fix(handlers): report cancellation when stream closes before first chunk
- Route the initial stream bootstrap read in readInitialStreamChunks through nextStreamChunk so a channel closed alongside context cancellation is reported as canceled rather than normal stream EOF.
- Add a regression test exercising ExecuteModelStream cancellation before the first deliverable chunk to verify the request lifecycle completes as canceled.

Closes: #6987
2026-10-26 02:53:27 +08:00
Luis Pater
90fe5b23d3 fix(handlers): report stream cancellation when channel closes with canceled context
- Check whether the request context is already canceled when the stream chunk channel closes in nextStreamChunk so select randomization does not report a canceled stream as EOF.
- Add unit tests verifying that a closed stream channel with a canceled context deterministically reports cancellation while a live context reports normal stream completion.

Closes: #6979
2026-10-25 22:30:21 +08:00
Luis Pater
0fe4cc2cfa fix(openai): report buffered stream error when responses websocket data channel closes first
- Drain any pending buffered error from errs via handlers.PendingStreamError before treating a closed data channel as a duplex socket close or incomplete stream timeout.
- Add regression test covering both standard and duplex websocket forwarding when errs holds a buffered error and both channels are closed.

Closes: #6981
2026-10-25 22:30:07 +08:00
Frank Dai
86d951cd50 fix(openai/responses): drop response.metadata for non-Codex clients
The Codex backend now sends a response.metadata event with prompt-moderation flags.
It is not a public Responses event, and clients that parse a closed event list
(Grok Build 1.0.60 and 1.0.70: "unknown variant response.metadata") fail the
whole turn on it. Filter it for standard Responses clients like the other private
Codex events; official Codex clients still receive it.
2026-10-25 00:28:55 -07:00