Skip to content

fix(functions): end a response the handler leaves open, as deployed functions do - #314

Open
chhavi-mandowara-cstk wants to merge 21 commits into
v2-devfrom
CL-8970
Open

chhavi-mandowara-cstk wants to merge 21 commits into
v2-devfrom
CL-8970

Conversation

@chhavi-mandowara-cstk

@chhavi-mandowara-cstk chhavi-mandowara-cstk commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What was wrong

A handler that returns without ending its response hung under launch:functions:serve until the client gave up. Azure and GCP (CLI V1) answer 504 CF005 after the timeout.

Deployed AWS functions (lambda-node-bridge/cf-sv-with-helpers.ts, finalizeResponse) end it as soon as the handler returns or its promise settles, with the status and headers it set:

  • already ended → done;
  • headers already sent → left for the handler to end;
  • otherwise → res.end().

This is CL-8970 gap 4. The ticket owner chose to match AWS exactly (option A, agreed with Dhruv), because any other choice would change behaviour for existing AWS sites. One consequence: a callback that answers after the handler returned gets an empty response, as it does on AWS today.

The change (src/functions/cloud-functions.ts)

  • Ending the response. After the handler returns, or throws, endLikeDeployedFunctions ends an open response with the status and headers it set. It leaves the response alone in two cases: headers were already sent, or res.sendFile/download/sendfile is still sending.

    • A file send counts as in flight only once the call returned without throwing.
    • A callback-style send ends the response like AWS once it settles, if its callback left the response open.
  • Serve's own 500 never crashes serve. This covers a handler that throws before its headers were sent, and an auto-end that fails (an invalid status or status message, a content-length mismatch). The error is logged, and serve answers a cache-control: no-store 500 without the headers the handler had set, with the status message reset. If even that end() throws, serve destroys the response.

  • Late changes no longer crash serve. The guards are installed before the handler runs and pass calls straight through until the response has ended. From then on, a later end with a body, write, writeHead, header call or file send is ignored with one warn: line naming the requested URL. send, json and redirect are covered through those calls.

    • An end() with no body is Node's own no-op and is not warned about.
    • A trailing callback gets ERR_STREAM_WRITE_AFTER_END (write, or end with a body) or ERR_STREAM_ALREADY_FINISHED, as Node does.
    • A late write returns false.
    • Only methods that exist are wrapped (Express 5 has no res.sendfile).
  • Piped streams. When a response closes, or a stream is piped into one that has already ended or whose client has gone, each source is unpiped, if it has unpipe, inside the 'pipe' event on the late path. On the next turn:

    • the exchange's own request body is drained, as Node would dump it;
    • a file stream (fs.ReadStream) that nothing else reads is destroyed;
    • a stream that still has a 'data' reader is resumed for that reader;
    • anything else is left paused for the function. On the late path, the source is paused again from a one-shot 'resume' listener after pipe() resumes it.

    Sources without listenerCount, resume, once or pause are left alone.

  • AGENTS.md.

    • The approved V1 differences describe all of this, including the limit: a file stream or the request behind a transform, a child's stdout or an upstream body stays open until the function closes it.
    • It notes that Express's res.sendfile deprecation warning names serve's wrapper.
    • It notes that Azure/GCP (V1) still deliver late answers.
    • The deployment agent's 2.x upgrade note warns that moving Azure/GCP to 2.x changes that.
  • .talismanrc. Refreshed checksums for cloud-functions.test.ts and AGENTS.md. Both are test code and prose, with no credentials.

Tests

src/functions/cloud-functions.test.ts (118 tests):

  • Auto-end: status and headers are kept for sync, empty and async handlers.
  • Streaming: a response the handler started streaming is left open and delivered whole. A request piped into its response is echoed.
  • Late changes: each of send, json, end, write, writeHead, setHeader, redirect, sendStatus(204), status(205).send(), removeHeader, appendHeader, setHeaders, sendFile, download and sendfile is ignored, warns once, and serve keeps answering.
  • Same-tick and no-op changes:
    • end("a"); write("b"); end("c") warns once;
    • json(...).end(); end(); end(cb) does not warn.
  • Late callbacks: their error codes, and write returning false.
  • Serve's 500:
    • an invalid status on the auto-end;
    • an invalid status message, then a throw;
    • stale content-length/set-cookie dropped and no-store kept;
    • a content-length mismatch, where the connection is dropped and the next request is still served.
  • File sends:
    • with and without a callback;
    • a file send that throws, or whose callback only sets a status;
    • a deterministic late change triggered from 'finish'.
  • Piped streams:
    • a file stream is destroyed when serve ends the response, when it is piped late, when the handler ends the response itself, and after the client disconnects;
    • a late file stream that also feeds a tee, a 'data' reader or a for await reader keeps delivering;
    • a file stream with a side reader finishes and closes;
    • a released or late PassThrough stays paused and buffering;
    • an endless producer, on close and late, stays paused and the next request is served;
    • a late shared hub writes nothing to the ended response, warns nothing and keeps feeding its sink;
    • the one-shot pause doesn't catch the function's own later resume;
    • a request body piped into the response is drained, so a keep-alive connection answers its next request;
    • an upstream body is left paused;
    • legacy, non-core and stream-like sources (with and without listenerCount, resume, once, pause) don't crash serve.
  • Express 5 shape: with res.sendfile removed, requests still answer.

