Skip to content

desktop: stuck session stays running; interrupt returns false and delete times out #62442

Open

Description

@kochetovdv

Description

opencode-stuck-session-bug.md

Plugins

none

OpenCode version

2.2.5

Steps to reproduce

active → running, interrupt → false, DELETE → 499 за 61,7

Screenshot

Image Image

Operating System

Windows 11

Terminal

powershell

Activity

  1. opencodejr commented on Nov 6, 2026

    @opencodejr
    Contributor

    Thanks for the detailed write-up. I tried to reproduce this on 2.2.5 using the CLI service on Linux with a simulated model. I tested these first-turn cases:

    • the model stream stalls with no finish or error
    • reasoning streams continuously
    • a long-running bash tool call
    • the stream disconnects mid-response, which triggers retries

    In every case POST /api/session/{id}/interrupt returned {"interrupted":true} the first time. The session left /api/session/active within a few seconds, and DELETE returned right away. The second interrupt returned false only because nothing was running any more, so I couldn't get the session stuck the way you describe.

    In your case the server seems to still list the session as running after it has stopped (or is stopping), and delete then waits for a cleanup that never finishes. To find what causes that, it would help to know:

    1. Which provider and model the stuck session used.
    2. Whether you clicked Stop before calling /interrupt yourself. If you did, what did the UI show when you clicked it, and did the first interrupt return true?
    3. Whether the first turn was running a tool (for example a shell command) when it got stuck.
    4. The service log from when that first prompt was sent until you tried Stop, especially any ERROR or Failed to drain Session lines. Please redact as you did before.
    5. Whether it still happens on 2.2.6 or newer, and whether restarting the app or background service clears it.

    You can reply here with the details, or edit the issue; if you edit it, please also leave a comment saying you've updated it so we know when you're done.

    Related issues, most likely first:

  2. kochetovdv commented on Nov 7, 2026

    @kochetovdv
    Author

    Follow-up with more data after the session became accessible again.

    Provider / model: deepseek / deepseek-flash, variant high. No plugins configured.

    The session is no longer running: it is now outcome=interrupted, time.idle=2026-11-06T22:40:56.865Z. The stale active entry cleared only after an interrupt/compaction; GET /api/session/active no longer lists it.

    Messages in the session (UTC):

    • 20:59:04.949Z — one user message (the initial prompt).
    • 22:19:40.929Z — idle with outcome=interrupted.
    • 22:19:40.941Z — manual compaction, status completed; the compaction model call produced 675 input / 492 output / 64 reasoning tokens.
    • 22:38:00.589Z — system date update; 22:38:00.595Z — a second user message (start).
    • 22:40:56.865Z — idle with outcome=interrupted.
    • There is no assistant message and no tool message for either turn; only user/system/idle/compaction entries.

    Stop / interrupt:

    • The user pressed Stop in the UI. I do not have the exact UI text.
    • The shared service log contains no /interrupt request from the UI before my manual call at 22:17:40Z. My manual POST /interrupt returned {"interrupted":false}; the session then became idle/interrupted at 22:19:40Z.
    • So either the UI Stop reaches a different path/process, or its request is not logged by the shared service. The first interrupt I can see did not return true.

    Tool activity: none. The only activity in the target project around the initial prompt was the context snapshot:

    20:59:04.978Z ... git rev-parse ... cwd=<project>
    20:59:05.050Z ... git diff-files ... work-tree=<project>
    20:59:16.999Z ... git update-index ... cwd=<project>
    

    No bash/tool call is attached to the session. This looks like a step before the model call, not a long-running shell command.

    Log window 20:59–22:12Z: no level=ERROR and no Failed to drain Session. The only target-related HTTP line is DELETE /api/session/<redacted> with http.span=61727 and status=499. My manual interrupt is logged as a CLI request but has no matching response line in the shared service log.

    Project/location clue: the stuck session is in the main repository <project> (a large repo with many worktrees). A session in a worktree <worktree> is currently working normally with the same model/provider. New sessions in the main repository reproduce the same “no assistant message, stays busy” behavior (the user reports three today). This points more to a pre-model context/snapshot step in the main project than to the provider.

    Not yet verified: 2.2.6+ and a full app/service restart. The user is ready to test both; I will update after that.

  3. opencodejr commented on Nov 7, 2026

    @opencodejr
    Contributor

    Thanks for the follow-up, the snapshot detail helped a lot.

    I tried that case on 2.2.5 (Linux, CLI service, simulated model, snapshots on). I made the snapshot step's git update-index hang forever, standing in for a very large repository. The session stayed running as you describe. However, here the first POST /interrupt returned {"interrupted":true}, the session left /api/session/active within a few seconds, and DELETE returned immediately. The same happened when the hung git process ignored termination signals.

    In 2.2.5, interrupt returns false while a session still shows as running only when a stop has already started and its cleanup never finishes. That fits what you saw: your first visible interrupt already returned false, so the UI's Stop probably did start a stop, even though it isn't in the service log. Cleanup then seems to get stuck on Windows, possibly waiting for the stalled git process. I can't test Windows, the desktop app or a large repo with worktrees here, so this needs a maintainer with that setup.

    Things that would help narrow it down:

    • Turn off snapshots for that project. Add "snapshots": false to its opencode.jsonc and see whether new sessions in the main repository start normally. If they do, that confirms the snapshot step is the trigger, and it also works around the problem for now. Undo/revert of file changes won't work while snapshots are off.
    • Check for leftover git processes. While a session is stuck, see whether a git.exe process (e.g. update-index or add) is still running under the OpenCode service, and whether it uses CPU.
    • Results on 2.2.6+ and after a full app/service restart, which you mentioned you'll try.

    Related issues, most likely first:

  4. kochetovdv commented on Nov 7, 2026

    @kochetovdv
    Author

    One more data point, and a strong lead. The stuck session is in a large main repository; a session in a worktree with the same model/provider works normally.

    Main repository measurements:

    • 103 git worktrees.
    • git ls-files --others --exclude-standard enumerates 197,306 untracked paths and takes 10.6 s just to list them.
    • Top-level generated directories: .tmp 74.7 GB, outputs 17.8 GB, .git 9.0 GB, scratchpad 7.3 GB, local-archive 3.0 GB, .codex-worktrees 2.25 GB.
    • .gitignore ignores node_modules/ and dist/; .git/info/exclude ignores .tmp/ and some worktree dirs, but not outputs/, scratchpad/, .audit-*, _out/, etc.
    • git status --porcelain -uno is fast (110 ms), so ordinary tracked status is not the problem. The untracked scan/snapshot path is.
    • The stuck session's only pre-model activity is OpenCode's snapshot git commands (git rev-parse, git diff-files, git update-index) in that working tree; no assistant or tool message follows.

    Hypothesis: the pre-model snapshot over this large untracked tree is the step that hangs or never finishes. That would explain why the service accepts requests and creates sessions, but the turn stalls before any model output, and why a worktree session works. The large .tmp directory is excluded from the untracked scan, but it is still 74.7 GB on disk and may add I/O pressure.

    Still pending: local excludes/cleanup, 2.2.6, and a full restart. I will update after testing.

  5. kochetovdv commented on Nov 7, 2026

    @kochetovdv
    Author

    Before/after local exclude on the main repository:

    • Before: git ls-files --others --exclude-standard returned 197,306 paths in 10.6 s.
    • Added local-only .git/info/exclude entries for generated/untracked trees (outputs/, _out/, _audit/, _review_out/, _to_delete/, .audit-20261105/, .qa-evidence/, .kimi-worktrees/, .review-worktrees/, .recovery-worktrees/, .worktrees/, .tmp-155-test/, .tmp-169-gocache/, tmp_pg_dumps/, tmp_scripts/, scratchpad/, __pycache__/).
    • After: 579 paths in 119 ms.

    This strongly supports the pre-model snapshot hypothesis: the first turn was spending its time enumerating a huge untracked tree before the model call. Next I will test a new session in the main project and report whether the turn reaches the model, and whether Stop/Delete behave normally.

  6. kochetovdv commented on Nov 7, 2026

    @kochetovdv
    Author

    Confirmed: after adding local-only excludes for generated/untracked trees in the main repository's .git/info/exclude, a new session in that repository completed normally and produced an assistant response.

    Before/after on the same working tree:

    • Before: 197,306 untracked paths; git ls-files --others --exclude-standard took 10.6 s.
    • After: 579 paths; the same command took 119 ms.
    • A new session in the affected repository reached the model and answered; no stuck running state.

    Root cause / impact: the pre-model snapshot enumerates a very large untracked working tree. The 10.6 s enumeration alone is not 79 minutes, so the snapshot/update path likely does additional work (index/copy) and can effectively hang. The session then has no assistant output and stays busy; Stop/Delete wait on that step. A session in a small worktree with the same model/provider works, which matches this explanation.

    This looks like a product-level robustness issue rather than only user configuration: the snapshot should bound or ignore large untracked trees, expose progress/timeout, and not leave the session permanently running. The local .git/info/exclude is a workaround; no tracked files were changed.

    I suggest keeping this issue open for a snapshot-side fix and/or documentation. If you prefer to treat it as an environment/usage issue, close with that rationale; otherwise I can provide a DEBUG log or a minimal reproduction repository with many untracked files.

  7. MaxToxin commented on Nov 29, 2026

    @MaxToxin

    Found the root cause on Windows 11 (OpenCode desktop 2.4.2), same symptoms: interrupt returns false, the session stays running, DELETE /api/session/{id} → 499, and POST /api/session/{id}/revert/stage → 499 after ~30 s.

    What produced it here: the session was opened in the home directory (C:\Users\Toxin), so the snapshot repository's worktree was the whole user profile:

    ~/.local/share/opencode/snapshot/global/<hash>/config -> worktree = C:/Users/Toxin
    

    That store had grown to 27 GB / 2.6M files / 821,604 loose objects. Since Snapshot.capture() runs before llm.stream() (as in #48657), every turn spent 120-160 s in git before the model was contacted at all — which is also why the provider saw no matching request. revert/stage never finished inside the 30 s client timeout, hence 499.

    Measured from ~/.local/share/opencode/opencode.db (time.firstToken - time.created): median 148 s in the home-dir session vs 1-10 s in sessions opened in project directories, same model, same provider, same hours. On 2026-11-28 between 14:00 and 16:50 UTC+3 every single turn was 121-202 s.

    The session also stayed claimed: session_v2.time_busy and time_suspended kept the interruption timestamp while no run existed, so interrupt did nothing. Clearing time_busy / time_suspended / idle_outcome in the DB released it; nothing in the UI could.

    Local workaround: "snapshots": false in the global config plus deleting the snapshot store (freed 26.5 GB). TTFT is back to 1-4 s.

    Suggestion: skip the capture (and release the claim) when the worktree is the user's home directory or the untracked set exceeds a threshold, and clear stale time_busy on startup.


    По-русски

    Нашёл причину на Windows 11 (OpenCode desktop 2.4.2), симптомы те же: interrupt возвращает false, сессия остаётся в состоянии running, DELETE /api/session/{id} → 499, а POST /api/session/{id}/revert/stage → 499 примерно через 30 секунд.

    Из-за чего это здесь: сессия была открыта в домашнем каталоге (C:\Users\Toxin), поэтому рабочей копией репозитория снимков оказался весь профиль пользователя:

    ~/.local/share/opencode/snapshot/global/<hash>/config -> worktree = C:/Users/Toxin
    

    Это хранилище разрослось до 27 ГБ / 2,6 млн файлов / 821 604 объектов. Поскольку Snapshot.capture() выполняется до llm.stream() (как описано в #48657), каждый ход тратил 120-160 секунд на git ещё до обращения к модели — поэтому провайдер и не видел соответствующего запроса. revert/stage не успевал уложиться в 30-секундный таймаут клиента, отсюда 499.

    Замеры из ~/.local/share/opencode/opencode.db (time.firstToken - time.created): медиана 148 с в сессии из домашнего каталога против 1-10 с в сессиях, открытых в каталогах проектов, при той же модели, том же провайдере и в те же часы. 28.11.2026 с 14:00 до 16:50 (UTC+3) каждый ход занимал 121-202 секунды.

    Кроме того, сессия оставалась занятой: session_v2.time_busy и time_suspended сохраняли метку времени прерывания, хотя запущенного прогона не было, поэтому interrupt ничего не делал. Сброс time_busy / time_suspended / idle_outcome в базе освободил её; через интерфейс сделать это было нельзя.

    Локальный обходной путь: "snapshots": false в глобальном конфиге и удаление хранилища снимков (освободило 26,5 ГБ). TTFT вернулся к 1-4 секундам.

    Предложение: пропускать снимок (и освобождать claim), когда рабочая копия — домашний каталог пользователя или количество неотслеживаемых файлов превышает порог, а также сбрасывать зависший time_busy при старте.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions