Closing a TUI tab leaks its runtime, session and context in --listen mode

オープン
#4,909 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@pcbeingused333 がすでに取り組んでいます。

2026年11月14日 から。

  • #4930 @pcbeingused333 による — オープン
  • #4931 @PerryLink による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go
領域
backend, cli

調査の方向性

Read AttachRuntime (pkg/server/session_manager.go around lines 451-463) next to finishSessionDeletion (lines 958-992), since the detach path should mirror the cleanup there. Then check the tab-close flow in Supervisor.CloseSession (pkg/tui/service/supervisor/supervisor.go:308) and the injector registration in cmd/root/run_listen.go:49. Done means a closed tab disappears from GET /api/sessions, its context is cancelled, and the persisted session still exists.

索引モデルが issue の本文から書いたものです。

説明

area/api area/runtime area/sessions area/tui
Description

In --listen mode every TUI tab attaches its runtime to the serving session
manager, and there is no detach path. The only code that removes an entry
from runtimeSessions is session deletion
(DeleteSession/BatchDeleteSessions → finishSessionDeletion,
pkg/server/session_manager.go:958-992), while closing a tab goes through
Supervisor.CloseSession (pkg/tui/service/supervisor/supervisor.go:308),
which cancels the TUI-local context and removes the tab from the supervisor
— but is not a session deletion, so none of that cleanup ever runs for a
closed tab.

Per closed tab, the following stay reachable for the life of the process:

  • the runtime.Runtime and session.Session held by the activeRuntimes
    entry (session_manager.go:451-463);
  • the context created by context.WithCancel(context.WithoutCancel(ctx))
    inside AttachRuntime — its cancel is only invoked on session deletion,
    so the whole context tree is retained;
  • the follow-up injector registered at cmd/root/run_listen.go:49
    (sm.RegisterFollowUpInjector(sess.ID, a.InjectUserMessage)), a closure
    that keeps the tab's *app.App reachable;
  • the recall handler AttachRuntime installs on the runtime
    (session_manager.go:460).

A long-running --listen process that cycles through tabs therefore
accumulates one runtime+session+context set per closed tab, none of it
collectable. A single CLI run is bounded by process exit; the same
unbounded accumulation applies to embedders that attach runtimes to a
serve api session manager.

Expected Behavior

Closing a tab releases what the tab attached to the session manager: the
runtimeSessions entry is removed, its context cancelled, and the follow-up
injector / recall handler dropped — while the persisted session itself stays
(tab close ≠ session delete).

Actual Behavior

Closed tabs keep their runtime, session and context attached until the
process exits. GET /api/sessions keeps listing tabs that were closed,
because GetActiveSessions ranges over runtimeSessions
(session_manager.go:505-510).

Steps to Reproduce
  1. docker-agent run config.yaml --listen 127.0.0.1:8080
  2. In the TUI, open several new tabs (each spawned tab attaches to the
    serving manager — see the wiring comment at cmd/root/run_listen.go:31-43)
  3. Close the tabs
  4. curl http://127.0.0.1:8080/api/sessions — every closed tab still shows
    up as an active session, and the underlying runtime/session/context are
    never released
Docker Agent version

docker-agent version dev Commit: 3c9f6d4

OS & terminal

No response

Model used

No response

Error output

Screenshots

No response

Additional context

Verified on current main (3c9f6d45b): no DetachRuntime exists anywhere
in the tree, and runtimeSessions.Delete has exactly one call site (session
deletion).

Suggested direction: a DetachRuntime(sessionID) symmetric with
AttachRuntime, called from the tab-close path — remove the entry, call
cancel(), and unregister the follow-up injector, recall handler and
event-log references (mirroring finishSessionDeletion's cleanup at
session_manager.go:989-992), leaving the persisted session intact. The
locker AttachRuntime returns carries the #3590 stream-guard contract
(callers hold it across direct RunStream calls), so a detach path must
keep that contract working for still-attached runtimes.

主要言語
Go
スター
4.7k
フォーク
565
平均マージ
18時間 52分
マージ済み PR(30日)
221

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

docker/docker-agent のほかの issue

docker/docker-agent の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。