372 Commits
Author SHA1 Message Date
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
Chenyme 470ac4afbc fix: preserve provider prefixes in public model names 2026-08-24 15:14:05 +08:00
Chenyme 3116c15beb fix: prevent transient upstream failures from cascading into cooldown 429s 2026-08-24 13:43:23 +08:00
Chenyme 4ae50ecf98 fix: support shared weekly limits for Grok Web Imagine 2026-08-24 11:12:09 +08:00
Chenyme 46cfa374af fix: align video generation with current mediaGenInput protocol 2026-08-20 20:48:59 +08:00
Chenyme 017d94a065 Merge remote-tracking branch 'origin/main' into pr/989
# Conflicts:
#	backend/internal/application/gateway/quality_retry.go
#	backend/internal/application/gateway/quality_retry_scan.go
#	backend/internal/application/gateway/quality_retry_test.go
#	backend/internal/infra/config/config.go
#	backend/internal/infra/config/config_test.go
#	backend/internal/transport/http/account/handler.go
#	backend/internal/transport/http/account/handler_test.go
#	backend/internal/transport/http/inference/handler.go
#	backend/internal/transport/http/inference/handler_test.go
#	config.example.yaml
2026-08-20 20:25:02 +08:00
Chenyme 2aace693e9 fix: avoid withholding late-thinking streams after the quality hold deadline 2026-08-20 20:19:22 +08:00
Chenyme 1316ed730b feat: add privacy-safe request diagnostics and bounded retention 2026-08-20 19:45:35 +08:00
Chenyme c07fa0b61e Merge remote-tracking branch 'origin/main' into pr/983
# Conflicts:
#	backend/internal/transport/http/inference/handler.go
2026-08-20 19:40:37 +08:00
lij768423-svg 6b288f209c fix: lengthen requestRetry hold so grok-4.6 thinking is not withheld
3s hold cuts encrypted thinking that arrives at end-of-stream, which
fills audits with HTTP 200 · error and quality_degraded retries.
Match the production lab defaults: 30s hold, minOutput 8, 12h
missing-thinking cooldown, 15m idle cooldown, grok-4.6 probe model.

requestRetry.enabled stays false in built-in Go defaults so existing
configs do not flip on upgrade; config.example.yaml now recommends it on.
2026-08-20 17:18:05 +08:00
Chenyme 68e3399821 Merge branch 'main' into guard 2026-08-20 16:38:56 +08:00
Chenyme 0772fb1c7a Merge branch 'main' into fix/clear-account-cooldown 2026-08-20 16:10:15 +08:00
Chenyme 0fb3a04124 fix: preserve quality strikes when clearing cooldown 2026-08-20 16:09:58 +08:00
Chenyme 7dd96657dd Merge branch 'main' into pr/980
# Conflicts:
#	backend/internal/application/gateway/quality_retry_scan.go
2026-08-20 15:38:29 +08:00
Chenyme a2f2687b33 fix: retry terminal empty streams without misclassifying tool output 2026-08-20 15:32:25 +08:00
Chenyme 7e71bf09ae Merge branch 'main' into fix/hold-tools-schema 2026-08-20 15:15:47 +08:00
Chenyme d93547dc19 fix: avoid replaying hosted tools during quality retries 2026-08-20 15:15:31 +08:00
Chenyme 5f156cd3f5 fix: preserve real thinking evidence across protocol conversion 2026-08-20 14:56:31 +08:00