You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Session create leaves a saved session and its engine behind when the broker commit fails #2972
When a session is created with the MCP broker on, createPerSessionEngine saves the session before it commits the session's broker attachment. If that commit fails, the create returns an error, but the saved session stays behind:
commitBrokerAttachment fails (service.go:3411, :3386 on main).
The function returns nil, ErrInternal. The deferred finalizeBrokerAttachment aborts the attachment.
Result:
The session record exists and carries an ExternalBinding for an attachment that was aborted.
Its engine is still registered in sessionEngines.
The caller gets an error and no session ID, so it cannot tell that the session exists, or clean it up.
What a retry with the same request ID, or a later call on that session, then sees has not been checked.
The other paths already handle this
The two other places that commit a broker attachment after publishing clean up when the commit fails:
Fork/Clear (placement_successor.go:489-495): calls cleanupEngine() and returns the saved ID with the error ("Saved already: report the ID with the error").
Rebuild (service.go:7505-7515): restores the prior engine, or deletes the new one.
The create path should do the same: remove the engine it installed, and either return the saved session's ID with the error or make the saved record recoverable (for example, remove it or mark it so a retry can finish the commit).
Scope
This happens on main today for every broker-attached session create. PR #2965 also routes named-definition sessions (agent_definition_name) through this path, so they are affected too once it merges.
Test
Inject a broker Commit failure after persistCreatedSession succeeds. Assert that the engine is gone from sessionEngines, and assert what a retry with the same request ID and a GetSession call see. A factory failure does not exercise this path, because it fails before the save.
I'd like to work on this. I'll inject a broker commit failure after the session is saved, then check engine cleanup and what GetSession and a retry with the same request ID see. Could you assign this to me if available?
Activity
ningsiyuan1024 commentedon Nov 25, 2026
I'd like to work on this. I'll inject a broker commit failure after the session is saved, then check engine cleanup and what GetSession and a retry with the same request ID see. Could you assign this to me if available?