Skip to content

fix: adversarial review P0/P1 hardening - #34

Merged
fannnzhang merged 12 commits into
mainfrom
fix/adversarial-review-p0-p1
Aug 13, 2026
Merged

fannnzhang merged 12 commits into
mainfrom
fix/adversarial-review-p0-p1

Conversation

@fannnzhang

Copy link
Copy Markdown
Contributor

Summary

Addresses the consolidated adversarial review findings (main @ 47f5dbc) across Hub, daemon, Desktop, and Mobile. Commits are split by concern.

P0

  • Security path-write: Hub fail-closed client_message_id validation; daemon hashes origin for attachment dirs + canonicalize containment; download host allowlist, no redirects, streamed size cap + timeout
  • Durable delivery: server no-drop fanout on backpressure (disconnect instead of drop+ack); client hole detection; Mobile hold-aware advance + per-topic ack serialization; messaging contract note
  • Host command replay: durable host-command ledger + persisted topic watermark; dead-letter/retention reclaim path; SnapshotRequired catch-up wiring
  • Jobs/approvals: supervised worker respawn; approval poller always sleeps; job health wired into health endpoint

P1

  • Desktop: access-token refresh + 401 retry; outbox unauthorized no longer permanent without refresh; focus/mark-read ordering and cleanup
  • Mobile: Lagged stream recovery; inbox rebind after invalidate; outbox account isolation / logout cache clear
  • Daemon: dispatch_loop deadlock avoidance; AppendBotMessage send path; Claude process-group kill on shutdown; UTF-8-safe slicing
  • Backend push: host-command ownership predicate; mailbox lease renewal; provider token storage; transient push deferrals (H4–H8)

Residual / follow-ups

  • No full monotonic outbox_id migration yet (in-batch serial claim + no-drop fanout landed)
  • Push provider_token plaintext alongside hash PK; pre-migration rows need re-register; APNs/FCM still NotWired where previously so
  • Quiet-hours deferral uses 60s polls, not exact window end

Test plan

  • cargo xtask check-rust (fmt/clippy/schema-parity/workspace tests)
  • Desktop check / test / biome / file-sizes / px-text (CI check:all scripts)
  • Mobile: Flutter 3.44.0 stable — pub get, build_runner, dart format, dart analyze --fatal-warnings, flutter test --exclude-tags ffi (79), FRB drift
  • CI green on this PR
  • Manual: malicious client_message_id cannot write outside workspace/.minos/attachments
  • Manual: daemon restart does not re-execute historical host commands
  • Manual: Desktop stays authed past 15m JWT TTL; Mobile inbox survives invalidate/Lagged

engineer and others added 12 commits August 12, 2026 06:15
Validate Hub client_message_id fail-closed (charset/length/path escapes)
while still accepting UUID, msg_*, and agent-result:* ids. Daemon no longer
uses raw origin as a path component (sha256 hex), asserts writes stay under
.attachments, allowlists download hosts to configured backend origin, and
streams downloads with size cap + timeout.
P0-2: fail closed when durable delivery cannot keep order.

Server:
- Revoke connections on catch-up barrier overflow and try_send backpressure
  instead of dropping frames while still acking outbox publish paths.
- Claim outbox rows ordered by (topic, topic_seq) via durable_event_log join.
- Same-batch dispatch remains serial; full monotonic outbox_id migration deferred.

Clients:
- Desktop tryAdvanceTopicCursor refuses silent gaps and triggers SnapshotRequired.
- Mobile tracks pending Dart holds, blocks AdvanceNow across holds, detects holes,
  and serializes inbox/conversation apply+ack chains.

Document the ordered no-drop + hole-detection contract in architecture-messaging.md §4.1.
P0-3: stop full host-topic replay from re-executing history after restart.

- Add host_command_ledger + host_topic_cursors (migration 0002), mirroring
  bot_delivery_ledger restart-safe exactly-once semantics.
- Hydrate host Subscribe resume cursor from SQLite; persist on durable apply.
- SnapshotRequired advances resume to retention_floor (not 0) and re-subscribes
  so catch-up cannot loop.
- Retention reclaim: dead-letter outbox rows no longer pin durable_event_log
  forever (ack_at_ms NULL + dead_at_ms set).

Deferred: pruning old completed ledger rows / cross-process inflight fencing.
P0-4: background jobs must not die permanently after a short DB outage.

- JobSupervisor enters extended respawn backoff after consecutive fatals
  instead of exiting the task forever.
- Approval timeout poller always sleeps after due-deadline ticks; skip
  undecodable rows; force-timeout pending approvals with NULL host so they
  cannot pin next_pending_deadline forever.
- Expose JobHealthRegistry on AppContext and include job snapshots in
  GET /health/jobs.
P1 Desktop:
- Proactive JWT refresh before expiry; shared ensureFreshCloudAccessToken
  single-flight for HTTP 401 → refresh → one retry in minos-cloud.
- Outbox classifies unauthorized/401 as transient (refreshable), not permanent.
- Timeline clears focusedConversationId on unmount; Hub mark-read waits for
  auth hydrate + observed message_seq so cold-start open commits read watermark.
P1 Mobile:
- FRB ui/social event forwarders continue after broadcast Lagged instead of
  breaking the stream for the process lifetime.
- ConversationsController rebinds socialEvents on every build so invalidate
  after reconnect cannot leave a dead subscription.
- im_outbox gains account_id (db v8); drain filters by current account;
  logout clears social_cache.db (outbox + conversations + messages).
- Enlarge mobile social/ui broadcast buffers to reduce lag under catch-up.
Spawn BotInboxDelivery off the dispatch loop so inject cannot self-deadlock
on the uplink drain. Bound AppendBotMessage sends instead of silent try_send
drops after accept. Reap Claude turns via process-group SIGTERM/SIGKILL on
shutdown, and use char-boundary-safe UTF-8 prefixes to stop panics taking
run_dispatch offline.
Require owning host_installation_id on host-command ack/finish (H4). Renew
mailbox leases on host Ping and delivery activity so long turns keep the
2-minute lease alive (H5). Persist provider_token alongside token_hash so
APNs/FCM have send material (H6). Treat user_online, quiet_hours, and
cooldown as deferred requeues that do not burn dead-letter attempts (H7/H8).
Apply cargo fmt across prior P0/P1 edits and resolve clippy -D warnings
(single_match / collapsible_else_if on mobile hole detection; Box::pin
large BotInboxDelivery future on daemon dispatch).
Keep CI dart format --set-exit-if-changed green after social apply-chain fixes.
Replace device_installations / host_installation_tokens with devices /
host_tokens and rename the wire fields to device_id / host_device_id.
Desktop login now issues a host_token bound to (account_id, DeviceId).
The realtime registry keys by (rail, DeviceId) so Account IM and Host
runtime can share one Mac without kicking each other. Native /ws/client
accepts Authorization: Bearer; host WS has no ticket.
Own DeviceId, refresh, and host_token in Keychain (AfterFirstUnlock).
Login/refresh/sign-out and Account IM now run in the Tauri host with
native Bearer /ws/client — no ticket. The webview only projects UI
state and forwards frames.
@fannnzhang
fannnzhang merged commit c3a1aa3 into main Aug 13, 2026
5 checks passed
@fannnzhang
fannnzhang deleted the fix/adversarial-review-p0-p1 branch August 13, 2026 08:29
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.

2 participants