Skip to content

feat(agent): publish MCP discovery phase and agent run id - #29450

Draft
ibetitsmike wants to merge 1 commit into
mike/mcp-discovery/2-protocol-persistencefrom
mike/mcp-discovery/3-agent-publication
Draft

ibetitsmike wants to merge 1 commit into
mike/mcp-discovery/2-protocol-persistencefrom
mike/mcp-discovery/3-agent-publication

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Stack context

This stack replaces #29114 after review feedback that a single mcp_settled bool was underdeveloped and the change too large to review. It defines how workspace MCP discovery is communicated from the agent to chats: the agent publishes one discovery report inside the existing context snapshot (PushContextState), coderd persists it atomically with the resources, and chatd, find_tools, the create/start workspace tools, and the chat context UI all consume that same committed report.

The report has three parts. Completeness: MCPDiscovery.phase is PENDING until the agent's initial MCP reload has finished (success, failure, or zero servers all count) and COMPLETE afterwards for the rest of the process; later reloads update outcomes but never move it back. Per-source outcomes stay on the existing ContextResource rows: mcp_config rows carry structural and semantic config errors, mcp_server rows carry discovered servers (including zero tools), failed servers with a sanitized error, and a retained previous connection as OK plus a warning. Freshness: every snapshot carries the agent_run_id of the process that produced it, and the agent reports the same id in Startup, so a snapshot is known to describe the current process when the two ids match. Timestamps are deliberately not used for freshness because ready_at is agent clock and received_at is coderd clock.

Discovery completeness, per-source outcomes, turn eligibility, and the result of an actual tool invocation stay separate facts. Out of scope: continuous health monitoring, reconnect detection, automatic retries, and any retry or reload UI.

Layers, bottom to top: #29448 agent diagnostics, #29449 protocol and persistence, #29450 agent publication, #29451 chat projection, #29452 first-turn gate, #29453 context UI. Each layer builds and passes its tests on its own. The composed stack was validated end to end with remote UAT; the record is on #29453.

Why

#29449 gives the protocol a discovery phase and a per-process run id; this layer makes the agent fill them in.

Fix

The agent generates agentRunID once in agent.New, sends it in UpdateStartup, and passes it to agentcontext, which stamps it on every push. agentmcp.Manager.Report() gains the discovery phase (pending until the first reload body reaches a terminal result, then complete), and settlement fires onChange once even when the catalog is unchanged so a zero-server workspace still publishes a complete report.

agentcontext.Manager samples the MCP report once, before ResolveContext, in both resolveAndBroadcast and Resync, and uses that single sample for the server rows, the config overlays, and the snapshot's phase. A phase captured before resolution can never label a pre-settlement catalog as complete, which closes the race a review of #29114 pointed out.

Testing

Tests cover phase capture before the catalog (channel-synchronized, no sleeps), the Resync path, zero-server settlement publishing a complete snapshot with unchanged resources, the drpc conversion of run id and phase, and the agent sending the same non-empty run id in Startup and in its first push. Remote UAT of the composed stack is recorded on #29453.

Review record

  • Codex review 1, requested 2026-09-17 04:29 UTC on 90487555c2: no findings (Codex Review: Didn't find any major issues).
  • Codex review 2, requested 2026-09-17 05:37 UTC on 6520ca9595: no findings on 6520ca9595.
  • Codex review 3, requested 2026-09-17 06:14 UTC on d9249ea1cd: no findings on d9249ea1cd.
  • Codex review 4, requested 2026-09-17 06:42 UTC on b1af1ff3f1: no findings on b1af1ff3f1.
  • Codex review 5, requested 2026-09-17 07:17 UTC on baed687966: no findings on baed687966.
  • Codex review 6, requested 2026-09-17 07:54 UTC on 1485469260: no findings on 1485469260.
  • Codex review 7, requested 2026-09-17 08:26 UTC on cf184f4385: no findings on cf184f4385.
  • Codex review 8 requested on 1e1da6fb0a: pending.

This PR was authored by Xum on behalf of @ibetitsmike.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 17, 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-09-17T09:10:00.786746Z 1e1da6f Manual request
ℹ️ 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 90487555c2

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike
ibetitsmike force-pushed the mike/mcp-discovery/3-agent-publication branch from 9048755 to 6520ca9 Compare September 17, 2026 05:34
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 6520ca9595

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike
ibetitsmike force-pushed the mike/mcp-discovery/3-agent-publication branch from 6520ca9 to d9249ea Compare September 17, 2026 06:11
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: d9249ea1cd

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike
ibetitsmike force-pushed the mike/mcp-discovery/3-agent-publication branch from d9249ea to b1af1ff Compare September 17, 2026 06:40
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: b1af1ff3f1

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike
ibetitsmike force-pushed the mike/mcp-discovery/3-agent-publication branch from b1af1ff to baed687 Compare September 17, 2026 07:15
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: baed687966

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike
ibetitsmike force-pushed the mike/mcp-discovery/3-agent-publication branch from baed687 to 1485469 Compare September 17, 2026 07:52
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 1485469260

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike
ibetitsmike force-pushed the mike/mcp-discovery/3-agent-publication branch from 1485469 to cf184f4 Compare September 17, 2026 08:25
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: cf184f4385

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike
ibetitsmike force-pushed the mike/mcp-discovery/3-agent-publication branch from cf184f4 to 1e1da6f Compare September 17, 2026 09:04
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 1e1da6fb0a

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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