Skip to content

feat(client-core): close Wave B6c-2a sync reconnect, burst, catch-up & open parity - #10454

Open
CommaBot wants to merge 11 commits into
mainfrom
feat/core-wave-b6c2a-sync-reconnect
Open

CommaBot wants to merge 11 commits into
mainfrom
feat/core-wave-b6c2a-sync-reconnect

Conversation

@CommaBot

@CommaBot CommaBot commented Dec 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Closes Wave B6c-2a — Sync Reconnect / Burst / Catch-up / Live / Syncing / Visited-Open 10-File Test & Production Parity Closure in pure-Pion Client Core (pion/client-core).

Production Parity Fixes Closed

  1. Incremental thread_after & Zero-Write Duplicate SSE Replay (thread_after.pion, station_events_sse.pion)

    • Added pure-Pion thread_after matching client/core-ts/src/station/thread-after.ts (last, unread, lastMessage, people, firstText 300-UTF-8-char cap, attachment-only vs text edit editedAt, and None fallback on sequence gaps, non-native Slack/Feishu/group surfaces, or local/non-email authors).
    • Added byte-equal on-disk check in StationEvents::apply_sse_thread so duplicate replayed SSE entries perform 0 entry/thread SQLite writes and leave summaries unchanged.
  2. Confirmed own.reads Read Recovery & Post-Restart Focus Retry (cc_read_recovery.pion, cc_chat_open_sync.pion)

    • Added ReadRecoveryState tracking server-confirmed own.reads (#heldReads) and active PUT /threads/:id/read requests so explicit chat.read repairs stale cached thread.read positions on shared threads while leaving unshared threads untouched.
    • Wired focus-driven auto-read check (attend_check_due_read) on client.focus (visible && focused && end) so an interrupted PUT /threads/:id/read across app restart automatically retries once the chat is shown and focused.
  3. Cold/Visited Chat Open Sync, Silent Backfill, F2a Catching Priority & Focused Live said: true (cc_chat_open_sync.pion, cc_topics_chat.pion)

    • Added prepare_chat_open_sync handling cold-open POST /batch (with 404 no route fallback to direct GETs and retry on stream reopen / backoff), unread-around ranged jump (from=&to=), visited-chat >= 1 page jump directly to latest page followed by silent older gap backfill (fill_next), < 1 page immediate cached open + single after= catch-up read, and immediate fallback to held entries (newer: true) when already offline or going offline mid-wait.
    • Added maybe_prioritize_catching_thread (F2a) scheduling focused GET /threads/:id summary + bounded after= continuation on sy.lane once per catching.epoch while preserving the open window and unreadLine.
    • Added window-scoped attend_chat_view (focus_showing_chat) marking said: true exclusively on non-resumed live SSE entries arriving while the chat is visible in an open window, immune to +5 min / -5 min station clock skew.
  4. SQLite Stream-Batch Rollback Replay, mayHurry Lock Close Redial, Streaks, Down Causes & Recorder (station_events_reconnect.pion, station_events_stream.pion, cc_station_diag.pion, cc_station_hooks.pion)

    • Added SQLite stream-batch failure recovery (1000ms -> 2000ms capped backoff, marks_let_go + sync.bump_epoch() retiring hung pre-rollback marks reads so recovery snapshots never stall behind rolled-back state) across BEGIN IMMEDIATE, statement, and COMMIT failures.
    • Added mayHurry immediate redial on the first lock_unconfirmed stream close (>= RECONNECT_MS), costly_streak (60s cap after 3 costly brief streams) vs brief_streak (BRIEF_MAX_MS = 8s cap on resumed brief streams), note_answered / healthChange fast recovery, cloud_events_opened wakeup from OFFLINE_RETRY_MS, station_down_cause (lock, network, updating, station, unreached), 426 station_too_old / app_too_old / page_too_old diagnostics, and connection performance recorder hooks.
  5. Cloud /v1/events First-Heartbeat Deadline & Safe Wake Socket Replacement (cloud_api.pion, cloud_sync.pion)

    • Added CLOUD_SOCKET_IDLE_MS (60s) first-data deadline on /v1/events and non-destructive background socket dial on wake() so a failed replacement dial leaves the existing open socket intact until a subsequent wake succeeds.

10-File Case-by-Case Coverage Mapping

client/core-ts/test/ Suite Cases Pion Test File & Exact Test Names
1. chat-reconnect.test.ts [1]–[5] b6c2a_chat_open_reconnect_test.pion:
• b6c2a chat-reconnect [1]: failed initial read with /batch before stream resumes retries on reopen
• b6c2a chat-reconnect [2]: failed initial read with /batch after stream already resumed retries via backoff
• b6c2a chat-reconnect [3]: failed initial read without /batch before stream resumes retries on reopen
• b6c2a chat-reconnect [4]: failed initial read without /batch after stream already resumed retries via backoff
• b6c2a chat-reconnect [5]: unread position wait recovers automatically when stream resumes
2. event-burst.test.ts [1]–[3] b6c1_event_burst_test.pion & b6c2a_burst_lock_syncing_test.pion:
• [1] b6c1 event-burst [1]: chat.open completes asynchronously before remaining slices of a 60-event SSE burst
• [2] b6c1 event-burst [2]: overview + patches before a whole overview coalesce through live StationEvents
• [3] b6c2a event-burst [3]: flushes cursor at yield boundary and stops immediately when stream link is replaced or authGen bumps mid-burst
3. f2a-catching-priority.test.ts [1] b6c2a_chat_open_reconnect_test.pion:
• b6c2a f2a-catching-priority [1]: opening cached thread during catching prioritizes summary + bounded continuation once per epoch and preserves unreadLine
4. link-lock-ended.test.ts [1]–[2] b6c2a_burst_lock_syncing_test.pion:
• b6c2a link-lock-ended [1]: station closing stream for lock_unconfirmed redials immediately and enters waiting admission state
• b6c2a link-lock-ended [2]: redials immediately only on first lock_unconfirmed close and backs off >= 2000ms thereafter
5. read-recovery.test.ts [1]–[2] b6c2a_read_said_thread_test.pion:
• b6c2a read-recovery [1]: explicit read repairs stale cached position via confirmed own.reads and leaves unshared threads alone
• b6c2a read-recovery [2]: after an interrupted PUT /threads/7/read and restart, showing and focusing the chat retries the read
6. reconnect-recovery.test.ts [1]–[29] b6c2a_reconnect_recovery_test.pion, station_events_wake_test.pion, wave_b3b1_test.pion, wave_b3b1_r3_test.pion:
• [1] b6c2a reconnect-recovery [1]: a lost event is read again in the same app after SQLite fails at BEGIN IMMEDIATE, statement, and COMMIT
• [2] b6c2a reconnect-recovery [2]: a replay that fills SQLite again backs off (1000ms -> 2000ms) and eventually keeps the missing message
• [3] b6c2a reconnect-recovery [3]: a snapshot held open before a rollback does not hold the recovery snapshot back
• [4]–[6] b6c2a reconnect-recovery [4]-[6]: costly brief streams back off to 60s and reset after STREAM_HELD_MS or UI wake; healthy 30s streams always retry in 2s
• [7],[8] b6c2a reconnect-recovery [7],[8]: incomplete fresh read (held across restart or 503 marks) does not persist heard cursor until all lists succeed
• [9] b6c2a reconnect-recovery [9]: failed CloudSync wake replacement keeps open socket, next wake replaces it, and 60s first-heartbeat deadline reconnects
• [10]–[15] b6c2a reconnect-recovery [10]-[15]: resumed brief cap BRIEF_MAX_MS, note_answered & healthChange fast recovery, cloud_events_opened on OFFLINE_RETRY_MS, and connection recorder
• [16]–[20],[23]–[26] b6c2a reconnect-recovery [16]-[20],[23]-[26]: down causes (lock, unreached, network, updating, station), outbox/pending recovery, and 426 appOld/pageOld/stationTooOld
• [21]–[22] station_events_wake_test.pion (wake: a freeze past STREAM_IDLE_MS..., wake: a frozen stream that stays silent goes POST_FREEZE_IDLE_MS..., wake: a stream from before a wake that breaks just after it opens again at once, once a wake)
• [27]–[29] wave_b3b1_test.pion & wave_b3b1_r3_test.pion (b3b1: behind the workspace in view until it had its first round..., b3b1: woken out of its wait, a stream of a workspace not in view opens again behind the one in view, b3b1 r4: a stream waiting behind the workspace in view is told as its wait is let go of...)
7. said-live.test.ts [1]–[3] b6c2a_read_said_thread_test.pion:
• b6c2a said-live [1]: live message comes in with said:true while resumed replay and out-of-view messages do not
• b6c2a said-live [2]: station clock 5 minutes ahead changes nothing of what comes in
• b6c2a said-live [3]: station clock 5 minutes behind changes nothing of what comes in
8. syncing.test.ts [1]–[3] b6c2a_burst_lock_syncing_test.pion:
• b6c2a syncing [1], [2], [3]: reports syncing through tally and remaining chats, ignores 403 thread, and clears on disconnect
9. thread-after.test.ts [1]–[4] b6c2a_read_said_thread_test.pion:
• b6c2a thread-after [1]: advances last, unread, lastMessage, people, firstText 300-char cap, and attachment-only vs text edit
• b6c2a thread-after [2]: returns None for non-object held, sequence gap, Slack surface, and local author
• b6c2a thread-after [3]: thread_after_letters advances letters count and lettersLast and rejects gaps
• b6c2a thread-after [4]: duplicate resumed entries and letters leave summary unchanged and perform 0 entry/thread SQLite writes
10. visited-chat-open.test.ts [1]–[4] b6c2a_chat_open_reconnect_test.pion:
• b6c2a visited-chat-open [1]: >= 1 page behind jumps to latest page first then backfills older gaps silently
• b6c2a visited-chat-open [2]: < 1 page behind shows cached messages immediately and catches up with one after= read
• b6c2a visited-chat-open [3] & [4]: already offline and goes-offline mid-wait both fall back immediately to held entries

Verification & Revert-Falsification Gates (Linux x86_64 + macOS)

  • Format, Typecheck & Structure Gates:
    • pionc fmt --check pion/client-core: passed (0 diffs)
    • pionc check --offline pion/client-core & pionc check --offline --target wasm32 pion/client-core: 0 diagnostics
    • node pion/client-core/scripts/check-structure.mjs --self-test & check-structure.mjs: 606 production .pion files <= 1500 lines (0 in OVER), 0 debug_assert(, 0 self-referencing closure cells
    • gen-pion-shapes.mjs --check, gen-mermaid-widths.mjs --check, gen-math-font.mjs --check, gen-pion-i18n.mjs --check, i18n-words.ts --target pion-core: all passed
  • wasm32 Builds: packages/{sync,views,present,vault,passwords} all compiled cleanly
  • Linux pion/client-core Suites:
    • pionc test --offline pion/client-core (debug): 2217 / 2217 passed (0 failed)
    • pionc test --offline --release pion/client-core: 2217 / 2217 passed (0 failed) (sync --release: 1805 / 1805 passed)
    • pionc test --offline --release pion/client-core/packages/core_runtime: 334 / 334 passed (0 failed)
  • Native C + Zero-pnpm Node Gates:
    • core_secure_posix_test: ok
    • parity-b6c1-sync.test.mjs, schema-chat-tag.test.mjs, core-perf-gate.test.mjs, parity-b6d2-budgets.test.mjs (46 / 46), parity-b6e3-views.test.mjs: 0 failures
  • 6 Revert-Falsification Proofs:
    1. 1a-thread-after-edit (thread_after.pion if text_changed mutated) -> fails b6c2a thread-after [1] (FALSIFIED_OK)
    2. 1b-sse-dup-skip (station_events_sse.pion n <= existing_last duplicate skip disabled) -> fails b6c2a thread-after [4] (FALSIFIED_OK)
    3. 2-read-recovery (cc_read_recovery.pion marks_loaded gate disabled) -> fails b6c2a read-recovery (FALSIFIED_OK)
    4. 3-chat-open-sync (cc_chat_open_sync.pion prepare_chat_open_sync bypassed) -> fails b6c2a chat-reconnect / visited-chat-open (FALSIFIED_OK)
    5. 4-sql-replay-and-lock-hurry (station_events_stream.pion sql_failed_in_stream replay disabled) -> fails b6c2a reconnect-recovery [1]-[3] (FALSIFIED_OK)
    6. 5-cloud-socket-idle-deadline (cloud_api.pion CLOUD_SOCKET_IDLE_MS mutated 60s -> 6000s) -> fails b6c2a reconnect-recovery [9] (FALSIFIED_OK)

R2 Review Closure (b6c2a_r2_review_test.pion & b6c2a_burst_lock_syncing_test.pion)

  • P1-1 (cc_chat_open_sync.pion, cc_gates.pion): Per-line (account_epoch, authGen, station_read_open, slot_id, req_gen) fence in cold /batch NDJSON stream interrupting stale streams before writing to SQLite, plus guaranteed cold_req release on completion so transient auth/read-gate transitions never deadlock on Waiting.
  • P1-2 (cc_chat_open_sync.pion): Removed global chat_open_sync.epoch bump in drop_stations; isolated each ChatOpenSlot and request by (account_epoch, slot_id, req_gen) across callbacks, on_drop, and retry timers.
  • P1-3 (cc_chat_attend.pion, cc_focus_windows.pion): Per-window chat_end / chat_end_seq / chat_seen tracking on FocusWindow and view-bounded auto-read (shown_newest / short from rendered ChatView, never DB chat_latest).
  • P1-4 (cc_read_recovery.pion, cc_calls_chat.pion, cc_wire.pion): Offline guard leaves held_reads and attend_sent clean; failed PUT preserves higher queued_target (max(confirmed, held)); stale (account_epoch, auth_gen) callbacks return immediately without mutating read_recovery; public chat.read awaits PUT /threads/:id/read, adopts station-returned n, and surfaces failures.
  • P1-5 (cc_chat_open_sync.pion): Hoisted slot.opened fast path ahead of SQL scans and bounded initial open to store::log_max_n (O(1) refresh entry reads across 100 vs 2,000 held entries).
  • P2-1..P2-5 (thread_after.pion, cc_chat_attend.pion, cc_chat_subs.pion, cc_chat_open_sync.pion, hub_wire_station.pion, b6c2a_burst_lock_syncing_test.pion): thread_after returns None on empty said; live_seqs bounded strictly to open chat slots and evicted to 0 on unsubscribe; multi-chunk whole-JSON /batch accepted up to mesh::max_body (16 MiB); HTTP 426 body preserved on HubWrappedStation::events_k; added bumpWorkspace authGen bump burst-yield test ([3b]).

Show it working
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

This branch has not been deployed

No deployments
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