Abort kills worker processes; fix #6, #21, #34; worker keepalive and backoff #67

Merged
jared merged 5 commits from backend-bugs into main 2026-11-23 01:44:45 -05:00
Owner

Closes #6, closes #21, closes #34, closes #1, closes #29. This also completes #8, whose engine side was #66.

This PR changes the worker, so the Deploy worker job will update CT 153 (a brief reconnect; Gandalf retries).

#8 follow-up: abort kills the command on the worker

  • The worker runs commands with spawn in their own process group. Behaviour is otherwise unchanged: the same timeout, the same 10 MB output limit and the same result fields as exec.
  • A new cancel_command message stops a command and everything it started: SIGTERM to the whole group, then SIGKILL after 5 s. The result reports cancelled: true. Older workers ignore the message.
  • The abort route sends it to the worker running each of the execution's commands.

#6: quick command to an offline worker

It's now refused before any execution is recorded, so no execution is left stuck in "running".

#21: prompts and waits

  • An unanswered prompt fails the execution with prompt_timeout, instead of continuing as if someone had chosen.
  • Prompt and wait steps never wait past the execution's overall deadline. A wait that gets cut short fails with execution_timeout.
  • PULSE_PROMPT_TIMEOUT_MS lets the test stack use 8 s; the default stays 60 minutes.

#34: deleting a connected worker

This gets a 409 that explains the worker would re-register on its next heartbeat. Offline workers delete as before.

#1 and #29: worker connection resilience

  • Keepalive: the worker pings the server every 30 s. If a ping gets no pong, the connection is dead (for example after a server restart or a network drop without a proper close), so the worker terminates it and reconnects.
  • Reconnects: these back off from 1 s, doubling to 60 s with up to 20% jitter, and reset after a successful connection.
  • Startup: a failed first heartbeat is logged and retried. Before, the process exited and systemd restarted it every 10 s.

Tests

  • Unit: process-tree kill (including a background child), cancel by execution, backoff limits, a missed pong terminates the connection while a received pong keeps it, and startup with the server down.
  • Integration:
    • an aborted quick command's process really is gone from the worker;
    • an offline worker is refused and no execution is recorded;
    • deleting a connected worker gets a 409;
    • an unanswered prompt fails the execution;
    • a worker started with the server unreachable keeps running and retrying.
  • Locally: unit 143/143, integration 46/46, UI 33/33. The process checks treat zombies as dead, which fixed a test flake seen under load.

🤖 Generated with Claude Code

Closes #6, closes #21, closes #34, closes #1, closes #29. This also completes #8, whose engine side was #66. **This PR changes the worker**, so the `Deploy worker` job will update CT 153 (a brief reconnect; Gandalf retries). ## #8 follow-up: abort kills the command on the worker - The worker runs commands with `spawn` in their own process group. Behaviour is otherwise unchanged: the same timeout, the same 10 MB output limit and the same result fields as `exec`. - A new `cancel_command` message stops a command and everything it started: SIGTERM to the whole group, then SIGKILL after 5 s. The result reports `cancelled: true`. Older workers ignore the message. - The abort route sends it to the worker running each of the execution's commands. ## #6: quick command to an offline worker It's now refused **before** any execution is recorded, so no execution is left stuck in "running". ## #21: prompts and waits - An unanswered prompt **fails** the execution with `prompt_timeout`, instead of continuing as if someone had chosen. - Prompt and `wait` steps never wait past the execution's overall deadline. A wait that gets cut short fails with `execution_timeout`. - `PULSE_PROMPT_TIMEOUT_MS` lets the test stack use 8 s; the default stays 60 minutes. ## #34: deleting a connected worker This gets a 409 that explains the worker would re-register on its next heartbeat. Offline workers delete as before. ## #1 and #29: worker connection resilience - **Keepalive:** the worker pings the server every 30 s. If a ping gets no pong, the connection is dead (for example after a server restart or a network drop without a proper close), so the worker terminates it and reconnects. - **Reconnects:** these back off from 1 s, doubling to 60 s with up to 20% jitter, and reset after a successful connection. - **Startup:** a failed first heartbeat is logged and retried. Before, the process exited and systemd restarted it every 10 s. ## Tests - Unit: process-tree kill (including a background child), cancel by execution, backoff limits, a missed pong terminates the connection while a received pong keeps it, and startup with the server down. - Integration: - an aborted quick command's process really is gone from the worker; - an offline worker is refused and no execution is recorded; - deleting a connected worker gets a 409; - an unanswered prompt fails the execution; - a worker started with the server unreachable keeps running and retrying. - Locally: unit 143/143, integration 46/46, UI 33/33. The process checks treat zombies as dead, which fixed a test flake seen under load. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared added 4 commits 2026-11-23 00:27:20 -05:00
- worker: commands run with spawn in their own process group (same
  timeout, 10 MB output limit and result fields as exec). A new
  cancel_command message (by command_id, or every command of an
  execution) sends SIGTERM to the group, then SIGKILL after 5 s; the
  result reports cancelled: true. Old workers ignore the message.
