Skip to content

fix(mcp): avoid task-group teardown abort in runTransport retry backoff#517

Open
pnascimento9596 wants to merge 1 commit into
repoprompt:mainfrom
pnascimento9596:fix/mcp-runtransport-teardown-abort
Open

fix(mcp): avoid task-group teardown abort in runTransport retry backoff#517
pnascimento9596 wants to merge 1 commit into
repoprompt:mainfrom
pnascimento9596:fix/mcp-runtransport-teardown-abort

Conversation

@pnascimento9596

Copy link
Copy Markdown

What changed

Replaced the three-child throwing task-group race in MCPService.run() with an explicit-task race that:

  • settles the first returned value or thrown error under a lock;
  • cancels all three operations after settlement;
  • awaits every task to completion before returning or throwing;
  • propagates caller cancellation through the same deterministic teardown path.

MCPServiceProxyTaskGroupPolicy, terminal-record persistence, the post-race cancellation check, kill-signal semantics, and runTransport() retry/backoff behavior are unchanged.

Added deterministic tests for every child winning with either a value or error, loser cancellation and completion before return, and outer cancellation draining all three children. The SIGABRT is a Swift 6.2 release-runtime interaction and is not unit-reproduced; the tests pin the replacement control-flow structure identified by the issue's crash forensics.

The contract ledger also reconciles three executable IDs that were already missing on current main, which was required for exact ledger verification after adding this suite.

Why

Issue #513 maps the residual swift_task_dealloc abort to the retry-backoff sleep in MCPService.runTransport() while the surrounding task group is being cancelled. This mirrors the crash class reported in #139 and fixed at the initialization site in #140 by commit 9f881efb.

Flagged decision for maintainer review: this restructures the second race site away from a value-returning throwing task group, following #140's explicit-task settlement and drain pattern. Please scrutinize the preserved first-completion priority, especially value versus error ordering.

Validation

Passed:

  • make dev-test FILTER=MCPServiceProxyRaceTests (3 tests)
  • make dev-test FILTER=MCPProxyTerminalRecordTests (7 tests)
  • failing-first structural run against a temporary cancel-without-await variant
  • make dev-test-list
  • python3 Scripts/test_suite_optimizer.py verify-ledger --ledger Scripts/Fixtures/test-suite-contract-ledger.tsv (3175 IDs)
  • make dev-format-check
  • make dev-lint
  • make guardrails
  • make dev-swift-build PRODUCT=repoprompt-mcp
  • contribution preflights: commit and push

Local full-root status: make dev-test-impacted correctly required the full root suite because the ledger is a broad boundary. Three coordinated full-root attempts did not complete green due unrelated, nondeterministic codemap/worktree failures. The repeated failure was PersistentAgentModeMCPReadFileConnectionTests/testPairAgentOwnedNoRangeReadSelectsNonEmptyWorktreeLogicalFile; it passed immediately when rerun alone. One attempt also failed two other unrelated codemap tests. The issue #513 focused suites stayed green.

Not run:

  • release-configuration build or packaged release smoke. The coordinated product build was debug SwiftPM; signed app packaging stopped before compilation because no signing identity or explicit ad hoc signing opt-in was configured.

Fixes #513

@provencher

Copy link
Copy Markdown
Collaborator

Thanks for contributing! This looks like a great fix

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.

repoprompt-mcp aborts in runTransport retry backoff during teardown (residual swift_task_dealloc crash after #140)

2 participants