Skip to content

feat(session): reuse existing tabs and automate session cleanup - #332

Draft
lymerin wants to merge 3 commits into
Tencent:mainfrom
lymerin:codex/279-session-lifecycle
Draft

lymerin wants to merge 3 commits into
Tencent:mainfrom
lymerin:codex/279-session-lifecycle

Conversation

@lymerin

@lymerin lymerin commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #279.

This PR builds on #306’s shared-window session support. It includes the #306 foundation commit and adds the ownership and cleanup changes for #279.

Issue coverage

Reuse an existing window or tab

  • session start --in-window creates a controlled tab in a normal user window without opening an Agent Window. This is provided by feat(session): add local shared-window sessions #306.
  • session start --in-window --tab-id <id> now claims an already-open tab in its own user window after the existing borrow confirmation. Startup creates neither a window nor a tab, and stopping the session releases control without moving or closing the borrowed tab.
  • Control remains limited to tabs explicitly created or borrowed by the session. Sharing a window does not grant access to its other user tabs.

Stop sessions when ownership ends

  • DSH starts its sessions with --ephemeral and a recoverable request ID. It renews each active session’s 45-second owner lease every 10 seconds.
  • When the owning agent’s turn ends (agent/status=idle), the plugin starts cleanup for that agent’s sessions. Plugin unload and conversation archival also start cleanup. If the plugin process exits without cleanup, the daemon stops the session after its lease expires. Ordinary CLI sessions remain persistent unless --ephemeral is selected.
  • Cancelling a start triggers cleanup through its request ID, including when the CLI exits before receiving a result. Cancelling an in-flight browser operation forwards cancellation to its RPC; the owning sessions are stopped when the agent turn ends.
  • Cleanup returns borrowed tabs, closes agent-created tabs, closes a dedicated Agent Window where appropriate, and removes the session record after confirmed cleanup. A shared user window stays open.

Recover interrupted starts and failed cleanup

  • A delayed start cannot discard an earlier cancellation. The daemon retains ownership until browser creation and cleanup settle.
  • A failed startup or stop remains reachable by its original request and session identity for retry. The existing plugin journal resumes abandoned cleanup on startup; the daemon also reaps expired leases and retries failed cleanup. An unconfirmed cleanup is not reported as closed.

Diagnose stale sessions

session list now reports owner_kind, lifecycle_state, and lease_expires_at_ms alongside the existing session identity and container information. Lifecycle states distinguish active, starting, cancelling, and failed cleanup. Request tokens are not exposed in the session list.

Validation

  • cargo check -p bsk --tests, Rust formatting, and diff checks passed.
  • Focused extension shared-window and DSH lifecycle tests passed. The profile-selection and tool tests passed together: 76/76.
  • Both cancelled-start cleanup scenarios passed as IPC integration tests, separately and together in a serial run: 2/2. The lease and session list output assertions passed.
  • Full workspace and live-browser regression runs were not performed for this revision.

@lymerin
lymerin force-pushed the codex/279-session-lifecycle branch 2 times, most recently from e01efb0 to 66b13db Compare September 24, 2026 15:48
@lymerin
lymerin force-pushed the codex/279-session-lifecycle branch from 66b13db to 875fc4d Compare September 29, 2026 06:45
@lymerin
lymerin marked this pull request as draft October 2, 2026 14:26

This branch has not been deployed

No deployments
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.

Session does not auto-disconnect and cannot reuse an already-open tab/window | session 不会自动断开,且不能复用已打开页签

1 participant