[PR #6560] [MERGED] fix: let processes exit when they log while the log worker starts #7227

Closed
opened 2026-10-23 04:17:43 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6560
Author: @kolacheee
Created: 9/23/2026
Status: ✅ Merged
Merged: 9/23/2026
Merged by: @kolacheee

Base: staging ← Head: fix/image-dimension-regression-hang


📝 Commits (2)

  • 3c6aead fix: let processes exit when they log while the log worker starts
  • c3f8ef8 test: drive the log-worker handshake through a real thread-stream

📊 Changes

7 files changed (+163 additions, -5 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
➕ patches/thread-stream@4.2.0.patch (+64 -0)
📝 pnpm-lock.yaml (+5 -2)
📝 pnpm-workspace.yaml (+2 -0)
➕ scripts/regressions/fixtures/thread-stream-ready-worker.cjs (+27 -0)
➕ scripts/regressions/log-worker-ready.regression.ts (+59 -0)
📝 scripts/run-regressions.mjs (+4 -3)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #6529

Why this change

image-dimension-limit.regression.ts passes every assertion, prints its success line, and then never exits, so the runner kills it at 30 seconds and the lane fails. It hit roughly one full lane in three.

The issue guessed at a keep-alive socket. It is not one. With a diagnostic dump at hang time, the only live handle is a MessagePort: the worker thread that pino-pretty runs in outside production. The worker stays referenced until a READY handshake sees its read index reach a write index it recorded earlier. thread-stream 4.2.0 checks that with ===. This spec logs retry warnings while the worker is still starting, so the read index can jump past the recorded value, or be reset under it, and the handshake never finishes. Every hung run showed the same state: ready: false, read index equal to write index.

Upstream fixed exactly this in pinojs/thread-stream#246 and #251 (issues #245 and #250), but no release carries it yet: npm's latest is still 4.2.0.

The spec is not the root cause, so the spec is unchanged. The same race can keep any non-production process open: pnpm dev, scripts, other regressions. User installs are not affected, because start.sh and start.bat set NODE_ENV=production, which skips the pretty worker.

What changed

  • patches/thread-stream@4.2.0.patch applies upstream's two commits (index.js +1 line, lib/wait.js), registered in pnpm-workspace.yaml next to the existing onnxruntime patch, with a note to drop it once a release after 4.2.0 ships the fix. The Dockerfiles already copy patches/.
  • log-worker-ready.regression.ts drives a real ThreadStream, the copy pino loads, through a scripted worker swapped in with thread-stream's own worker-path hook, as upstream's tests do. One scenario reads past the handshake's recorded value; the other overfills a 4-byte buffer so thread-stream's own flushSync and resetIndexes run twice while the handshake is pending. Both fail on unpatched 4.2.0 (no ready within 5 s) and pass with the patch.
  • The regression runner prints each file that did not pass, with its status, before the summary. Before this, a timeout showed up only as 1 failed with no failing file named in the summary.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

What the agent ran:

  • image-dimension-limit.regression.ts alone, same machine, same loop: 11 of 30 runs hung after printing success on unpatched staging, 0 of 40 with the patch.
  • log-worker-ready.regression.ts against the unpatched and patched copies of thread-stream: both scenarios fail on the first and pass on the second, 25 of 25 runs.
  • pnpm install --frozen-lockfile with the patch; pnpm check; the full pnpm regression:node lane (358/358, after rebasing onto staging with #6556). A local CodeRabbit review reported 0 findings.
  • podman build -f Dockerfile: both installs (full and --prod) applied the patch, the image contains only the patched thread-stream, and the container answered /api/health with 200.

Still to verify by hand:

  • Run pnpm regression a few times and confirm image-dimension-limit.regression.ts no longer times out.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

CHANGELOG entry added under [Unreleased]. No docs under docs/ change.

UI evidence (if applicable)

Not applicable, no UI change.

Summary by CodeRabbit

  • Bug Fixes
    • Development servers, scripts, and regression checks now exit reliably when logging occurs while the logging worker is starting.
    • Worker readiness is handled more reliably, preventing intermittent startup hangs.
  • Tests
    • Regression summaries now identify each check that did not pass and show its status.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/6560 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/23/2026 **Status:** ✅ Merged **Merged:** 9/23/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/image-dimension-regression-hang` --- ### 📝 Commits (2) - [`3c6aead`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3c6aeadcd8252287910b925dc592a73f35b1dca8) fix: let processes exit when they log while the log worker starts - [`c3f8ef8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c3f8ef8910ec8403d913a20e420920d48ee71f68) test: drive the log-worker handshake through a real thread-stream ### 📊 Changes **7 files changed** (+163 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) ➕ `patches/thread-stream@4.2.0.patch` (+64 -0) 📝 `pnpm-lock.yaml` (+5 -2) 📝 `pnpm-workspace.yaml` (+2 -0) ➕ `scripts/regressions/fixtures/thread-stream-ready-worker.cjs` (+27 -0) ➕ `scripts/regressions/log-worker-ready.regression.ts` (+59 -0) 📝 `scripts/run-regressions.mjs` (+4 -3) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #6529 ## Why this change `image-dimension-limit.regression.ts` passes every assertion, prints its success line, and then never exits, so the runner kills it at 30 seconds and the lane fails. It hit roughly one full lane in three. The issue guessed at a keep-alive socket. It is not one. With a diagnostic dump at hang time, the only live handle is a `MessagePort`: the worker thread that pino-pretty runs in outside production. The worker stays referenced until a READY handshake sees its read index reach a write index it recorded earlier. `thread-stream` 4.2.0 checks that with `===`. This spec logs retry warnings while the worker is still starting, so the read index can jump past the recorded value, or be reset under it, and the handshake never finishes. Every hung run showed the same state: `ready: false`, read index equal to write index. Upstream fixed exactly this in [pinojs/thread-stream#246](https://github.com/pinojs/thread-stream/pull/246) and [#251](https://github.com/pinojs/thread-stream/pull/251) (issues [#245](https://github.com/pinojs/thread-stream/issues/245) and [#250](https://github.com/pinojs/thread-stream/issues/250)), but no release carries it yet: npm's latest is still 4.2.0. The spec is not the root cause, so the spec is unchanged. The same race can keep any non-production process open: `pnpm dev`, scripts, other regressions. User installs are not affected, because `start.sh` and `start.bat` set `NODE_ENV=production`, which skips the pretty worker. ## What changed - `patches/thread-stream@4.2.0.patch` applies upstream's two commits (`index.js` +1 line, `lib/wait.js`), registered in `pnpm-workspace.yaml` next to the existing onnxruntime patch, with a note to drop it once a release after 4.2.0 ships the fix. The Dockerfiles already copy `patches/`. - `log-worker-ready.regression.ts` drives a real `ThreadStream`, the copy pino loads, through a scripted worker swapped in with thread-stream's own worker-path hook, as upstream's tests do. One scenario reads past the handshake's recorded value; the other overfills a 4-byte buffer so thread-stream's own `flushSync` and `resetIndexes` run twice while the handshake is pending. Both fail on unpatched 4.2.0 (no `ready` within 5 s) and pass with the patch. - The regression runner prints each file that did not pass, with its status, before the summary. Before this, a timeout showed up only as `1 failed` with no failing file named in the summary. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes What the agent ran: - `image-dimension-limit.regression.ts` alone, same machine, same loop: **11 of 30 runs hung** after printing success on unpatched staging, **0 of 40** with the patch. - `log-worker-ready.regression.ts` against the unpatched and patched copies of `thread-stream`: both scenarios fail on the first and pass on the second, 25 of 25 runs. - `pnpm install --frozen-lockfile` with the patch; `pnpm check`; the full `pnpm regression:node` lane (358/358, after rebasing onto staging with #6556). A local CodeRabbit review reported 0 findings. - `podman build -f Dockerfile`: both installs (full and `--prod`) applied the patch, the image contains only the patched `thread-stream`, and the container answered `/api/health` with 200. Still to verify by hand: - Run `pnpm regression` a few times and confirm `image-dimension-limit.regression.ts` no longer times out. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) CHANGELOG entry added under `[Unreleased]`. No docs under `docs/` change. ## UI evidence (if applicable) Not applicable, no UI change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Development servers, scripts, and regression checks now exit reliably when logging occurs while the logging worker is starting. * Worker readiness is handled more reliably, preventing intermittent startup hangs. * **Tests** * Regression summaries now identify each check that did not pass and show its status. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:17:43 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7227
No description provided.