Skip to content

Worker: don't hang when fetch:plan replies with an error - #1521

Open
stuartc wants to merge 1 commit into
mainfrom
fix/fetch-plan-hang
Open

Worker: don't hang when fetch:plan replies with an error#1521
stuartc wants to merge 1 commit into
mainfrom
fix/fetch-plan-hang

Conversation

@stuartc

@stuartc stuartc commented Sep 2, 2026

Copy link
Copy Markdown
Member

Short Description

Fixes a bug where the worker would hang forever (and quietly leak a capacity slot) if Lightning rejected a fetch:plan request after a run had already been claimed.

Implementation Details

Lightning is going to start being able to reply with an error to fetch:plan (e.g. when it can't resolve the job's adaptor — adaptor_not_ready, adaptor_not_found, etc).

Found a loose unresolved promise when the run channel is joined and sendEvent rejects when fetching the plan. Turns out we were leaving it stuck (not catching the rejection).

What happens is that joinRunChannel just hung forever, the upstream try/catch in server.ts (which does the clean up) doesn't get the exception, and the worker's slot for that run was occupied forever. The lost runs janitor does mark it as lost, so it's not completely "silent" but it doesn't look like we'd get the slot back.

So wrapping the call in a try/catch makes a failed call do the same as a failed or timed out join on the run channel.

QA Notes

Theres a test that forces fetch:plan to error and confirms joinRunChannel rejects instead of hanging.

AI Usage

  • I have used Claude Code
  • I have used another model
  • I have not used AI

joinRunChannel awaited sendEvent(GET_PLAN) inside an unguarded async
callback, so a rejection (now possible since Lightning can reply an
error to fetch:plan for adaptor resolution failures) became an
unhandled rejection instead of settling the outer promise. The
worker's local capacity slot for that run leaked until restart.

Wrap the await in try/catch and reject, mirroring the existing
error/timeout branches in the same file.
@github-project-automation github-project-automation Bot moved this to New Issues in Core Sep 2, 2026

@elias-ba elias-ba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josephjclark I looked at this and it looks good to me. Do you wanna have a look too before we merge ? @stuartc and the connections team will need it in prep for their work on the new adaptor registry.

@josephjclark

Copy link
Copy Markdown
Collaborator

Taking a look

@josephjclark josephjclark left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep looks good. Do you want this released now?

@stuartc

stuartc commented Sep 2, 2026

Copy link
Copy Markdown
Member Author

Yep looks good. Do you want this released now?

Ah thanks for the offer, can go out on the next one - or I'll shout. The code that would hit this is still in a branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New Issues

Development

Successfully merging this pull request may close these issues.

4 participants