Repository navigation
feat(step): queue Step model requests when the server asks to wait - #369
Merged
Merged
Conversation
Requests to Step's API hosts now carry X-StepCode-Queue-ID. When the server answers 429 with X-StepCode-Queue-State: waiting, the request holds its place: the client polls the region's queue endpoint, resends the original bytes under the same id once ready, and releases the place on stop. Servers that do not queue ignore the header, so nothing else changes. - core: modelFetch hook, request teardowns settled on dispose, and the ephemeral model_queue session event - providers: StreamIdleHold pauses the idle watchdog while waiting; isStepProvider / isStepPlatformUrl as the single Step identity source - step: queue client, model_queue setting (STEPCODE_MODEL_QUEUE env, default on), x-step-client defaults to stepcode-cli - cli: TUI queue status, -p stderr line, json/rpc live events
liuedcson
requested review from
MelodyVAR,
Uking-xxx and
ZouR-Ma
as code owners
November 26, 2026 09:50
… 20 minutes - Drop the client switch (STEPCODE_MODEL_QUEUE and model_queue): the queue only engages when Step's server answers with a queued 429. - Poll every 5s when the server names no interval (capped at 30s); one call waits in line at most 20 minutes across resends, then ends as wait_timeout. - Leave the line with a cancel whenever this side stops waiting: a stop, the wait bound, a status endpoint that keeps failing, or an unexpected status. - Send x-step-client-version with x-step-client so the server can admit client releases per client. - /btw side questions carry the client identity and go through the queue.
- A 429 with X-StepCode-Queue-State: closed, on the first send or a resend, ends the call with the non-retryable 410 a closed poll gives. A resend the server closed used to go back to the retry policy, which re-entered the line at the tail under a new id. - A 429 with X-StepCode-Limit-Scope keeps its status, codes and headers and gains a leading sentence: the user's own usage limit, or Step's capacity. - Closed reasons and limit scopes are fixed lists shared with the server (StepQueueClosedReason, StepLimitScope). Only reasons a user can act on are named: queue_full, user_limit, max_wait_exceeded; the 20-minute wait on this side reports max_wait_exceeded too. Anything else reads as the generic text.
- A queued call now reports its phase, not just its place: `waiting` while it waits, `ready` once the server admitted it and the same bytes go out again. The resend used to leave the row showing the last place it had, then the row vanished with no way to tell an admitted call from one still in line. - ModelQueueState carries `state` (`ModelQueuePhase`: waiting | ready) and the position only while waiting. Reports go out on a change of either, so an admitted place reaches live consumers and `--include-live-events` streams. - Presentation follows: the TUI status row reads "Starting..." for an admitted place, and `-p` writes it like every other change.
- A child runs as an rpc process started with --include-live-events, so its model_queue frames already reach the parent, but the event projection ignored them: a child waiting in line looked like a child doing nothing. - The projection now folds each child's frames by queue id and keeps the call updated last as `queue` on its live record (state and position only). One call leaving the line keeps another's place; two children never share a fold. - The live roster carries `queue` field by field, and the lane snapshot validation accepts it (and refuses a malformed one whole), so a host that reads lane snapshots can show it. A settled turn drops it: a final result never carries a live field.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
StepCode requests to Step's API hosts can now wait in a server-side queue instead of failing when the pool is busy.
api.stepfun.com/api.stepfun.ai(any provider) carryX-StepCode-Queue-ID, a fresh UUID per model call.429withX-StepCode-Queue-State: waiting, the client:GET https://api.stepfun.{com,ai}/stepcode/v1/queuewith the same header, at the server'sRetry-After-Ms/retry_after_ms(5 s when the server names none, 30 s cap);ready;410 queue_closedwhen the place isclosed: a status answer, or a429withX-StepCode-Queue-State: closedon the first send or a resend (polling404counts as closed;401/403pass through;429/5xxback off with a 30 s budget). The reason comes from a fixed list shared with the server, only reasons a user can act on:queue_full,user_limit,max_wait_exceeded; anything else reads as a generic text;max_wait_exceeded;POST .../stepcode/v1/queue/cancelwhenever this side stops waiting after it was queued: a stop, the 20-minute bound, a status endpoint that keeps failing, or an unexpected status. A place the server closed is not cancelled.model_queueevent carriesqueue.state(waitingwhile it keeps its place,readyonce the server admitted it and the same bytes go out again). An admitted place has no position left, so the status says the request is starting instead of naming a place it no longer has.x-step-client-version(the Step product version) next tox-step-client, so the server can admit releases per client.429carryingX-StepCode-Limit-Scopekeeps its status, codes and headers (the retry policy is unchanged) and gains a leading sentence:user_quota(the user's own usage limit) orupstream_capacity(Step's capacity)./btwside questions carry the same identity headers and go through the queue.Switch
None on the client. The server alone decides: the queue engages only when it answers
429withX-StepCode-Queue-State: waiting.Compatibility
x-step-clientnow defaults tostepcode-cli(wasstepcode/cli); an explicitSTEP_CLIENTis kept. Dashboards keyed on the old values need updating.Pieces
createAgentSession({ modelFetch }); request teardowns that session/runtime dispose settle within a bound (so a stop during-pstill releases the place); ephemeralmodel_queuesession event (rpc/json emit it with--include-live-events, never persisted).StreamIdleHold;isStepProvider/isStepPlatformUrlas the single source for Step identity (telemetry endpoint classification keeps its previous coverage).-pwrites queue status to stderr.model_queueframes (it runs as an rpc process started with--include-live-events) fold by queue id into a livequeueon its record, so a host can show a child waiting in line; the lane snapshot validation accepts it and a settled turn drops it.Tests
pnpm run check; targeted suites (queue client, session, teardowns, print/json/rpc, TUI, signal exit process test);./test.shpasses exceptsubagent-invocation.test.ts, which fails only on hosts where the isolated temp path exceeds the socket path limit.