Skip to content

fix(store): adopt runs.offers_choice under contract 7; reclaim the mobile share cache - #1630

Merged
huichen merged 4 commits into
mainfrom
pr/huichen
Nov 16, 2026
Merged

huichen merged 4 commits into
mainfrom
pr/huichen

Conversation

@huichen

@huichen huichen commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Two fixes: an existing desktop database can open again after the choice mark reached SCHEMA without a contract of its own, and the phone's share cache reclaims old copies instead of locking attachment handoff for a day.

Commits

  • fix(store): migrate runs.offers_choice before startup validation — adopt the column under contract 7 (APP_DB_SCHEMA_VERSION 6 → 7), keep the released 6 immutable, and drop the ADDED_COLUMNS entry the contract step now owns. Tests cover a contract-6 database with and without the early column, the double-open idempotence, and a rollback retried from its ledger. ER.md documents the field.
  • fix(mobile): reclaim the share export cache instead of refusing — namedExternalFile now frees the oldest copies under futureos-exports (copies younger than EXPORT_PROTECT_MS first, then the oldest anyway when a burst leaves no room) instead of throwing attachment_export_cache_full until the 24 h retention expired. The one refusal left is the code mapped to a localized attachment.exportCacheFull line; a native failure still shows its own words.

Verification

