anthropics / anthropics/claude-code

Remote Control: sessions served by a crashed server are never re-claimed — restart doesn't restore them and messages to disconnected sessions queue forever

Đang mở
#91,087 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
area:cowork bug has repro platform:windows
Ngôn ngữ chính
Python
Star
145k
Fork
23.1k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

## Environment

- Claude Code v2.1.251, native installer (`~/.local/bin/claude.exe`)
- Windows 11 Home 10.0.26200
- claude.ai subscription login, server mode (`claude remote-control`)

## Summary

When a `claude remote-control` server dies uncleanly (crash, or force-kill), the sessions it was serving lose their backend assignment. After that:

1. **Restarting `claude remote-control` in the same directory does NOT bring those sessions back**, contradicting the docs ("brings back every session the server was serving", [Resume sessions after stopping the server](https://code.claude.com/docs/en/remote-control#resume-sessions-after-stopping-the-server)). Only the single session recorded in the project's `bridge-pointer.json` is re-adopted at startup.
2. **Messages sent from claude.ai to such a disconnected session queue forever** ("Connecting…" / "not connected to \"). No later registration or work-poll ever re-queues the session, so it is never served again. The docs' crash advice ("send it a message from a connected device. Claude Code serves it again") only works while the session's assignment is intact — not after a crash, which is when it matters most.
3. The only CLI recovery is `claude remote-control --session-id `, one session at a time — exclusive by design (per-environment lock + single-session mode), so with several stale sessions you must serially swap dedicated hosts, and an unclean swap breaks the previously reattached session again.

## Steps to reproduce

1. `claude remote-control` in a project directory; attach 2–3 sessions from claude.ai; let them go idle.
2. Kill the server process forcefully (simulates the organic crash we hit: the TUI printed `Session failed: Process exited with error cse_…`, later the process died; `Capacity: 0/32`).
3. Run `claude remote-control` again in the same directory.
4. In claude.ai, all sessions except the bridge-pointer one stay "not connected to \". Messages sent to them are held indefinitely; the new server's debug log shows only empty `GET .../work/poll` responses for them.

## Expected

After a restart in the same directory — graceful stop or crash — previously served sessions are re-claimed (or at minimum, a queued message triggers re-serving, as documented for crashed sessions).

## Actual

Only the pointer session is adopted. Restart debug log (`--debug-file`):

```
[bridge:init] Found prior environment env_01JX83s1q4BtT415SpMxEm5z in pointer (ageMs=67284); requesting reuse on registration
[bridge:api] POST /v1/environments/env_01JX83s1q4BtT415SpMxEm5z/bridge/reconnect session_id=[REDACTED]
[bridge:api] POST .../bridge/reconnect -> 200
[bridge:init] Adopted session cse_01MRnoE7fRhYtAAk8tW3U4UW re-queued via bridge/reconnect
[bridge:init] Registered, server environmentId=env_01JX83s1q4BtT415SpMxEm5z
```

For every other previously served session: no reconnect is attempted at registration, and nothing ever serves them again.

## Workaround (proves the backend supports this)

Manually calling the same endpoint the CLI uses for the pointer session — but for each disconnected session — immediately re-queues it onto the already-running server; a worker spawns within ~10 s and the session shows connected again on claude.ai:

```
POST /v1/environments//bridge/reconnect
{"session_id": "cse_…"}
anthropic-beta: oauth-2025-04-20,environments-2025-11-01
```

Suggestion: on registration, re-queue every session still recorded for that environment/directory (server- or client-side), or persist the serving set locally and replay `bridge/reconnect` for each entry on startup. A `--reconnect-all` (or `--reconnect `) flag on `claude remote-control` would also cover it.

## Related observations from the same incident

- One auto-created session's worker crash-loops on resume: the child exits after ~1 s with `CCRClient: Epoch mismatch (409, reason=session_not_active), shutting down`, surfacing in the server TUI as `Session failed: Process exited with error cse_01KC7tyHzRyCGYyF7964dHqB`. This failure preceded the original server crash.
- One pre-created session ended up with **no `environment_id`** server-side. `--session-id`/`--continue` for it fail with `Error: Session … has no environment_id. It may never have been attached to a bridge.`, and `bridge/reconnect` answers `Session not found`. It was later auto-archived — such a session is permanently unrecoverable, taking any queued messages with it.

🤖 Filed with [Claude Code](https://claude.com/claude-code) after live-debugging the incident.

_The real me: claude (Fable) debugging claude... pretty pretty good ! No way I would have found the workaround and couldn't lose all these sessions_

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Start at the `claude remote-control` startup and registration path, then inspect how `bridge-pointer.json` leads to the `bridge/reconnect` request. Compare that single-session flow with the server's handling of other previously served sessions and queued messages. Done means a restart re-queues all recoverable sessions for the environment and their queued messages resume serving.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
backend, cli, distributed-systems
Loại issue
Lỗi
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.