Skip to content

fix(worker): await runAgent to prevent premature worker exit#517

Merged
zbigniewsobiecki merged 1 commit intodevfrom
fix/await-manual-run-agent-completion
Feb 24, 2026
Merged

fix(worker): await runAgent to prevent premature worker exit#517
zbigniewsobiecki merged 1 commit intodevfrom
fix/await-manual-run-agent-completion

Conversation

@zbigniewsobiecki
Copy link
Copy Markdown
Member

Summary

  • Fix worker premature exit: triggerManualRun() used fire-and-forget (.then/.catch/.finally) for runAgent(), which caused worker containers to process.exit(0) before agents completed. Replaced with try/catch/finally using await so worker callers block until the agent finishes. API server behavior unchanged (outer call is already not awaited).
  • CLI org support: Added --org flag to cascade login for persisting org context, and display effective org in cascade whoami when admin context-switches.
  • README: Updated webhook callback URLs to current domain.

Test plan

  • npm run typecheck — passes
  • npm run lint — passes (biome, 600 files clean)
  • tests/unit/triggers/manual-runner.test.ts — 9/9 tests pass, updated to remove fire-and-forget timing hacks (setImmediate/setTimeout polling)
  • Pre-commit hooks (lint + typecheck) pass
  • Pre-push hooks (full test suite) pass
  • CI passes

🤖 Generated with Claude Code

…ker exit

triggerManualRun() used fire-and-forget (.then/.catch/.finally) for runAgent(),
which worked for the long-lived API server but caused worker containers to
exit before the agent completed. Replace with try/catch/finally using await
so callers that await triggerManualRun() (e.g. worker-entry.ts) block until
the agent finishes. The API router caller already doesn't await the outer
promise, so its behavior is unchanged.

Also includes:
- CLI: add --org flag to login, show effective org in whoami
- README: update webhook callback URLs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aaight
Copy link
Copy Markdown
Collaborator

aaight commented Feb 24, 2026

🤔 Just a sec, looking into that worker exit fix now

@aaight
Copy link
Copy Markdown
Collaborator

aaight commented Feb 24, 2026

Thanks for taking a look! 👍

The main fix is in src/triggers/shared/manual-runner.ts - replaced the .then/.catch/.finally fire-and-forget pattern with try/catch/finally + await so worker containers block until the agent completes.

Tests updated to remove the timing hacks (setImmediate/setTimeout polling) since we now properly await completion.

CI checks are still running, but local verification is complete (typecheck, lint, full test suite all passing).

@zbigniewsobiecki zbigniewsobiecki merged commit f388bab into dev Feb 24, 2026
5 checks passed
@zbigniewsobiecki zbigniewsobiecki deleted the fix/await-manual-run-agent-completion branch February 24, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants