Skip to content

serve: /v1/responses keeps its responses: store, previous_response_id and background, in a bounded store - #968

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-responses-store
Oct 29, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-responses-store

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

/v1/responses가 store, previous_response_id, background를 받고 저장한 응답을 조회, 삭제, 취소할 수 있게 했습니다.

What and why

/v1/responses refused previous_response_id, store: true and background: true by name, so a client could not continue a conversation by id or run a long generation in the background. This PR keeps each response in a bounded in-memory store. store defaults to true, as in the OpenAI API.

  • GET /v1/responses/{id} reads a stored response and DELETE drops it.
  • previous_response_id continues the stored conversation (its input and output, not its instructions). /v1/responses/input_tokens counts the continued conversation the same way.
  • background: true answers queued at once and generates on its own thread. The client polls GET until the response is completed or failed, or ends it with POST /v1/responses/{id}/cancel. While running background responses fill either bound below, a new background request gets 503 with Retry-After.
  • The store holds at most 1,024 responses and 256 MiB of their JSON text. Past either bound it drops the oldest finished response first. A response that alone exceeds the byte bound is not kept, and a running background response is never dropped.
  • Still refused by name: a previous_response_id that names no stored response, conversation, an item_reference item, and background together with store: false or stream: true.

docs/serving.md lists the new routes and the bounds, and the refused list now names only what is still refused.

