Repository navigation
feat(streaming): harden cancellation, headers and output framing - #3
Merged
Merged
Conversation
Adopt a freshly spawned server only after terminating the one it replaces, ignore the late exit of a replaced child and re-arm the stopping flag on every spawn. An admin restart or a markStale/resolve cycle used to orphan a live `opencode serve` (and its port), the exit of the stale child cleared the tracking of its successor, and a server restarted after stop() was no longer supervised at all. Also report the client's own request timeout as 504 timeout_error with code upstream_timeout instead of 503 upstream_unreachable, matching the documented status table; a caller abort still surfaces as 499.
ensureConnected() kept a single resolver slot, so concurrent completions that raced the initial connection waited for the whole timeout even though the stream was already up, and stop() left them pending. Track a set of waiters and release all of them. Report connectivity through a dedicated event_stream_connected gauge instead of labelling a session-cache series "event_stream".
Client-disconnect detection moves into src/http/disconnect.ts. On Node >= 16 the IncomingMessage "close" event fires as soon as the request body has been read, so the per-surface listeners either missed the disconnect or aborted a healthy request. The response/socket close is the reliable signal: a disconnect now really interrupts the turn, cancels a pending attachment download and releases the sticky slot. Also, in the same pass: - the SSE head keeps the headers Fastify set on the reply (CORS and the new x-request-id), which reply.hijack() would otherwise discard; - a sanitised caller-supplied x-request-id is echoed on every response and used as the request id in the log lines; - the chat adapter reads the reasoning field from Config, not from module state shared by every server in the process; - /v1/responses closes the reasoning summary part, rejects an input_file carrying only a file_id, and no longer leaks the stream gauge when the response head cannot be written; - response_format and text.format are rendered into the prompt as a JSON-only instruction; - isPrivateHost classifies IPv4/IPv6 by address family: public names such as fdic.gov are no longer blocked, and site-local, multicast, NAT64 and 6to4 literals are; - the unused bootstrapLogger, SSE_HEADERS and modality set are gone.
Correct the drift the batch exposed: the `created` example was in milliseconds while the text promises seconds, temperature/top_p were documented as forwarded upstream although nothing reads them, and OPENCODE_REASONING_FIELD was listed as an adapter-level setting outside Config. Startup validation no longer claims a missing key is fatal. Document the streaming 429 caveat (retry_after_ms in the error frame), the response-side disconnect detection, the new x-request-id header, JSON output mode, the reasoning_summary_part.done frame, the event_stream_connected metric and the input_file file_id rejection.
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.
Summary
A batch of defects and improvements found while auditing the gateway against its
own contract and documentation (the full proposal list is in the commit
messages; the temporary proposal file was removed before the first commit).
Fixes
child is terminated, a replaced child's late exit no longer clears the
successor's tracking, and supervision is re-armed after
stop(); a requesttimeout now answers
504 timeout_error.(
src/http/disconnect.ts). The previousrequest.rawlistener fired when thebody had been read, so a disconnect never cancelled the turn or a pending
attachment download.
x-request-id.EventHub.ensureConnected()releases every concurrent waiter instead of onlythe last one.
isPrivateHost()classifies IPv4/IPv6 by address family: public names such asfdic.govare no longer blocked and site-local, multicast, NAT64 and 6to4literals now are.
Configinstead of modulestate shared by every server in the process.
/v1/responses: closesresponse.reasoning_summary_part, rejects aninput_filethat carries onlyfile_id, and no longer leaks theactive_streamsgauge when the response head cannot be written.Features
x-request-id: a validated caller-supplied correlation id, echoed on everyJSON and SSE response and used as the request id in the logs.
response_format(chat) andtext.format(Responses) arerendered into the prompt as a JSON-only instruction.
Documentation
createdexample unit, thetemperature/top_pclaim,OPENCODE_REASONING_FIELDbeing described as outsideConfig, the startupvalidation list, the streaming
429caveat and thepnpm builddescription.event_stream_connectedmetricand the closed reasoning part.
Verification
pnpm typecheck— cleanpnpm build— cleanpnpm test— 214 passed (15 files)pnpm lint:commits— clean for every commit on the branch