Skip to content

fix(agent-core-v2): suppress automatic MCP retry status repeats - #4491

Closed
sailist wants to merge 1 commit into
mainfrom
bug-315-10-28-mcp-retry-event-dedup
Closed

sailist wants to merge 1 commit into
mainfrom
bug-315-10-28-mcp-retry-event-dedup

Conversation

@sailist

@sailist sailist commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Transient MCP failures trigger automatic reconnects, but each retry emits another failure status, causing repeated MCP failure rows in the TUI.

Bug Reproduction Steps

  1. Configure a Streamable HTTP MCP server that is unavailable.
  2. Start the TUI and wait through several automatic reconnect attempts.
  3. Observe repeated MCP server "<name>" failed: ... rows. Restoring the server allows the connection to recover.

Root Cause

McpConnectionManager.transition emitted every public failed → pending → failed transition. The TUI's status deduplication key changes on pending, so each later failed passes deduplication and appends another row. Durable failure episodes were already deduplicated; the problem is limited to observable status events. This is a targeted fix at the event-production boundary, not a change to retry policy.

Code Changes

  • Identify automatic retry attempts at the state-transition boundary using retryDue and a connecting entry with an existing failure streak.
  • Suppress emission only for the automatic retry's intermediate pending state and its return to retryWaiting.
  • Preserve initial failures, manual reconnects, recovery, needs-auth, terminal failures, status snapshots, retry scheduling, and durable records.
  • Update three existing regression tests without increasing the test count.

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
Automatic MCP retry statuses Every retry emitted pending and another failed, producing repeated TUI error rows Automatic retry intermediates are not emitted; initial failure and recovery are still emitted CLI/TUI users and SDK consumers with transient MCP failures No separate opt-out; live snapshots still expose current state and nextRetryAt
Manual reconnects, recovery, needs-auth, and terminal failures Status events emitted normally Unchanged CLI/TUI users, SDK consumers, and MCP authorization flows N/A
Status snapshots and durable failure records Live state and episode records retained Unchanged Session restore, status queries, and durable episode tracking N/A

Affected module: agent-core-v2 MCP connection management. Verification: 46 focused tests passed locally and on m0-dev; full typecheck and lint passed with 0 errors; m0-dev full suite passed 17,903 tests with 0 failures; native SEA smoke passed; a real MCP session completed connected → error → connected.

Checklist

  • I have read the CONTRIBUTING document.
  • Related issue: N/A — the bug was reproduced and fixed directly in this PR.
  • Existing regression tests were updated to cover the fix.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill; no changeset was added at the author's request.
  • No documentation update is needed because configuration and public interfaces are unchanged.

@changeset-bot

changeset-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 74f572b

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T10:16:09.338926Z 74f572b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74f572b577

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

}
const after = toPublicEntry(entry);
if (plan.forceEmit === true || !publicEntriesEqual(before, after)) {
const suppressRetryStatus = event.type === 'retryDue' || (automaticRetry && plan.target === 'retryWaiting');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve a settlement event for pending OAuth updates

When an OAuth tokens-saved or token-invalidation event arrives while an automatic retry is connecting, handleMcpOAuthEvent sees pending and waits for the first non-pending onStatusChange event before calling reconnectAfterCurrent (workspaceMcpService.ts:214-234). If that attempt fails transiently into retryWaiting, this condition suppresses its settlement event, and later automatic retry/failure pairs are suppressed as well; the OAuth handler therefore remains subscribed and does not perform its intended reconnect until a later success or terminal event, potentially after multiple backoff cycles. Retain an internal settlement signal for this waiter or deduplicate only at the user-facing event consumer.

AGENTS.md reference: AGENTS.md:L111-L113

Useful? React with 👍 / 👎.

@sailist sailist closed this Oct 28, 2026
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.

2 participants