Skip to content

fix: preserve historical databases and make session recovery resumable - #1186

Merged
tallcode merged 22 commits into
mainfrom
fix/database-preservation
Oct 18, 2026
Merged

tallcode merged 22 commits into
mainfrom
fix/database-preservation

Conversation

@tallcode

Copy link
Copy Markdown
Collaborator

Older Desktop databases and interrupted runs must preserve their original history and remain recoverable. This change adds verified upgrade boundaries, coordinated offline recovery, durable queued-input acceptance, and database ownership checks across Desktop history and run management.

Changes

  • Preserve unowned managed images, chat workspaces and review repositories until explicit deletion authorizes cleanup. Keep required conversation migrations independent of optional metadata failures.
  • Add a checksummed Desktop schema contract (version 3) and Agent schema 7, verified pre-upgrade SQLite snapshots including committed WAL, admission checks, and explicit failures for inconsistent or incomplete authoritative history.
  • Add future data backup|verify|restore|resume|rollback. Backups cover both stores, managed files, legacy sources and Agent configuration. Restore stages and verifies complete inventories, fences startup while incomplete, retains original preimages, and resumes safely in the persisted forward/rollback direction.
  • Persist queued acceptance receipts before acknowledgment, preserve cancelled/interrupted inputs without replaying model/tool effects, serialize fault recovery, and commit exact-run terminal outcomes before releasing failed runtime leases.
  • Rebuild disposable history indexes without rewriting authority. Healthy history reads use read transactions rather than writer reservations.
  • Bind conversations, pagination, background repair, mutation and deletion retries to verified Agent database ownership and instance identity. Preserve missing history as an explicit unavailable/read-only state. Keep orphan-run local termination and bound the entire idle confirmation to five seconds; retain the existing independent Force quit fallback.

Validation

  • Merged the latest origin/main before the pre-PR static pass.
  • cargo fmt -p future-agent -p futureos -p future-cli -p future-rpc -p future-app-settings -p future-app-workspaces --check
  • cargo clippy -p future-agent -p futureos -p future-cli -p future-rpc -p future-app-settings -p future-app-workspaces -p future-channel -p future-tui --all-targets -- -D warnings
  • cargo clippy -p futureos --no-default-features --features headless --all-targets -- -D warnings
  • Desktop npm run lint (ESLint and TypeScript); two existing JSDoc warnings, no errors.
  • Desktop and CLI debug build passed before the final main synchronization; the same GUI feature combination passed cargo check in the primary workspace.
  • git diff --check
  • Per user instruction, no local unit tests were run. Regression cases are compiled by Clippy; test execution is delegated to PR CI. Fixtures cover released/fresh/partial upgrades, failed migration commits, backup integrity and omitted files, interrupted forward/rollback renames, damaged preimages/replacements, queued acceptance recovery, concurrent exact-run cancellation, source/instance changes and stalled state RPCs.

Recovery boundaries

Offline full backup/restore requires stopped writers and restoration to the original data root; backups include credentials and external user workspaces are not copied. Existing preimage directories are retained. Unknown legacy deletion intents remain pending rather than being applied to an unproven database. Already physically deleted bytes require a prior backup or retained legacy source. New migrations do not rewrite historical message bodies; frozen migration identities remain unchanged.

@tallcode
tallcode enabled auto-merge (squash) October 18, 2026 12:31
@tallcode
tallcode merged commit e513ebc into main Oct 18, 2026
15 checks passed
@tallcode
tallcode deleted the fix/database-preservation branch October 18, 2026 13:26
huichen added a commit that referenced this pull request Oct 19, 2026
…base (#1209)

`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 added a commit that referenced this pull request Oct 19, 2026
…_health rejection (#1217)

doctor_all_checks_passed mocked a reachable agent without
get_storage_health, so on hosts whose sandbox probe passes the Sessions
check warned and the test never reached 'All checks passed.'; it stayed
green in CI only because CI's probe fails. Add the complete report and
unit tests for the incomplete-report and schema-mismatch rejection paths
so the contract added in #1186 is actually guarded.
huichen added a commit that referenced this pull request Oct 29, 2026
… off it

A remote command that times out says only that the *caller* waited. The lane
that made it wait had no record at all, so "agent slow" could not be closed:
a job that ran for 38 s, a process that was descheduled, and a lock held by the
checkpoint all looked identical from the desktop log.

1. Name the job. Every writer job may now declare itself (`call_as`), and a job
   that holds the ordered writer for >=1 s writes one row:

     storage job slow: job=commit elapsed=38120ms queued=0ms

   `elapsed` and `queued` are deliberately both present: a long `elapsed` names
   a job that must be split, a long `queued` with a short `elapsed` names a
   process that was not running (sleep, app-nap, paging) or a lane held by an
   earlier job. The cut is the same 1 s the command-side diagnostics use
   (`SLOW_COMMAND_MS`), so the two files can be read against each other. The
   idle reclaim slice and the checkpoint are timed the same way, which is what
   separates them from a writer job: the checkpoint has its own thread and
   never joins the writer's queue.

2. Shrink what holds it, without touching an atomicity contract. The compaction
   pass read its source row and each event page on the writer; those are pure
   reads, so they moved to the read lane and the writer now only publishes and
   retires. The remaining long jobs were already bounded by construction
   (reclaim slices stop at 10 ms, `content::reclaim` works in LIMIT 16/64
   steps, compaction pages by COMPACTION_PAGE_EVENT_LIMIT, legacy import commits
   per session). `delete_many` and `prune_events` are single transactions on
   purpose — splitting them would change what a failed delete leaves behind —
   so they stay as they are and the new row will say so.

3. Take the fence off the writer. `session_presence` is the first RPC of every
   remote content command, and it was read on the ordered writer because that
   was the only connection when it was written (2026-10-18, #1186): measured on
   2026-10-29, four commands released together after 18–21 s because one writer
   job was running, and two had already hit their 30 s deadline. It now runs on
   its own fence connection — not the writer, not the two-worker read pool, so
   neither a long write nor a large history page can delay it. The connection is
   opened on first use, so a process that never fences carries no extra fd.

   The trade is ordering, not freshness: a fence sees every committed write but
   not one still queued. That is why the desktop now asks once more (150 ms)
   before treating `missing` as fact — `deleted` and `import_failed` are
   verdicts and are never re-asked. Identity stays read live; it is two indexed
   rows, and a cache would only be another thing to invalidate.

4. The rest of the read-only queries that were still queued on the writer:
   `typed_events` (+ its paged sibling), `import_records`, and the compaction
   scans above. `queued_receipt`/`has_queued_receipt_run` deliberately stay:
   they are the admission check that a prompt was not already queued, so they
   must not read behind an accepted write. `load_metadata` stays for the same
   reason in the other direction — its read may repair the history index, which
   is a write.

Tests: the row's cut and field shape; a fence read answering while a writer job
holds the lane, plus the mirrored assertion that the writer lane still waits for
the job in front of it; `get_session_presence` answering under the same hold
through the RPC dispatcher; and the desktop's recheck — `missing` asked twice
(`deleted` and `present` once). `agent/src/session` (625), `agent rpc` (786),
`agent_bridge` (391) and `application` (109) are green, clippy `-D warnings` and
`make check-docs` clean on 1.99.1.
huichen added a commit that referenced this pull request Oct 29, 2026
…er; name the writer (#1415)

* refactor(packages,tui,host,agent): share config io and the TLS provider

The TUI depended on `future-host` for three calls and on `future-tasks` for
nothing at all, so `cargo test -p future-tui` linked the whole application
backend — Agent, remote stack, bundled SQLite — to reach one TLS install and
two config-file helpers. `cargo tree -p future-tui`: 318 crates → 180.

- `packages/config` (`future-config`) owns the strict-read + atomic-write
  primitives. The host keeps its `Error` boundary and the lenient-read /
  snapshot / rollback helpers it alone uses; the TUI reads and writes
  `~/.future/tui/settings.json` through the shared primitives.
- `packages/http` (`future-http`) owns the HTTP entry points and the
  process-wide TLS provider decision. `future_agent::http` re-exports them, so
  every existing caller keeps its path and Ring is chosen in one place.
- The TUI drops `future-host` and `future-tasks`, plus the stale comment that
  claimed `install_rustls_provider` was its only use of the host.

* fix(agent,host): name what holds the writer, and take the fence reads off it

A remote command that times out says only that the *caller* waited. The lane
that made it wait had no record at all, so "agent slow" could not be closed:
a job that ran for 38 s, a process that was descheduled, and a lock held by the
checkpoint all looked identical from the desktop log.

1. Name the job. Every writer job may now declare itself (`call_as`), and a job
   that holds the ordered writer for >=1 s writes one row:

     storage job slow: job=commit elapsed=38120ms queued=0ms

   `elapsed` and `queued` are deliberately both present: a long `elapsed` names
   a job that must be split, a long `queued` with a short `elapsed` names a
   process that was not running (sleep, app-nap, paging) or a lane held by an
   earlier job. The cut is the same 1 s the command-side diagnostics use
   (`SLOW_COMMAND_MS`), so the two files can be read against each other. The
   idle reclaim slice and the checkpoint are timed the same way, which is what
   separates them from a writer job: the checkpoint has its own thread and
   never joins the writer's queue.

2. Shrink what holds it, without touching an atomicity contract. The compaction
   pass read its source row and each event page on the writer; those are pure
   reads, so they moved to the read lane and the writer now only publishes and
   retires. The remaining long jobs were already bounded by construction
   (reclaim slices stop at 10 ms, `content::reclaim` works in LIMIT 16/64
   steps, compaction pages by COMPACTION_PAGE_EVENT_LIMIT, legacy import commits
   per session). `delete_many` and `prune_events` are single transactions on
   purpose — splitting them would change what a failed delete leaves behind —
   so they stay as they are and the new row will say so.

3. Take the fence off the writer. `session_presence` is the first RPC of every
   remote content command, and it was read on the ordered writer because that
   was the only connection when it was written (2026-10-18, #1186): measured on
   2026-10-29, four commands released together after 18–21 s because one writer
   job was running, and two had already hit their 30 s deadline. It now runs on
   its own fence connection — not the writer, not the two-worker read pool, so
   neither a long write nor a large history page can delay it. The connection is
   opened on first use, so a process that never fences carries no extra fd.

   The trade is ordering, not freshness: a fence sees every committed write but
   not one still queued. That is why the desktop now asks once more (150 ms)
   before treating `missing` as fact — `deleted` and `import_failed` are
   verdicts and are never re-asked. Identity stays read live; it is two indexed
   rows, and a cache would only be another thing to invalidate.

4. The rest of the read-only queries that were still queued on the writer:
   `typed_events` (+ its paged sibling), `import_records`, and the compaction
   scans above. `queued_receipt`/`has_queued_receipt_run` deliberately stay:
   they are the admission check that a prompt was not already queued, so they
   must not read behind an accepted write. `load_metadata` stays for the same
   reason in the other direction — its read may repair the history index, which
   is a write.

Tests: the row's cut and field shape; a fence read answering while a writer job
holds the lane, plus the mirrored assertion that the writer lane still waits for
the job in front of it; `get_session_presence` answering under the same hold
through the RPC dispatcher; and the desktop's recheck — `missing` asked twice
(`deleted` and `present` once). `agent/src/session` (625), `agent rpc` (786),
`agent_bridge` (391) and `application` (109) are green, clippy `-D warnings` and
`make check-docs` clean on 1.99.1.

* chore(agent): drop a scratch file that rode along with the commit

The commit message was staged by the same `git add -A` as the work; the
message text is in the commit body, not the tree.
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