Repository navigation
fix(mcpbroker): idle-session broker workspace refresh + concurrency fixes - #1530
Merged
Merged
Conversation
6 tasks done
Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: OpenAI <[email protected]>
Co-Authored-By: OpenAI <[email protected]>
Co-Authored-By: OpenAI <[email protected]>
Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
ResetWorkspaceEnrollment took logical.mu before a.mu, the reverse of every other method that holds both (Commit/Abort/beginOperation/ freezeAuthenticatedCatalogue/RefreshGrantedAuthorizationCatalogue) — a concurrent lazy-authorization catalogue refresh racing an explicit /tools-connect refresh could deadlock the attachment. Reordered to match the package convention and folded its two-pass route filter into one pass. RetryWorkspaceEnrollment composed two independently-locking public methods (cancel, then ConnectWorkspaceServices), releasing runEntryMu between them — a real, if narrow, window for a prompt to start between cancellation and the replacement begin. Collapsed into a single lock acquisition delegating to new connectWorkspaceServicesLocked/cancelWorkspaceEnrollmentLocked helpers. Both fixes ship with regression tests verified to fail against the pre-fix code (a hanging lock-order reproduction, and an AST-based structural check that RetryWorkspaceEnrollment acquires runEntryMu exactly once). Also adds the acceptance plan's named Scenario 1/2 tests (TestIdleSessionBrokerRefresh_Scenario1_ExistingConversationControls, _Scenario1_DestructiveCatalogueReplacement, _Scenario2_RestartAndExplicitRecovery, TestInvariant_idle_session_broker_refresh_serialization, and _preserves_toolhive_custody) proving AC1.1-AC1.4 and AC2.1-AC2.4 end to end, including fault injection at each destructive-replacement boundary (broker reset, engine build, attachment commit, snapshot persistence) and simulated broker-process-loss recovery over a shared session store. Co-Authored-By: Claude Sonnet 5 <[email protected]>
jhrozek
force-pushed
the
impl/idle-session-broker-workspace-refresh
branch
from
September 14, 2026 20:43
d57a299 to
4796d08
Compare
Merged
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements idle-session MCP broker workspace refresh (ADR 0335): an owner of a broker-backed mecak8s session can run
/tools-connectafter any completed conversation turn to destructively replace the session's ToolHive-owned broker tool bundle, and to recover broker capability after a broker-process restart. This PR also fixes two concurrency bugs found during a follow-up panel review and adds the acceptance plan's five named test proofs.engine/session/workspace_enrollment.go: relaxes the workspace-enrollment lifecycle from pre-prompt-only to idle-without-conflicting-control.internal/adapter/mcpbroker/workspace_enrollment.go: addsResetWorkspaceEnrollment, the narrow root-internal operation that withdraws the completed catalogue while preserving the logical broker session/grant custody.internal/adapter/server/workspace_enrollment.go: destructive-replacement sequencing (reset → withdraw engine → begin → discover → build engine → complete → persist), each step fail-closed.cmd/mecatui/*: mecatui//tools-connectand/mcpexpose the same recovery action whenever the session is stably idle, instead of fresh-session-only.ResetWorkspaceEnrollmenttooklogical.mubeforea.mu, the reverse of every other method holding both — a concurrent lazy-authorization catalogue refresh racing an explicit refresh could deadlock the attachment. Reordered to match the package convention.RetryWorkspaceEnrollmentcomposed two independently-locking public methods, releasingrunEntryMubetween cancel and begin — a narrow window for a prompt to slip in between them. Collapsed into one lock acquisition.Development stage
Contract linkage
406ac5cd674dbc000d8854254837ff5f368dc3a8Interface conformance
Matches the approved contract: no gRPC/protobuf schema change, no exported
engine/API change. The two fixes in this PR (lock ordering insideResetWorkspaceEnrollment; collapsingRetryWorkspaceEnrollmentto a singlerunEntryMuacquisition via new unexportedconnectWorkspaceServicesLocked/cancelWorkspaceEnrollmentLockedhelpers) are internal-only and change no public surface.Issue relationship
Closes #1463
Type of change
Test plan
Baseline checks
task lint) — 0 issues across all modulestask test)go run ./cmd/mecademo)task docs)task site:build)task api:check)/panel-review— ran, found the two concurrency bugs above (now fixed) and the missing named acceptance tests (now added); no unwaived blocker remains.Changes
internal/adapter/mcpbroker/workspace_enrollment.goResetWorkspaceEnrollment; single-pass route filterinternal/adapter/server/workspace_enrollment.goRetryWorkspaceEnrollmentserialization gap via*Lockedhelpersinternal/adapter/server/session_mutation_inventory.gointernal/adapter/mcpbroker/workspace_enrollment_test.gointernal/adapter/server/mcp_broker_test.gobrokerEngineResultWithStorehelper (engines that drive a real persisted turn)internal/adapter/server/workspace_enrollment_test.goTestIdleSessionBrokerRefresh_Scenario1_ExistingConversationControls,_Scenario1_DestructiveCatalogueReplacement,_Scenario2_RestartAndExplicitRecovery,TestInvariant_idle_session_broker_refresh_serialization,_preserves_toolhive_custody, plus the two retry regression testsUser-facing change
An owner can run
/tools-connecton an established (non-empty-conversation) broker-backed session to replace its connected tools, and can recover broker capability with the same command after a broker-process restart, without needing to start a fresh session. Starting a refresh is destructive: broker tools become unavailable until the replacement completes.Special notes for reviewers
/panel-reviewpass across Spec/Standards/Test-adequacy/Domain axes, each independently verified to reproduce against the pre-fix code before being fixed (a hanging lock-order repro, and an AST-based structural check).task testhere meansgo testscoped to the touched packages plus a fulltask testrun kicked off locally before opening this PR; CI is the authoritative full run.