Skip to content
December 5, 2026
3 min read
Andrew Riefenstahl

What Happens When a Background Worker Dies Mid-Job?

Building custom MCP servers got me thinking about what happens when an agent job goes sideways. I built Railgate, killed a worker mid-job, and traced how the job recovered.

Railgate
Rust
Fault tolerance
Auditability
Observability
Agent infrastructure
PostgreSQL
The Railgate replay timeline with the original worker offline and a second worker claiming the job from its saved checkpoint.

I’ve been building custom MCP servers lately so agents can do things like read a database or pull up an error in the logs. Talking to a couple of teams got me thinking about what happens after the tool call. Say an agent starts pulling a report and the worker dies halfway through. Do you really have to start over?

That’s how I got to Railgate. It’s a gateway and runtime for agent jobs. I wanted to see if the job could outlive the worker. So I killed the worker.

Where the second worker picked up

I ran two workers locally against a test API with three pages of sample data. Step through the replay.

  1. Save progress. The first worker reads page one and saves the cursor for page two in Postgres.
  2. Kill the worker. I kill its container while the page-two request is in flight.
  3. Requeue the job. The dead worker’s lease runs out, so Railgate puts the same job back in the queue.
  4. Pick up at page two. A second worker claims the job and finishes the report. The first one stays down.

The second worker took over 5.6 seconds after the kill. Almost all of that is the dead worker’s lease running out, which is a configured recovery window rather than time spent recovering; the handoff itself is a claim and a read from the checkpoint. Railgate had all six records 12.4 seconds after accepting the job.

Four requests for three pages. The second worker had to ask for page two again. It sent the same idempotency key. If that call were charging a card, I’d test what the payment API actually does when it sees the key twice.

I also made the test API return a 503. Railgate scheduled a retry, and the job finished on its second attempt after I brought the API back. See the retry.

How I know what actually ran

  • Did it finish? The job record gives me a status and an outcome I can show the person waiting for the report. I used the job journal and the test API’s request history to check where it picked up.
  • Who approved it? The approval history ties the reviewer’s decision to the action and its outcome. In the approval replay, the API saw zero calls before approval and one after.
  • Where did the time go? With OpenTelemetry export on, the worker’s job span continues the request trace after the HTTP response. That’s where I’d look if the job seemed slow.

If the ledger can’t write, the call doesn’t go out. On routes with the call ledger enabled, the gateway records the admission decision in a hash-chained ledger before dispatch.

Where I’d try it first

I’d start with an overnight reconciliation job. If an API goes down on page twenty, the person opening the report in the morning should be able to tell whether it finished and whether they need to step in.

Workers claim jobs from the same Postgres queue, so I can add replicas to work through more jobs in parallel. I’d test database recovery and API routing separately before relying on it in production.

Run the tests locally · Talk through a workflow with me

Markdown

Continue Reading