Skip to content

fix(desktop): bound gateway-launch.log reads and rotate it at shell start - #33652

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/32719-launchlog-bounded-tail-rotate
Nov 9, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/32719-launchlog-bounded-tail-rotate

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The gateway failure dialog opens without delay and shows the launch log's real last lines, however long the app has been installed.

The desktop shell's gateway-launch.log only ever appends and has no size cap or rotation. The two places that show it to the user read the whole file into one string to keep its last 60 lines: runtime/gateway/failure-dialog.js inside showUnrecoverableGatewayError, and gateway-supervisor.js on the launch-failure path. On a long-lived install the file grows to hundreds of MB. The read is synchronous and runs in the main process the moment the gateway has failed, so the shell stalls for seconds and its resident memory spikes while the user is waiting on the error dialog. Past V8's string limit the read throws, the surrounding catch swallows it, and the dialog shows an empty log pane.

Why it matters

This hits a real install (a 350 MB launch log was reported, growing about 1.66 MB/day). The failure dialog is exactly where a user needs the last log lines, and that is where the whole-file read makes the shell slowest and eventually shows nothing.

Not a goal

  • Changing the 60-line tail content for a small log.
  • The gateway child's stdio-error handling.
  • What the gateway child writes to the file.

What changed (motivation → approach → change)

Symptom: the failure dialog stalls the main process for seconds, spikes RSS, and eventually shows an empty log pane. Root cause: both dialog sites read the whole unbounded, ever-appending launch log to keep only its last 60 lines, and nothing caps the file.

Approach, reusing what the shell already has rather than adding a mechanism:

  • New readLogTail(filePath, { fs, lines, maxBytes }) in gateway-wait.js reads only the final 256 KiB of a log and returns its last 60 lines via the existing tailLines; a log under the cap is read whole as before, so a short log shows the same lines. Both reader sites now call it.
  • New rotateLaunchLog(logPath, { fs, capBytes }) in gateway-wait.js does a size-gated, one-generation rename to gateway-launch.previous.log when the log is over 10 MiB, matching the one-previous-generation shape native-logging.js already uses for chromium.log. It runs once in main.js, in the single-instance lock winner and before the gateway child is spawned in app.whenReady. Only the lock winner rotates: a rejected second instance renaming the log would pull it out from under the primary's live gateway child, and on Windows the child holds the path so the rename fails. A log under the cap is left untouched, and the previous generation is renamed rather than deleted, so content users attach to reports stays on disk (at most two generations).
  • docs/build/desktop-app.md states the cap and the bounded read.

Why this change

The reporter asked for the failure dialog to open without delay and show the log's real last lines however long the app has been installed. The two fixes together do that: the bounded read removes the stall, the memory spike and the empty-pane failure, and the start-of-shell rotation bounds the file on disk. The reader fix changes no visible behaviour for a normal small log. The rotation keeps one previous generation rather than deleting anything, so it does not lose logs a user is told to send. Both ends reuse the existing chromium.log rotation shape rather than adding a new mechanism.

Backwards compatibility

Compatible: nothing that works today stops working. tailLines stays exported and unchanged; the two readers switch to readLogTail, which returns the same 60-line tail for any log under 256 KiB.

Removes nothing: the diff adds two helpers and re-points two internal callers. No path is hidden, no records or rows are deleted, no validator is tightened, and no public key or function is removed or renamed. The one on-disk effect is that a launch log over 10 MiB is renamed to gateway-launch.previous.log instead of growing unbounded; the content is retained, not deleted.

Tests

  • website/electron/test/gateway-wait.test.js: readLogTail returns the same 60-line tail as a whole read for a small log; reads only the file's tail (not the head filler) for a log far over the cap; returns "" for a missing file. rotateLaunchLog renames over the cap, overwrites an existing previous generation, leaves an under-cap log untouched, and is a no-op on first launch.
  • website/electron/test/crash-arming-order.test.js: asserts rotateLaunchLog is called exactly once, after the single-instance lock, and before app.whenReady() — the ordering that keeps a rejected second instance from rotating the primary's log.
  • website/electron/test/gateway-supervisor.failure-dialog.test.js: the fake fs now models statSync/readSync so the launch-log reclassification path exercises readLogTail.

Proof: not provable -- frontend test (prove.py runs Python only). Verified manually: the new gateway-wait.js tests fail on origin/main (readLogTail/rotateLaunchLog are not functions) and pass on this branch; the ordering test fails when rotateLaunchLog is placed at module load before the lock and passes with it inside the lock winner.

Manual verification

