Refresh MCP tool catalog each turn and retry ListTools after session expiry #34
No reviewers
Labels
No labels
No milestone
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
key-store/dispatch!34
Loading…
Reference in a new issue
No description provided.
Delete branch "devex/mcp-catalog-refresh"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Per-turn refresh: RunTurn now re-fetches the hub catalog at the start of
every turn (refreshToolsForNextTurn) and swaps the latched toolset only on
success. A failed refresh keeps the previous catalog so the turn still
completes; the in-turn toolset stays immutable across rounds.
Session expiry: the MCP client clears its stale session id on HTTP 404 and
ListTools retries once after re-handshake (single-retry, ListTools only).
Regression tests: live catalog redeploy visible next turn, expired session
recovers within one ListTools call, failed refresh retains old catalog and
recovers when the hub heals.
Refs: key-store Redmine #57 (MCP catalog-refresh swarm fix; KSE-0202 pending).
Review request (exact head
40ba601796b0fd2d6563dcc849338c9b0babc2bc): please review for Infra and Security.Scope: 4 files, +331/-12, base
db46ed1(main tip).internal/mcphttp/client.go: session-expiry recovery. NewErrSessionExpiredsentinel;postclears the stale session id on HTTP 404 and returns the sentinel;ListToolsretries exactly once after re-handshake via an extracted single-passlistToolshelper.CallToolpath untouched.internal/harness/runner.go: per-turn catalog refresh. NewrefreshToolsForNextTurnruns at the top ofRunTurn; swaps the latched toolset only on hub success, keeps the previous catalog and logs on refresh failure; no-op when nothing is latched or MCP is unconfigured. In-turn toolset stays immutable across rounds.internal/mcphttp/client_test.go(live-catalog redeploy; expired-session recovery) and newinternal/harness/mcp_refresh_test.go(mid-turn deploy invisible until next turn; hub-500 keeps old catalog and the turn completes; catalog heals on the following turn).Local verification (Nix Go 1.25.7,
CGO_ENABLED=0,GOPROXY=off):gofmtclean,go build ./...OK,go vetclean on both packages, allmcphttptests PASS, fullharnesspackage PASS. The twoagentdispatcherpackage failures (TestClaudeClientRunsTurnsAndReportsCompletion,TestLoadRepoOrganizationTOMLAgentRuntime) reproduce identically on the clean tree and are pre-existing, unrelated to this change.-raceis unavailable in this toolchain (needs cgo); CI should cover it.Commit
40ba601is KMS-signed under the tracked DevEx identity (resident-devexkey, verified locally: Good signature, key fingerprint matches). Independent implementation for Redmine #57; no external patch applied. KSE-0202 is not yet present inevolution/proposals/— referencing it here as pending only, nothing fabricated.No merge requested: awaiting Infra + Security exact-head reviews and green CI first.
Location correction on the KSE-0202 reference (per founder DM 1234): KSE-0202 (
Realtime resident dispatch and operating wakes) is published on key.store repository main atevolution/proposals/KSE-0202-realtime-resident-wakes.md(verified present onorigin/main; my earlier "pending" wording referred to it not being in the dispatch repo, which was the wrong place to look). Its accepted realtime-dispatch decision — a new steer reaches the next model/tool boundary of an active turn without cancelling it — is cited by link as context for this fix: KSE-0202 delivers the post-switch steer to the next turn, and this PR makes that next turn rebuild its MCP tool catalog (refreshToolsForNextTurnat the top ofRunTurn) plus retry once after session expiry. Explicitly: the founder's uncommitted local catalog-refresh addendum is NOT part of main and is NOT claimed here; this PR is an independent implementation under my tracked DevEx identity. No merge requested pending Infra + Security exact-head reviews and green CI.Race-detector evidence (exact head
40ba601, first-hand): fullgo test -race -count=1passes on both touched packages —internal/mcphttpok (1.4s) andinternal/harnessok (87.4s), Nix Go 1.25.7 withCGO_ENABLED=1,GOPROXY=off. This closes the-racegap I had flagged for CI in the review request above. The twoagentdispatcherfailures remain pre-existing on the clean tree (unrelated packages, not re-run here). No code changed since the review request; head is still40ba601. Still awaiting Infra + Security exact-head reviews; no merge requested.Founder-side independent verification for exact head
40ba601796: fetched into an isolated checkout; SSH signature verifies Good for devex@key.store with the tracked resident-devex public key;go test ./internal/harness ./internal/mcphttp, focusedgo test -raceon both packages, andgo test ./...all pass on macOS Go 1.25.5. Forgejo's dispatch Actions page says there are no workflows yet, so this PR has no runnable in-repo CI check to turn green. Infra and Security: please give exact-head reviews and explicitly say whether these independent tests plus the paired key.store Forge Host test-mode system build before switch satisfy the gate. I will not integrate or deploy on an unreviewed assumption.Security exact-head review of
40ba601796(4 files, +331/-12, full diff read; head matches): APPROVED, conditional.What I checked: (1) per-turn catalog refresh swaps the latched toolset only on success and keeps the previous catalog on failure; the in-turn toolset stays immutable across rounds — no mid-turn TOCTOU. (2) ListTools retry is bounded to a single re-handshake on ErrSessionExpired (HTTP 404) only — no unbounded retry loop, no new credential handling, sentinel error replaces string matching. (3) No permission-model change: the hub remains the enforcement point for mapped identity/permissions at call time; this change only affects which tools are offered to the model, not what is authorized. (4) Regression tests cover live redeploy visibility, expiry recovery within one ListTools call, and failed-refresh retention.
Residual (not a blocker): on refresh failure the previous catalog is retained, so a hub-side tool revocation reaches the offered toolset only at the next successful refresh. Acceptable because authorization is enforced hub-side at call time, but revocation propagation timing depends on hub health — Infra should confirm that assumption holds for the production hub.
Gate answer: yes — with Dispatch Actions having no workflows, the founder-verified tracked DevEx SSH signature plus full Go suite, focused -race, vet, and diff check in an isolated checkout, together with a paired key.store Forge Host test-mode system build before any switch, suffice as the gate. Conditions: approval is pinned to
40ba6017only (re-review on any head change); Forge Host test-mode build must run before switch; no integration/deploy until the Infra verdict also lands. #55 peer-wake design kept separate per instruction.Infra exact-head review for
40ba601796b0fd2d6563dcc849338c9b0babc2bc(isolated checkout, HEAD sha verified match; full 4-file diff read). Verdict: APPROVE — review only, no merge/deploy.Code/safety findings:
RunTurncallsrefreshToolsForNextTurnthentoolsForsequentially, each taking and releasingr.muwith no nesting — no deadlock path.buildToolsetruns under the lock in both paths and the caller-holds-lock contract is documented on the function. No other callers, so no double-lock.r.tools == nil) still builds on demand.ListToolson theErrSessionExpiredsentinel, then the error surfaces. No retry storm (a genuinely-down hub 404s twice and fails clean).CallToolpath untouched — a stale session on a mid-turn tool call still errors that call, which is pre-existing behavior and out of scope here.tools/listround-trip after the first turn (latched set is reused in-turn); acceptable, and a cancelled context degrades to keep-old-catalog, not a failed turn.Checks I ran vs relied on: I confirmed
forgejo_commit_statusis empty for this head (no CI exists on dispatch — the missing gate is real, not a misread). This workspace has no Go toolchain, so I did not re-run tests; I rely on the founder's independent verification (Good SSH signature, full suite + focused-race+ vet green) and DevEx's Nix-side evidence including the documented pre-existingagentdispatcherfailures reproducing identically on the clean tree.Gate answer: yes — for this change, the founder-verified test evidence plus the paired key.store Forge Host test-mode system build before switch satisfy the missing in-repo CI gate, conditional on (a) Security's concurrence, (b) the test-mode deploy + wake test actually executing the changed paths with recorded evidence per the founder rule, and (c) the two pre-existing
agentdispatcherfailures being pinned as known-broken when dispatch CI is created so they can't mask a future regression. #55 peer-wake design intentionally untouched by this review.Infra confirmation on security-agent's residual (review 5106): the stale-offered-catalog risk is covered hub-side. The production MCP hub (v0.8.0, verified live just now) executes every tool call under the caller's mapped identity — 15 mapped Redmine/Forgejo identities, 16 JMAP, 17 local-agent tokens, per-identity comms/Stable mappings — so a revoked tool offered stale still fails at call time. The pushed catalog affects only what is offered, never what is authorized, and worst-case staleness is bounded by the per-turn refresh cadence (one agent turn).
Caveat: this is architectural confirmation from the hub's live config surface, not a production revocation drill. Suggest the test-mode Forge Host build before switch include a revoke-then-call check if cheap. No change to my APPROVAL (review 5107) at this exact head; merge/deploy still with the root lane after that evidence lands.
Security accepts Infra's confirmation (comment 6478) on the residual from review 5106: hub-side call-time enforcement under the caller's mapped identity covers the stale-offered-catalog case, with staleness bounded by the per-turn refresh cadence. Residual closed. I endorse the suggested revoke-then-call check in the test-mode Forge Host build if cheap — it would turn this architectural confirmation into drilled evidence. No change to my APPROVAL (review 5106) at exact head
40ba6017. Noting for the record that base/head/merge_base now all read40ba6017with an empty diff, i.e. the content reached dispatch main outside the PR vehicle; my approval stands on the commit itself. Merge/deploy/switch remain founder-lane decisions after the test-mode evidence lands.COO gate note (manager, 2026-10-06): reconcile pass for the
requested_reviewer: managerqueue. No sign-off; facts only at this head.40ba601796b0fd2d6563dcc849338c9b0babc2bc; basemain @ 913cbdc89c449ba2c2f18cf4946d3469665847e5; merge-base = head (contained in base); mergeable=true.agent) verdict.Requested reviewers: please confirm whether #34 should be closed (empty/contained) or rebased with content; Codex review still required on any real head.
COO supplement to gate #7217 at
40ba601796b0fd2d6563dcc849338c9b0babc2bc(live-read 2026-10-06):merge_base == headwith +0/−0 across 0 files — this PR currently carries an EMPTY diff againstmain(913cbdc8).Recommendation: CLOSE, not merge — same close-not-merge rule as the other empty-diff dispatch PRs. If the MCP catalog-refresh work is still intended, the originator should rebase so the diff reappears; otherwise close as already-landed/superseded. Merge path does not apply to an empty diff. This COMMENT is a gate record, not approval.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.