fix(runtime): handle trigger() rejections when waking idle agents#17
Merged
Conversation
agent.trigger() was called fire-and-forget in two supervisor paths: the relay new-message callback and wakeUnblockedAgents. Since the returned promise was never awaited or .catch()ed, any rejection (e.g. a failed spawn or credential refresh) became an unhandled promise rejection that could crash the supervisor process — the try-catch in wakeUnblockedAgents did not cover the async rejection either. Both call sites now use void agent.trigger().catch(...) and log the failure via log.error, matching the existing agent.start().catch(...) pattern in start(). Adds regression tests that assert no unhandledRejection event is emitted when a woken agent's trigger() rejects (using plain function mocks, since vi.fn() attaches internal handlers to returned promises that would mask the unhandled rejection). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
AgentProcess.trigger()is an async method that can reject (it awaitsrelay.recv,credentialManager.ensureFresh(),runOneShot(), and the preamble/env providers). The supervisor called it fire-and-forget — withoutawaitor.catch()— in two places:setNewMessageCallbacklambda that wakes idle on-demand / idle_cached agents when a message arrives.wakeUnblockedAgents()when a completed task unblocks dependent agents. The surroundingtry/catchthere does not cover the promise, since it is never awaited.Any rejection became an unhandled promise rejection, which can crash the whole supervisor process.
Fix
Both call sites now use:
This matches the existing
agent.start().catch(...)error-handling pattern already used inSupervisor.start().Tests
unhandledRejectionevent is emitted when a woken agent'strigger()rejects, covering both the new-message wake path and the task-unblock wake path. Both tests fail without the fix and pass with it.vi.fn(), because vitest mocks attach internal handlers to returned promises (formock.settledResults), which would mask the unhandled rejection.trigger: vi.fn()returnedundefined, which is not a validPromise<void>).Full
@wanman/runtimesuite: 48 files, 716 passed / 8 skipped (pre-existing skips).tsc --noEmitclean.🤖 Generated with Claude Code