Repository navigation
fix(remote): serve empty history for a session the agent no longer has - #590
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
revision = -1("reserve event storage before the first prompt, without listing an empty transcript",agent/src/session/sqlite_store.rs), andcontains()requiresrevision >= 0, so the Agent itself reportssession not found; orThe thread's
last_message_atisNULLand 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'ssession not foundrejection 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 (
syncEnginelane never establishes →timelinePendingstays true), so the empty state was never shown.get_staterejected 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 thebeforetail 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_sessionalready 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_statedrives the real bridge + mock agent:before), the forward read andget_stateall answer as success with no rows and a terminal cursor;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 warningsunderdesktop/src-tauri: clean.cargo test(desktop backend): the new test and the neighbouringremote::*/remote_host::businesshistory 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.