DeepSeek-Reasonix icon indicating copy to clipboard operation
DeepSeek-Reasonix copied to clipboard

feat(desktop): resume after quota exhaustion with lossless model switching / 配额耗尽后无损切模并自动续跑

Open SivanCola opened this issue 4 months ago • 0 comments

Problem

When a model's periodic usage quota is exhausted, Reasonix treats the response like an ordinary HTTP 429, retries requests that cannot succeed, and blocks model switching while background jobs remain active. Users can end up restarting the desktop app just to select another model and continue the task.

Root cause

Periodic quota exhaustion and transient TPM/RPM throttling share HTTP 429, while controller rebuilds previously owned Jobs, the subagent scheduler, the Delivery workspace lease, and LSP exclusively. The desktop model-switch guard therefore had no safe way to preserve session-scoped background work.

What changed

  • Add provider.QuotaExceededError, preserving APIError unwrapping, trace IDs, and response bodies while failing periodic quota exhaustion immediately without retry notices.
  • Keep structured rate_limit_exceeded responses on the ordinary backoff path, even when gateway text describes a short-lived quota reset.
  • Add ref-counted sessionruntime.Resources for Jobs, SubagentScheduler, WorkspaceLease, and LSP, with failure-atomic controller handoff and grace-bounded final cleanup.
  • Allow desktop model switching when only migratable background jobs remain; foreground turns and pending approvals/questions still block switching.
  • Add session-scoped background-job cancellation for local desktop and reuse Remote Workbench job/cancel.
  • Render a dedicated quota recovery card, open a refreshed model switcher, and submit one synthetic continuation only after a successful recovery switch.
  • Show running background jobs beside the model selector with per-job stop actions.
  • Reuse a legacy synthetic-message prefix so previous Reasonix releases also hide the recovery instruction when reopening the same session.

Product behavior

  • Periodic quota exhaustion stops the foreground turn immediately.
  • Ordinary TPM/RPM 429 responses still retry with the existing backoff policy.
  • Reasonix does not auto-select a replacement model; the user explicitly chooses one.
  • Token Mode and settings rebuild policies are unchanged.
  • CLI, serve, ACP, Remote Workbench model-switch policy, and already-running subagent model selection remain unchanged.

Backward compatibility

Surface Previous-version behavior Conclusion
turn_done.outcome = quota_exhausted Unknown outcomes fall back to the existing error text Safe additive enum value
Persisted synthetic recovery message Uses an existing interrupted-before-visible prefix recognized by previous releases Readable and remains hidden from titles, previews, and user-turn counts
Desktop bridge methods New methods are additive; existing payloads and persisted state are unchanged Safe additive API
Session resources In-memory ownership only; no session/config/state schema change No migration required
Job manager Done lifecycle Internal-only channel; existing callers retain Close behavior and bounded grace No persisted compatibility impact

Verification

  • go test ./...
  • cd desktop && go test ./...
  • go test -race ./internal/provider ./internal/sessionruntime ./internal/jobs
  • ./scripts/cache-guard.sh
  • Node 24: cd desktop/frontend && pnpm build
  • Frontend quota notice test and TypeScript checks
  • gofmt and git diff --check

Cache guard remains above the release threshold. The recovery prompt is appended at the conversation tail; stable prompt prefixes, provider request serialization, and tool schema ordering are unchanged.

Cache impact

Cache-impact: low - quota recovery only appends a synthetic tail turn; stable prompt prefixes, provider serialization, and tool schema ordering are unchanged. Cache-guard: ./scripts/cache-guard.sh - all release cache guard cases passed. System-prompt-review: SivanCola reviewed the boot resource-reuse changes; no provider-visible system prompt, memory prefix, output-style, or skill-index behavior changed.

SivanCola avatar Jul 30 '26 07:07 SivanCola