389 Commits
Author SHA1 Message Date
Chenyme 838aca3c8f chore: bump version to v3.1.8 and implement auto-delete feature for unlinked Console accounts 2026-10-21 19:22:41 +08:00
Chenyme 4e220e815c feat: implement transient retry tracking and enhance related tests 2026-10-18 10:27:06 +08:00
Chenyme 716d8475f2 Merge branch 'main' into fix/voice-ws-timeout-and-stt-billing 2026-10-16 15:18:38 +08:00
Chenyme c9c3e7ddb2 Merge branch 'main' into feat/auto-disable-degraded-accounts 2026-10-16 14:39:45 +08:00
Chenyme 659ee8ca69 refactor: enhance request retry configuration and auto-disable logic; update documentation and tests for clarity 2026-10-15 13:44:11 +08:00
Chenyme 837993aa02 Merge branch 'main' into feat/legacy-http-proxy 2026-10-15 11:32:34 +08:00
Chenyme 0a3efcc459 feat: enhance proxy URL normalization and test logic 2026-10-15 11:32:17 +08:00
Chenyme 1e434d1d3d Merge branch 'main' into fix/video-retry-account-scope-bypass 2026-10-15 11:10:12 +08:00
Chenyme 6cd06ea5e7 fix: add recovery test for video job on worker shutdown 2026-10-15 11:10:00 +08:00
carfeii 6ea58d3a89 fix(voice-ws): observe request timeout and bill confirmed STT duration regardless of transport outcome
Two issues in the voice/STT WebSocket proxy:

1. The established proxy never watched c.Request.Context().Done(), so
   server.requestTimeout had no effect on a quiet, already-admitted
   session: the account lease, concurrency slot, and upstream connection
   stayed open past the configured deadline until a transport error
   occurred on either side. Added a watcher that closes the session once
   the request context is canceled, extracted as watchRequestTimeout so
   it is unit-testable without a real WebSocket upgrade.

2. STT billing was gated on the downstream client closing cleanly
   (successful == ErrorCode == ""), even though the cost is already
   incurred the moment the upstream sends a confirmed transcript.done
   duration. A client that received a complete transcription and then
   disconnected abnormally left EstimatedCostInUSDTicks at zero,
   understating usage against the key's billing limit. Billing is now
   keyed on having a confirmed duration, not on how the transport ended.
2026-10-05 18:21:45 +08:00
inter b789e8466d feat(settings): support auto-disable degraded accounts in management UI and filter bound accounts by ID 2026-10-04 22:22:31 +08:00
inter 6c19399527 feat(gateway): auto-disable degraded accounts 2026-10-04 22:22:31 +08:00
inter ea563c31ce feat(egress): support legacy authenticated HTTP proxy format 2026-10-04 22:12:27 +08:00
carfeii 31bbe64dc9 fix: video job retry can bypass client key account scope
Every other account-selection path (text chat, image generation, voice,
voice websocket) threads the requesting client key's AccountScope through
to beginSelectionSessionForKey. The video job's background retry/recovery
worker (runVideoJob) used the unscoped beginSelectionSession instead, so
once the job's originally pinned account failed, the fallback search for a
replacement ignored the client key's provider/tier restrictions entirely.

A client key restricted to e.g. Super-tier accounts could end up consuming
a Free-tier (or wrong-provider) account's quota purely because its pinned
account hit a transient failure, silently widening access beyond what the
key was configured to allow.

media.Job already stores ClientKeyID, so the fix looks up that key and
passes its AccountScope into beginSelectionSessionForKey, matching every
other selection path. Added a regression test
(TestVideoRetryDoesNotEscapeClientKeyAccountScope) that fails against the
prior code (confirmed: the out-of-scope account was used) and passes with
the fix.
2026-09-30 15:26:04 +08:00
Solaris-star a88cd8808c fix(gateway): cool down Build accounts after unknown 403 2026-09-29 17:02:07 +08:00
lij768423-svg 7f3f3d3ce0 fix: withhold vis<8 and plaintext-ratio dumps; count streamed visible only
requestRetry still leaked grok-4.6 dumps after the short-usage patch:
fake-enc/burst required visible >= minOutput, plaintext thinking vetoed
the dump detectors, and chat usage.completion inflated visible tokens.

Withhold when reasoning>=80 or ciphertext meets the floor and the visible
flush is <2s. Plaintext thinking still withholds if flush<2s and
reasoning/output >= 0.8. Cipher-only HasThinking waits until visible text
has streamed for 2s, or the stream ends. Visible tokens come from
streamed content only.

