Skip to content

Catch failed cleanups in awaitRuntimeOperation and test it - #459

Open
leninworld wants to merge 1 commit into
useagenthq:mainfrom
leninworld:catch-runtime-operation-cleanup
Open

leninworld wants to merge 1 commit into
useagenthq:mainfrom
leninworld:catch-runtime-operation-cleanup

Conversation

@leninworld

@leninworld leninworld commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #299

What changed

  • awaitRuntimeOperation (backend/src/engines/runtime-operation.ts) called cleanup() four times without a rejection handler: right away when the signal was already aborted, in the abort listener, and when the operation resolved or rejected after an abort. A cleanup that failed there became an unhandled rejection. All four now end in .catch(() => {}), like the two calls that already had one.
  • New backend/src/engines/runtime-operation.test.ts covers the function itself, which no test imported before:
    • resolves with the value, or rejects with the operation's error, and never runs cleanup when not aborted;
    • aborted mid-flight: rejects with signal.reason and runs cleanup once, then runs it again when the operation settles and drops the late value or error;
    • signal already aborted: rejects at once and runs cleanup, then again after the operation resolves or rejects;
    • a cleanup that rejects, at each of the four call sites: no unhandled rejection.

Testing

  • bun test ./backend/src/engines/runtime-operation.test.ts (from the repo root): 10 pass, 0 fail.
  • On main the four rejecting-cleanup tests fail with error: cleanup failed (6 pass, 4 fail). Removing the .catch at any one site makes only that site's test fail.
  • bunx -p typescript@5.9.3 tsc --noEmit in backend (after installing each package's deps, as CI does): no errors, including the new test file. bun test ./backend/test/ratchet.test.ts and bun test scripts/agent-docs.test.ts: pass.

Not checked: I did not run the full backend suite (it needs the Postgres test database) or stop a real sandbox turn. The six callers keep the same behaviour apart from the swallowed cleanup error.


Proof this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

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.

Add unit tests for awaitRuntimeOperation and catch cleanup errors

1 participant