Skip to content

fix(remote): serve empty history for a session the agent no longer has - #590

Merged
huichen merged 2 commits into
mainfrom
claude/remote-empty-session-history
Sep 13, 2026
Merged

huichen merged 2 commits into
mainfrom
claude/remote-empty-session-history

Conversation

@huichen

@huichen huichen commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

Problem

Opening a conversation whose agent session no longer has a transcript left the Android/iOS app stuck on 正在加载消息… ("loading messages") forever.

The desktop sidebar already answers such a thread with empty history, so it looked fine in the GUI — only the phone hung.

Why the session is empty

A thread can be bound to a session id the Agent holds no transcript for:

  • it was created but never prompted — the Agent keeps that row at revision = -1 ("reserve event storage before the first prompt, without listing an empty transcript", agent/src/session/sqlite_store.rs), and contains() requires revision >= 0, so the Agent itself reports session not found; or
  • the Agent dropped it (restart / environment switch).

The thread's last_message_at is NULL and it has no runs — it is genuinely empty, not a loading failure.

Why the phone hung

The desktop's local UI path (commands/threads.rs) special-cases the Agent's session not found rejection into an empty page / empty agent state. The remote bridge (remote_host/business.rs) that serves the phone did not: it forwarded the rejection as a failed reply.

The mobile timeline treats a failed history page as "not loaded yet" and only schedules another retry (syncEngine lane never establishes → timelinePending stays true), so the empty state was never shown. get_state rejected the same way, and that aborts the reconcile before history is even requested.

Fix

Map the missing identity to empty history/state in the remote bridge, mirroring the desktop UI:

  • get_session_entries (both the before tail page and the forward page) → {"entries": [], "hasMore": false, "nextOffset": 0}
  • get_state → {} (no model, no active run)

Every other rejection is still surfaced unchanged — a genuine agent failure must not look like an empty conversation.

Nothing changes on the mobile side. ensure_agent_session already recreates and re-binds the session on the next prompt, so the empty answer is not sticky.

Tests

a_missing_agent_session_reads_as_empty_history_and_state drives the real bridge + mock agent:

  • the tail read (before), the forward read and get_state all answer as success with no rows and a terminal cursor;
  • a non-missing failure (agent exploded) still comes back as a rejection.

Verified the test fails on the unmodified bridge (assertion left: Bool(false), right: Bool(true)) and passes with the fix.

Checks

  • cargo fmt --check + cargo clippy --all-targets -- -D warnings under desktop/src-tauri: clean.
  • cargo test (desktop backend): the new test and the neighbouring remote::* / remote_host::business history tests pass. 26 unrelated tests fail on Windows both with and without this change (git_review, shadow_review, agent_bridge::import, transfer-loop timings) — pre-existing environment failures; CI runs that group on Linux.

A thread can be bound to a session id the Agent holds no transcript for:
one created but never prompted (the Agent keeps that row at `revision = -1`,
so `contains()` refuses it) or one dropped by a restart. The desktop UI
already answers such a thread with empty history and recreates the session
on the next prompt, but the remote bridge forwarded the Agent's
"session not found" rejection to the phone.

The mobile timeline treats a failed history page as "not loaded yet" and
only schedules another retry, so opening such a thread sat in "loading
messages" forever. `get_state` rejected the same way, which aborts the
reconcile before history is ever requested.

Map the missing identity to empty history/state in the remote bridge and
keep every other failure a rejection.
@huichen
huichen enabled auto-merge (squash) September 13, 2026 08:57
@huichen
huichen merged commit 8fe7825 into main Sep 13, 2026
12 checks passed
@huichen
huichen deleted the claude/remote-empty-session-history branch September 13, 2026 09:03
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.

1 participant