Gandalf sends about 4,300 commands a day through Pulse's internal API, all to a single worker (pulse-worker-01). Quick, scheduled and Gandalf commands relied entirely on the worker sending a command_result. If the worker was at capacity, disconnected or restarted mid-command, the execution stayed running forever. Failed commands also lost the worker's error message.
What changes
Server (server.js)
Command timeout: direct commands now time out on the server at the command timeout plus 30 s. When that happens, the execution fails with a command_result entry carrying an error. The UI already renders that ("✗ Command Result — Failed — Error: …"), so there's no UI change.
Worker socket closes: every command sent over that socket fails at once. Pending workflow step waits resolve as failures, so the engine moves on.
Backstop: every 5 minutes, a sweep fails executions still running past EXECUTION_MAX_MINUTES + 10 that nothing is tracking. Restart recovery already existed.
Terminal-state guard:updateExecutionStatus only changes a running execution, and returns whether it did. A late result, or the workflow engine finishing after an abort, can no longer flip a failed execution to completed or fire a second webhook. This also fixes the status-flip part of #8.
Abort: aborting a quick command clears its pending timeout.
#14:error, exit_code, signal and timed_out are kept in the log entry, the broadcast and the workflow step result.
Reconnect bug (already in main): when a worker reconnected, the old socket closing removed the new socket's mapping and marked the worker offline, so commands failed with "Worker not connected" until the next heartbeat. Now a socket only cleans up mappings that still point to itself.
Worker (worker/worker.js, takes effect when the worker is updated, see #40)
At capacity, the worker sends a failed result instead of staying silent.
Failures include exit_code, signal and timed_out.
Gandalf compatibility
Checked against Gandalf's PulseClient (monitor.py):
Statuses are still completed or failed.
On success, stdout is still in the first command_result log entry.
The new failure fields are additive.
Stuck commands now fail sooner, and Gandalf already retries once on failed. No Gandalf changes needed.
Testing
jest: 61 tests pass. eslint: 0 errors.
End-to-end run of the real server.js against a stubbed DB, with real ws clients. Long timers were scaled down 1000×, and polling followed Gandalf's logic. 13/13 checks pass:
Gandalf happy path:completed with the right stdout.
Failure details:exit_code and error appear in the log and the broadcast.
No result: the execution stays running, then fails with "No result from the worker within 90s". A late result can't flip it back.
Worker disconnect: Gandalf and quick commands fail immediately, and the UI receives execution_status.
Reconnect race: a stale socket closing leaves the command running, and its result still completes it.
Abort: no stray timeout entry afterwards, and a later success result can't flip the execution to completed.
The WebSocket-auth checks from #41 still pass, with enforcement off (15) and on (12).
Closes #7. Closes #14.
## Why
Gandalf sends about 4,300 commands a day through Pulse's internal API, all to a single worker (`pulse-worker-01`). Quick, scheduled and Gandalf commands relied entirely on the worker sending a `command_result`. If the worker was at capacity, disconnected or restarted mid-command, the execution stayed `running` forever. Failed commands also lost the worker's error message.
## What changes
**Server (`server.js`)**
- **Command timeout:** direct commands now time out on the server at the command timeout plus 30 s. When that happens, the execution fails with a `command_result` entry carrying an `error`. The UI already renders that ("✗ Command Result — Failed — Error: …"), so there's no UI change.
- **Worker socket closes:** every command sent over that socket fails at once. Pending workflow step waits resolve as failures, so the engine moves on.
- **Backstop:** every 5 minutes, a sweep fails executions still `running` past `EXECUTION_MAX_MINUTES + 10` that nothing is tracking. Restart recovery already existed.
- **Terminal-state guard:** `updateExecutionStatus` only changes a `running` execution, and returns whether it did. A late result, or the workflow engine finishing after an abort, can no longer flip a failed execution to `completed` or fire a second webhook. This also fixes the status-flip part of #8.
- **Abort:** aborting a quick command clears its pending timeout.
- **#14:** `error`, `exit_code`, `signal` and `timed_out` are kept in the log entry, the broadcast and the workflow step result.
- **Reconnect bug (already in `main`):** when a worker reconnected, the old socket closing removed the *new* socket's mapping and marked the worker offline, so commands failed with "Worker not connected" until the next heartbeat. Now a socket only cleans up mappings that still point to itself.
**Worker (`worker/worker.js`, takes effect when the worker is updated, see #40)**
- At capacity, the worker sends a failed result instead of staying silent.
- Failures include `exit_code`, `signal` and `timed_out`.
## Gandalf compatibility
Checked against Gandalf's `PulseClient` (`monitor.py`):
- Statuses are still `completed` or `failed`.
- On success, stdout is still in the first `command_result` log entry.
- The new failure fields are additive.
Stuck commands now fail sooner, and Gandalf already retries once on `failed`. **No Gandalf changes needed.**
## Testing
- jest: 61 tests pass. eslint: 0 errors.
- End-to-end run of the real `server.js` against a stubbed DB, with real `ws` clients. Long timers were scaled down 1000×, and polling followed Gandalf's logic. 13/13 checks pass:
- **Gandalf happy path:** `completed` with the right stdout.
- **Failure details:** `exit_code` and `error` appear in the log and the broadcast.
- **No result:** the execution stays `running`, then fails with "No result from the worker within 90s". A late result can't flip it back.
- **Worker disconnect:** Gandalf and quick commands fail immediately, and the UI receives `execution_status`.
- **Reconnect race:** a stale socket closing leaves the command running, and its result still completes it.
- **Abort:** no stray timeout entry afterwards, and a later success result can't flip the execution to `completed`.
- The WebSocket-auth checks from #41 still pass, with enforcement off (15) and on (12).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Quick, scheduled and Gandalf commands relied entirely on the worker sending
a command_result. If the worker was at capacity, disconnected or restarted,
the execution stayed 'running' forever (#7). Failed commands also lost the
worker's error message (#14).
- Direct commands now get a server-side timeout: the command timeout plus
30 s. When it expires, the execution fails with a command_result entry
carrying the error, which the UI already renders and Gandalf treats as
'failed' and retries.
- When a worker socket closes, every command sent over it fails at once.
Pending workflow step waits resolve as failures, so the engine moves on.
- Every 5 minutes, a backstop sweep fails 'running' executions past
EXECUTION_MAX_MINUTES + 10 that nothing is tracking.
- updateExecutionStatus only changes a 'running' execution and reports
whether it did. A late result, or the engine finishing after an abort,
can no longer flip a failed execution to completed or fire a second
webhook.
- Aborting a quick command clears its timeout.
- command_result keeps error, exit_code, signal and timed_out in the log,
the broadcast and the workflow step result.
- The worker reports "at capacity" as a failed result instead of staying
silent, and includes exit_code, signal and timed_out on failures.
- Fix: after a worker reconnected, the old socket closing removed the new
socket's mapping and marked the worker offline, so commands got "Worker
not connected" until the next heartbeat.
Closes#7Closes#14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jared
scheduled this pull request to auto merge when all checks succeed 2026-11-22 01:17:42 -05:00
jared
merged commit 8e77c1af0a into main2026-11-22 01:17:46 -05:00
jared
deleted branch exec-reliability2026-11-22 01:17:49 -05:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Closes #7. Closes #14.
Why
Gandalf sends about 4,300 commands a day through Pulse's internal API, all to a single worker (
pulse-worker-01). Quick, scheduled and Gandalf commands relied entirely on the worker sending acommand_result. If the worker was at capacity, disconnected or restarted mid-command, the execution stayedrunningforever. Failed commands also lost the worker's error message.What changes
Server (
server.js)command_resultentry carrying anerror. The UI already renders that ("✗ Command Result — Failed — Error: …"), so there's no UI change.runningpastEXECUTION_MAX_MINUTES + 10that nothing is tracking. Restart recovery already existed.updateExecutionStatusonly changes arunningexecution, and returns whether it did. A late result, or the workflow engine finishing after an abort, can no longer flip a failed execution tocompletedor fire a second webhook. This also fixes the status-flip part of #8.error,exit_code,signalandtimed_outare kept in the log entry, the broadcast and the workflow step result.main): when a worker reconnected, the old socket closing removed the new socket's mapping and marked the worker offline, so commands failed with "Worker not connected" until the next heartbeat. Now a socket only cleans up mappings that still point to itself.Worker (
worker/worker.js, takes effect when the worker is updated, see #40)exit_code,signalandtimed_out.Gandalf compatibility
Checked against Gandalf's
PulseClient(monitor.py):completedorfailed.command_resultlog entry.Stuck commands now fail sooner, and Gandalf already retries once on
failed. No Gandalf changes needed.Testing
server.jsagainst a stubbed DB, with realwsclients. Long timers were scaled down 1000×, and polling followed Gandalf's logic. 13/13 checks pass:completedwith the right stdout.exit_codeanderrorappear in the log and the broadcast.running, then fails with "No result from the worker within 90s". A late result can't flip it back.execution_status.completed.🤖 Generated with Claude Code