Repository navigation
Conversation
Every TUI tab attaches its runtime and session to the session manager (AttachRuntime), but closing a tab only cancelled the supervisor context: the manager cleans up on session deletion, so in --listen mode each closed tab leaked its runtime, session, attach context, follow-up injector and recall handler for the process lifetime. Add SessionManager.DetachRuntime, symmetric with AttachRuntime: remove the entry, cancel the attach context, clear the recall handler and drop the injector and event log, leaving the persisted session alone and attachable again. The TUI spawner's cleanup, run by Supervisor.CloseSession, calls it. Signed-off-by: PerryLink <novelnexusai@outlook.com>
golangci-lint's embeddedstructfieldcheck requires an empty line between an embedded field and regular fields; the detach test added in d5f2248 tripped it, so the lint job failed on that file. No behavior change.
| func (f *runExecFlags) startSessionCoordinator(ctx context.Context, out *cli.Printer, rt runtime.Runtime, sess *session.Session) (app.Opt, error) { | ||
| if f.listenAddr == "" { | ||
| return f.recallCoordinatorOpt(ctx, rt, sess), nil | ||
| opt, _ := f.recallCoordinatorOpt(ctx, rt, sess) |
There was a problem hiding this comment.
[blocking] High confidence: include the initial tab in the detach lifecycle. It goes through startSessionCoordinator rather than createSessionSpawner, but this branch discards the detach callback, and the --listen branch never returns one. With --listen, open another tab and close the initial tab: its cleanup only stops toolsets and calls rt.Close() (cmd/root/backend.go:126-134), while LocalRuntime.Close does not unregister it from the manager (pkg/runtime/runtime.go:1300-1303). Consequently f.listenSM retains the initial runtime/session, its injector bound to the closed App, and its event-log entry; the closed tab also remains in GET /api/sessions. This leaves #4909's closed-tab cleanup requirement unmet. Propagate the detach callback into the initial tab's cleanup, including the --listen path, and add lifecycle regression coverage for closing initial and spawned tabs.
startSessionCoordinator discarded the detach callback for both branches, and the --listen branch never returned one, so closing the initial tab only stopped its toolsets and closed the runtime. The manager kept the runtime, session, attach context, follow-up injector and event log, and the closed tab stayed in GET /api/sessions (docker#4909). Return the detach callback from both branches and wrap the initial tab's cleanup with detachOnClose, the same wrapper the spawner uses for spawned tabs. Cover the listen detach and the wrapper's once/detach-before-cleanup order in cmd/root tests.
|
Thanks — fixed in 30e933f.
Tests:
|
golangci-lint's gocritic flags the deferred closure in runOrExec as deferUnlambda and suggests `defer cleanup()`. That rewrite is wrong here: deferring the func value captures cleanup when the defer is registered, so the detachOnClose wrapper installed after startSessionCoordinator returns would never run and a closed initial tab would keep its runtime attached (docker#4909). Keep the closure, which reads cleanup when it runs, and annotate the false positive; no behavior change. Signed-off-by: PerryLink <novelnexusai@outlook.com>
|
CI update: the lint job was red on a single gocritic finding ( I kept the closure. Checked locally with golangci-lint v2.14.0 (the CI version): 0 issues; project |
aheritier
left a comment
There was a problem hiding this comment.
Reviewed all five changed files and both commits since b704b1d against #4909. The ordinary close path now releases the attachment without deleting the stored session, but detach must preserve the busy guard until the old stream stops and must not tear down a replacement attachment.
Prior threads: #4611195948 is addressed in code, although GitHub still shows the thread as unresolved and outdated. 30e933f threads detach through both coordinator branches and passes the wrapped cleanup to the initial tab; spawned tabs use the same wrapper. The follow-up commit correctly keeps the deferred closure so it calls the wrapped cleanup. The new tests cover the coordinator callback and cleanup order separately, but neither closes actual initial and spawned tabs and checks the serving manager afterward. Add that lifecycle regression coverage.
Overlap with #4930: Both open PRs deliver #4909, including initial-tab detach, recall-handler cleanup, and sequential same-ID event-log reattachment. This PR also detaches the private non-listen recall coordinator. The same-ID tests establish that a new source can be registered, not that a replacement survives overlapping cleanup or that an existing cursor can resume correctly. Land one fix for #4909, not both.
|
👋 We’ve requested changes on this PR. Once you’ve addressed the feedback, please mark it ready for review. |
Closing a TUI tab runs the supervisor's cleanup off-lock, so detaching immediately removed the runtimeSessions entry that AddMessage and UpdateMessage probe to reject edits while the tab's stream is still running. Mark the attachment closing and drop the entry only once the stream releases its docker#3590 guard, so a REST edit cannot interleave with the stream it has to be rejected against. Bind the detach to the attachment it was created for instead of the session ID: AttachRuntime returns a *RuntimeAttachment handle whose Detach no-ops for a stale cleanup, and registration/teardown is serialised under sm.mux, so a same-ID replacement keeps its runtime registration, injector, key cache, event log and recall handler. A reused runtime also keeps the recall handler installed by the replacement. Continue the event-log sequence across a same-ID reattachment so a client reconnecting with its old Last-Event-ID does not silently filter out the replacement's events, and signal a gap when a cursor cannot belong to the current log. Resolve serve mcp --attach discovery against the run's active sessions so a closed initial tab is not advertised as a live target: an explicit session ID that is no longer attached fails clearly, while run-level discovery picks the only live session or lists the candidates. Cover the real lifecycle: closing an actual initial tab and an actual spawned tab through supervisor.CloseSession must detach both from the serving manager, and the listener test uses an injected temporary run registry. Signed-off-by: PerryLink <novelnexusai@outlook.com>
|
Thanks — reworked in [blocking] Preserve the #3590 busy guard until the old stream stops The ID-only [blocking] Bind cleanup to the attachment that owns it The handle is the attachment identity. [blocking] Lifecycle regression coverage for real initial and spawned tabs
[should-fix] SSE cursors on same-ID reattach A log recreated for a reattached session continues the previous log's sequence [should-fix] Do not advertise the closed initial tab as a live target
[should-fix] Isolate the listener test from the real run registry
Validation, matching the CI tools: On the overlap with #4930: understood — one fix for #4909, not both. This |
In
--listenmode every TUI tab attaches its runtime to the serving session manager (AttachRuntime), but closing a tab only cancels the supervisor's session context: the session manager drops entries only on session deletion (DeleteSession→finishSessionDeletion), so per closed tab the runtime, the session, the attach context (context.WithCancel(context.WithoutCancel(ctx))), the follow-up injector closure and the recall handler all stay reachable for the process lifetime (#4909).Fix
SessionManager.DetachRuntime(sessionID), symmetric withAttachRuntime: removes the runtime entry, cancels the attach context, clears the runtime's recall handler and drops the follow-up injector, key cache and the session's event log. The persisted session is untouched, and — unlikeDeleteSession— the event log is not marked permanently deleted, so the session can be attached again (a reopened tab).Supervisor.CloseSessionalready runs off the lock, now calls it, so closing a tab releases its runtime.recallCoordinatorOptreturns the detach function alongside the app option.Tests
pkg/server/session_detach_test.go:TestDetachRuntime_CleansUpAttachedState— after attach + injector + event source: the runtime entry is gone, the attach context is cancelled, the recall handler is cleared, the injector and event log are dropped; the stored session survives, and re-attaching works (the event log is not blacklisted the way deletion blacklists it).TestDetachRuntime_UnknownSessionIsNoop.go test ./pkg/server/ ./pkg/tui/service/supervisor/ ./cmd/root/passes, andgo vet ./pkg/server/ ./cmd/root/is clean.Closes #4909