Skip to content

Report HTTP server responses to the dependency graph - #247

Merged
Domiii merged 2 commits into
mainfrom
dominik/dg-response
Nov 17, 2026
Merged

Domiii merged 2 commits into
mainfrom
dominik/dg-response

Conversation

@Domiii

@Domiii Domiii commented Nov 17, 2026 •

Copy link
Copy Markdown

🤖

Summary

  • An HTTP server's response was not in the dependency graph.
    • A request's chain could not show when its response started, streamed and ended.
    • Body writes were only generic asyncInit{WRITEWRAP} nodes, shared with every socket write.
  • http.ServerResponse now reports the response vertices workerd reports for a fetch handler's response.
    • Kinds from backend#13944: responseStart{status}, responseData{length}, responseEnd.

Model

  • The response is the server's effect: head, body writes, end. Each is a vertex.
  • Its cause is the JS that writes it.
    • node writes every head, chunk and end from a JS call.
    • So each node is made in its writer's execution, and its primary cause is executionPoint → that execution.
    • workerd makes them in KJ turns, so it needs an explicit scheduler edge from the JS settlement. node does not.
  • No explicit edges.
    • A creator edge from responseStart would outrank executionPoint within 50 ms of the head (backend getPrimaryCause, ignorePredecessorEdge).
    • Example: writeHead(200); rows = await query(); end(body). responseEnd must lead to the query, not to the head.

Sites

node site
responseStart{status} ServerResponse#writeHead, after the head is stored. Covers the implicit head of write/end/flushHeaders.
responseData{length} OutgoingMessage write_ of a ServerResponse, after the send, for ≥ 1 byte. Covers write(chunk) and end(chunk).
responseEnd OutgoingMessage#end of a ServerResponse, once it is finished.
  • length: the chunk's bytes, as the message counts them.
  • Bindings are stateless. Sites call gated wrappers in internal/async_hooks.
  • ServerResponse vs ClientRequest, which shares OutgoingMessage: instanceof, checked only while instrumented.
  • Not reported:
    • 1xx informational heads (writeInformation): not the response's head.
    • Writes ignored for bodiless responses (HEAD, 204, 304).
    • http2 responses: Http2Stream writes run through Writable buffering, so they need their own sites.

Prod behavior

  • Unrecorded: 1 JS boolean check per head, per body write and per end().
  • Recording: 1 binding call per head, per write of ≥ 1 byte and per end. Writes and ends also do 1 instanceof.
    • Each binding returns after the cached-bool gate. Buffer.byteLength runs only for string chunks whose length was not computed yet.
    • No JS-visible state.

Data

  • Builds: this PR linux-node-20261117-840941fc92c8-9b4881ad1084-dev (BK Merge pull request #1 from iojs/v1.x nodejs/node#619), main linux-node-20261117-53a4b1e02991-5d351da35be9 (BK src: rework early debug signal handling nodejs/node#615).
  • Benchmark, in-process ms, medians of 5 runs:
    • head+end ×1e5: 1e5 ServerResponses without a socket, each writeHead(200) + end().
    • write str ×1e5, write buf ×1e5: 1e5 5-byte writes to one response without a socket.
    • http ×2e3: 2e3 keep-alive requests to an in-process server, each response 10 writes + end().
run head+end ×1e5 write str ×1e5 write buf ×1e5 http ×2e3
recorded, main 33 37 42 371
recorded, this PR 36 38 45 376
recorded, this PR, RECORD_REPLAY_DISABLE_FEATURES=["dependency-graph"] 34 37 43 359
unrecorded (RECORD_REPLAY_DONT_RECORD=1), main 21 29 35 151
unrecorded, this PR 21 30 44 150
  • Cost, as rate × scale:
    • Recordings: about 30 ns more per response for head + end. Writes and the HTTP round trip are within noise.
    • Unrecorded runs: within noise.

REPLAY_BACKEND_REV

An http.ServerResponse reports a responseStart{status} node at its head
(writeHead, also implicit), a responseData{length} node per body write
of at least one byte, and a responseEnd node at end(). Data and end have
a creator edge from the start. All are made in the JS that writes, so
each one's execution is its cause. Kinds as workerd reports them
(backend#13944).

JS assigns a response its id at the head, only while instrumented; the
C++ graph keeps each started response's start node until its end.

REPLAY_BACKEND_REV: backend master with nodejs#13944.
@Domiii Domiii self-assigned this Nov 17, 2026
Data and end are caused by the JS that writes them (executionPoint). A
creator edge from the head would be their primary cause within 50 ms of
it. Without it, the bindings are stateless and responses carry no id.
The sites call gated wrappers in internal/async_hooks.
@Domiii
Domiii merged commit 7750d9a into main Nov 17, 2026
3 checks passed
@Domiii
Domiii deleted the dominik/dg-response branch November 17, 2026 21:54
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