Skip to content

feat(server): correlate /v1 responses with request IDs - #1181

Open
Allegro-ma-non-troppo wants to merge 3 commits into
ROCm:mainfrom
Allegro-ma-non-troppo:wp-53-request-id
Open

Allegro-ma-non-troppo wants to merge 3 commits into
ROCm:mainfrom
Allegro-ma-non-troppo:wp-53-request-id

Conversation

@Allegro-ma-non-troppo

Copy link
Copy Markdown
Collaborator

Why

A client that received a /v1 error had nothing it could give an operator to identify that particular attempt. Identical retries and concurrent requests were especially hard to distinguish.

What changed

  • Send a fresh, server-generated x-request-id when a parsed /v1 response starts. This includes errors, preflights and the first headers of an SSE stream. Print one matching flm.http_response id=… method=… route=… status=… line on stdout; it identifies the registered route or unmatched without requiring prompt or body logging.
  • Let browser JavaScript read the header only on actual responses from an already-permitted origin. Allowed origins, allowed request headers and /api responses are unchanged.
  • Do not echo incoming IDs or reuse completion IDs or cancellation keys. The record marks the start of the response, not successful delivery or stream completion.

Benchmark: client and operator behavior

Client / operator Before After
OpenAI Python SDK No support ID on success or on HTTP status errors Use completion._request_id or exc.request_id to report the attempt
Streaming or browser client No ID before iterating a stream or in a permitted cross-origin fetch Read stream.response.headers before iteration, or Response.headers in the browser
Server operator Infer the attempt from surrounding output Search stdout for flm.http_response id=<returned ID> to find the method, route and HTTP status

Tests run

  • Windows Release; native http_guard and error_model passed with zero compiler warnings. All four new HTTP regressions failed on main for missing IDs and passed with local, disabled and wildcard CORS. Across these runs and the existing error/connection suite: 58 passed, 0 failed, 8 configuration-specific skips (each exercised in another mode).
  • With qwen3:0.6b on NPU, raw HTTP returned 12 in-scope IDs for 12 complete matching stdout records. The real Python SDK read IDs on success, 404 and before the first SSE event. Queue-full retained its JSON 503 and Retry-After: 1; the pre-parse connection-cap 503 stayed untagged. Chrome read the ID with a permitted origin; --cors 0 still blocked it.
  • With stdout and stderr redirected separately, the record was visible on stdout before a second request or shutdown. In a separate four-thread generator test, forced entropy-constructor and entropy-read failures each returned 512 distinct, valid IDs without exceptions.
  • Injected a handler exception after the first stream event: one HTTP 200, one ID/record, the original error and one [DONE]. In paired raw captures, removing only the new headers left the stream preamble and complete chunked body byte-identical to main, both with and without an allowed Origin.

Acceptance and limits

Scope follows the normalized /v1 path, not the JSON protocol. No inference, JSON/SSE payload, cancellation or retry-policy change. A client that receives no headers (including a connection refused before the target is parsed) has no server ID to report; supporting that would require a separate client-correlation design. Local validation was on Windows, not Linux/macOS or multiple devices. The post-header fault was injected in a handler, not induced on physical hardware.

Generate one server-owned ID at the HTTP header boundary and join it to a content-safe response-start record. Preserve cancellation keys, stream bodies and existing origin policy.

WP-53

This branch was successfully deployed

1 active deployment
npu-approval — 3a959b85 Deployed Nov 28, 2026 by Allegro-ma-non-troppo via npu-approve #802
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant