Skip to content

perf(acp): skip the MCP no-report wait on hosts that never announce MCP servers - #37698

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/acp-skip-mcp-init-wait
Nov 16, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/acp-skip-mcp-init-wait

Conversation

@chenmingwei23

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: a session start or resume on AcpRuntime stops waiting 6 s for an MCP-init frame that its host never sends.

drain_init holds every session start and resume for up to _MCP_DRAIN_NO_REPORT_CEILING (6.0 s, acp/session_handle_mcp.py) until the first MCP-init frame arrives. Only the kiro family names such a frame (notification_aliases.mcp_init: kiro-cli and KAS). codex-acp, claude-agent-acp and goose send plain session/update only, so on them nothing can end the wait early and every start and resume pays the full 6 s.

Why it matters

This affects every codex session today, with no switch: codex is in ACP_BACKENDS_ACP_RUNTIME, so each codex chat, cron, subagent or app session start and resume waits the full 6 s before its first turn. Shared claude and goose chats (runtime sharing preview, their switches on) pay the same. On a goose shared chat it was measured on a pod: a warm-up turn took about 7 s with the wait and about 1 s without it.

Not a goal

  • No change for kiro-cli or KAS: they announce their servers and keep the wait.
  • No change to which MCP servers a session gets, or to how a switched-off spec server is reported.
  • No change to the ceiling itself.

What changed (motivation -> approach -> change)

The wait can only end on a frame the host names -> ask the host's harness whether it names one -> gate the three drain sites on that.

  • AcpRuntime._host_sends_mcp_init (acp/runtime_class.py), set once from harness_for(backend).notification_aliases.mcp_init. An unknown backend keeps the wait; the spawn refuses it later with the harness's own error.
  • The three drain sites read it beside _expect_mcp_reports: the readiness drain in runtime_session_create and runtime_session_load, and the external-only drain in runtime_session_load. On a host that names no MCP-init frame they call drain_init(no_report_ceiling=0.0).
  • _expect_mcp_reports itself is unchanged, so _guard_unresolved_mcp_refs still calls record_switched_off(spec) on every host: the session's MCP status and the model's [MCP SERVERS] block still name a server the spec switched off.

Backwards compatibility

Compatible: no config, data or API changes; a host that names an MCP-init frame waits as before.

Removes nothing: only the length of a wait on hosts that can never end it early changes.

Tests

  • test/test_acp_drain_skips_mcp_init_wait.py: _host_sends_mcp_init is False for codex, claude and goose and True for kiro-cli and KAS; on codex, claude and goose record_switched_off(spec) is still called; an unknown backend keeps the wait. Its module docstring names the one-line change that breaks each test.
  • With the three source files reverted, 4 of the 7 cases fail (the flag cases and the unknown-backend case). The switched-off case passes either way on its own; it fails if the host check is folded into _expect_mcp_reports, the shape an earlier version of this change had.
  • Run locally one file at a time: test_runtime_bindings.py, test_acp_runtime_session_start.py, test_kiro_cloud_session.py, test_unattended_mcp_wait.py, test_acp_runtime.py (701 passed). flake8, black, isort and mypy are clean.

Proof: PROVEN test_only_a_host_that_names_an_mcp_init_frame_waits_for_one[codex|claude|goose], test_an_unknown_backend_keeps_the_wait (head f1f0f00)

Manual verification

