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

Aperta
#91,087 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
area:cowork bug has repro platform:windows
Lingua principale
Python
Stelle
145k
Fork
23.1k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

## 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_

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend, cli, distributed-systems
Tipo di issue
Bug
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.