Repository navigation
fix(computers): backpressure large mirror transfers - #537
Merged
Merged
Conversation
Await transport capacity instead of aborting the shared link during large catch-up. Read durable mirrors in bounded SQL rows and retain safe HTTP/2 failure diagnostics. Fixes: #411
nixuuu
added a commit
that referenced
this pull request
Nov 11, 2026
This was referenced Nov 11, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 11, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 11, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 11, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 11, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 11, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 11, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 11, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 11, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 11, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 12, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 12, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 12, 2026
Defines the incremental thread-sync contract in the Polish linked-computer and UI API documentation. This is the bottom layer of the approved stack, based on dev after #537. The protocol uses a durable, commit-ordered per-thread sequence separate from transcript seq, epochs, bounded range repair, 64-record / 64 KiB batches and durable apply before ACK. Client watches use bounded recent windows, older-history paging and lazy large content. Legacy peers retain their protocol; peers negotiating ranges never fall back to whole-thread snapshots. Stack: docs → mirror/storage (#539) → client watches (#541) → progress/diagnostics (#543). Final caps and cleanup pass the retention check twice at fixed tolerances. The accepted performance comparisons and complete validation status are in #543; those measurements compare the whole stack, not isolated layers. Validation: documentation review, clean diff, generation, workspace typecheck, lint, formatting and production web build pass at stack head. This layer changes documentation only; its copy audit has no UI text changes. Related: #537
nixuuu
added a commit
that referenced
this pull request
Nov 12, 2026
…#539) Linked thread mirrors resume from their durable epoch/sequence after interruption instead of restarting a whole-thread transfer. Each batch contains at most 64 records / 64 KiB, carries the home head and exact remaining count, and receives an ACK only after entities and cursor commit. Missing ranges are repaired incrementally; the same stream handles live tail. Large items carry compact previews and owner-scoped lazy references. Peers negotiate `thread_ranges_v1`; old peers retain their existing protocol. New peers never fall back to snapshot replication. Deterministic source failures pause only the affected thread, independently of link presence. Failure metadata contains sanitized reason/code/frame size, without content or exception text. Migrations 0120 and 0121 add journal/cursors and durable failure suppression. This layer follows dev's 0119; the client and progress layers add 0122 and 0123 in order. Source changes and journal invalidations commit together; bootstrap inserts historical IDs set-wise and seals bounded public projections. Retry suppression survives reconnect in PostgreSQL rather than an unbounded heap map; its row holds at most 512 encoded bytes and a 128-character signature. The publisher holds one unacknowledged batch per subscription and drops it after ACK or termination; its waiting map contains scalar cursors/callbacks and has a 15-second ACK timeout. Active mirror head/cursor metadata is scalar per mirrored thread and is released with the subscription. Focused real gRPC checks cover roughly 100 MB of history, interrupted catch-up after commit/before ACK, durable resume, gap repair, live tail, exact remaining count, epoch rebuild, owner isolation, unknown fields, deterministic failure isolation and old/new compatibility. The retention check additionally verifies suppression across 20 failure/reconnect cycles at each of 1/10/50 threads. No workflow or artifact requirement is bypassed. The earlier accepted full-stack comparison found roughly 100 MB catch-up at 1,938 → 1,121 ms (paired median −817 ms), at most 63,963 encoded bytes / 64 records per batch, and about 148.51 KiB batch allocation including external bytes. Large outputs remain lazy; this is not an eager 100 MB download. These are full-stack results, not isolated mirror-layer deltas. Latest bounded-memory, steady sanity and required-check results are in #543. Copy audit: no user-facing copy changes in this layer. No maintainer logs, private hosts, IDs, tokens or content are included. Related: #537
nixuuu
added a commit
that referenced
this pull request
Nov 12, 2026
Web, desktop and mobile open a bounded recent thread window and resume by durable sequence. Cached messages remain visible through a thread failure or unreachable home. Thread-scoped Retry / Load from scratch actions replace global connection errors, and presence changes trigger automatic recovery. - Recent windows use one initial request and a 512 KiB public-record budget, normally 24 turns and at most 128 items. Independent turn/item paging also bounds a huge single turn. Older pages and full item content load after initial rows. - Live batches retain 64-record / 64 KiB limits. Active readers share pending I/O and scalar heads, with at most eight distinct in-flight range reads per active thread. Completed batches are not cached. - Reusable recent windows share a process-wide eight-entry LRU (at most 4 MiB encoded record payload plus object overhead), one pending read per active thread and normalized page sizes. Invalidation, eviction and final reader close release references; closed pending reads cannot repopulate the cache. Metadata queues cap both count (128) and encoded bytes (64 KiB), with weak size memoization across fan-out. - Large items expose owner-scoped previews; “Load full item” fetches at most 48 KiB/request. Deterministic failures get one fresh-window repair, one smaller-window repair, then a thread error. Healthy link presence survives watch failures. Additive protobuf fields and migration 0122. Mobile stays JS/TS only, with unchanged production fingerprints: iOS `6ddec9ef559ee0095ac33e94ff9418a942053b17`, Android `5f6eae3ab278f1cd543e9ed763f923a319b65ec9`. Focused real gRPC/Connect checks pass for sequence watches (10 tests / 1,955 assertions), independent history windows (3), remote resume/offline recovery (1) and failure classes (5). They cover huge history/single turns, binary mobile Connect, stale cursors, lazy content, independent paging, eight simultaneous resumes with cancellation, direct database edits and bounded repair while unary works. Final whole-stack validation is in #543. The first-open bottleneck was historical journal seeding: the SQL trace drops bootstrap 3,901 → 62 ms and bounded-window reading 3,956 → 118 ms using set-based historical IDs. A browser trace shows one watch request and no history/lazy request before rows. Four accepted browser matched pairs (two ABBA blocks, production builds, fresh contexts) measured first-ever rows at 1,340.30 → 1,318.25 ms (paired median −23.30 ms). Eight-viewer heap after GC fell 248.62 → 98.87 MiB (paired −149.73 MiB). These earlier full-stack comparisons precede the final cache caps; their focused retention and steady recheck are in #543. Copy audit (`docs/copy.md` §8): scoped errors name this thread or computer; actions use Retry / Load from scratch. Unknown items explain version availability; previews offer “Load full item”. English sentence case, punctuation and accessible labels checked. Browser review covers light/dark, desktop/phone widths, short/long labels and reserved progress space. No raw exceptions, private hosts, tokens or thread content in diagnostic copy. Related: #537
nixuuu
added a commit
that referenced
this pull request
Nov 12, 2026
Thread headers show an icon and compact remaining-record count in reserved space. Accessible labels expose the exact count or “Up to date”. Settings → Diagnostics reports durable applied/head sequences, remaining records, caught-up status and sanitized failure reason/code/frame size. Cached content and recovery actions are in #541. The additive owner-scoped RPC returns at most 100 metadata rows/page (50 default), plus aggregates. Visible pages refresh every five seconds and stop in the background. It never reads transcripts or returns routes, private hosts, tokens or exception text. Migration 0123 stores failed-frame byte counts without successful-batch writes. The stack upgrades monotonically from dev's 0119 through mirror 0120/0121, clients 0122 and progress 0123. A real PostgreSQL regression test upgrades through each stage and verifies durable journal and failure state are preserved; no later migration can be silently skipped between squash commits. Copy audit (`docs/copy.md` §8): indefinite syncing becomes “N records to go” / “Up to date”; readable failure summaries expose technical details only behind disclosure. Verb-led actions, sentence case, accessible labels and non-colour meaning checked. Browser review covers light/dark, desktop/phone widths and short/long names. Production mobile fingerprints are unchanged (JS/TS only): iOS `6ddec9ef559ee0095ac33e94ff9418a942053b17`, Android `5f6eae3ab278f1cd543e9ed763f923a319b65ec9`. Final caps/cleanup verification: the opt-in real gateway-to-gateway memory check passed **twice**, 773 assertions per run. Each run uses separate home/viewer processes, native PostgreSQL within the same swap-disabled scope, 1/10/50 threads, five warm-up cycles and then twenty reconnect plus twenty real decode/write-failure cycles per thread count. Eight client watchers use the actual domain reducer and cached content. The largest history grows from 16 to 64 MiB. Tolerances were fixed before execution and unchanged: at most 4 MiB above warm-up, at most 1 MiB late-cycle drift. Worst observed values across both runs were **0.964 MiB / 0.787 MiB**. Closed `SequenceWindow` count was zero throughout; scope swap was zero. | Threads | Home peak over warm-up, MiB | Viewer peak over warm-up, MiB | Home late drift, MiB | Viewer late drift, MiB | | --- | ---: | ---: | ---: | ---: | | 1 | 0.964 | 0.910 | 0.787 | 0.384 | | 10 | 0.487 | 0.046 | 0.035 | 0.196 | | 50 | 0.838 | 0.261 | 0.462 | 0.135 | After growing history to 64 MiB, the median home/viewer GC heaps across the two runs are 77.26/75.50 MiB (1 thread), 77.86/74.69 MiB (10) and 79.61/75.23 MiB (50). Failure-phase viewer cycle 1 → 20 medians are 76.13 → 75.32, 74.31 → 74.56 and 74.91 → 75.08 MiB, respectively. This supplies repeated-failure evidence for the earlier post-failure comparison gap rather than attributing it to a proven per-failure leak. It is a finite retention check, not a proof against every possible native allocator leak. Application bounds: process-wide reusable recent windows cap encoded record payload at 4 MiB (8 entries), with one pending window read and at most 8 pending range reads per actively viewed thread. Final close/invalidation/eviction releases references. Metadata queues cap count and bytes at 128 / 64 KiB and memoize lengths weakly. The mirror owns one 64-record/64 KiB batch per subscription until ACK/termination (15-second ACK timeout); no completed payload cache remains. Failure suppression is durable, at most 512 encoded bytes per stored failure, rather than a process-wide growing error map. Active head/cursor metadata remains scalar per actively mirrored thread and is released with the subscription. SQL prepared statements retain the dependency's existing 100-entry LRU per connection (gateway pool at most 10); failed plans are evicted. RSS also contains JIT/native/allocator high-water pages: no exact byte attribution of the earlier +13/+22 MiB RSS difference is claimed from a JS heap graph. Latest steady sanity comparison after caps, dev `8cb743d2451b51a5af44de80ffe88f626056e555` versus stack `a47fd0bf5e5ee447d113634a7e1fc0928aa5bd40`: **four accepted matched pairs, two complete ABBA blocks**, no rejected pair. Workload and warm-up match the earlier full comparison's steady phase: 1,000 turns / ~16 MB output, eight remote watchers (four delayed 250 ms), five idle seconds, pre/post-watch GC checkpoints and 750 scripted-worker deltas at 20 ms. CPUs are pinned (home 2, viewer 3, driver 4, native PostgreSQL 6). Both gateways, workers, driver and PostgreSQL run beneath a `systemd-run --user --scope -p MemorySwapMax=0` scope. Scope swap max/current is checked at start, every second and end; current remains zero. | Steady metric | Dev median | Stack median | Median paired delta | | --- | ---: | ---: | ---: | | Unary RPC p95, ms | 80.27 | 4.86 | −75.41 | | Combined gateway CPU, % of one core | 54.12 | 40.48 | −13.87 pp | | Home peak RSS, MiB | 239.11 | 249.62 | +11.14 | | Viewer peak RSS, MiB | 1,102.46 | 275.64 | −824.31 | Load1 ≤12; final observed maximum 2.20. Swap-in rejects at 1,024 KiB/s once or 128 KiB/s for three consecutive samples; observed peak 64 KiB/s and no sustained-threshold run. Host swap-out rejects at 4,096 KiB/s; all four final pairs had **zero host swap-out bytes**. Each delta is the median matched B−A difference, so it need not equal the difference of the independent A/B medians. P95 measures unary `GetThread` latency under stream load, not token latency. An initial separate four-pair sanity omitted the old GC warm-up (p95 80.22→4.93 ms, CPU 56.14→40.48%, home RSS paired +28.26 MiB); it is retained separately and not pooled into the aligned comparison. The earlier accepted four-pair full-stack comparisons remain the source for other phases: first-ever browser rows 1,340.30→1,318.25 ms (paired −23.30 ms), ~100 MB lazy catch-up 1,938→1,121 ms (paired −817 ms), viewer heap with eight active watchers 248.62→98.87 MiB (paired −149.73 MiB), batch maximum 63,963 encoded bytes / 64 records and ~148.51 KiB allocation including external bytes. Those measurements precede the final caps and are not presented as new per-layer results. Browser layout and mobile fingerprints are unchanged by the final gateway/test-only edits. Validation before the migration-number correction: install, generation check, full workspace typecheck, lint, format check and production web build pass. Focused schema (23), mirror range (9), sequence-watch (10), history-window (3), remote recovery (1), failure-class (5) and compatibility/backpressure (4) tests pass one file at a time. Full `bun run check:tmp` passes at that earlier head: **2,402 passed / 166 skipped / 0 failed**, 31,618 assertions across 450 files in 1,367.79 seconds, with clean temp cleanup. The opt-in memory check is skipped in that default run and was separately executed twice as described above. SQL contents and measured runtime behavior are unchanged by the subsequent migration renumbering; post-correction migration/integration checks are recorded separately below. All four stack layers have green CI at their corrected heads, including every test shard, static checks, builds and artifact uploads. No workflow change or check bypass was needed. Merge the complete stack together, not individual layers. Post-correction verification at `3de5a12d99cd39e4aefa493b35a949e031e5cb0c`: **75 tests passed / 0 failed, 3,367 assertions across 17 focused files**, run one file at a time. This includes schema, all migration/upgrade/index files, the staged 0119 → 0121 → 0122 → 0123 upgrade, all range/sequence/failure/diagnostic/backpressure integrations, and the opt-in memory check (773 assertions, fixed tolerances unchanged, scope swap zero). The schema suite also passes all 23 tests at each actual intermediate branch head (mirror and clients), verifying their migration registries independently. Generation, full workspace typecheck, lint, format and production web build pass. The two renamed SQL files are byte-for-byte unchanged. No performance benchmarks were repeated for this numbering correction. Related: #537
This was referenced Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Large mirror catch-up could fill the shared link's fail-fast output queue even though the producer yielded to I/O. Overflow aborted the dialer's HTTP/2 session, failed every multiplexed call with
Unavailable, and forced the same bootstrap through reconnect backoff. A same-version two-gateway regression reproduces this with a roughly 98 MB timeline. This matches the reported GOAWAY/code-14 loop; the original incident logs did not retain the overflow reason.RPC producers now await bounded transport capacity in both directions, with slots reserved for control frames. Cancellation and link closure release waiting writers. Large persisted mirrors and incremental-delta bases are read in 4 MiB SQL chunks, avoiding the database driver's 16 MiB result-row limit without raising it. Client and listener diagnostics record GOAWAY codes/initiators, safe failure categories and transfer byte/frame counts without addresses, tokens, content or raw debug data.
This urgent compatibility fix preserves the existing wire format. The separately planned incremental protocol will replace whole-thread bootstrap projections with acknowledged sequence ranges. Thread-scoped client recovery and progress UI follow separately.
Validation:
bun install,bun run gen:check,bun run typecheck,bun run lint,bun run format:check, and the web production build passed.TMPDIR=/var/tmp bun run check:tmppassed: 2,369 tests passed, 165 skipped, zero failures; nothing left in the temp dir.[email protected]).Fixes: #411