Skip to content

Engine client and runtime download: a stalled loop no longer launches over a running engine, and a failed download keeps its typed error (#441) - #450

Merged
SSFSKIM merged 8 commits into
mainfrom
fix/441-engine-client-flakes
Nov 20, 2026

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Closes #441. Refs #444. Version 0.28.22: two of the races were in shipped code.

Product fixes

A running engine judged absent and launched over (src/services/engine/client.mjs, #441's services-engine-service.test.mjs:454, and :828 once)

  • When Node's event loop stalls, it runs the timers that came due before the I/O that completed during the stall. A stall longer than the connect's first window (250 ms, on a loaded machine) let the window's timer reject before the socket connect, which the running engine had already accepted. The client then called openApplication over a running engine. The engine that open started lost the lock and exited, and the connect still succeeded.
  • Fix: within()'s timeout waits one more turn (setImmediate) before rejecting, so I/O that has already finished wins.
  • Repro: the new test in services-engine-client.test.mjs blocks the thread for 300 ms just after the window is armed. Without the fix it fails 1 !== 0 launches.
  • Left alone: Connection.call's per-request timer has the same ordering for stalls over 1 s. It wasn't seen in any log.

Download reported ENOTEMPTY in place of its typed error (src/runtime/install.mjs, #441's runtime-install.test.mjs:263, 3 sightings)

  • When a body overran its pinned length, the pipeline rejected before the file's write stream had finished opening. The file then appeared inside the staging directory the caller was already removing. This affects every caller of download(): the runtime install, the sandbox helper and the Linux engine.
  • Fix: on failure, download() destroys the file stream and returns once it has closed. The body is wrapped before the file opens, and both steps sit inside the typed error boundary. That way, a body that can't be read, written to a destination that can't be opened, still answers download_failed (review finding).
  • Tests:
    • A test holds the file's open for 50 ms through an fs override and asserts the file was opened and closed before the rejection. It fails if the close wait is removed.
    • A second test covers a locked body written to a missing directory. Without the fix it fails with an uncaught ENOENT.

Test and spike fixes

  • spike-engine-client.test.mjs:68 and :80 (an extra ping, 5 sightings): the spike client capped the ping's wait at what was left of the test's 150 ms window. The product client had already fixed this by giving the ping its full second. The spike client (scripts/spike, not shipped) now matches it, and also takes the within() change. Two new tests (an open that lands late, and a 300 ms stall) fail on the old spike client.
  • native-engine.test.mjs:321 (the losing engine's stderr came back empty, 2 sightings): the test now waits for close, which follows the end of stdio, instead of exit. There's no deterministic repro: it needs the real engine, so it runs only on hosted.

Checks

  • An independent medium-level review found two P2s in the download change, both fixed above. It found nothing on re-review. The reviewer confirmed that each new regression test fails with its fix reverted.
  • Local loops passed every run, six in parallel: spike-engine-client, services-engine-client, services-engine-service and runtime-install, 48/48 each; runtime-install 30/30 after the fix wave.
  • Not run locally: native-engine.test.mjs and the cases that start the real engine. This PR's test gate covers them.

Sminos-Session: cursor235#b93055dd (cua on macbook)

…look absent and launched over (refs #441)

After a stall the loop runs its due timers before the I/O that completed
meanwhile, so the first window's timer beat a connect the engine had already
accepted, and the client launched a running engine (services-engine-service's
afterActionRepairs and no-launch cases on a loaded hosted runner). The window's
rejection now waits one turn, after that I/O. A test forces the stall.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…lds to done I/O, as the service's client (refs #444)

The spike's ping was bounded by what was left of its 150 ms test window, so a
slow round trip on a loaded runner launched over the running fake and pinged it
again (spike-engine-client :68 and :80). Ports src/services/engine/client.mjs's
full ping wait and the stall fix, with both forced in tests.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…exit (refs #444)

'exit' may come before the child's stderr pipe is read to its end, which left
the engine.lock assertion reading ''.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…so staging removal never meets a late file (refs #441)

A body overrunning the pin failed the pipeline before the write stream had
opened its file; the file then appeared in the staging directory the caller was
removing, and ENOTEMPTY replaced archive_length_mismatch. The failure now waits
for the file's close. A test holds the thread pool busy to force the late open.

Sminos-Session: cursor235#b93055dd (cua on macbook)
#441)

Sminos-Session: cursor235#b93055dd (cua on macbook)
…close-wait test holds the open itself (refs #441)

A body that cannot be read (a locked one from an injected fetch) threw before
the pipeline listened to the already-opening file, so an unopenable destination
raised an uncaught error where download_failed was returned before; the body is
now wrapped first, both setup steps inside the typed boundary, and the close is
waited for only when a file was made. The close-wait test now delays the file's
open through the stream's fs option and asserts it was opened and closed before
the typed failure returned: it fails with the close wait removed, as the locked-
body test fails on the previous ordering.

Sminos-Session: cursor235#b93055dd (cua on macbook)
Sminos-Session: cursor235#b93055dd (cua on macbook)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T18:03:48.631726Z a3c1f2e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@SSFSKIM

SSFSKIM commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

This also covers the services-engine-service 'the engine is running; nothing launches it' failure that #444 recorded on #171's head 9371d23 (run 44784520843). The message and the path (establish → openApplication after the first window's timeout) are the same as #441's, and that head doesn't have this PR's within() fix.

Sminos-Session: cursor235#b93055dd (cua on macbook)

Sminos-Session: cursor235#b93055dd (cua on macbook)
@SSFSKIM
SSFSKIM enabled auto-merge (squash) November 20, 2026 18:20
@SSFSKIM
SSFSKIM merged commit d44a4fe into main Nov 20, 2026
7 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

1 participant