Release notes: Added: /v1/responses keeps its responses (store, previous_response_id, background) with GET, DELETE and cancel, in a store bounded to 1,024 responses and 256 MiB.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. Logic two models (or two call sites) share has one common owner; I lifted it there instead of
    copying it (AGENTS.md "Common code first", docs/rust-quality.md R14). Where I found an existing copy, I
    named it below.
  • Model code holds only architecture facts. A model's own files carry only what its architecture forces
    (tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
  • Dead code is gone. Nothing I made unused is left behind (functions, flags, gate clauses, docs).
  • No silent failure. Undefined input is a named error or panic, never a defined-looking output.
  • Comments state what is true now. No dates, issue numbers or how a bug was found (tools/check-comments.sh).
  • No relaxed gate. No band, tolerance or lint moved to make a check pass; a re-pin carries PIN(YYYY-MM-DD):
    and its reason.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": none.

What I ran

Real bloomery-serve on a DGX Spark (Qwen3.8 FP4-Local with its MTP draft), started with bloomery-serve -m <FP4-Local folder> --parallel 1 --ctx-size 16896. A client sent the requests below (greedy, reasoning.effort: none) and printed one line per check:

first 200 completed "Paris" store True
CHECK PASS store defaults to true
CHECK PASS GET answers the stored response as it was sent
CHECK PASS continued answer == inline conversation's answer
input_tokens continued {'input_tokens': 43, 'object': 'response.input_tokens'} inline {'input_tokens': 43, 'object': 'response.input_tokens'}
CHECK PASS input_tokens counts the continued conversation as the inline one
background 200 queued answered in 0.001s
background end completed after 1.4s "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20"
cancel 200 cancelled
slots after cancel [False]
CHECK PASS the cancelled generation freed its slot
CHECK PASS DELETE drops it
CHECK PASS GET after DELETE is 404
filled 1025 responses in 214.1s
after fill: first 404 fill[0] 404 fill[-1] 200
CHECK PASS past the bound the oldest response is dropped
fill responses still kept 1024 of 1025
ALL PASS

The GPU gates for the serve crate on the same card:

gate-q38-serve-rules rc=0
test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 295 filtered out; finished in 0.00s
test result: ok. 27 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
gate-serve-draft-rules rc=0
test result: ok. 28 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.05s
test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
test result: ok. 44 passed; 0 failed; 3 ignored; 0 measured; 0 filtered out; finished in 0.39s
test result: ok. 46 passed; 0 failed; 3 ignored; 0 measured; 0 filtered out; finished in 0.39s

BLOOMERY_BOX_LOCAL=1 just gate-serve on a DGX Spark exits 0, with the serve crate's lib and integration binaries all ok:

test result: ok. 406 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 9.56s
test result: ok. 111 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.97s

Hardware (if the change is for a machine)

NVIDIA GB10, 595.84, [N/A]
CUDA Version 13.3.1

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added documentation Improvements or additions to documentation serve The HTTP server: crates/serve labels Oct 29, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MUST_FIX: cross-origin browser clients cannot use the new response deletion route.

Must fix

1. Allow DELETE in the shared CORS preflight

crates/serve/src/api.rs:1636 adds DELETE, but api.rs:1533 permits only GET, POST, OPTIONS. A cross-origin browser deletion triggers OPTIONS and then fails the method check. The browser never sends DELETE.

Adding the method now avoids client workarounds for the new endpoint. Replace cors_preflight below, update its doc sentence, and extend the existing OPTIONS test to assert that DELETE is allowed.

pub(crate) fn cors_preflight() -> [(&'static str, String); 2] {
    [
        (
            "Access-Control-Allow-Methods",
            "GET, POST, DELETE, OPTIONS".to_owned(),
        ),
        ("Access-Control-Allow-Headers", "*".to_owned()),
    ]
}

Checked

Duplicates: 47 introduced or renamed definitions checked; no duplicated owner. Dryer reported no pairs.

Complexity: api::route rose from 28 to 29 through one route arm; harmless dispatch growth.

Silent failure: 11 sites followed. Wrong field types return 400; internal response builders and the route guard establish the defaulted fields; clone failure in the test panics.

Tests: mutation checks by inspection covered 11 new or changed tests. Dropped eviction, admission, history reservation, cancellation, persistence, failure reporting, metadata, and refusal branches reach assertions. No assertion checks DELETE preflight.

Gates: no numeric pins moved; stored-state refusal cases now have positive behavior tests.

Escape catalog: no C1–C4 pattern matched.

Notes

Static review; no build or gates run here. The reported card run lacks both measured commit hashes and the exact model file. New tests have no FAIL-first evidence in the PR body.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

… and background, in a bounded store

A response is kept unless the request sends store: false. GET
/v1/responses/{id} reads it, DELETE drops it, and previous_response_id
continues its conversation (its input and output items, not its
instructions). background: true answers queued at once and generates on a
thread of its own; POST /v1/responses/{id}/cancel ends a running one as a
client gone ends a request. The store holds at most 1,024 responses and
256 MiB of their JSON and drops the oldest finished one first; a running
background response is never dropped.
@juliankang4
juliankang4 force-pushed the dgx-spark-q38-usab-responses-store branch from b5cc46b to 09f823d Compare October 29, 2026 14:26

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the last review: item 1 is fixed. api.rs:1533 permits DELETE, and api.rs:6470 checks the preflight header.

Verdict: CLEAN: the previous CORS blocker is fixed, and no new defect was found in the interdiff.

Checked

Duplicates: 0 new definitions in the interdiff; the shared cors_preflight remains the owner. Dryer reported no pairs.

Complexity: crapper flagged api::route, 28 → 29, for one harmless dispatch arm already reviewed; the interdiff adds no branch.

Silent failure: 0 new defaulting or discarded-error sites.

Tests: mutation inspection protects api.rs:1533. Removing DELETE from the method list makes the added assertion at api.rs:6470 false.

Gates: no pins, tolerances, test cases or lint levels relaxed.

Correctness: OPTIONS uses the shared headers for both response path spellings. DELETE still requires a valid key when authentication is configured. No inference hot path changes.

Escape catalog: no C1–C4 patterns matched.

Notes

Static review; no builds or gates run here. The reported GPU runs lack both measured commit hashes and the exact model file. The PR body has no FAIL-first output for the added assertion.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit c0d14f3 into midagedev:main Oct 29, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation serve The HTTP server: crates/serve

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant