Skip to content

fix(server): return the saved state explicitly from successor creation - #2649

Merged
ChrisJBurns merged 1 commit into
mainfrom
fix/server-successor-saved-flag
Nov 2, 2026
Merged

ChrisJBurns merged 1 commit into
mainfrom
fix/server-successor-saved-flag

Conversation

@ChrisJBurns

Copy link
Copy Markdown
Contributor

Closes #2612

Summary

Before this change, Clear and Fork decided whether to close a pre-opened identity broker session from a convention: createPlacedSuccessorLocked returned a non-empty session ID exactly when it had saved the successor. Nothing enforced that, so a mistake could leak a broker session holding a converted refresh token, or close the wrong one.

  • createPlacedSuccessorLocked now returns (id, saved, err). saved is the single source of truth: the function's own deferred close and Clear's deferred close both read it.
  • Clear compares the preset owner with the source as reloaded under the mutation lease, before it cancels the source. The ticket asked for this check where Clear builds the preset, but at that point the owner comes from the same session, so the check could never fail. The existing check before the save stays.
  • Two test comments said only the authenticator emits bearer_rejected. The identity broker emits it too; the comments now say so.

Testing

  • New TestCreatePlacedSuccessorReportsSavedExactly. It checks that saved is true exactly when the successor can be loaded from the store, on success, on a store failure before the save, and on a reference-commit failure after the save. Forcing a wrong flag on either side makes it fail.
  • New TestSuccessorSavedThenFailedKeepsItsBrokerSession (Clear and Fork). When the successor is saved and a later commit fails, the call returns the ID with an internal error, and the successor's broker session stays open.
  • New TestClearRefusesASourceWhoseOwnerChangedBeforeCancelling. It fails before the change because the source ended up cancelled.
  • The feat(server): open the identity broker session before any change #2606 tests that close an unsaved successor's broker session still pass.
  • go test -race ./internal/adapter/server/... passes except TestACPUsesHostGovernanceRootAndClosesRejectedBinding and TestLoadACPSessionOwnsExactBindingUntilOverrideLifecycleEnds, which fail the same way on a clean main.
  • task lint passes for the root module. It stops at an existing gosec finding in environment/microvm/launch_ownership_darwin.go:754, which this PR does not touch.
  • Not yet run: the full task test:race and the offline demo.
  • Not covered by a test: the MCP broker commit-failure path, which the existing fixture cannot make fail. It returns saved the same way as the reference-commit path, which is tested.

API compatibility

No wire change. The change is an internal return value and the order of an internal check, and API callers get the same session IDs and error codes as before. The one new refusal, a source whose owner changed between Clear's two loads, uses the existing internal error, and no server path reassigns a session's owner.

createPlacedSuccessorLocked now returns whether it saved the successor,
and Clear and Fork close a pre-opened identity broker session from that
flag instead of from a non-empty session ID. Clear also checks the
source's owner after the reload under the mutation lease, before it
cancels the source.

Closes #2612

Co-authored-by: Mecatl <[email protected]>
@ChrisJBurns
ChrisJBurns marked this pull request as ready for review November 2, 2026 19:55
@ChrisJBurns
ChrisJBurns merged commit bfd42a4 into main Nov 2, 2026
65 of 76 checks passed
@ChrisJBurns
ChrisJBurns deleted the fix/server-successor-saved-flag branch November 2, 2026 20:23
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Nov 18, 2026
2 tasks
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.

Return the saved state explicitly from successor creation

2 participants