On Linux, a node harness on a 300 MB log showed the old whole-file read at ~497 ms and +315 MB RSS versus the bounded read at ~1 ms and 0 MB, with an identical 60-line tail. We only have Linux; the Windows rename-under-open-handle concern is addressed by ordering (rotate before spawn), which crash-arming-order.test.js enforces at the call site.

Screenshots / video

N/A — this diff touches no user-visible frontend surface (Electron main-process log handling and docs only).

Related Issues

Closes #32719

Sibling sweep

Swept: git grep -nE "readFileSync\((gatewayLogPath|launchLogPath)" -- website/electron/
Sibling: website/electron/runtime/gateway/failure-dialog.js -- changed here
Sibling: website/electron/gateway-supervisor.js -- changed here
Siblings: none beyond these two -- the whole-file launch-log read existed only at these two dialog sites; the on-disk append has no second writer this fix needs to touch.

Pattern harvest

Not generalizable: the two whole-file reads of an unbounded append-only log are specific to the launch-log dialogs; chromium.log already has the bounded/rotated shape this change mirrors, so there is no new class to ratchet.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

CI notes

  • The 11 failures in website/electron/test/gateway-supervisor.runtime-owners.test.js are present identically on origin/main (platform-specific launchd assertions) and are unrelated to this change.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 143fc3885be8d59c16d9304ea74a1c0972312191 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check. The diff adds and changes no user-visible control, label or state. The failure dialog shows the same 60-line launch-log tail; only the read and the on-disk rotation behind it changed.

[UX-REVIEWED] 143fc38

Description read

[DESCRIPTION-READ] 1b78c3e292e2ab8cea2d5dbd26e5e0a34043ee9045ab2c5c8fd499f36706f505

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 143fc3885be8d59c16d9304ea74a1c0972312191 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

The bounded tail read on its own meets the Goal. The rotation that rides along has a nameable harm (the file grows on disk without limit), and nothing in it is a second copy of an existing mechanism.

Notes

  • Item 3 — undeclared: the description says the rotation "runs once in main.js, in the single-instance lock winner" and that crash-arming-order.test.js "asserts rotateLaunchLog is called exactly once". The diff does the reverse. It calls rotateLaunchLog(gatewayLogPath(), { fs, log: glog }) in the supervisor's fresh-spawn path, and the test asserts calls.length, 0 in main.js. A reviewer who checks the stated ordering is checking a design that did not ship.
  • Item 3 — oversized: the Goal covers only the dialog ("opens without delay and shows the launch log's real last lines"). Items 1–2 already deliver that whatever the file's size. The rotation adds a second rotation helper next to rotateNativeLog (website/electron/native-logging.js:718), and it adds rename-on-spawn timing on the gateway spawn path.
    Subtraction: defer rotateLaunchLog and its call in gateway-supervisor.js to a separate change scoped to the disk size.
    Clears when: the mechanism is removed, or a human amends the Goal.

What this change ships

Inventory (6 items) — 4 justified

Intent: when the gateway fails, the user sees the launch log's last lines straight away, however big the log has grown — a FIX.

  1. The gateway-failure dialog reads only the last 256 KiB of the launch log — justified
  2. The launch-failure reclassification dialog reads the same bounded tail — justified
  3. A launch log over 10 MiB is renamed to gateway-launch.previous.log when a fresh gateway spawns — rides along, undeclared (description names main.js), oversized
  4. A rotation failure now writes a line to the shell log — rides along
  5. The desktop-app doc states the size cap and the bounded read — justified
  6. A test pins that main.js never rotates the launch log — justified

[FIRST-PRINCIPLES-REVIEWED] 143fc38

Description read

[DESCRIPTION-READ] 67098aebc085682f3710f88d80629de3e65ccf0cb3fe67737856316af58753d2

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 143fc3885be8d59c16d9304ea74a1c0972312191 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. Rotating in the fresh-spawn path is sound, the bounded tail read fixes the stall at its cause, and both changes revert cleanly.

Notes

  • The description doesn't match the diff. It says rotation "runs once in main.js, in the single-instance lock winner", and that crash-arming-order.test.js "asserts rotateLaunchLog is called exactly once, after the single-instance lock". The diff does the opposite: it rotates in gateway-supervisor.js's fresh-spawn path, and the test asserts that main.js never calls rotateLaunchLog. The new gateway-supervisor.launchlog-rotate.test.js isn't listed under Tests either. The title and ## What changed describe a design this revision replaced, so a reader learns the wrong reason it is safe.

[DESIGN-REVIEWED] 143fc38