Does not enable requestRetry and does not change lab Docker/VERSION
defaults.
2026-09-12 10:55:54 +08:00
Chenyme 15bf810ace fix: cap account cooldown from upstream Retry-After 2026-09-02 18:04:26 +08:00
Chenyme 9b80510055 Merge branch 'main' into fix/web-free-video-duration-cap 2026-09-01 11:17:26 +08:00
Chenyme eadfece376 fix: cap free-tier video duration before upstream 2026-09-01 11:16:49 +08:00
Chenyme 08de857a75 Merge branch 'main' into pr/1029
# Conflicts:
#	backend/internal/transport/http/inference/handler_test.go
2026-09-01 10:20:27 +08:00
Chenyme d3ba8ff6d5 fix: safely normalize Build function parameter root unions 2026-08-31 23:41:13 +08:00
Chenyme c6acb00e0f Merge branch 'main' into pr/1027
# Conflicts:
#	backend/internal/application/gateway/service_test.go
#	backend/internal/transport/http/inference/handler.go
2026-08-31 18:53:19 +08:00
buddhism5080 f0044b76b6 fix: cap Grok Web free-account video duration before upstream
Free Web accounts 429 when duration exceeds 6s, which then rotates
accounts without changing the payload. Add a Grok Web setting
(freeVideoDurationCap, default 6) and clamp duration for free-tier
accounts at the Web adapter so retries are not wasted.
2026-08-31 16:04:05 +08:00
buddhism5080 5efc09a29f fix: lift Build function parameter root unions for xAI grammar
Codex/OpenAI Responses tools often send a root oneOf/anyOf whose
branches are $ref or nested unions. xAI/Build grammar requires a
root object or a root union of inline objects. Lift only the root
union, keep property $ref/$defs, and fail locally if the result is
still illegal.

Also treat streamed 400 JSON as ClassifyUpstreamHTTPError instead of
copyStream, so invalid-argument is request-scoped and does not rotate
accounts. Compatibility warning is function_parameters_root_normalized.
2026-08-31 16:04:05 +08:00
Chenyme 2645f5ef01 Merge branch 'main' into fix/audit-client-vs-upstream-stream-interrupt 2026-08-31 15:08:22 +08:00
Chenyme e42b2ef7d5 Merge branch 'main' into fix/selector-skip-credential-material-errors 2026-08-31 14:59:10 +08:00
Chenyme db8378e1d3 fix: skip accounts on transient credential-material load failures 2026-08-31 14:58:01 +08:00
Chenyme b086d759c5 fix: record hidden recovery and classify pinned-account failures 2026-08-31 14:39:20 +08:00
Chenyme c92dea8b06 Merge branch 'main' into pr/1019
# Conflicts:
#	backend/internal/application/gateway/attempt.go
#	backend/internal/infra/provider/cli/adapter.go
#	backend/internal/infra/provider/cli/responses_reasoning_recovery.go
2026-08-31 14:09:16 +08:00
Chenyme 22587daac6 Merge pull request #1018 from buddhism5080/fix/audit-retry-stream-failure
fix(audit): record stream failure after a prior 429 retry
2026-08-31 11:33:32 +08:00
Chenyme cf13fe1a2d fix: limit stream failure attempts to 2xx responses 2026-08-31 11:28:07 +08:00
Chenyme 95915fad28 refactor: enhance quality hold logic and replay safety across accounts 2026-08-31 10:34:58 +08:00
Chenyme d139aa5b39 Merge remote-tracking branch 'origin/main' into pr/1015 2026-08-31 10:21:50 +08:00
Chenyme 653d912dfb Merge pull request #1013 from lij768423-svg/feat/encrypted-thinking-floor-upstream
fix: withhold fake encrypted thinking (ciphertext floor + burst dump)
2026-08-31 10:11:06 +08:00
Chenyme b3d4c972c5 fix: make encrypted-thinking hold split-safe 2026-08-31 10:05:25 +08:00
Chenyme 7caa52c14f fix: preserve upstream outcomes during reasoning recovery 2026-08-31 09:40:39 +08:00
buddhism5080 5b3e7efa1f fix(inference): classify output-loop guard as upstream_output_loop
Doom-loop aborts were wrapped as a generic stream read failure, so audits
and SSE trailers reported upstream_stream_interrupted. Keep the sentinel
distinct so a model repeating the same delta is not mixed with a transport
cut.
2026-08-29 20:22:00 +08:00
buddhism5080 acc0fb5361 fix(audit): distinguish client vs upstream stream interrupts
After a 2xx SSE handoff, a client hangup is client_stream_interrupted and keeps the upstream status. upstream_stream_interrupted is only for an upstream cut. Pre-header 499 request_canceled is unchanged.
2026-08-29 05:57:47 +08:00
buddhism5080 7cc10b1190 fix(gateway): skip accounts whose credential material fails to load
A timeout or lock on GetCredentialMaterial used to abort the whole
selector as no available accounts. Treat those per-account failures
like a stale claim so the rest of the pool can still be used. Request
cancellation still stops selection. Missing credentials still invalidate
the routing snapshot.
2026-08-29 04:59:59 +08:00
buddhism5080 6f5f99c2d8 fix(audit): keep hidden reasoning recovery and pinned-account 503s
Compaction-blob 400s recovered inside the Build adapter were returned as
200 with no audit attempts. Record each hidden upstream call (stage +
what the retry did) on the successful response.

