Skip to content

fix: close abandoned static web asset readers - #23062

Merged
nwparker merged 3 commits into
mainfrom
nwparker/perf-09-25-static-web-stream-lifetime
Sep 26, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/perf-09-25-static-web-stream-lifetime

Conversation

@nwparker

@nwparker nwparker commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​256 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​256
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​34 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​27

Historical release-test CI prerequisite

The CI merge base advanced the package version beyond a historical release fixture: the test expected 1.4.203 but read today’s 1.4.214 package. The build-identity helper now accepts an optional package version alongside its existing release inputs, and that test supplies its historical 1.4.201 version. Normal callers still read package.json. Both original version/build-number assertions remain; all 16 tests pass, and two exact before/after comparisons confirm unchanged default output. Targeted lint, including the no-module-mocking rule, passes. Application and native terminal code are unchanged; fresh CI remains required.

ELI5

When a browser stops downloading an Orca web-client file, the host now closes its file reader too. It also avoids opening a reader after the browser has already left.

What Changed

Canceled bundled web-client downloads no longer accumulate file descriptors. The handler checks response ownership before and after asynchronous file inspection, stops reading when the response closes or fails, and removes its response listeners when the source closes.

Successful GET/HEAD bytes, MIME types, cache headers, allowed paths and proxy-prefixed routing remain unchanged. Read errors still produce500 before headers or disconnect afterward; the empty500 now advertises zero bytes and disables caching so clients can finish the error response and retry.

Why

Piping a stream into a response does not close the source when the client disappears under backpressure. This reuses the existing local-build feed's ownership pattern. A blanket pipeline replacement would destroy the response on a source error and lose the intended pre-header500 policy.

Linked Issue

Fixes #23060

Visual Proof

N/A — HTTP/file resource cleanup and complete error framing, with no intentional rendered change. No app was launched.

Performance proof

Actual handler, native HTTP and real synthetic files:

Resource/scenario Baseline Candidate
Open streams after25 canceled downloads 25 0
Open streams after HTTP server closes 25 0
Readable bytes in those unclosed streams 1,638,400 0
Readers created after disconnect during stat 1 0
Bytes in a completed GET 8,388,608 8,388,608

The unchanged permanent count test fails against exact baseline source with25 open readers. Resource counts are deterministic; read volume during disconnect is scheduling-sensitive. Buffered bytes are not a total heap measurement. No UI latency, throughput or typical cancellation-frequency claim is made.

Testing

  • Final 13 tests/two suites pass after the cache-header correction: nine new real-stream ownership/error tests and four existing transport/routing tests.
  • Four selected permanent regressions fail against baseline: retained readers, stale post-stat creation, ending a closed response, and stale500 Content-Length.
  • Native HTTP covers GET/HEAD and a file-open failure. Other cases cover abort before open, response/source errors, foreign listener preservation and closure during successful/failed stat.
  • Node typecheck, focused lint/format and whitespace checks pass. Native macOS HTTP/files exercised; HTTPS, live SSH, native Linux/Windows and rendered browser journeys were not run.
  • Reproduce: ORCA_BACKGROUND_LAUNCH=1 pnpm test src/main/runtime/rpc/static-web-client-handler-stream.test.ts src/main/runtime/rpc/ws-transport-static-web.test.ts.

Review

Merge risk: low to moderate. The change crosses stat/open/error/close boundaries in production asset serving. Exact output/header and ownership oracles cover those transitions. Independent review exercised eight additional real HTTP lifecycle cases and caught a transient-error cache-header issue before publication; the final empty500 uses no-store.

Negative user-facing trade-offs: none identified. Two one-shot response listeners and one source-close listener are limited to each GET's lifetime. No new polling, timer, queue, subprocess or retained registry. The500 framing/cache correction is an intentional improvement to error delivery; successful response lengths and cache headers are unchanged.

Invariant: each static reader belongs to its live response and cannot restart after abandonment. Failure source: repeated canceled requests and delayed stat completion. Oracle: closed descriptors/listener cleanup, no stale source and exact HTTP results. Diagnostics are test counts using synthetic files. This asset-only change does not alter a terminal/session reliability invariant or claim broader transport coverage.

Agent skill upstream boundary

  • Not applicable; no skill source changed.

Notes

The shared diff-note catalog entries are now in main and have dropped out of this diff. The remaining Japanese/Korean values make the AI the note’s recipient. The identical English placeholders in MarkdownPreview and DiffCommentPopover have matching translated values.

The serving host still owns its package files. HTTP response loss says nothing about PTY/process liveness. No RPC opcode/schema/capability, published terminal data, Git/folder-workspace handling, WSL launch or mobile terminal stream changes. HTTP and HTTPS share the handler; only HTTP was exercised.

Checklist

  • Focused fix with ELI5, mechanism, reuse rationale, proof and risk.
  • Independent review completed; baseline failures retained and no trade-off fix bundled.
  • Visual proof N/A and platform/runtime gaps recorded.
  • Full application/platform matrix; focused checks above pass and CI covers the branch.

The Japanese/Korean recipient wording is now consistent across both the diff-note and Markdown-note placeholders. Both English keys contain “Add note for the AI”; both translated values match. This addresses the review consistency finding. All four localization gates and the nine stream tests pass after the fresh-main rebase.

@pullfrog

pullfrog Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: efd5b6d0-da86-4796-ad76-e02da65b0f92

📥 Commits

Reviewing files that changed from the base of the PR and between 9e99e4b and 30975d0.

📒 Files selected for processing (2)
  • config/scripts/hourly-build-version.mjs
  • config/scripts/hourly-build-version.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The static web handler exits when a response is destroyed, ties file-stream cleanup to response events, and avoids writing status to destroyed responses. Tests cover stream lifecycle cases and real HTTP GET and HEAD behavior. Japanese and Korean AI note labels have updated wording. The hourly-build identity function accepts an optional package version, and its test supplies that value directly.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 30975

Abandoned static responses are fenced and their file streams cleaned up, while hourly-build callers retain the package.json fallback. No material merge risk is evidenced; normal CI validation remains appropriate.

Architecture Summary

Architecture risk: 🔵 Low · up to 30975

The change affects 2 systems.

Changed systems: config, src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — config (service) was modified; 2 changed files map to changed impact.
  • observed — src (service) was modified; 4 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in src/main/runtime/rpc/static-web-client-handler-stream.test.ts: Added mocked filesystem instrumentation, temporary fixtures, HTTP and fake-response helpers, and cleanup for servers, streams, and temporary files.
  • observed — Modified behavior in src/main/runtime/rpc/static-web-client-handler-stream.test.ts: Added tests asserting that destroying responses closes paused file streams and removes only handler-owned listeners; an already-closed response should trigger no stat, stream creation, or header setting.
  • observed — Modified behavior in src/main/runtime/rpc/static-web-client-handler-stream.test.ts: Added success and failure cases for stat completing after response destruction, asserting no stream, headers, or end call. Also tests destruction while a file is still opening and checks stream closure and listener cleanup.
  • observed — Modified behavior in src/main/runtime/rpc/static-web-client-handler-stream.test.ts: Added tests asserting that a response error closes its file reader, and that a source error after headers causes response disconnection while retaining status 200.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The static handler changes and stream lifecycle tests match the stated reader-cleanup scope. The changes to config/scripts/hourly-build-version.mjs and its test are unrelated to static web-client re… Remove the hourly build changes and the Japanese and Korean locale changes, or provide a directly linked coding requirement that requires them.
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #23060 is closed and provides historical context only. No active directly linked issue supplies coding requirements for this pull request.
Title check ✅ Passed The title clearly identifies the main change: closing abandoned static web asset readers. It is concise and directly related to the production fix.
Description check ✅ Passed The description is detailed and covers the required sections, including the user impact, implementation, rationale, linked issue, visual proof, testing, risks, platform gaps, and checklist status. It …
Full details: Out of Scope Changes check

Explanation

The static handler changes and stream lifecycle tests match the stated reader-cleanup scope. The changes to config/scripts/hourly-build-version.mjs and its test are unrelated to static web-client response handling. The Japanese and Korean locale changes are also unrelated. A prerequisite reference does not establish that these changes belong in this pull request.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Close abandoned readers — static-web-client-handler.ts now registers close/error listeners on the response that destroy() the file ReadStream, and removes those listeners when the stream closes. A client that disconnects under backpressure no longer leaves a descriptor open, since stream.pipe(response) alone only unpipes.
  • Ownership re-checks — early returns when response.destroyed at entry, after await stat, and inside writeHttpStatus, so no headers or readers are produced for a response that is already gone (covers the delayed-stat window).
  • Correct 500 framing — a pre-headers read error now rewrites Content-Length: 0 + Cache-Control: no-store before the 500 instead of advertising the asset length with an empty body; after headers it disconnects the response.
  • Tests — nine new tests cover 25 abandoned readers, close-before/during-stat, response/source errors, real HTTP GET/HEAD, and an empty 500; both suites pass locally (13 tests).

@nwparker
nwparker force-pushed the nwparker/perf-09-25-static-web-stream-lifetime branch from 4d7a719 to 2b4a995 Compare September 26, 2026 19:50

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

This run covered the delta since the prior pullfrog approval at 2b4a9952: commit 21741ca353, merged as 373e85aacc, which restores three missing diff-note translation keys across all six locale catalogs. The static-web handler and its tests are unchanged from the approved revision.

  • Restore diff-note catalog entries — DiffCommentDraftCard references DiffCommentPopover.f6c449191e ("Add note for the AI"), 5fa4bfebaa ("Add note"), and 5e9b3d0c2e ("Adding..."), which were absent from every locale's catalog; all three are now present in en, es, fr, ja, ko, and zh, each translated from an existing entry for the same English string.

ℹ️ Unrelated i18n change merged from another open PR

The delta is the head of ci/fix-note-catalog, which is also PR #23256 ("fix(i18n): restore missing diff note draft text"). The merge commit 373e85aacc pulls that PR's content into this one, so the same six-file change would land twice. The content is byte-identical and correct, and it will not conflict, but it makes this fix's diff include an unrelated i18n change and can leave #23256 a no-op. Worth confirming which PR should own the catalog restoration.

Technical details
# Duplicate i18n change across PR #23062 and PR #23256

## Affected sites
- `src/renderer/src/i18n/locales/{en,es,fr,ja,ko,zh}.json` — the added `f6c449191e` / `5fa4bfebaa` / `5e9b3d0c2e` entries under `...diff.comments.DiffCommentPopover` are identical to the diff of open PR #23256.

## Required outcome
- Decide which PR owns the catalog restoration. If #23256 is the intended vehicle, drop `373e85aacc` from this branch; otherwise close #23256 once this merges.

## Open questions for the human
- Was `ci/fix-note-catalog` merged here only to make this PR's missing-key CI check pass? If so, landing #23256 unblocks both.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor Author

The catalog entries are an identical prerequisite from #23256, included to restore strict CI after updating from main. Git applies this content once; landing either branch does not duplicate catalog entries. #23256 is the standalone catalog review. This PR’s runtime-file change and its tests remain unchanged, and all nine focused stream tests pass at 373e85a. I am retaining the prerequisite while CI runs and will let the base comparison drop it once the catalog correction lands.

@pullfrog pullfrog 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.

ℹ️ No critical issues — one minor consistency suggestion inline.

Reviewed changes

This run covered the delta since the prior pullfrog review at 373e85aacc: commit f2865ad15d, which retranslates the Japanese and Korean DiffCommentPopover.f6c449191e ("Add note for the AI") hint so the note is addressed to the AI rather than about it. The static-web handler and its tests are unchanged from the approved revision.

  • Correct the ja/ko recipient wording — ja AI に関するメモを追加 → AI 向けのメモを追加, ko AI에 대한 메모 추가 → AI에게 전달할 메모 추가, matching the actual action (a note sent to the AI).

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread src/renderer/src/i18n/locales/ja.json Resolved
@nwparker
nwparker force-pushed the nwparker/perf-09-25-static-web-stream-lifetime branch from f2865ad to b608869 Compare September 26, 2026 20:55
@nwparker

Copy link
Copy Markdown
Contributor Author

Reviewed the latest scope and docstring warnings. The four locale values reconcile shared main-branch catalog maintenance and address the reviewer’s consistency request for the identical English note placeholders. This prerequisite and its localization checks are disclosed in the description; the static handler and its tests are unchanged by the rebase. No issue will be created: the user explicitly requested PR-only work. Generic 80% docstring coverage is declined under AGENTS.md’s concise, non-obvious-comments-only policy. No new actionable code finding remains; successful current-head CI is still required.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

This run covered the delta since the prior pullfrog review at f2865ad15d: commit b608869dcb, a fresh-main rebase plus the Japanese/Korean wording alignment. The static-web handler and its tests are unchanged from the approved revision.

  • Rebased onto fresh main — the three diff-note catalog entries added by earlier commits now exist on the base, so en/es/fr/zh drop out of the diff and the duplicate-with-#23256 concern is moot.
  • Aligned ja/ko recipient wording — MarkdownPreview.d737791433 and DiffCommentPopover.f6c449191e now share the same ja (AI 向けのメモを追加) and ko (AI에게 전달할 메모 추가) rendering for the one English source "Add note for the AI", resolving the prior inline consistency note.

Minor: the PR body's "Notes" section still describes this branch as restoring the three diff-note catalog entries, which is now stale after the rebase — cosmetic only, no code impact.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

This run covered the delta since the prior pullfrog review at b608869: commits 9e99e4b265 and 30975d0e22, which make the pre-existing hourly-version identity test hermetic. The static-web handler, its tests, and the ja/ko locale values are unchanged from the approved revision.

  • Injectable package version — getHourlyBuildIdentity now accepts an optional packageVersion and uses it in place of reading package.json (packageVersion ?? JSON.parse(readFileSync(...)).version), so the release script's runtime behavior is unchanged.
  • Hermetic fixture for the regression test — the "unpublished buggy main release" test passes packageVersion: '1.4.201' directly instead of mocking node:fs, so it no longer depends on the repository's current package version. All 16 tests in the file pass locally.

ℹ️ PR description's historical-fix paragraph is now slightly stale

The "Historical release-test CI prerequisite" paragraph says "Only the test input changes—release generation and application code are unchanged," but 30975d0e22 also edits the exported getHourlyBuildIdentity in config/scripts/hourly-build-version.mjs. Runtime behavior is unchanged because the new option defaults to reading package.json, so this is documentation accuracy only.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 1554f15 into main Sep 26, 2026
41 checks passed
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.

Aborted static web downloads retain file readers after server shutdown

1 participant