Skip to content

feat: Create and poll background Responses #2898

Closed

Description

@inureyes

Part of #2903

Context

Line numbers are at origin/main 8d3e16ad. background: true is rejected with 400 at src/server/responses_translator.rs:131. #2896 provides prepare_response_run, drive_response_run, and ResponseEventSink (emit, on_started, record_terminal, finish_registration, generation_finished). #2897 provides on ResponsesStore: admit_background(snapshot, input_items, effective_store) -> Result<InFlightToken, BackgroundAdmitError { Disabled, LimitReached { limit }, OverBudget }>, mark_background_in_progress(id), finish_background(id, terminal) -> ResponseObject, background_snapshot(id), background_status(id).

Scope

Create. In create_response (routes/responses.rs:85), when background == Some(true):

  • Synchronous 400s before any job exists: everything :94-173 validates, plus store disabled, max_jobs 0, and stream: true (message says not yet supported, until the streaming sub-issue removes it). Remove BackgroundUnsupported.
  • Move work that can take long into the job, because create must return at once: expand_request_video_parts (:130, :188), apply_auto_compaction (:181, a full generation pass), and prepare_response_run (media reads). Failures there end as failed.
  • Admit, then return HTTP 200 with the queued object. LimitReached and OverBudget return 429 rate_limit_exceeded; a full queue (can_accept_request, or reserve_single_stream_queue_slot failing) returns the foreground's 503. Add background: Option<bool> to ResponseObject, serialized only when Some(true), so foreground bytes do not change.

Run. tokio::spawn the async prelude, then spawn_blocking(drive_response_run) with BackgroundSink: emit drops events, record_terminal calls finish_background, generation_finished is a no-op. Nothing observes the client, so a disconnect cannot cancel.

queued to in_progress. AdmissionWaiter::arm is not usable alone: model_provider.rs:2643-2667 answers at dispatch (immediately for media), before any slot starts. Hold the waiter so a rejection maps to failed, and flip status in on_started.

Terminal. completed or incomplete as final_status decides; failed with error: { code, message }, code server_error, server_overloaded for QueueFullError, or invalid_prompt for media or render failures. Snapshots stay output: [] with zero usage until terminal (proposed default; partial text is available by streaming).

Read and delete. retrieve_response (:1260) falls back to background_snapshot. DELETE on an active job returns 400 asking the client to cancel first. Cancel keeps working through cancel_in_flight until the cancel sub-issue replaces it; the job's registered token must be the one admit returned.

Shutdown. start_server installs no signal handler for the single-model server (only router_server.rs:1730 listens), so a signal ends the process and jobs vanish, as documented in-memory behavior. When the worker exits while the process lives, ChatWorkerGoneError becomes failed; no job stays active forever. A panic in the prelude or driver also records failed through a drop guard.

Interactions.

  • previous_response_id naming an active job: 400 previous response '<id>' has not finished (status: <status>), using background_status in the translator.
  • conversation appends at terminal through persist_response; history is resolved at create.
  • context_management runs inside the job. Emit its item as today.
  • Media is allowed. The capability gate stays synchronous.
  • MCP: the translator rejects mcp tools (responses_translator.rs:68, docs/responses-api.md:477) and no server-side tool loop exists, so there is nothing to integrate.

Out of scope

Streaming, full cancel response, router pool behavior.

Acceptance criteria

Tests in new src/server/routes/responses_background_route_tests.rs on the scripted provider:

  • Create returns 200 queued with background: true before any token is scripted.
  • GET moves queued, in_progress, completed, with final output equal to the foreground object's output.
  • incomplete at the token limit; failed with error on a scripted failure.
  • Validation errors return 400 and create no job.
  • Limit returns 429 and leaves no job.
  • Dropping the create response does not cancel.
  • Worker exit and driver panic end as failed, with active_background_jobs() == 0.
  • store: false result is retrievable, then gone after expiry.
  • previous_response_id on an active job returns the 400; after terminal it chains.
  • DELETE on an active job returns 400.
  • Foreground golden test: the JSON for a non-background response has no background key.

Dependencies

#2896, #2897.

Verification

cargo fmt --all -- --check
cargo clippy --all-targets --features cuda -- -D warnings  # metal,accelerate on macOS
cargo test --lib --profile test-fast --features cuda server::routes::responses -- --test-threads=1

Manual: on qwen3-0.6b-4bit, curl a background: true create and poll to completed.

Activity

  1. added
    status:ready
    type:enhancement
    priority:medium
    status:in-progress
    status:review
    and removed
    status:ready
    status:in-progress
    on Nov 9, 2026
  2. added
    status:done
    and removed
    status:review
    on Nov 10, 2026
  3. added 2 commits that reference this issue on Nov 10, 2026
    2c2a8ba
    310da24
  4. added a commit that references this issue on Nov 13, 2026
    0b01dfb
  5. added this to the 0.9 milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:mediumstatus:donetype:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions