Skip to content

fix(agent-core-v2): observe aborted source rejections#2161

Open
morluto wants to merge 1 commit into
MoonshotAI:mainfrom
morluto:codex/fix-abortable-rejection
Open

fix(agent-core-v2): observe aborted source rejections#2161
morluto wants to merge 1 commit into
MoonshotAI:mainfrom
morluto:codex/fix-abortable-rejection

Conversation

@morluto

@morluto morluto commented Jul 24, 2026

Copy link
Copy Markdown

Related Issue

No linked issue. This is a focused fix for deterministic promise ownership behavior in the internal v2 engine.

Problem

When abortable() receives an already-aborted signal, it rejects its returned promise before attaching handlers to the supplied source promise. If that source rejects later, Node emits unhandledRejection; with the default throw policy, that can terminate the process.

The MCP reconnect path can create reconnect work before wrapping it with the tool execution signal, making it the clearest affected caller.

already-aborted signal ──> caller receives AbortError
                                  │
source work continues ────────────┴──> later rejection
                                          │
                              before: unhandled
                              after:  observed by abortable

What changed

  • Attach source settlement handlers before checking whether cancellation has already won.
  • Remove the abort listener on either source settlement path without creating a detached cleanup promise.
  • Add a regression test that observes the actual Node unhandledRejection boundary for the supplied source promise.

This does not attempt to cancel the source operation; it preserves the existing contract while retaining ownership of its eventual rejection.

Test plan

  • pnpm --filter @moonshot-ai/agent-core-v2 exec vitest run test/_base/utils/abort.test.ts --reporter=verbose — 9 passed
  • pnpm --filter @moonshot-ai/agent-core-v2 test — 4,082 passed
  • pnpm --filter @moonshot-ai/agent-core-v2 typecheck — passed
  • pnpm --filter @moonshot-ai/agent-core-v2 lint:domain — passed for 938 files
  • pnpm exec oxlint --type-aware packages/agent-core-v2/src/_base/utils/abort.ts packages/agent-core-v2/test/_base/utils/abort.test.ts — 0 warnings, 0 errors

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove the fix works.
  • Ran gen-changesets; no changeset is needed for an internal-only agent-core-v2 change.
  • No user documentation update is needed for this internal utility fix.

@changeset-bot

changeset-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 338d4bf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

1 participant