Mutation checks: I removed or inverted each guard and each release rule, one at a time, and each change turned a test red. Coverage of cloud-functions.ts is unchanged from v2-dev apart from the new code, which is fully covered.

Full suite in the pre-push hook: 201 suites, 4163 tests passed. Every hook ran, with no --no-verify.

E2E (http-sanity cloud-functions checks, AWS expectations)

I ran all 22 checks against launch:functions:serve built from each side, using e2e PR #487:

  • v2-dev 8899a3e: 13/22.

  • This branch: 16/22, last measured at 2c08689. Later commits change only stream release and serve's 500. Now passing:

    • a handler that never ends the response still answers
    • a handler that never ends the response keeps the status it set
    • a response ended after the handler returned is not delivered

    a response the handler started streaming is delivered whole passes on both sides, and no check got worse. The 6 that still fail are later gaps (5–11).

e2e PR #487 adds those checks and Dhruv's res.send('gone', 410) check, all behind LAUNCH_E2E_CLOUD_FUNCTION_PARITY. The owner's dev11 run on AWS passed the first 20 checks. A rerun with all 22 is pending.

Review

Eleven review passes. Accepted findings are fixed with tests, and each review thread has a reply. Not changed:

  • res.writeHead() with no end() is left open. AWS's finalizeResponse does the same, because headersSent is true.
  • A throw after the body started still ends the response. This is pre-existing v2-dev behaviour, pinned by a test. What AWS does in this case isn't verified.
  • No immediate release between serve's end() and 'close'. I found no deterministic reproducer.
  • "Request rejected before the function ran" log. A callback-less file send that fails still goes through Express's error path, which logs this line. That behaviour was already on v2-dev and is outside this gap.
  • Commit trailers. This public repo follows the ticket's no-footer rule.
  • Third-party stream policy. This covers an endless producer with a side reader, the function's own pause, and a request or file behind a transform. It's proposed as a follow-up ticket, because every serve-side rule tried so far has a counterexample.

QA: the Launch QA agent tests CL-8970 in the repos once it is in QA; GoCD sanity covers dev11.

Jira: https://contentstack.atlassian.net/browse/CL-8970

…unctions do