- server: the abort route sends cancel_command to the worker running each
  of the execution's commands.
- Tests: the whole process tree dies on cancel (a background child too),
  execution-wide cancel leaves other executions alone, and end to end an
  aborted quick command's process is gone from the worker. Liveness
  checks treat zombies as dead (an orphan waits to be reaped).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- #6: a quick command to a disconnected worker is refused before an
  execution is recorded, instead of leaving one stuck in 'running'.
- #21: an unanswered prompt fails the execution (prompt_timeout) instead
  of continuing as if someone had chosen; prompt and wait steps never
  wait past the execution's deadline, and a wait cut short by it fails
  with execution_timeout. PULSE_PROMPT_TIMEOUT_MS (minimum 1 s, default
  60 min) lets the test stack use 8 s.
- #34: deleting a connected worker is a 409 explaining it would
  re-register on its next heartbeat; offline workers delete as before.

Tests for each (integration 45/45).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- #1: the worker pings the server every 30 s over the WebSocket; if the
  previous ping got no pong, the connection is dead (server restart or
  network drop without a close) and is terminated so it reconnects. The
  ws server answers pings itself, so the server needs no change.
- #29: reconnects back off from 1 s doubling to 60 s with up to 20%
  jitter, reset on a successful connection; a failed first heartbeat is
  logged and retried instead of exiting into a systemd crash loop.
- stop() no longer schedules a reconnect.
- Tests: backoff bounds, missed pong terminates, pong keeps, startup with
  an unreachable server (unit and end to end). The #6 test now waits for
  the worker to show offline before sending one command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merge remote-tracking branch 'origin/main' into backend-bugs
CI / UI screenshots (before/after) (push) Skipped
CI / Lint (eslint) (push) Successful in 35s
CI / Test (jest) (push) Successful in 39s
CI / Security (npm audit) (push) Successful in 21s
CI / Integration (api) (push) Canceled after 3m54s
CI / Scan (secrets, workflows, shell) (push) Canceled after 3m18s
CI / UI (playwright) (push) Canceled after 0s
CI / Deploy (push) Canceled after 0s
CI / Lint (eslint) (pull_request) Canceled after 0s
CI / Deploy worker (push) Canceled after 0s
CI / Test (jest) (pull_request) Canceled after 0s
CI / Notify (push) Canceled after 0s
CI / Security (npm audit) (pull_request) Canceled after 0s
CI / Integration (api) (pull_request) Canceled after 0s
CI / Scan (secrets, workflows, shell) (pull_request) Canceled after 0s
CI / UI (playwright) (pull_request) Canceled after 0s
CI / UI screenshots (before/after) (pull_request) Canceled after 0s
CI / Deploy (pull_request) Canceled after 0s
CI / Deploy worker (pull_request) Canceled after 0s
CI / Notify (pull_request) Canceled after 0s
986791ae20
jared added 1 commit 2026-11-23 00:36:29 -05:00
Register a prompt's pending answer before announcing it
CI / UI screenshots (before/after) (push) Skipped
CI / Lint (eslint) (pull_request) Successful in 51s
CI / Security (npm audit) (pull_request) Successful in 51s
CI / Integration (api) (pull_request) Successful in 3m51s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 3m35s
CI / Test (jest) (push) Successful in 1m41s
CI / Scan (secrets, workflows, shell) (push) Successful in 2m57s
CI / Test (jest) (pull_request) Successful in 48s
CI / UI (playwright) (pull_request) Failing after 11m39s
CI / Lint (eslint) (push) Successful in 40s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / UI screenshots (before/after) (pull_request) Successful in 35s
CI / Notify (pull_request) Skipped
CI / Security (npm audit) (push) Successful in 52s
CI / Integration (api) (push) Successful in 3m6s
CI / UI (playwright) (push) Successful in 2m18s
CI / Deploy (push) Skipped
CI / Deploy worker (push) Skipped
CI / Notify (push) Skipped
b5af336338
An answer arriving between the 'prompt' log entry and the registration got
'No pending prompt' (404); CI hit it under load on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jared merged commit a1f26b2bb1 into main 2026-11-23 01:44:45 -05:00
jared deleted branch backend-bugs 2026-11-23 01:45:41 -05:00
Sign in to join this conversation.