Client: one Rust client for every app, slice 1 (#426) #480

Closed
kayg wants to merge 1 commit from issue/426-client into dev
Owner

For #426, N7. This adds the shared Rust device client and proves the first slice on Linux. The CLI is calternal-client because the existing server binary is already calternal.

The ADRs are:

  • 0040: One Rust client for every app. Rust owns the Installation session, SQLite store, offline queue, journal sync and yrs editing; UniFFI exposes async calls to thin adapters.
  • 0041: macOS uses Mac Catalyst, amending 0009.
  • 0042: Apple platforms 26.0+, with apps/ios, apps/watchos, apps/macos and packages/apple.

The client API is:

  • Client::open(server, database), begin_login(), finish_login(device_code, device).
  • list_notes(limit, offset), resolve_note(id_or_title), show_note(id_or_title), append_note(id, text).
  • sync(), next_changes(), pending_count(), pending_note_ids().
  • Owned NoteSummary, Change and DeviceCode records and typed ClientError values cross UniFFI.

CLI commands are login, notes list, notes show, notes append and watch. List reads are local; notes list --sync first catches up. Device sign-in adds start, approve and token routes behind the existing auth crate, plus a browser approval page. Each CLI gets a revocable Installation token.

SQLite commits yrs state and pending work before sending. The client retries state-vector differences and clears pending work only after the server's durable acknowledgement. Tests cover concurrent writers, cancellation, reconnect, large documents, per-user sign-in isolation and a deleted note whose queued edit must remain recoverable. The existing server test helper now owns child cleanup before its first readiness probe and retries TCP resets only during health checks.

On this shared Linux host, with 100,000 local note rows and the default page of 100, debug build:

  • Library: p50 0.250 ms, p95 0.376 ms, maximum 2.188 ms over 100 warm samples.
  • CLI, including startup and output: p50 6.182 ms, p95 12.990 ms, maximum 17.289 ms over 30 warm samples.

These measure the local page, not initial download or printing all 100,000 notes. Initial sync replays the retained journal to repair the server's asynchronous list projection. An authoritative snapshot cursor can remove that cost in a later server slice.

Validation: cargo fmt --all --check; cargo clippy --workspace --all-targets -- -D warnings; cargo test --workspace (460 passed, 3 ignored); explicitly named real_server_login_list_read_append and offline_append_restarts_and_syncs_once; explicit 100k performance test; UniFFI Swift generation on Linux. Generated Swift, header and module map stay in a temporary directory. The optional swift-format executable was unavailable.

Queued edits whose note is deleted or whose lineage changes remain readable by id. Explicit sync reports the conflict after updating other notes; the live stream continues. A richer recovery UI and one persistent socket for editor rooms are recommended next slices. No Swift app is added here.

A rendered Chromium proof also passes: real browser passkey setup, approval of the CLI Installation, local CLI list/read, and a CLI append appearing in the actual web editor without reload; API readback matches. The expected pre-sign-in /api/v1/actions 401 is classified, with no page errors or other console errors. The ASCII marker was used because this host's Skia font fallback aborts on the crab emoji; Unicode appends pass Rust/server/peer tests, and browser emoji rendering remains unverified here.

For #426, N7. This adds the shared Rust device client and proves the first slice on Linux. The CLI is calternal-client because the existing server binary is already calternal. The ADRs are: - 0040: One Rust client for every app. Rust owns the Installation session, SQLite store, offline queue, journal sync and yrs editing; UniFFI exposes async calls to thin adapters. - 0041: macOS uses Mac Catalyst, amending 0009. - 0042: Apple platforms 26.0+, with apps/ios, apps/watchos, apps/macos and packages/apple. The client API is: - Client::open(server, database), begin_login(), finish_login(device_code, device). - list_notes(limit, offset), resolve_note(id_or_title), show_note(id_or_title), append_note(id, text). - sync(), next_changes(), pending_count(), pending_note_ids(). - Owned NoteSummary, Change and DeviceCode records and typed ClientError values cross UniFFI. CLI commands are login, notes list, notes show, notes append and watch. List reads are local; notes list --sync first catches up. Device sign-in adds start, approve and token routes behind the existing auth crate, plus a browser approval page. Each CLI gets a revocable Installation token. SQLite commits yrs state and pending work before sending. The client retries state-vector differences and clears pending work only after the server's durable acknowledgement. Tests cover concurrent writers, cancellation, reconnect, large documents, per-user sign-in isolation and a deleted note whose queued edit must remain recoverable. The existing server test helper now owns child cleanup before its first readiness probe and retries TCP resets only during health checks. On this shared Linux host, with 100,000 local note rows and the default page of 100, debug build: - Library: p50 0.250 ms, p95 0.376 ms, maximum 2.188 ms over 100 warm samples. - CLI, including startup and output: p50 6.182 ms, p95 12.990 ms, maximum 17.289 ms over 30 warm samples. These measure the local page, not initial download or printing all 100,000 notes. Initial sync replays the retained journal to repair the server's asynchronous list projection. An authoritative snapshot cursor can remove that cost in a later server slice. Validation: cargo fmt --all --check; cargo clippy --workspace --all-targets -- -D warnings; cargo test --workspace (460 passed, 3 ignored); explicitly named real_server_login_list_read_append and offline_append_restarts_and_syncs_once; explicit 100k performance test; UniFFI Swift generation on Linux. Generated Swift, header and module map stay in a temporary directory. The optional swift-format executable was unavailable. Queued edits whose note is deleted or whose lineage changes remain readable by id. Explicit sync reports the conflict after updating other notes; the live stream continues. A richer recovery UI and one persistent socket for editor rooms are recommended next slices. No Swift app is added here. A rendered Chromium proof also passes: real browser passkey setup, approval of the CLI Installation, local CLI list/read, and a CLI append appearing in the actual web editor without reload; API readback matches. The expected pre-sign-in /api/v1/actions 401 is classified, with no page errors or other console errors. The ASCII marker was used because this host's Skia font fallback aborts on the crab emoji; Unicode appends pass Rust/server/peer tests, and browser emoji rendering remains unverified here.
Client: one Rust client for every app, slice 1 (#426)
Some checks failed
CI / server (pull_request) Successful in 29s
CI / rust (pull_request) Successful in 3m4s
CI / web (pull_request) Failing after 47m19s
81491beee9
Author
Owner

Replaced by #481 (ADR 0041 corrected to proposed).

Replaced by #481 (ADR 0041 corrected to proposed).
kayg closed this pull request 2026-10-16 09:00:10 +00:00
Some checks failed
CI / server (pull_request) Successful in 29s
CI / rust (pull_request) Successful in 3m4s
CI / web (pull_request) Failing after 47m19s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!480
No description provided.