Pinned conversation acquire treated a missing/disabled owning account as
an empty pool (upstream_unavailable) even when other accounts existed.
Return upstream_pinned_account_unavailable, skip bot-flag scheduling
exclusion for pinned acquire, and persist the selection failure plus
owning account id on the audit row.
2026-08-29 02:24:20 +08:00
buddhism5080 c7805f823c fix(audit): record stream failure after a prior 429 retry
When the first account returns 429 and the next account's 2xx stream
later fails, diagnostics previously kept only the 429 row. Always
append a response_stream attempt for the handed-off account unless
one is already present.
2026-08-28 22:43:50 +08:00
lij768423-svg 7b2cba3f43 fix: withhold floor-met thinking that dumps a short answer in under 1s
Encrypted_content can clear the byte floor while usage still bills hundreds
of reasoning tokens against a few visible tokens. Treat that fast dump as
missing thinking even before the hold deadline.
2026-08-28 11:36:30 +08:00
lij768423-svg 318c2dacd7 fix: withhold stub-only thinking when hold expires with enough output
A reasoning item start plus visible tokens at the deadline is not late
ciphertext. Treat it as missing thinking and rotate, matching the TUI
dump after 30s.
2026-08-28 11:36:30 +08:00
lij768423-svg ffaa2c7ba2 fix: hold TUI follow-ups and hosted-tool turns
Do not skip missing-thinking intercept on previous_response_id or hosted
tools. TUI always declares those. First attempt stays pinned; withhold
unpins and rotates. Compaction with no reasoning is held unless the
gateway set skipQualityHold.
2026-08-28 11:36:30 +08:00
lij768423-svg f343670fa7 fix: treat short encrypted_content stubs as missing thinking
Non-empty ciphertext is not proof of reasoning. HasThinking now requires
encrypted_content / Anthropic signature to meet max(256B, 4 bytes per
usage reasoning token). A hold-expired short greeting billed as heavy
thinking, or a barely-over-floor flush in under a second, is withheld.

Recommended requestRetry values stay 30s / minOutput 8 / 6 attempts /
fail_closed / 12h / 15m idle, plus the new floor knobs. enabled remains
false so stock installs do not intercept.
2026-08-27 19:03:27 +08:00
haswysa 2408b67ddb fix(gateway): keep portable reasoning summaries during compaction recovery
Same-account recovery now strips ciphertext while rewriting readable
summaries as developer messages, continues to session reset when the
stripped retry still returns 400, and only rotates accounts after
reasoning_recovery_failed. Drop Diagnostic substring matching so
unrelated 400s do not scan the account pool.
2026-08-26 08:05:37 +08:00
haswysa 1de4c8152d fix(gateway): failover account on reasoning recovery failure and strip unportable reasoning
In multi-account pools, server-side encrypted compaction blobs and reasoning states can fail to decode when a session drifts across accounts or upstream nodes, causing xAI to return HTTP 400 ("Could not decode the compaction blob").

Previously, isRetryable(400) evaluated to false in the gateway service, treating all 400 responses as non-retryable client errors. When provider reasoning recovery failed on the active account, the gateway immediately propagated the 400 to the client instead of attempting other healthy accounts in the candidate pool.

Fixes:
1. Gateway failover: Recognize reasoning_recovery_failed in isRetryableResponse so the gateway excludes the failing account and attempts the next candidate within the request attempt loop.
2. Reasoning recovery: Completely strip all reasoning items and convert compaction items to compatibility boundary messages during downgrade retries.
3. History normalization: Convert unencrypted reasoning items without portable content to developer boundary messages.
4. Error markers: Add compaction decode patterns to reasoningDecodeFailureMarkers.

Tested:
- Added TestRecoverReasoningDecodeFailureCompactionBlob
- Updated TestReasoningWithoutEncryptedContentBecomesBoundary
- All backend packages pass (go test ./...)
2026-08-26 06:37:08 +08:00
Chenyme d7fca59d68 fix: cool accounts after non-streaming idle responses 2026-08-25 18:10:57 +08:00
Chenyme f819f298a8 fix: quarantine runtime-selected account leases 2026-08-25 17:37:48 +08:00
Chenyme af5dec368d fix: reconcile stale Grok Console quota after 429 2026-08-24 16:48:13 +08:00