Toolchain: pinned rustc 1.99.1 (Homebrew's 1.96.0 shadowed off PATH), Node 26.3.0, ulimit -n 8192. Run at b566353fd in the main checkout, tracked tree clean.

  • cargo fmt --all -- --check → clean
  • cargo check -p future-host -p future-app-settings --all-targets → clean, 8.2 s
  • cargo clippy -p future-host -p future-app-settings --all-targets -- -D warnings → clean, 7.4 s
  • cargo test -p future-app-settings → 22 passed
  • cargo test -p future-host --lib → 2269 passed / 0 failed / 15 ignored, 446 s
  • mobile: npx tsc --noEmit clean; npx eslint on the five changed files clean; npx jest src/remote/__tests__/files.test.ts src/features/chat/__tests__/useFileDownload.test.ts → 2 suites, 261 passed
  • make check-docs → 421 docs OK, 0 pairs pending, provider matrix 13 rows

Notes

  • Opening this build's app.db upgrades it from contract 6 to 7. The step is checksummed, transactional and snapshotted before it runs; a failure rolls back and retries from the ledger like the other steps. A row written before the column existed is kept, with the mark defaulting to 0.
  • A fresh install and a database that already carries the column both converge on contract 7 without replaying the ALTER, so early marks survive either layout.

User-visible changes

  • Existing desktop databases upgrade to contract 7 on next open. Before: a database at version 6 without runs.offers_choice — the released contract and every desktop built since the mark landed — was refused at startup with Desktop database is incomplete: required runs.offers_choice is missing. After: it opens, the column is added inside a snapshotted transaction, and the run rows are kept. Revert 898ff2e3d.
  • Mobile attachment handoff reclaims its cache instead of refusing. Before: once 100 MB or 128 copies piled up in futureos-exports, every open/share threw attachment_export_cache_full until the 24 h retention expired (a burst of 7 MB wavs was enough to lock sharing for a day). After: the oldest copies are deleted to make room, copies younger than 10 minutes are preserved while an older one is available, and the single remaining refusal is shown as a localized sentence (attachment.exportCacheFull, en + zh) rather than the internal code. Revert 666cbc8b9.

huichen and others added 4 commits November 16, 2026 21:40
Opening or sharing an attachment hands the OS a copy under
`futureos-exports`, kept for 24 hours. The cap that guarded that directory
only ever counted, never reclaimed: once 100 MB of copies (or 128 of them)
accumulated, every later handoff threw `attachment_export_cache_full` and
kept throwing until retention expired — a burst of 7 MB podcast wavs was
enough to lock sharing for a whole day.

Reclaim instead of refusing. Copies older than `EXPORT_PROTECT_MS` go first,
because a handoff is a live `content://` grant an app may still be reading;
if a burst inside that window leaves no room, a second pass reclaims the
oldest anyway. Refusal now survives only for a single file larger than the
whole budget, which the transfer layer already rules out, and it deletes
nothing on the way out.

The refusal code also reached the user verbatim, because the handoff alert
appends the failure's own words on Android. Keep that for native failures —
they name the URI grant or chooser that refused — but map our own code to
`attachment.exportCacheFull` in both locales.
The choice mark reached SCHEMA (and the best-effort ADDED_COLUMNS list)
without a contract step, so a database already at version 6 — the released
contract, and every desktop written by it — has no such column. Startup reads
the header, sees �ersion == APP_DB_SCHEMA_VERSION, runs �alidate_core
before any migration can touch the table, and refuses to open:

  Desktop database is incomplete: required runs.offers_choice is missing.

The same shape as #1496 (workspaces.archived_at): ADDED_COLUMNS only runs
from �pply_schema, i.e. on a fresh database, never on the current-version
path. Adopt the column under contract 7, with the released 6 kept immutable:

- 
uns_offers_choice.sql adds the column; ADDITIVE_COLUMN_STEPS skips the
  ALTER on a fresh install or a build that wrote the column early, so an
  existing mark and its row survive either layout.
- APP_DB_SCHEMA_VERSION 6 -> 7, so the upgrade is checksummed, transactional
  and snapshotted before it runs.
- Drop the ADDED_COLUMNS entry: the contract step now owns the column.

Tests cover both layouts (missing column fails �alidate_core first, an early
column is recorded without replaying), the double-open idempotence, and a
rollback that retries from its ledger like the other steps.

ER.md documents the run field.
@huichen
huichen enabled auto-merge (squash) November 16, 2026 14:27
huichen added a commit that referenced this pull request Nov 16, 2026
The multi-device e2e test asserted "the controller must not be told to
stand by just because a device connected" by counting *any* control packet
in a 300 ms window. The machine also announces a device's own arrival
(`control: active`) on that same channel, from a task the handshake spawns
after it has answered, so that notice races the activation of the sealed
channel: while the seal has no key it is dropped, and once the client's
`secure_ready` activated one it is delivered. On a loaded runner it is
delivered, the `active` lands inside the window, and the assertion reported
a displacement that never happened (CI run 43885835542 on PR #1630).

`told_to_stand_by` now opens each packet and counts only a control state
that is not `active` — and, deliberately, any state this test does not know
and any packet it cannot open — so a real "stand by" notice still fails it
(verified by publishing one at a device's connect) while the device's own
arrival no longer does. The window, the assertion and its message are
unchanged; only what counts as news is.
@huichen
huichen merged commit c9cbebf into main Nov 16, 2026
48 of 50 checks passed
huichen added a commit that referenced this pull request Nov 16, 2026
The multi-device e2e test asserted "the controller must not be told to
stand by just because a device connected" by counting *any* control packet
in a 300 ms window. The machine also announces a device's own arrival
(`control: active`) on that same channel, from a task the handshake spawns
after it has answered, so that notice races the activation of the sealed
channel: while the seal has no key it is dropped, and once the client's
`secure_ready` activated one it is delivered. On a loaded runner it is
delivered, the `active` lands inside the window, and the assertion reported
a displacement that never happened (CI run 43885835542 on PR #1630).

`told_to_stand_by` now opens each packet and counts only a control state
that is not `active` — and, deliberately, any state this test does not know
and any packet it cannot open — so a real "stand by" notice still fails it
(verified by publishing one at a device's connect) while the device's own
arrival no longer does. The window, the assertion and its message are
unchanged; only what counts as news is.
@huichen
huichen deleted the pr/huichen branch November 16, 2026 15:22
huichen added a commit that referenced this pull request Nov 16, 2026
The multi-device e2e test asserted "the controller must not be told to
stand by just because a device connected" by counting *any* control packet
in a 300 ms window. The machine also announces a device's own arrival
(`control: active`) on that same channel, from a task the handshake spawns
after it has answered, so that notice races the activation of the sealed
channel: while the seal has no key it is dropped, and once the client's
`secure_ready` activated one it is delivered. On a loaded runner it is
delivered, the `active` lands inside the window, and the assertion reported
a displacement that never happened (CI run 43885835542 on PR #1630).

`told_to_stand_by` now opens each packet and counts only a control state
that is not `active` — and, deliberately, any state this test does not know
and any packet it cannot open — so a real "stand by" notice still fails it
(verified by publishing one at a device's connect) while the device's own
arrival no longer does. The window, the assertion and its message are
unchanged; only what counts as news is.
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