goose pod run (from #37567): a shared goose chat's warm-up turn took about 7 s with the wait and about 1 s without it. No separate codex run: codex-acp sends no MCP-init frame, so its saving is the same 6 s ceiling.

Screenshots / video

N/A: no user-visible UI change.

Related Issues

Split out of #37567 at its First Principles review, which asked that a change reaching every codex session not ride along under a goose switch.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision bef145a7787b7da0a4c1729145f75e7d36489f53 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of bef145a7787b7da0a4c1729145f75e7d36489f53 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

The wait-skip is aimed at the cause: only a host that names an MCP-init frame can end the wait. The new helper and cached field re-read data the runtime already reads at the same call site.

Notes

  • Item 1 — duplicate of src/kiro_crew/acp/runtime_reader_loop.py:920 (_notification_aliases): _host_announces_mcp_starts calls harness_for(acp_backend).notification_aliases.mcp_init again. Each of the two drain sites in runtime_session_create.py:1103 and runtime_session_load.py:721 already reads self._harness.notification_aliases.mcp_readiness one line above the new check. I counted 4 direct self._harness.notification_aliases readers and 2 _notification_aliases() readers. The diff's own reason for its ValueError → True fallback is that "the spawn refuses it later", so the fallback changes nothing anyone sees. Subtraction: delete _host_announces_mcp_starts and the _host_sends_mcp_init field (plus its docstring rows), and read self._harness.notification_aliases.mcp_init inline at the three sites.

What this change ships

Inventory (4 items) — 3 justified

Intent: codex, claude and goose session starts and resumes no longer stall 6 s waiting for an MCP-init frame their host never sends. This is a FIX (perf).

  1. Codex/claude/goose session start and resume skip the 6 s no-report wait — justified
  2. A new runtime flag and module helper hold "this host names an MCP-init frame", with unknown backends kept waiting — duplicate of runtime_reader_loop.py:_notification_aliases
  3. Switched-off spec servers keep their disabled row on these hosts — justified
  4. acp-client spec paragraph describing the third zero-ceiling case — justified

[FIRST-PRINCIPLES-REVIEWED] bef145a

Description read

[DESCRIPTION-READ] 899f00d35ec614a3785dd82cfe81aa949019a11762214dcccc014646acff930a

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of bef145a7787b7da0a4c1729145f75e7d36489f53 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the drain is now gated on the harness's own notification_aliases.mcp_init declaration, a positive check that keeps the parity rule, and an unknown backend still waits.

[DESIGN-REVIEWED] bef145a

Description read

[DESCRIPTION-READ] 90f0532f9045599b0bacf085441ee2e89b658ccf6a2a655e0aac1e671811c072

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of bef145a7787b7da0a4c1729145f75e7d36489f53 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] bef145a

False positive or not applicable? A repository writer can comment:
/ai-review override gpt bef145a7787b7da0a4c1729145f75e7d36489f53 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed bef145a7787b7da0a4c1729145f75e7d36489f53 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] bef145a

Verdict parsed from the review's SHA-scoped output markers for commit bef145a7787b7da0a4c1729145f75e7d36489f53.

False positive or not applicable? A repository writer can comment:
/ai-review override fable bef145a7787b7da0a4c1729145f75e7d36489f53 false-positive: <reason, 20 to 500 characters>

@chenmingwei23
chenmingwei23 force-pushed the fix/acp-skip-mcp-init-wait branch from f1f0f00 to 8138992 Compare November 15, 2026 21:21
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Opus on f1f0f00 (acp-client.md drain paragraph still says every other agent keeps the ceiling): real, fixed in 8138992.

The drain_init() paragraph now names the third zero-ceiling case: a host whose harness declares no notification_aliases.mcp_init (AcpRuntime._host_sends_mcp_init False: codex-acp, claude-agent-acp, goose) passes a zero ceiling at all three drain sites; an unknown backend keeps the wait; switched-off servers are still recorded from _expect_mcp_reports alone.

Coverage Gate and Detect changed surface on f1f0f00 were one infra failure: Detect changed surface died fetching the repo (fatal: protocol error: bad pack header), and Coverage Gate failed closed on it (surface detection (changes) never reported -- failing closed.). This push reruns both.

@chenmingwei23
chenmingwei23 enabled auto-merge (squash) November 15, 2026 22:08
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 15, 2026
@KiroCrewCaptain

KiroCrewCaptain commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider thinks the change is probably fine but estimates an 18% chance that this change introduces a defect, above the 12% limit for approving on its own.

The change skips the 6 s MCP-init wait only on hosts whose harness declares no notification_aliases.mcp_init, which is every harness outside the kiro family. On those hosts the frames that would end the wait early (the _kiro.dev MCP initialized, init-failure and oauth-request methods) are never sent, so the wait always ran out the ceiling for nothing. Kiro-cli and KAS keep the wait. An unknown backend falls back to waiting. _expect_mcp_reports is untouched, so switched-off servers are still recorded. The zero-ceiling path is the one MCP-free runtimes already use, and late config frames are still handled by the turn dispatcher. CI and all review lanes passed. The one gap: no test checks that the drain call sites pass a zero ceiling, so I left that as a non-blocking note.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit bef145a778 · 96 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified on this head: only the kiro and KAS harnesses declare the _kiro.dev/mcp/* frames that can end the no-report wait early. Codex, claude and goose declare session_update only, so on those hosts the 6 s ceiling always ran to the end, and a zero ceiling removes only dead time. The kiro and KAS paths keep the old wait, and unknown backends keep it too. The review checked the harness-parity rule (the gate reads a declared capability, not "not kiro"), found no blocking call on the event loop, and ran the 7 new tests on this head: they pass and are deterministic, with no host state. The acp-client spec is updated in the same commit.

Done well: _expect_mcp_reports is left alone, so record_switched_off(spec) still runs on every host, and a test pins that choice against the obvious refactor.

Optional:

  • The tests pin the _host_sends_mcp_init flag, not the drain call sites. Reverting only the and self._host_sends_mcp_init conjuncts leaves all 7 green. A spy on drain_init asserting no_report_ceiling == 0.0 for a codex create_session and load_session, plus a kiro case, would pin the behaviour.
  • The Design lane note about slow MCP servers on codex has no reply yet. A codex run with one slow node server, or a codex-acp reference showing session/new waits for server start, would back the "Removes nothing" claim.
  • A smaller shape is available: read self._harness.notification_aliases.mcp_init at the two live sites, next to the mcp_readiness read. The _wait_managed_mcp conjunct is only reached on KAS, where the flag is always True, so the spec could name two drain sites instead of three.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 15, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/acp-skip-mcp-init-wait branch from 8138992 to 63537c3 Compare November 15, 2026 23:27
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 15, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Backend Tests (3.12, 1) and Coverage Gate on 63537c3: not this PR.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 16, 2026
…CP servers

codex-acp, claude-agent-acp and goose send no MCP-init frame, so drain_init's
6 s no-report ceiling could never end early on them and every session start and
resume on AcpRuntime paid it in full. Gate the three drain sites on whether the
host's harness names an MCP-init method; the spec's switched-off servers are
still recorded off _expect_mcp_reports.
@chenmingwei23
chenmingwei23 force-pushed the fix/acp-skip-mcp-init-wait branch from 63537c3 to bef145a Compare November 16, 2026 01:18
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 16, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 16, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved. On head bef145a the review confirmed that only the Kiro and KAS harnesses declare notification_aliases.mcp_init, and that only _kiro.dev/mcp/* frames can end the no-report wait early. On codex, claude and goose the 6 s ceiling therefore always ran to the end, and a zero ceiling removes only that wait. Kiro and KAS keep their current behaviour. A zero-ceiling drain still applies config_option_update and collects OAuth requests. An unknown backend still keeps the wait, and acp-client.md is updated in the same commit. The 7 new tests pass, and readiness is green on this head.

Done well: the gate reads the harness's own positive mcp_init declaration instead of "not kiro". A test keeps record_switched_off running on every host.

Optional:

  • Add a drain_init spy test, following the one in test/test_acp_runtime_drain_init.py, for codex create, resume and the external-only drain, so that dropping any of the three and self._host_sends_mcp_init conjuncts makes a test fail. Today all tests stay green when those conjuncts are reverted.
  • _host_announces_mcp_starts and its ValueError fallback can be dropped and self._harness.notification_aliases.mcp_init read inline. self._harness already raises for an unknown backend on the line before.
  • In the evidence sections, say that on main only codex is affected, and name the current head in the Proof line. If you have one, add a codex start timing.

@chenmingwei23
chenmingwei23 merged commit 7b3644f into main Nov 16, 2026
100 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/acp-skip-mcp-init-wait branch November 16, 2026 02:39
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 16, 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