Repository navigation
fix(agent): a freshly created conversation is present in its own database - #1209
Merged
Merged
Conversation
…base `bind_events` reserves a new session's event storage with a `revision=-1` placeholder row (`sqlite_store/events.rs`), but `presence` answered `revision>=0`, so `get_session_presence` reported a brand-new conversation as `missing`. The Desktop source fence (#1186) reads `missing` as "this id is not in your database" and refuses to prompt (`agent_bridge/prompt.rs`), so the first turn could never land and the revision could never advance — every new conversation was permanently unusable (measured on two threads: 386 failed runs, zero entries). Presence now counts any row for the id as proof of membership, with a tombstone still winning (a deleted identity refuses re-creation but leaves its placeholder behind, which must not resurrect it). The integrity guard and `list_sessions` keep their `revision>=0` rule, so an empty session stays hidden until its first turn lands.
huichen
enabled auto-merge (squash)
October 19, 2026 04:00
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.
The deadlock
ServerSession::new→configure_journal→bind_eventswrites arevision=-1placeholder row for a new session (agent/src/session/sqlite_store/events.rs:192), so that its event journal has storage before the first transcript entry exists.list_sessionsdeliberately hides that row.get_session_presencethen asked whether the id wasrevision>=0(agent/src/session/presence.rs), so a brand-new conversation answeredmissing. The Desktop source fence added in #1186 readsmissingas "this id belongs to another database" and refuses to prompt (desktop/src-tauri/src/agent_bridge/prompt.rs:281). The first turn could never land, so the revision could never advance.Measured on this machine: two conversations created at 11:38 and 11:40 today —
sessions.revision = -1, zero entries, zero run events, and 386 failed runs carryingConversation source is unavailable.The one predicate that changed
plus
let present = has_row && !deleted;Two rules keep the widening from being a loosening:
deletedis answered whenever a tombstone exists.live_row && deleted → "session catalogue conflicts with a deletion tombstone"now checks the real (revision>=0) row only, which is exactly what it checked before — previouslypresentwasrevision>=0.list_sessionsandstorage_healthkeeprevision>=0, so an empty conversation stays hidden and out of the session count until its first turn lands.Why this does not weaken #1186
#1186 asks: "does this session id belong to the database I am connected to?" A
revision=-1placeholder row is written by this database's ownbind_eventsand is therefore the strongest possible yes — the id could not exist here otherwise. The case #1186 exists for — an id that belongs to a different Agent database — has no row at all here, and still answersmissing.Both ends are pinned by tests:
rpc::tests::a_just_created_session_is_present_before_its_first_turn— end-to-end throughhandle_command_internal: build the session the waynew_sessiondoes (realServerSessionconstruction, which writes the placeholder), askget_session_presence, requirepresent; assertlist_sessionsstill hides it; and assert an id with no row at all still readsmissing.agent_bridge::presence::tests::a_session_with_no_row_is_still_refused_as_unavailable(Desktop) — amissingverdict still producesConversation source is unavailable, and records no thread-source binding.Both were falsified once: restoring
revision>=0makes the first fail withleft: "missing"; disabling the fence check makes the second fail on the error assertion.Verification
cargo fmt --check,cargo clippy -p future-agent --all-targets -- -D warnings,cargo clippy --features gui --all-targets -- -D warnings(desktop),cargo test -p future-agent --lib session::(428 passed) and--lib rpc::(735 passed) on the pinned 1.97 toolchain.One failure is pre-existing on this host and unrelated:
grpc::tests::the_public_serve_wrappers_bind_serve_and_report_bind_failuresfails on a cleanorigin/maincheckout too.Not in this PR
Effect
Same as every agent-side fix: takes effect when the running agent binary is replaced.