Description read

[DESCRIPTION-READ] 9288ac0acc8980eccfba5fabcb424786c43881ab12f6ab946b200328dac0cefb

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 143fc3885be8d59c16d9304ea74a1c0972312191 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 143fc38

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 143fc3885be8d59c16d9304ea74a1c0972312191 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 143fc3885be8d59c16d9304ea74a1c0972312191 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 143fc38

Verdict parsed from the review's SHA-scoped output markers for commit 143fc3885be8d59c16d9304ea74a1c0972312191.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 143fc3885be8d59c16d9304ea74a1c0972312191 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 9, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/32719-launchlog-bounded-tail-rotate branch from 251e310 to ad42b30 Compare November 9, 2026 10:14
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Fixed in ad42b30.

The finding was correct: rotating the launch log at shell boot, before startGateway() -> resolveGatewayConflict() decides, would rename the file out from under a surviving gateway that the shell then reuses, so that gateway kept writing to gateway-launch.previous.log while the dialogs read the new file.

The rotation now lives in the supervisor's fresh-spawn path (spawnGateway in website/electron/gateway-supervisor.js), run just before the new gateway opens its descriptor on the log. The reuse path returns at resolveGatewayConflict() === "reuse" before that point, so a reused gateway is never rotated out from under. website/electron/main.js no longer rotates at boot.

Added website/electron/test/gateway-supervisor.launchlog-rotate.test.js: a fresh spawn rotates the log once (before the fd opens), and a reused healthy gateway does not rotate. The docstring on rotateLaunchLog and docs/build/desktop-app.md now state the fresh-spawn-only placement.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 9, 2026
…pawn

The two gateway failure dialogs read the whole gateway-launch.log into one
string to show its last 60 lines, and the log only ever appends with no cap.
On a long-lived install the file reaches hundreds of MB, so the synchronous
read in the main process stalls for seconds and spikes RSS the moment the
gateway fails, and past V8's string limit the read throws and the dialog shows
an empty log pane.

Add readLogTail, which reads only the file's last 256 KiB, and route both
reader sites through it. Add rotateLaunchLog, a size-gated one-generation
rename in the shape native-logging.js already uses for chromium.log. Rotate in
the supervisor's fresh-spawn path, just before the new gateway opens its log
fd, so a shell that reuses a surviving gateway never rotates the log that
gateway is still writing to (off Windows through an inherited descriptor, on
Windows through the path).

Closes #32719
@chenmingwei23
chenmingwei23 force-pushed the fix/32719-launchlog-bounded-tail-rotate branch from ad42b30 to 143fc38 Compare November 9, 2026 12:57
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 9, 2026
@chenmingwei23
chenmingwei23 marked this pull request as ready for review November 9, 2026 16:17
@chenmingwei23
chenmingwei23 requested review from a team and KiroCrewCaptain as code owners November 9, 2026 16:17
@chenmingwei23
chenmingwei23 requested a review from Zedmor November 9, 2026 16:17
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 9, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 9, 2026 17:05

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tier 1 auto-approve: fix (8 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: the desktop shell reads only the last 256 KiB of gateway-launch.log for failure dialogs and rotates the log at a fresh gateway spawn; bounded change with tests.

@KiroCrewCaptain
KiroCrewCaptain merged commit 5a22d7e into main Nov 9, 2026
102 of 103 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/32719-launchlog-bounded-tail-rotate branch November 9, 2026 17:08
bolichen97 pushed a commit that referenced this pull request Nov 10, 2026
…pawn (#33652)

The two gateway failure dialogs read the whole gateway-launch.log into one
string to show its last 60 lines, and the log only ever appends with no cap.
On a long-lived install the file reaches hundreds of MB, so the synchronous
read in the main process stalls for seconds and spikes RSS the moment the
gateway fails, and past V8's string limit the read throws and the dialog shows
an empty log pane.

Add readLogTail, which reads only the file's last 256 KiB, and route both
reader sites through it. Add rotateLaunchLog, a size-gated one-generation
rename in the shape native-logging.js already uses for chromium.log. Rotate in
the supervisor's fresh-spawn path, just before the new gateway opens its log
fd, so a shell that reuses a surviving gateway never rotates the log that
gateway is still writing to (off Windows through an inherited descriptor, on
Windows through the path).

Closes #32719

Co-authored-by: kirocrew-agent <agent@kirocrew.local>
(cherry picked from commit 5a22d7e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop shell: gateway-launch.log has no size cap, and the gateway failure dialogs read the whole file to show its last 60 lines

2 participants