A handler that returned without ending its response hung under
launch:functions:serve (Azure and GCP answer 504 CF005 after the timeout).
Deployed AWS functions (lambda-node-bridge's finalizeResponse) end it as
soon as the handler returns or its promise settles, with the status and
headers it set, and leave a response whose headers were already sent for
the handler to end. Do the same.

Anything the handler writes after that (end, write, writeHead, setHeader,
and so send, json and redirect through them) is ignored with one warn:
line, so a late answer cannot crash serve with ERR_HTTP_HEADERS_SENT.
…AGENTS.md

Test code and prose; no credentials.
Review follow-ups for ending an open response like deployed functions:

- A late res.sendStatus(204), res.status(205).send() or a direct
  removeHeader/appendHeader/setHeaders call still reached Node's header
  methods after the forced end and threw ERR_HTTP_HEADERS_SENT. Ignore
  those too.
- res.sendFile and res.download finish asynchronously, so the forced end
  cut them to an empty 200 with no warning. A response they are sending is
  now left for them to end.
- The warning names the requested URL instead of the route pattern.
- Tests poll instead of sleeping and clean their globals in afterEach.
…AGENTS.md

Test code and prose; no credentials.
Second review follow-ups for ending an open response like deployed
functions:

- A file send is marked only once res.sendFile/download/sendfile returned
  without throwing, and a callback-style send clears its mark when it
  settles; if the response is still open then, it is ended as AWS would.
  Before, a send that threw, or whose callback only set a status, left
  the request hanging, and the lowercase res.sendfile was cut short.
- Once a response has ended for any reason (forced end, the 500 path, or
  the handler itself), later end/write/header/file calls are ignored with
  one warning instead of crashing serve. A callback passed to them gets
  ERR_STREAM_ALREADY_FINISHED on the next tick, and write returns false.
- The warning now says the response was changed, not answered, so it
  also fits header-only calls.
- AGENTS.md: the deployment agent's 2.x upgrade drops late answers on
  Azure and GCP; tests clean LAUNCH_TEST_PAGE in afterEach.
…AGENTS.md

Test code and prose; no credentials.
Final review follow-ups for ending an open response like deployed AWS
functions:

- Install the late-change guard when the response finishes, whatever
  ended it, so a late header change after a callback-less file send can
  no longer crash serve (and the guard's repeat branch is covered).
- Destroy a stream piped into a response that serve ends for the
  handler, so serve no longer keeps its file descriptor open.
- A late write's callback gets ERR_STREAM_WRITE_AFTER_END, as Node does;
  end keeps ERR_STREAM_ALREADY_FINISHED.
- The warning says deployed AWS functions, since Azure and GCP (V1)
  still deliver late answers.
…AGENTS.md

Test code and prose; no credentials.
@snyk-io

snyk-io Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 2 25 ✅ Passed
🟡 Medium Severity 0 1 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 2
  • Medium without fixes: 1
  • Low without fixes: 0

✅ BUILD PASSED - All security checks passed

@dhruv-parekh-cs dhruv-parekh-cs 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.

Reviewed the whole PR (launch-cli#314, CL-8970) at 5b11fbe.

Off-diff:

  • Low src/functions/cloud-functions.ts:290 (answerRequestError, pre-existing): a callback-less res.sendFile/res.download that fails (missing file) logs "Request rejected before the function ran: 404 Error" although the function ran. Fix: in the no-callback branch of trackAnswering, pass a callback that ends with err.status, or have answerRequestError tell route-raised errors apart.

Cross-repo (CL-8970, with contentstack/contentfly-e2e-tests#487): the contracts match (status kept on a never-ended response, a started stream left to finish, a late answer dropped). e2e#487's Azure/GCP gaps cover clouds still on 1.6.0, so it can merge before or after this PR. Note that serve's late-change guard swallows the late res.end('late') that e2e#487's send-after-return fixture makes, so serve can't show how the AWS bridge treats it (see the Medium there).

3 medium, 7 low: not approved.

— 🤖 launch-pr-review-agent (Claude)


Generated by Claude Code

Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Outdated
ignoreLateChanges(response, answering);
return;
}
if (response.headersSent) {

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.

Medium A handler that calls res.writeHead(...) (or flushHeaders()) and returns without end() still hangs forever.
headersSent is true as soon as writeHead stores the header, so this treats the response as a started stream and never ends it, though no body was written. A redirect written as res.writeHead(302, {Location}) that forgets .end() is finalized by AWS but hangs under serve (no timeout in 2.x).
Fix: decide "streaming" from an actual body write (count calls to write), not headersSent, and end responses that only have headers.


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Keeping this as is, because it matches AWS. The lambda bridge's finalizeResponse (cf-sv-with-helpers.ts) does:

if (res.writableEnded) { resolve(); return; }
if (res.headersSent) {            // writeHead / flushHeaders set this
  res.once("finish", onComplete);
  res.once("close", onComplete);
  return;                          // waits for the handler to end it
}
res.end();

So a deployed res.writeHead(302, {Location}); return; is not finalized by AWS either. It waits on finish/close until the Lambda timeout. If serve ended it, the function would work locally and hang when deployed, which is the kind of gap this ticket closes. Deciding from body writes would diverge from the bridge. AGENTS.md documents this: "a response whose headers were already sent … is left for the handler to end".


Generated by Claude Code

Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.test.ts Resolved
…lid status

Review follow-ups on #314:

- Wrap the late-change methods when the request starts, passing calls
  through until the response has ended, so a write or end between end()
  and 'finish' (for example res.end('a'); res.write('b')) is ignored with
  the warning instead of crashing serve.
- If ending the response for the handler throws (an invalid status or
  status message), log the error and answer 500 instead of an unhandled
  rejection that stopped serve.
- Serve's own 500 for a handler that throws is sent only if the response
  has not ended, so it no longer triggers a false late-change warning.
- A stream piped into a response that serve ended, or that had already
  ended, is unpiped, and only a file stream is destroyed; a stream the
  function owns, such as a shared PassThrough, is left open.
- Only methods that exist are wrapped (Express 5 has no res.sendfile).
- The late-change test after a file send waits for 'finish' instead of a
  fixed timer.
…AGENTS.md

Test code and prose; no credentials.
@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 2 25 ✅ Passed
🟡 Medium Severity 0 1 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 2
  • Medium without fixes: 1
  • Low without fixes: 0

✅ BUILD PASSED - All security checks passed

@dhruv-parekh-cs dhruv-parekh-cs 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.

Re-review since 5b11fbe (9b95f1f): 0 high, 0 medium, 7 low. Not approved: 7 lows are open, and the limit is 3.

My earlier mediums:

  • Invalid status crashing serve: fixed. The narrower case that is left is the low on line 294.
  • Late changes between end() and 'finish': fixed, because the guard is now installed before the handler runs.
  • writeHead-only responses hanging: settled. The cited finalizeResponse waits on 'finish' the same way when headersSent is set, so serve matches AWS.

Cross-repo (CL-8970, with contentstack/contentfly-e2e-tests#487): the contracts still match. The writableEnded guard that #487 now adds to send-after-return makes the late res.end a no-op under this serve as well, so either PR can merge first.

— 🤖 launch-pr-review-agent (Claude)


Generated by Claude Code

Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
…ing 500

Review follow-ups on #314:

- An end() with no body on an ended response passes through to Node's
  own no-op, so res.json(data).end() no longer logs a late-change warning.
- Streams piped into a response are released when it closes, whoever
  ended it, and a stream piped into an already-ended one is released at
  once. Each is unpiped and destroyed unless it still feeds another
  destination: an upstream response, web stream or child stdout no longer
  leaks, a file stream also piped to a cache file is not cut short, and a
  stream piped late is not left flowing with no reader.
- Serve's 500 (a handler that throws, or a failed auto-end) resets the
  status message and drops the connection if even that end throws, so an
  invalid status message or a content-length mismatch no longer crashes
  serve.
- .talismanrc: refreshed the checksum for cloud-functions.test.ts (inline
  test functions, no credentials).
@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 2 25 ✅ Passed
🟡 Medium Severity 0 1 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 2
  • Medium without fixes: 1
  • Low without fixes: 0

✅ BUILD PASSED - All security checks passed

@dhruv-parekh-cs dhruv-parekh-cs 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.

Re-review of #314 since 9b95f1f (d516665, 9d63bfa).

The new close-time release crashes serve for streams that aren't core Node Readables (the two Highs), and destroys streams the function owns or still pipes after a disconnect (the two Mediums).

Cross-repo (CL-8970, with contentstack/contentfly-e2e-tests#487): no new contract issue; #487's route helper still differs from serve's validator (the Medium I posted there). Either PR can merge first.

Not approved: 2 high and 2 medium open.

— 🤖 launch-pr-review-agent (Claude)


Generated by Claude Code

Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
} catch (error) {
console.error(error);
answerServerError(response);
}

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.

Low Moving the release from here to close can print a false late-change warning.

Between serve's end() and 'close' (delayed e.g. by a pipelined request on the same socket), a still-piped source's data goes through the guarded write, so serve warns that the function changed its response although it didn't.

Fix: keep the immediate release after serve ends the response, in addition to the close listener.


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed. I can't reproduce the window this needs deterministically. 'close' follows 'finish' within the same tick unless the socket carries a pipelined request, and serve's own end() happens after the handler has returned. A source that is still writing at that moment is the function's late write, and the warning names it accurately. Adding a second release path that no test can exercise would be untested code. If you have a reproducer, I'll add it with a test.


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correction to my reply above: the response emits 'close' on the next tick after 'finish' (resOnFinish → process.nextTick(emitCloseNT)), not in the same tick. The rest stands: I have no deterministic reproducer for a source still writing between serve's end() and that 'close'.


Generated by Claude Code

Comment thread src/functions/cloud-functions.ts Resolved
} catch (error) {
console.error(error);
response.status(500).send();
if (!response.writableEnded) {

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.

Low When a handler throws after the body started, the client gets a clean 200 with a cut-off body.

answerServerError sets statusCode = 500 after headers were sent (no effect) and ends normally, so res.write('partial'); throw looks like success, not the documented 500. Pre-existing.

Fix: when response.headersSent, response.destroy(error) as Express's finalhandler does.


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed in this PR. It is pre-existing v2-dev behaviour, and the test "ends a response the handler started writing and then threw on, logs the error, and keeps serving" pins it. What AWS does here isn't verified: the bridge rethrows non-ApiErrors out of the server's async request listener. I'd rather not switch serve to destroy() on a guess. AGENTS.md now limits the documented 500 to a handler that throws before its headers were sent.


Generated by Claude Code

Comment thread src/functions/cloud-functions.ts Resolved
…reign stream

Review follow-ups on #314 (Dhruv, 9d63bfa):

- A piped source is unpiped only if it has unpipe(), so a legacy
  Stream.pipe source (request, through, event-stream) no longer crashes
  serve when its response closes.
- Only a file stream (fs.ReadStream) is destroyed, and only on the next
  turn when nothing reads it any more (no 'data' or 'readable' listener,
  which every pipe() adds). This drops the internal _readableState read
  that crashed on readable-stream v2/v3 sources, keeps a function-owned
  stream (an SSE PassThrough, a child's stdout) alive across requests,
  and lets a late tee or async iterator keep reading the file.
- A stream piped after the client disconnected is released too.
- Serve's 500 drops the headers the failed handler had set (a stale
  content-length or set-cookie) when they were not sent yet.
- A late end() with a body gives its callback ERR_STREAM_WRITE_AFTER_END,
  as Node does.
- .talismanrc: refreshed the checksum for AGENTS.md (prose, no credentials).
@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 2 25 ✅ Passed
🟡 Medium Severity 0 1 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 2
  • Medium without fixes: 1
  • Low without fixes: 0

✅ BUILD PASSED - All security checks passed

@dhruv-parekh-cs dhruv-parekh-cs 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.

Re-review of #314 since 9d63bfa (27a2f35, 2c08689).

The 2 highs and 2 mediums from my review at 9d63bfa are fixed: no _readableState.pipes read, unpipe is guarded, only fs.ReadStreams are destroyed, and a pipe after a disconnect is released. This pass: 7 lows.

Cross-repo (CL-8970, with contentstack/contentfly-e2e-tests#487): no issues; either PR can merge first.

Not approved: 7 lows open (more than 3).

— 🤖 launch-pr-review-agent (Claude)


Generated by Claude Code

Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.test.ts Resolved
Comment thread .talismanrc Outdated
checksum: 038f5cd182e1fd0105e6e10dde7f5068a0c15883222450f72ea3904890a56c0c
- filename: src/functions/cloud-functions.test.ts
checksum: ca4e03b4ae6d4e39fe5ad654f781b002deb37f2f30ebf58c27feeb162696c562
checksum: 4ecfc8deb42597cda166c7156720901c12665c1439495b4f3b35b942db4fda49

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.

Low The commits in this range (27a2f35, 2c08689) are authored by Claude but end without the #claude_code# footer and the Co-Authored-By: Claude trailer.

The workspace CLAUDE.md (Git conventions) says these are never optional for internal repos; launch-cli's exception covers only its PR title format.

Fix: end future commits with the footer and trailer (the Conventional Commits subjects can stay).


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed, on purpose. The ticket owner set explicit rules for this public repo: semantic commit and PR titles, with no +Claude and no Claude Code footer in commits or PRs. That instruction takes precedence over the workspace's internal-repo template, so these commits follow it.


Generated by Claude Code

Review follow-ups on #314 (Dhruv, 2c08689):

- After unpiping a source, serve settles it on the next turn: a file
  stream nothing else reads is destroyed as before; any other stream not
  read through 'readable' is resumed, so it drains and finishes. A file
  stream with a side 'data' reader, a gzip transform feeding the
  response (and the file behind it), a child's stdout or an upstream
  body no longer stay paused holding a descriptor, socket or child, and
  the close path now leaves a stream in the same flowing state as the
  late-pipe path. Serve still never destroys a stream the function owns.
- Serve's 500 restores its cache-control: no-store default after
  dropping the failed handler's headers.
- The readable-stream v2/v3 test builds that shape inline instead of
  relying on a hoisted, undeclared package.
…AGENTS.md

Test code and prose; no credentials.
@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 2 25 ✅ Passed
🟡 Medium Severity 0 1 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 2
  • Medium without fixes: 1
  • Low without fixes: 0

✅ BUILD PASSED - All security checks passed

@dhruv-parekh-cs dhruv-parekh-cs 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.

Re-review of #314 since 2c08689 (f6f8ddd, ed948ba).

The fixes for my seven earlier lows hold. The resume() I suggested on line 233 goes too far, though: resuming a released stream that has no other consumer can spin serve on an endless stream and drops data from a stream the function keeps (inline). That's my suggestion being incomplete, not a misreading of it. This pass: 5 lows.

No high or medium findings from earlier reviews are still open.

Cross-repo (CL-8970, with contentstack/contentfly-e2e-tests#487): no contract issue; #487's guard is offline and doesn't depend on the stream handling here. Either PR can merge first.

Not approved: 5 lows open (more than 3).

— 🤖 launch-pr-review-agent (Claude)


Generated by Claude Code

Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
Comment thread AGENTS.md Resolved
Comment thread src/functions/cloud-functions.test.ts Resolved
Comment thread src/functions/cloud-functions.test.ts Resolved
Review follow-ups on #314 (Dhruv, ed948ba):

- A released stream is resumed only when it still has a 'data' reader,
  so that reader gets the rest; a stream nothing reads is left paused, as
  Node leaves it after an unpipe. Resuming every released stream could
  spin serve on an endless synchronous producer and drained a queue the
  function reuses across requests.
- A released source without listenerCount (a stream-like object) is
  left alone instead of throwing from setImmediate, and one without
  resume is never resumed.
- Tests: the released-PassThrough test now expects it paused and
  buffering; an endless producer no longer blocks the next request; a
  non-core stream with a reader is resumed through its own resume; and
  two stream-like objects without listenerCount or resume keep serve up.
  The gzip drain test is dropped with the behaviour it pinned.
- AGENTS.md states the rule and its limit: only a file stream nothing
  reads is closed for the function; anything else it leaves paused stays
  open until the function closes it.
…AGENTS.md

Test code and prose; no credentials.
@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 2 25 ✅ Passed
🟡 Medium Severity 0 1 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 2
  • Medium without fixes: 1
  • Low without fixes: 0

✅ BUILD PASSED - All security checks passed

@dhruv-parekh-cs dhruv-parekh-cs 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.

Re-review of #314 since ed948ba (4b128ee, c30e51b).

The fixes for my lows at ed948ba hold (the listenerCount guard, the AGENTS.md wording, no resume of a stream nothing reads). Leaving every unread stream paused trades the spin for two other problems, one of them new (inline):

  • Medium (inline, line 233): a request body piped into the response is now left paused, which stalls the upload and the keep-alive connection.
  • Low src/functions/cloud-functions.ts:233: a transform, child stdout or upstream body is left paused when the handler returns before its pipe sends headers or the client disconnects, so the file, child or socket behind it stays open for the life of functions:serve (e.g. createReadStream(f).pipe(createGzip()).pipe(res) holds one fd per request). The deleted test ('drains a transform it unpiped…') covered this. This is my earlier low at 233 (2c08689), back in another form; draining in bounded, setImmediate-yielding batches would cover it and the endless producer alike.
  • Low src/functions/cloud-functions.ts:341: the late-pipe path still drains. Serve's unpipe runs inside pipe(), and pipe() then calls src.resume() itself, so a stream piped into an already-ended response flows with no reader: an endless synchronous producer still blocks serve there, and a reused PassThrough loses its data. Deferring the late-path release with process.nextTick avoids it. (Same spot as my earlier low at 341.)
  • Low AGENTS.md:564: "Any other stream is left paused, as Node leaves it after an unpipe" is not true on the late-pipe path (above), and the request body, which serve owns, isn't mentioned.

No high or medium findings from earlier reviews are still open.

Cross-repo (CL-8970, with contentstack/contentfly-e2e-tests#487): no contract issue; #487 doesn't depend on this stream handling. Either PR can merge first.

Not approved: 1 medium open.

— 🤖 launch-pr-review-agent (Claude)


Generated by Claude Code

Comment thread src/functions/cloud-functions.ts Resolved
return;
}
if (read && typeof source.resume === 'function') {
source.resume();

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.

Low An endless synchronous producer that still has a side 'data' reader (a byte counter, a logging tap) still blocks serve.

s = new Readable({ read() { this.push(Buffer.alloc(1024)); } }); s.on('data', c => n += c.length); s.pipe(res); res.end('done'): after the response closes, settleReleased sees a 'data' listener and calls resume(); that listener applies no backpressure, so flow() never yields and the next request is never served. While piped, the response's backpressure held it back; serve's resume() is what starts the loop.

Fix: resume through a bounded drain that yields between batches (or pause again after a bounded number of chunks) instead of a bare resume().


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed in this PR. This is the same trade-off as your earlier finding on line 233, from the other side. Serve can't tell from a 'data' listener whether it is a byte counter on an endless producer, or a reader that needs the rest of a finite stream (the side-reader file case, which otherwise holds its descriptor).

A bounded, yielding drain would cover both, but it also drops data from a queue the function reuses. That was your other finding on the earlier resume-everything version. Choosing between those needs a design decision, not another tweak inside gap 4. I'm proposing to the ticket owner that the remaining third-party stream policy move to a follow-up ticket. Today's rule covers serve's own streams (the request, file descriptors) and is documented in AGENTS.md.


Generated by Claude Code

return;
}
if (read && typeof source.resume === 'function') {
source.resume();

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.

Low source.resume() overrides a pause the function's own 'data' reader is holding.

A reader that does src.pause(); await save(); src.resume() gets the next chunk while save() is still running if the response closes during that window, so saves overlap and can finish out of order.

Fix: record whether the stream was flowing (readableFlowing === true) before the unpipe, and resume only when serve's unpipe is what paused it.


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed in this PR, for the same reason as the endless-producer finding. Resuming only streams that were flowing before the unpipe would also skip a file stream that the response's backpressure had paused. That is exactly the side-reader case you asked to close in the round before. Serve can't tell a backpressure pause from the function's own pause. I'm proposing the third-party stream policy as a follow-up ticket rather than another rule swap inside gap 4.


Generated by Claude Code

Comment thread src/functions/cloud-functions.test.ts Resolved
…e after pipe() returns

Review follow-ups on #314 (Dhruv, c30e51b):

- A request or upstream body (http.IncomingMessage) that serve releases
  is drained. A handler that pipes its request into its response and
  returns before a large body arrives no longer stalls the upload and the
  keep-alive connection: Node does not dump a request pipe() already
  consumed, so leaving it paused hung the next request on that socket.
- A stream piped into an already-ended response is released on the next
  tick, after pipe() has called resume() itself, so it ends up paused
  like one released on close instead of flowing with no reader.
- The endless-producer test caps its producer and asserts it stayed
  paused, so a regression fails the test instead of hanging the run.
- AGENTS.md describes the drained bodies and that both paths leave any
  other stream paused.
- .talismanrc: refreshed the checksums for cloud-functions.test.ts and AGENTS.md (test code and prose, no credentials).

Copy link
Copy Markdown
Contributor Author

Re-review at c30e51b, with the off-diff lows addressed in c225c9d:

  • Late-pipe path still drains (cloud-functions.ts:341): fixed. A stream piped into an already-ended response is released on process.nextTick, after pipe() has called resume() itself, so it ends up paused like one released on close. Test: a late PassThrough stays paused and buffers a later write (readableLength 4). Releasing synchronously turns it red.
  • AGENTS.md:564: fixed. It now names the drained request and upstream bodies, and that both paths leave any other stream paused.
  • Transform, child stdout or upstream left paused (cloud-functions.ts:233): partly fixed. Upstream bodies (IncomingMessage) are now drained along with the request. A transform or a child's stdout stays paused, which AGENTS.md documents as the function's to close. A bounded drain for those is the design question I'm proposing as a follow-up ticket, since every rule so far has a counterexample: an endless producer, a reused queue, or the function's own pause.

Generated by Claude Code

@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 2 25 ✅ Passed
🟡 Medium Severity 0 1 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 2
  • Medium without fixes: 1
  • Low without fixes: 0

✅ BUILD PASSED - All security checks passed

@dhruv-parekh-cs dhruv-parekh-cs 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.

Re-review of #314 since c30e51b (c225c9d).

The medium from my review at c30e51b is fixed: a request body piped straight into the response is drained on release, and the late-pipe release now runs after pipe() returns, so the late path no longer drains (that low and the AGENTS.md low are fixed too). This pass: 4 lows (inline). The first is my own suggestion taken at its broader form: instanceof IncomingMessage also matches upstream bodies, where comparing against this exchange's request was the narrower option.

No high or medium findings from earlier reviews are still open.

Cross-repo (CL-8970, with contentstack/contentfly-e2e-tests#487): no contract issue; either PR can merge first.

Not approved: 4 lows open (more than 3).

— 🤖 launch-pr-review-agent (Claude)


Generated by Claude Code

Comment thread src/functions/cloud-functions.ts Resolved

function settleReleased(source: Readable): void {
if (source instanceof IncomingMessage) {
source.resume();

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.

Low (pre-existing) A request piped into the response through a transform still stalls the keep-alive connection.

request.pipe(new PassThrough()).pipe(response) (or a gzip), ended before a large body arrives: on close only the transform is released and it stays paused; once its buffer fills it backpressures the request, which Node won't dump because pipe() already consumed it, so the next request on that socket is never answered. The direct request.pipe(response) case is fixed by this commit; this one isn't.

Fix: on response close, if this exchange's request is still incomplete and nothing outside serve still reads it, unpipe and drain it; or at least name the case in AGENTS.md next to the gzip example.


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Documented in 294fd07, the second option you gave. AGENTS.md now names "a file stream or the request behind a transform (for example gzip)" among the streams left to the function, noting that this "stays open, or stalls that keep-alive connection, until the function closes it".

Unpiping the request from the function's own transform would cut into a pipeline the function built, and serve can't tell when that's safe. That belongs with the follow-up on third-party stream policy.


Generated by Claude Code

Comment thread src/functions/cloud-functions.ts Resolved
Comment thread src/functions/cloud-functions.ts Resolved
…pipe at once

Review follow-ups on #314 (Dhruv, c225c9d):

- Only this exchange's own request body is drained on release, as Node
  would dump it. An upstream body (a live feed, an SSE relay) piped into
  the response is left paused like any other stream instead of being read
  at full speed after the client has gone.
- A stream piped into an already-ended response is unpiped inside the
  'pipe' event again, so a shared hub's next write does not reach the
  ended response and log a false late-change warning, and a throwing
  unpipe surfaces in the caller's pipe() as on v2-dev. To undo pipe()'s
  own resume, the source is paused from a one-shot 'resume' listener
  (removed on the next turn); a reader it still has is resumed by the
  settle step, as on close. An endless producer piped late no longer
  spins.
- AGENTS.md names only the request as drained and lists a request piped
  through a transform among the streams left to the function.
- .talismanrc: refreshed the checksum for cloud-functions.test.ts (test code, no credentials).
@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 2 25 ✅ Passed
🟡 Medium Severity 0 1 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 2
  • Medium without fixes: 1
  • Low without fixes: 0

✅ BUILD PASSED - All security checks passed

@dhruv-parekh-cs dhruv-parekh-cs 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.

Re-review since c225c9d (294fd07, 738037a): 0 high, 0 medium, 5 low (inline). The two around line 226 are the third-party stream trade-offs AGENTS.md already documents; they fit the follow-up ticket you proposed.
No high or medium findings from earlier reviews are still open.
Cross-repo (CL-8970, with contentstack/contentfly-e2e-tests#487): no new contract issue; these commits only change serve's stream release, which #487 doesn't exercise.
Not approved: 5 lows open in this pass, and the limit is 3.

— 🤖 launch-pr-review-agent (Claude)


Generated by Claude Code

}

function settleReleased(source: Readable, request: Readable): void {
if (source === request) {

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.

Low Narrowing the drain to source === request leaves a released upstream IncomingMessage paused and never destroyed, so its socket stays held.

A proxy handler http.get(url, up => up.pipe(res)) whose client aborts (or which pipes after the handler returned) has up unpiped and left paused for good; each such request keeps one upstream connection, and with a bounded agent (new Agent({ keepAlive: true, maxSockets: 10 })) the 11th request queues forever. AGENTS.md documents this ("an upstream body then stays open"), and the default agent is unbounded, so it is low for local serve.

Fix: destroy a released IncomingMessage that isn't this exchange's request and has no 'data' reader, the same way fs.ReadStream is handled — or cover it in the proposed follow-up ticket on third-party stream policy.


Generated by Claude Code

}

function settleReleased(source: Readable, request: Readable): void {
if (source === request) {

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.

Low (pre-existing, documented in AGENTS.md) The request body behind a transform still stalls the keep-alive connection.

request.pipe(zlib.createGunzip()).pipe(response) with the handler returning before a large upload arrives: serve ends the response, the gunzip is unpiped and paused, the request stops being read, and the next request on that socket (agent with maxSockets: 1) never gets an answer.

Fix: on the response's 'close', if !request.complete, unpipe the request from everything and resume() it (AWS buffers the whole body anyway) — fine to leave to the follow-up ticket.


Generated by Claude Code

const pause = (): void => {
source.pause();
};
source.once('resume', pause);

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.

Low The one-shot 'resume' listener can't tell pipe()'s own resume from the function's.

If the source is already flowing into another destination, pipe() doesn't resume it, so the listener stays armed until the next turn and pauses the function's own resume() in that window: hub.pipe(other); hub.pipe(endedRes); Promise.resolve().then(() => { hub.unpipe(other); hub.resume(); }) leaves hub paused with data buffered, and settleReleased won't resume it (no 'data' reader).

Fix: arm the listener only when pipe() will resume the source, i.e. when source.readableFlowing !== true at that point.


Generated by Claude Code

source.pause();
};
source.once('resume', pause);
setImmediate(() => source.removeListener('resume', pause));

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.

Low pauseOnResume guards once and pause but calls source.removeListener unchecked inside setImmediate.

A stream-like source that has once/pause but no removeListener, piped into an ended response, throws TypeError: source.removeListener is not a function on the next turn, outside any try, and takes serve down. Unlikely with real Node streams, but it's the same duck-typed class of source the unpipe guard was added for.

Fix: add typeof source.removeListener === 'function' to the guard (or check it in the callback).


Generated by Claude Code

] as const;

interface Answering {
request: Readable;

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.

Low Answering.request is set in trackAnswering but never read; the release paths use the closure's request.

Dead state that a later change could read and drift from the closure value.

Fix: drop the field, or pass answering.request so there is one source of truth.


Generated by Claude Code

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.

3 participants