Skip to content

fix(agent): a freshly created conversation is present in its own database - #1209

Merged
huichen merged 3 commits into
mainfrom
fix/presence-placeholder-present
Oct 19, 2026
Merged

huichen merged 3 commits into
mainfrom
fix/presence-placeholder-present

Conversation

@huichen

@huichen huichen commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

The deadlock

ServerSession::new → configure_journal → bind_events writes a revision=-1 placeholder 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_sessions deliberately hides that row.

get_session_presence then asked whether the id was revision>=0 (agent/src/session/presence.rs), so a brand-new conversation answered missing. The Desktop source fence added in #1186 reads missing as "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 carrying Conversation source is unavailable.

The one predicate that changed

- "SELECT EXISTS(SELECT 1 FROM sessions WHERE id=?1 AND revision>=0),
+ "SELECT EXISTS(SELECT 1 FROM sessions WHERE id=?1),      -- membership: any row
+  EXISTS(SELECT 1 FROM sessions WHERE id=?1 AND revision>=0),  -- integrity guard only
   EXISTS(SELECT 1 FROM session_tombstones WHERE session_id=?1),
   EXISTS(SELECT 1 FROM legacy_imports WHERE session_id=?1 AND status='skipped')",

plus let present = has_row && !deleted;

Two rules keep the widening from being a loosening:

  1. A tombstone still wins. A deleted identity cannot be re-created, but constructing the refused session leaves its placeholder row behind; that leftover must not resurrect the id, so deleted is answered whenever a tombstone exists.
  2. The integrity guard is unchanged in meaning. 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 — previously present was revision>=0.

list_sessions and storage_health keep revision>=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=-1 placeholder row is written by this database's own bind_events and 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 answers missing.

Both ends are pinned by tests:

  • rpc::tests::a_just_created_session_is_present_before_its_first_turn — end-to-end through handle_command_internal: build the session the way new_session does (real ServerSession construction, which writes the placeholder), ask get_session_presence, require present; assert list_sessions still hides it; and assert an id with no row at all still reads missing.
  • agent_bridge::presence::tests::a_session_with_no_row_is_still_refused_as_unavailable (Desktop) — a missing verdict still produces Conversation source is unavailable, and records no thread-source binding.

Both were falsified once: restoring revision>=0 makes the first fail with left: "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_failures fails on a clean origin/main checkout too.

Not in this PR

  • The two empty conversations are not deleted (deleting data is the user's call). They hold no entries and are not listed.
  • The 386-failed-run resend loop is not fixed here; it is being diagnosed and filed separately.

Effect

Same as every agent-side fix: takes effect when the running agent binary is replaced.

…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
huichen enabled auto-merge (squash) October 19, 2026 04:00
@huichen
huichen merged commit e97f454 into main Oct 19, 2026
30 of 32 checks passed
@huichen
huichen deleted the fix/presence-placeholder-present branch October 19, 2026 04:45
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