fix: stop delegation cleanup from leaking unhandled rejections - #18
Open
Tyagiquamar wants to merge 1 commit into
Open
fix: stop delegation cleanup from leaking unhandled rejections#18Tyagiquamar wants to merge 1 commit into
Tyagiquamar wants to merge 1 commit into
Conversation
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
pressFntracks spawned delegations inpendingRlmCallsusing:Promise.prototype.finally()returns a new promise that rejects with the same reason when the original rejects. Nothing ever handles that derived promise, so every failed delegation leaks anunhandledRejectioneven when the caller handled the error correctly.Two concrete consequences:
process.on("unhandledRejection")handler (seeJsEnvironment.exec) to surface stray async failures to the model. The leaked rejection from the cleanup chain gets captured there, so sandbox code that correctly recovers viatry { await press(...) } catch { ... }still sees the error appended to its iteration output — teaching the model that its error handling failed when it didn't.Provenance: found by code inspection while reading the delegation lifecycle; no matching open issue at the time of writing. Reproduced with a regression test.
Fix
Attach both fulfillment and rejection handlers so no dangling promise is created; the original promise's handling semantics are unchanged:
The
.then(...)result always fulfills, so nothing rejects unhandled.Testing
Added
caught delegation failure does not surface as a phantom errorintest/rlm.test.ts: a child whose LLM driver throws is awaited inside a sandboxtry/catch; asserts the run completes and that root-iteration events carry no error.expected 'child boom' to be null(the caught child error leaked into the parent's iteration output).npx vitest --run test/rlm.test.ts— 56/57 pass on Windows; the single failure (auto-resolve file paths > resolves .md file paths...) is pre-existing onmainand is addressed by fix: resolve Windows-style backslash paths in input resolution #17.npm run build— clean compile.