Skip to content

mcpx: serve the exited-child supervisor report for the whole grace (#16797) - #17060

Merged
dezren39 merged 2 commits into
mainfrom
felix/16797-restart-supervisor
Nov 30, 2026
Merged

dezren39 merged 2 commits into
mainfrom
felix/16797-restart-supervisor

Conversation

@developing-today-fleet

@developing-today-fleet developing-today-fleet Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #16797

Root cause

Proven by instrumenting the spawn path (lane 0640-GS, after 0640-GV's diagnostic verdict isolated the defect to the restart path's supervisor spawn): when a supervised server's child has already exited, the supervisor served the exit report to the first attacher and finishWhenDone then ended the supervisor on that attacher's detach — listener closed, socket removed, all within ~15ms.

A restart in a daemon whose warm start is still settling runs two NewSupervised calls for the same socket (the warm start's, and pool.Restart's fallback spawn after its restart dial finds no live supervisor). The trace (daemon pid 14949): warm's call spawned supervisor 14959, whose instantly-refusing child was reported and consumed; the restart fallback spawned supervisor 14986 at 02:39:14.068, it listened and spawned its child — and warm's still-polling first call collected that supervisor's report at .092, so the supervisor exited at .093. The restart's own spawn poll then dialed a removed socket for the full 20s and reported supervisor did not attach within 20s, hiding the child's real failure (fakemcp: refusing to start). The same one-shot report loss hits any two spawners racing one socket, and any spawner whose first poll lands after its own supervisor's report was consumed.

Change (2 commits)

  1. Failing-first test — TestSupervisorServesExitedReportForTheWholeGrace (internal/mcpclient): a supervisor with an already-exited child must serve the same exit report to a second attacher after the first reporter detaches, and must still finish when the grace runs out. Fails pre-fix: second attach after the first report: dial unix .../sup.sock: connect: no such file or directory (run 46342803920).
  2. Fix — finishWhenDone (internal/mcpclient/supervised.go): once the child's exit has been reported, the supervisor keeps the listener up and keeps serving the same report until the first-attach grace (10s from the child's exit — the bound that already governed the never-attached case) expires, then finishes as before. The attached-then-exited path (exit reaches a live daemon as EOF after the drain) is unchanged; nothing can linger past the grace.

No new dependencies.

Gate (read from the job logs)

Composition note for the merge: this PR and #17040 are independent and each merge-ready; the fully-green e2e state is the two together, in either order. The warm test's only failure without #17040 is the #16312 cleanup leak.

Lane 0640-GS (Felix). Merge is Felix's call.

{
  "direct_parent": null,
  "links": [],
  "lineage": {
    "design": null,
    "roadmap_item": null,
    "priority": null
  },
  "pm_meta": 1,
  "provenance": {
    "queue_id": null,
    "scheduled_start": null,
    "picked_up_at": null,
    "work_started_at": null,
    "created_at": "2026-11-30T03:07:13Z",
    "session_id": null,
    "lane": null,
    "host": "htch-runtime",
    "worktree": "/home/hatch",
    "model": null,
    "lane_start_issues": [],
    "workspace_ref": {
      "kind": "worktree",
      "id": "/home/hatch",
      "repo": "developing-today/code",
      "branch": "main",
      "sha": "010b47d1c4cecdcd1b7d6ea260b7c9b0a61fb89e"
    },
    "auth_subject": "felix",
    "stamped_by": "fleet 0.1.0 (native)"
  }
}

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

Felix added 2 commits November 30, 2026 02:44
… detach (#16797)

TestSupervisorServesExitedReportForTheWholeGrace: a supervisor
whose child already exited serves the exit report to a first
attacher, and a second, racing attacher must collect the same
report afterwards. On current code the supervisor exits on the
first detach and removes its socket, so the second attach fails —
the unit form of the restart failure on #16797, where a warm start
and a restart fallback spawn race two NewSupervised calls for one
socket and the loser burns its whole spawn timeout reporting
'did not attach' instead of the child's real failure.
…16797)

finishWhenDone ended the supervisor as soon as the first reporting
attach detached: the listener closed and the socket was removed.
A second spawner racing for the same socket — the shape the
restart path takes when a warm start and the restart's fallback
spawn overlap — then had nothing to dial, and its spawn poll
burned the full 20s timeout reporting 'supervisor did not attach'
while the child's real failure (e.g. fakemcp's 'refusing to
start') sat in a report nobody could still collect.

The supervisor now keeps the listener up and keeps serving the
same exited report until the first-attach grace (10s from the
child's exit — the bound that already governed the
never-attached case) runs out, then finishes as before. The
attached-then-exited path (exit reaches a live daemon as EOF
after the drain) is unchanged, and no new process can linger
past the grace.
@coderabbitai

coderabbitai Bot commented Nov 30, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d2f2c5d4-58d4-49f6-9cee-142e781d51dc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@developing-today-fleet

Copy link
Copy Markdown
Contributor Author

Verification addendum (0640-GS) — the flake-doctrine dimensions not in the original gate:

  • Linux, -race -shuffle=on -count=5 over the supervised suite (go test ./internal/mcpclient/ -run 'TestSupervisor|TestNewSupervised') — run 46345305171: 45 PASS / 0 FAIL / 0 data races; the new grace test passes 5/5.
  • macOS, full package (go test ./internal/mcpclient/ -count=1) — run 46345323424: ok (36.5s) at this head a3f18f1; the supervisor lifecycle incl. the new grace behavior executes green on darwin.

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.

mcpx e2e remainder from #15689: TestRestartReportsAServerThatDoesNotComeBack + TestDaemonWarmReadsTheServersAtStartupFromTheEnvironment (run 46259867572)

1 participant