Skip to content

Timeline perf integration (do not merge: verification branch for #7238 #7239 #7245 #7244 #7246 #7243 #7247 #7254 #7249 #7241 #7108 #7240 #7248 #7242 #6215) - #7250

Closed
ymichael wants to merge 68 commits into
mainfrom
bb/timeline-perf-integration

Conversation

@ymichael

@ymichael ymichael commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Do not merge. This branch only checks that these PRs work together. Each PR lands on its own.

Root cause

The Nov 7 timeline and server performance audit split its fixes into separate PRs. They overlap in:

  • the timeline build, selection memo, caches and windows;
  • the pruning transaction and sweep;
  • the plugin runtime.

Each PR was verified only against origin/main.

Change

Merged onto origin/main 55135d1, at the PR heads below:

The parity, replay, memory and timing evidence covers the timeline set and #7254. The other PRs have typecheck, targeted tests and CI. Every conflict and its resolution is in audit/INTEGRATION.md; the resolved hunks are in this branch's merge commits.

Resolutions each PR's rebase must carry

Verification

All runs are in-process on APFS clones of the Nov 7 snapshot. #7247's migrations were applied once to a base clone used by every arm.

check (head 1f65878) result
parity with main, 162 threads, every variant, forward 4,652 hashes, 0 differences
parity with main, reverse read order 2,462 hashes, 0 differences
append replay: 64 thread-runs × 16 real appends through the push path, against a new connection 1,024 steps, 5,120 deltas, 0 mismatches (windows, applied deltas, outline, turn details)
prune replay: production schedule on 8 threads, 5 variants, after every row-removing prune 443 checks, 0 differences

Before/after (harness, all 10 scenarios on the 12 threads, plus push on 4):

  • Method: 3 alternating main/integration pairs, 5 repeats each, median of per-run medians.
  • Load: 2.7–4.6 for every run.
  • S6 marks the cases the coordinator asked for.
case (thread) main ms integration ms Δ deterministic metrics, main → integration
S6 cold latest (u738kqjs29) 195 21.8 -89% rows read 7663 → 793
S6 cold latest (avim9t7kpe) 99.7 11.3 -89% rows read 5888 → 40
cold latest (kdrbtee92b) 31.6 24.3 -23%
cold latest (wg5iwwrezi) 50.7 44.2 -13%
cold latest (d5ej4e2gtv) 31.6 31.1 -2%
cold latest, other 7 threads -12% to +1%
S6 phone after app (avim9t7kpe) 94.6 0.3 -100%
phone after app (u738kqjs29) 184 0.5 -100%
CLI log after app (u738kqjs29) 25.6 1.4 -95%
nested after app (avim9t7kpe) 42.0 112 +165% accepted #7247 cost shift
nested after app (wg5iwwrezi) 27.9 17.9 -36%
S6 older-page walk (avim9t7kpe) 189 13.1 -93% rows read 11777 → 73
older-page walk (u738kqjs29) 846 224 -73% rows read 34700 → 11981
older-page walk (6e9knccemi) 840 550 -35% rows read 56704 → 35383
S6 thread log --all (u738kqjs29) 1519 504 -67% rows read 57686 → 24773
S6 thread log --all (avim9t7kpe) 191 12.7 -93% rows read 11777 → 73
S6 thread log --all (kdrbtee92b) 738 483 -35%
S6 thread log --all (6e9knccemi) 1052 656 -38% rows read 64266 → 38610
S6 thread log --all (d5ej4e2gtv) 3906 2786 -29% rows read 157212 → 148496
S6 thread log --all (ymhw6pktq4) 518 340 -34%
turn details, first full walk (6e9knccemi) 1588 142 -91%
turn details, re-expand (6e9knccemi) 1588 4.0 -100%
turn details, first full walk (u738kqjs29) 684 176 -74%
turn details, re-expand (u738kqjs29) 684 0.4 -100%
outline second load (kdrbtee92b) 8.8 2.1 -76%
outline cold load, 12 threads -7% to +12% accepted #7243 checkpoint cost
cold build with SQL counter (u738kqjs29) 193 21.1 -89% SQL rows 19463 → 950, duplicates 11798 → 155
S6 push: warm delta after one append (u738kqjs29, active) 12.4 1.0 -92%
S6 push: cold after appends (u738kqjs29, active) 200 20.2 -90%
push: warm delta after one append (kdrbtee92b) 2.7 1.8 -33%
push: warm delta after one append (wg5iwwrezi:active) 9.5 3.3 -65%
push: warm delta after one append (txqr3djnmd:active) 7.0 1.8 -74%
capacity: median cold open of 712 threads 17.9 17.1 -4%

Accepted trade-offs (coordinator):

The capacity regression from #7245's decode-cache eviction is fixed (−4%).

Full table, every scenario × thread (per-run medians in parentheses)

cold

thread case main ms integration ms Δ metrics main → int
u738kqjs29 app-latest 195 (195/200/194) 21.8 (22.5/21.7/21.8) -89% eventRowCount 7663→793; eventDataBytes 13415640→1136399
kdrbtee92b app-latest 31.6 (32.0/31.6/31.4) 24.3 (23.7/24.3/24.9) -23%
avim9t7kpe app-latest 99.7 (99.2/99.7/105) 11.3 (11.2/11.3/12.0) -89% eventRowCount 5888→40; eventDataBytes 12044203→30871
6e9knccemi app-latest 15.7 (15.7/16.0/15.7) 14.8 (14.8/14.4/14.9) -6%
d5ej4e2gtv app-latest 31.6 (31.6/31.6/31.4) 31.1 (31.0/31.1/31.1) -2%
9h3n4aiax8 app-latest 16.3 (15.9/16.4/16.3) 15.1 (15.1/15.0/15.2) -7%
wg5iwwrezi app-latest 50.7 (50.7/50.7/52.3) 44.2 (44.2/43.6/44.2) -13%
pvd2eqmdcv app-latest 14.3 (13.9/14.6/14.3) 13.5 (13.7/13.5/13.5) -6%
i2qj9tb7j3 app-latest 25.1 (25.1/25.4/24.9) 22.6 (22.5/23.0/22.6) -10%
y6xhxw8t8w app-latest 30.3 (30.3/30.2/30.8) 26.6 (28.2/26.1/26.6) -12%
dbcv9uurw7 app-latest 22.6 (22.4/22.6/22.8) 19.8 (20.0/19.8/19.8) -12%
ymhw6pktq4 app-latest 9.1 (9.0/9.1/9.1) 9.2 (9.2/9.2/8.2) +1%
thread case main ms integration ms Δ metrics main → int

variants

thread case main ms integration ms Δ metrics main → int
u738kqjs29 summaryOnly-after-app 25.1 (25.3/25.1/24.8) 1.1 (1.1/1.1/1.2) -96% eventRowCount 7663→793; eventDataBytes 13415640→1136399
u738kqjs29 cliLog-after-app 25.6 (25.9/25.6/25.4) 1.4 (1.3/1.4/1.4) -95% eventRowCount 7663→793; eventDataBytes 13415640→1136399; repeatMs 0.2→0.1
u738kqjs29 includeNestedRows-after-app 25.5 (25.8/25.5/24.5) 1.2 (1.2/1.2/1.2) -95% eventRowCount 7663→793; eventDataBytes 13415640→1136399; repeatMs 0.2→0.1
u738kqjs29 phone8-after-app 184 (184/184/181) 0.5 (0.5/0.5/0.5) -100% eventRowCount 7663→793; eventDataBytes 13415640→1136399
kdrbtee92b summaryOnly-after-app 9.3 (9.3/9.4/9.3) 5.9 (6.7/5.9/5.9) -37%
kdrbtee92b cliLog-after-app 11.9 (11.9/11.9/11.8) 8.7 (8.7/8.6/9.0) -27%
kdrbtee92b includeNestedRows-after-app 12.3 (12.4/12.3/12.1) 8.8 (8.8/8.8/9.0) -28%
kdrbtee92b phone8-after-app 21.9 (21.9/22.0/21.6) 0.7 (0.7/0.7/0.7) -97% foldedEventCount 1295→0
avim9t7kpe summaryOnly-after-app 16.7 (16.7/17.0/16.5) 0.5 (0.5/0.5/0.4) -97% eventRowCount 5888→40; eventDataBytes 12044203→30871
avim9t7kpe cliLog-after-app 15.9 (15.9/16.0/15.6) 0.5 (0.5/0.5/0.5) -97% eventRowCount 5888→40; eventDataBytes 12044203→30871; repeatMs 0.1→0
avim9t7kpe includeNestedRows-after-app 42.0 (41.0/42.8/42.0) 112 (112/114/110) +165% repeatMs 42.2→0.1; repeatRebuilt True→False
avim9t7kpe phone8-after-app 94.6 (93.8/94.6/94.9) 0.3 (0.3/0.3/0.3) -100% eventRowCount 5888→40; eventDataBytes 12044203→30871; repeatMs 0.1→0
6e9knccemi summaryOnly-after-app 3.3 (3.2/3.5/3.3) 1.6 (1.6/1.6/1.6) -52%
6e9knccemi cliLog-after-app 4.3 (4.3/4.3/4.3) 2.6 (2.6/2.6/2.6) -40%
6e9knccemi includeNestedRows-after-app 4.4 (5.4/4.2/4.4) 2.6 (2.6/2.6/2.6) -41%
6e9knccemi phone8-after-app 9.7 (10.3/9.6/9.7) 0.9 (0.9/0.9/0.9) -91%
d5ej4e2gtv summaryOnly-after-app 2.5 (2.5/2.5/2.7) 1.1 (1.1/1.1/1.1) -56%
d5ej4e2gtv cliLog-after-app 3.1 (3.1/3.1/3.2) 1.7 (1.7/1.7/1.7) -45%
d5ej4e2gtv includeNestedRows-after-app 3.1 (3.1/3.1/3.0) 1.7 (1.7/1.7/1.7) -45%
d5ej4e2gtv phone8-after-app 8.8 (8.5/8.8/8.8) 7.0 (7.0/7.1/7.0) -20%
9h3n4aiax8 summaryOnly-after-app 2.6 (2.7/2.6/2.6) 0.8 (0.8/0.9/0.8) -69%
9h3n4aiax8 cliLog-after-app 2.9 (2.8/3.0/2.9) 1.0 (1.0/0.9/1.0) -66%
9h3n4aiax8 includeNestedRows-after-app 7.0 (7.0/7.0/7.2) 4.1 (4.1/4.1/4.0) -41%
9h3n4aiax8 phone8-after-app 9.3 (9.0/9.3/9.3) 5.2 (5.2/5.2/5.1) -44% eventRowCount 672→132; eventDataBytes 786936→154671
wg5iwwrezi summaryOnly-after-app 19.4 (19.4/19.5/19.3) 10.1 (10.1/10.0/10.3) -48%
wg5iwwrezi cliLog-after-app 25.6 (27.0/25.6/25.3) 16.8 (16.3/16.8/17.4) -34% repeatMs 27.8→0.2; repeatRebuilt True→False
wg5iwwrezi includeNestedRows-after-app 27.9 (27.3/28.0/27.9) 17.9 (17.3/18.1/17.9) -36% repeatMs 27.1→0.2; repeatRebuilt True→False
wg5iwwrezi phone8-after-app 36.3 (36.3/37.8/35.6) 3.2 (3.2/3.1/3.3) -91%
pvd2eqmdcv summaryOnly-after-app 2.4 (2.4/2.5/2.4) 1.3 (1.3/1.2/1.3) -46%
pvd2eqmdcv cliLog-after-app 3.1 (3.1/3.2/3.1) 1.9 (1.9/1.9/2.0) -39%
pvd2eqmdcv includeNestedRows-after-app 4.2 (4.2/4.5/3.3) 1.9 (1.9/1.9/2.0) -55%
pvd2eqmdcv phone8-after-app 5.2 (5.1/6.8/5.2) 2.7 (2.6/2.7/2.7) -48%
i2qj9tb7j3 summaryOnly-after-app 5.9 (5.9/6.4/5.9) 2.4 (2.5/2.4/2.4) -59%
i2qj9tb7j3 cliLog-after-app 7.5 (7.4/7.5/8.4) 4.3 (4.3/4.3/4.4) -43%
i2qj9tb7j3 includeNestedRows-after-app 8.3 (8.3/8.7/7.6) 4.3 (4.3/4.3/4.4) -48%
i2qj9tb7j3 phone8-after-app 10.1 (9.5/11.0/10.1) 5.4 (5.6/5.4/5.4) -47%
y6xhxw8t8w summaryOnly-after-app 9.4 (9.4/8.5/9.6) 3.9 (4.6/3.9/3.9) -59%
y6xhxw8t8w cliLog-after-app 12.0 (12.0/12.0/11.7) 6.9 (6.9/6.8/7.3) -42%
y6xhxw8t8w includeNestedRows-after-app 12.7 (12.7/11.8/12.8) 7.3 (8.3/7.1/7.3) -43%
y6xhxw8t8w phone8-after-app 4.8 (4.8/4.9/4.8) 3.0 (3.0/3.0/3.0) -38%
dbcv9uurw7 summaryOnly-after-app 8.2 (8.2/8.2/7.2) 3.8 (3.8/3.8/3.8) -54%
dbcv9uurw7 cliLog-after-app 10.7 (9.5/10.7/11.3) 6.2 (6.2/7.2/6.2) -42%
dbcv9uurw7 includeNestedRows-after-app 10.9 (10.9/10.9/9.9) 6.4 (7.5/6.4/6.4) -41%
dbcv9uurw7 phone8-after-app 15.7 (15.3/15.7/15.9) 1.8 (1.8/1.8/1.8) -89%
ymhw6pktq4 summaryOnly-after-app 1.4 (1.4/1.4/1.4) 0.8 (0.8/0.8/0.8) -43%
ymhw6pktq4 cliLog-after-app 1.7 (1.7/1.6/1.7) 1.1 (1.1/1.1/1.1) -35%
ymhw6pktq4 includeNestedRows-after-app 1.7 (1.7/1.7/1.7) 1.1 (1.1/1.1/1.1) -35%
ymhw6pktq4 phone8-after-app 3.1 (3.0/3.1/3.1) 1.5 (1.5/1.6/1.5) -52%

walk

thread case main ms integration ms Δ metrics main → int
u738kqjs29 app 846 (837/846/894) 224 (230/224/224) -73% eventRowsRead 34700→11981
kdrbtee92b app 194 (190/194/194) 152 (152/148/153) -21%
avim9t7kpe app 189 (188/190/189) 13.1 (13.1/13.6/13.1) -93% eventRowsRead 11777→73
6e9knccemi app 840 (840/843/830) 550 (538/550/550) -35% eventRowsRead 56704→35383
d5ej4e2gtv app 1847 (1832/1857/1847) 1511 (1523/1511/1510) -18% eventRowsRead 86461→78476
9h3n4aiax8 app 135 (135/135/132) 44.3 (44.3/45.4/44.0) -67% eventRowsRead 13938→1502
wg5iwwrezi app 49.7 (51.7/49.7/48.6) 42.2 (42.2/42.6/41.8) -15%
pvd2eqmdcv app 68.9 (70.5/68.3/68.9) 58.4 (57.6/58.4/62.7) -15%
i2qj9tb7j3 app 67.6 (71.5/67.6/65.7) 62.0 (62.0/63.1/60.5) -8%
y6xhxw8t8w app 205 (204/206/205) 175 (173/176/175) -15% eventRowsRead 11372→10352
dbcv9uurw7 app 22.3 (22.3/23.2/21.9) 19.8 (19.9/19.8/19.3) -11%
ymhw6pktq4 app 163 (163/163/161) 136 (134/144/136) -17%

walk-cli

thread case main ms integration ms Δ metrics main → int
u738kqjs29 cli-all 1519 (1519/1529/1512) 504 (500/513/504) -67% eventRowsRead 57686→24773
kdrbtee92b cli-all 738 (738/746/734) 483 (489/483/481) -35%
avim9t7kpe cli-all 191 (198/191/188) 12.7 (12.9/12.5/12.7) -93% eventRowsRead 11777→73
6e9knccemi cli-all 1052 (1068/1052/1027) 656 (655/658/656) -38% eventRowsRead 64266→38610
d5ej4e2gtv cli-all 3906 (3922/3906/3898) 2786 (2769/2786/2788) -29% eventRowsRead 157212→148496
9h3n4aiax8 cli-all 137 (135/138/137) 44.8 (44.8/45.6/44.8) -67% eventRowsRead 13938→1502
wg5iwwrezi cli-all 62.6 (62.1/63.7/62.6) 51.1 (51.1/54.2/51.1) -18%
pvd2eqmdcv cli-all 74.1 (74.2/73.0/74.1) 59.4 (57.5/59.4/61.1) -20%
i2qj9tb7j3 cli-all 72.6 (72.6/71.3/72.7) 65.0 (65.8/65.0/64.7) -10%
y6xhxw8t8w cli-all 232 (232/235/231) 194 (194/196/194) -16% eventRowsRead 11372→10352
dbcv9uurw7 cli-all 25.5 (25.4/25.7/25.5) 22.4 (22.4/22.4/22.5) -12%
ymhw6pktq4 cli-all 518 (518/522/505) 340 (341/340/332) -34%

details

thread case main ms integration ms Δ metrics main → int
u738kqjs29 turn-dabd1c25da-t3 684 (677/684/689) 0.4 (0.4/0.4/0.4) -100%
u738kqjs29 turn-dabd1c25da-t3#first 684 (677/684/689) 176 (176/178/176) -74%
kdrbtee92b turn-da1f5fa598-t1 480 (472/480/503) 0.3 (0.3/0.3/0.3) -100%
kdrbtee92b turn-da1f5fa598-t1#first 480 (472/480/503) 170 (170/164/180) -65%
avim9t7kpe turn-da15fcbc31-t1 643 (642/645/643) 0.7 (0.7/0.7/0.7) -100%
avim9t7kpe turn-da15fcbc31-t1#first 643 (642/645/643) 119 (121/119/119) -82%
6e9knccemi turn-da9ab5128d-t2 1588 (1586/1588/1596) 4.0 (4.5/3.9/4.0) -100%
6e9knccemi turn-da9ab5128d-t2#first 1588 (1586/1588/1596) 142 (138/155/142) -91%
d5ej4e2gtv turn-da2e060369-t4 177 (177/174/177) 0.1 (0.1/0.1/0.1) -100%
d5ej4e2gtv turn-da2e060369-t4#first 177 (177/174/177) 172 (172/175/170) -3%
9h3n4aiax8 turn-019ff43e-7dd8-7f33-9e26-c9ff76f8be2 90.3 (91.7/89.8/90.3) 0.0 (0.0/0.0/0.0) -100%
9h3n4aiax8 turn-019ff43e-7dd8-7f33-9e26-c9ff76f8be2 90.3 (91.7/89.8/90.3) 96.3 (97.7/96.3/95.4) +7%
wg5iwwrezi turn-da8858afa2-t1 148 (148/148/150) 0.4 (0.4/0.4/0.4) -100%
wg5iwwrezi turn-da8858afa2-t1#first 148 (148/148/150) 41.3 (42.0/41.3/40.3) -72%
pvd2eqmdcv turn-da12aed7b7-t1 33.3 (35.1/32.8/33.3) 0.1 (0.1/0.1/0.1) -100%
pvd2eqmdcv turn-da12aed7b7-t1#first 33.3 (35.1/32.8/33.3) 34.4 (36.2/34.3/34.4) +3%
i2qj9tb7j3 turn-da6a6e4f09-t4 23.5 (24.6/23.5/23.4) 0.2 (0.2/0.2/0.2) -99%
i2qj9tb7j3 turn-da6a6e4f09-t4#first 23.5 (24.6/23.5/23.4) 14.2 (14.3/14.0/14.2) -40%
y6xhxw8t8w turn-da3a386e4b-t1 55.3 (55.3/51.9/56.4) 0.3 (0.3/0.3/0.3) -99%
y6xhxw8t8w turn-da3a386e4b-t1#first 55.3 (55.3/51.9/56.4) 20.9 (21.1/20.9/20.0) -62%
dbcv9uurw7 turn-daa89f176d-t1 27.2 (26.9/27.2/27.2) 0.2 (0.2/0.2/0.2) -99%
dbcv9uurw7 turn-daa89f176d-t1#first 27.2 (26.9/27.2/27.2) 15.3 (15.5/15.3/15.1) -44%
ymhw6pktq4 turn-da7ca02626-t1 153 (153/152/156) 0.1 (0.1/0.1/0.1) -100%
ymhw6pktq4 turn-da7ca02626-t1#first 153 (153/152/156) 157 (172/153/157) +2%

outline

thread case main ms integration ms Δ metrics main → int
u738kqjs29 outline-cold 7.6 (7.3/7.6/8.2) 8.2 (8.2/8.2/8.0) +8%
u738kqjs29 outline-second-load 0.2 (0.2/0.2/0.2) 0.2 (0.2/0.2/0.2) +0%
kdrbtee92b outline-cold 10.7 (10.3/10.7/10.7) 11.3 (11.3/11.4/11.2) +6%
kdrbtee92b outline-second-load 8.8 (8.8/8.8/8.7) 2.1 (2.1/2.1/2.0) -76%
avim9t7kpe outline-cold 2.9 (2.8/3.0/2.9) 2.9 (2.9/2.8/2.9) +0%
avim9t7kpe outline-second-load 0.1 (0.1/0.1/0.1) 0.1 (0.1/0.1/0.1) +0%
6e9knccemi outline-cold 28.9 (28.2/29.9/28.9) 30.3 (31.3/30.3/30.3) +5%
6e9knccemi outline-second-load 0.9 (0.9/0.9/1.2) 1.0 (0.9/1.0/1.0) +11%
d5ej4e2gtv outline-cold 143 (143/143/142) 146 (146/152/146) +3%
d5ej4e2gtv outline-second-load 1.5 (1.4/1.5/2.2) 1.5 (1.5/1.5/1.5) +0%
9h3n4aiax8 outline-cold 7.5 (7.5/7.4/7.5) 7.4 (7.8/7.3/7.4) -1%
9h3n4aiax8 outline-second-load 0.2 (0.2/0.2/0.2) 0.2 (0.2/0.2/0.2) +0%
wg5iwwrezi outline-cold 2.5 (2.5/2.5/2.8) 2.8 (2.8/2.6/2.8) +12%
wg5iwwrezi outline-second-load 0.1 (0.0/0.1/0.1) 0.1 (0.1/0.1/0.1) +0%
pvd2eqmdcv outline-cold 7.9 (7.8/7.9/8.1) 7.9 (8.0/7.9/7.9) +0%
pvd2eqmdcv outline-second-load 0.1 (0.1/0.1/0.1) 0.1 (0.1/0.1/0.1) +0%
i2qj9tb7j3 outline-cold 9.7 (9.7/10.1/9.7) 10.0 (10.1/10.0/10.0) +3%
i2qj9tb7j3 outline-second-load 0.2 (0.2/0.2/0.2) 0.2 (0.2/0.2/0.2) +0%
y6xhxw8t8w outline-cold 15.0 (14.9/16.0/15.0) 15.9 (15.6/16.0/15.9) +6%
y6xhxw8t8w outline-second-load 0.4 (0.4/0.4/0.4) 0.4 (0.4/0.4/0.4) +0%
dbcv9uurw7 outline-cold 2.9 (2.9/2.8/2.9) 2.7 (2.7/2.6/2.7) -7%
dbcv9uurw7 outline-second-load 0.1 (0.1/0.1/0.1) 0.1 (0.1/0.1/0.1) +0%
ymhw6pktq4 outline-cold 8.5 (8.6/8.3/8.5) 8.7 (8.9/8.7/8.7) +2%
ymhw6pktq4 outline-second-load 0.1 (0.1/0.1/0.1) 0.1 (0.1/0.1/0.1) +0%

sqlcount

thread case main ms integration ms Δ metrics main → int
u738kqjs29 app-latest-sql 193 (193/193/200) 21.1 (21.1/21.0/21.7) -89% eventRowCount 7663→793; eventDataBytes 13415640→1136399; sqlRowsRead 19463→950; sqlDuplicateRows 11798→155
kdrbtee92b app-latest-sql 30.7 (30.7/30.6/30.9) 24.9 (25.1/24.2/24.9) -19% sqlRowsRead 2264→1332; sqlDuplicateRows 965→33
avim9t7kpe app-latest-sql 102 (100/102/103) 11.0 (11.0/10.8/11.0) -89% eventRowCount 5888→40; eventDataBytes 12044203→30871; sqlRowsRead 5897→49
6e9knccemi app-latest-sql 15.7 (15.7/15.6/16.1) 14.3 (14.6/14.3/14.1) -9%
d5ej4e2gtv app-latest-sql 31.3 (31.5/31.0/31.3) 30.5 (30.5/30.2/31.4) -3%
9h3n4aiax8 app-latest-sql 15.9 (16.3/15.9/15.8) 11.5 (11.5/11.3/11.8) -28% eventRowCount 851→326; eventDataBytes 1004035→384570; sqlRowsRead 925→399; sqlDuplicateRows 72→71
wg5iwwrezi app-latest-sql 51.9 (51.2/52.6/51.9) 43.0 (43.0/43.2/42.4) -17% sqlRowsRead 3358→2653; sqlDuplicateRows 730→25
pvd2eqmdcv app-latest-sql 14.0 (14.0/14.0/13.9) 13.1 (13.1/13.8/12.9) -6% sqlRowsRead 448→447; sqlDuplicateRows 71→70
i2qj9tb7j3 app-latest-sql 24.9 (24.3/24.9/25.7) 22.9 (22.9/22.0/23.1) -8%
y6xhxw8t8w app-latest-sql 30.0 (30.0/30.0/31.1) 27.2 (27.5/27.2/27.1) -9% sqlRowsRead 1540→1537; sqlDuplicateRows 78→75
dbcv9uurw7 app-latest-sql 22.9 (22.9/22.3/22.9) 19.5 (21.3/19.5/19.5) -15%
ymhw6pktq4 app-latest-sql 8.5 (8.5/8.7/8.5) 9.1 (8.5/9.2/9.1) +7%

capacity

thread case main ms integration ms Δ metrics main → int
all reopen-capacity 17.9 (17.9/17.9/18.0) 17.1 (17.1/17.5/17.1) -4%

push

thread case main ms integration ms Δ metrics main → int
kdrbtee92b cold-before-append 32.7 (32.7/32.7/32.9) 28.6 (28.6/28.6/29.6) -13%
kdrbtee92b warm-delta-after-append 2.7 (2.8/2.7/2.6) 1.8 (1.8/1.7/1.9) -33%
kdrbtee92b cold-after-append 31.0 (30.5/31.0/31.4) 24.9 (24.9/25.1/24.8) -20%
u738kqjs29:active cold-before-append 213 (209/213/222) 24.2 (24.9/24.2/24.2) -89% eventRowCount 7663→793; eventDataBytes 13415640→1136399; foldedEventCount 7662→792
u738kqjs29:active warm-delta-after-append 12.4 (11.8/12.4/12.4) 1.0 (1.1/1.0/1.0) -92% eventRowCount 7669.5→799.5; eventDataBytes 13416264→1137023
u738kqjs29:active cold-after-append 200 (198/200/201) 20.2 (20.9/20.2/20.0) -90% eventRowCount 7675→805; eventDataBytes 13416794→1137553; foldedEventCount 7674→804
wg5iwwrezi:active cold-before-append 55.5 (57.0/55.5/54.8) 49.9 (49.9/48.7/50.0) -10%
wg5iwwrezi:active warm-delta-after-append 9.5 (9.6/9.5/9.4) 3.3 (3.5/3.3/3.3) -65%
wg5iwwrezi:active cold-after-append 52.3 (51.3/52.3/52.8) 44.6 (44.7/44.6/44.3) -15%
txqr3djnmd:active cold-before-append 29.8 (29.5/30.7/29.8) 26.6 (27.4/26.6/26.6) -11%
txqr3djnmd:active warm-delta-after-append 7.0 (6.9/7.1/7.0) 1.8 (1.8/1.8/1.8) -74%
txqr3djnmd:active cold-after-append 28.8 (27.9/28.8/30.2) 24.0 (25.3/24.0/24.0) -17%

Typecheck and tests on 1f65878 (env -u BB_ACCOUNT_POOL_PARENT_URL -u BB_SERVER_URL -u BB_CLI, turbo):

  • Typecheck: --filter='...[origin/main]', 104 of 104 packages.
  • @bb/db 690; @bb/thread-view 515.
  • @bb/server test/services/threads, test/system, test/provider-corpus and test/public: 1,270 passed.
  • CI: every workflow run passes, or is skipped by the selector.

Recommended landing order

Checked with git merge-tree.

  1. Read thread head state without building a timeline window #7238 (keeps SDK 0.6.134)
  2. Stop re-reading delegated children in timeline window selection #7239
  3. Stop pruning from invalidating timelines it cannot change #7246
  4. Resume resolved-item pruning passes and bound each advance to its budget #7254 (conflicts with Stop pruning from invalidating timelines it cannot change #7246 in the sweep and docs; announce through Stop pruning from invalidating timelines it cannot change #7246's per-pass logic)
  5. Stop re-projecting whole turns on turn-details pages and whole epochs on outline loads #7243
  6. Copy fork history without stalling the server #7249
  7. Delete the branch a removed worktree created when nothing would be lost #7242
  8. Checkpoint SQLite WALs from a worker thread instead of inside commits (behind an experiment) #7108
  9. Skip unwatched terminal output lookups and build RPC result paths only on failure #7240 (re-bump the SDK to 0.6.135)
  10. Keep the server responsive when agents saturate the CPU (behind an experiment) #6215 (re-bump the SDK to 0.6.136; keeps protocol 265)
  11. Name the real work in event loop stall records #7241
  12. Run marketplace plugin servers in their own worker threads (experiment) #7248 (carries the Checkpoint SQLite WALs from a worker thread instead of inside commits (behind an experiment) #7108 and Name the real work in event loop stall records #7241 resolutions; re-bump the SDK to 0.6.137)
  13. Share timeline window builds across page shapes and key caches correctly #7245 (drops the extra generation revision field)
  14. Make timeline pushes cost closer to the rows that changed #7244 (carries the Share timeline window builds across page shapes and key caches correctly #7245 resolutions, the memo accounting and Name the real work in event loop stall records #7241's cost)
  15. Read timeline pages without whole turns, and page long turns by sequence #7247, last. It carries the durable-bump gate, the parented-rows merge, the memo changes, the rowsKey, the plan-capture guard and the single-render helper. Migrations 0155 and 0156 still follow 0154 unless main adds one first; in that case, regenerate with drizzle-kit and never hand-edit snapshots.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 30 commits October 23, 2026 20:50
On macOS the clutch scheduler gives a busy plain process only its fair
share against agent workloads, so under 15+ concurrent agents the server
main thread got ~6% of a core while having work ~88% of the time.
Spawning the server and daemon through taskpolicy -a gives them the
application scheduling policy, which keeps their latency at baseline
under heavy CPU contention. The policy is not inherited by their
children, so agents and terminals keep their normal priority.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The host daemon now sets nice 10 (below-normal on Windows) on provider
processes, terminal shells and environment lifecycle scripts right after
spawning them, so the builds and tests agents run inherit it. When many
agents saturate the CPU on Linux, the server keeps its share instead of
being preempted for most of each event-loop turn.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-workloads-thr_vw834vqyax

# Conflicts:
#	packages/process-utils/src/index.ts
…r-many-concurrent-agents-thr_vw834vqyax

# Conflicts:
#	packages/bb-app/src/logged-process.ts
…thr_vw834vqyax' into bb/server-stalls-under-many-concurrent-agents-thr_vw834vqyax
The server sends the experiment to daemons in the session handshake and in
provider-session-policy.replace (protocol 257). While it is on, the daemon
lowers provider processes and environment lifecycle scripts to nice 10. The
server and daemon mirror the value to <data dir>/agent-cpu-priority.json; the
launcher reads it at each spawn to decide on taskpolicy -a, and the daemon
seeds its own setting from it before the handshake. A missing or unreadable
file means off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…window

`bb thread show`, `bb thread commands`, `bb thread options`, and
`sdk.status` read their fields through `threads.timeline({ summaryOnly })`.
That builds and projects the whole latest page, which on a thread with a
long open turn decodes thousands of events on the event loop, and then
returns no rows. Agents polling child threads with `bb thread show`
repeated that build on every check (Discord report; #4674, #6499).

Add `GET /threads/:id/head-state` (`sdk.threads.experimental_headState`),
which decodes only the latest to-do snapshot and provider state events,
and switch those callers to it. On a production snapshot the summaryOnly
read took 4-174 ms per thread and the head-state read 0.2-0.9 ms, with
identical values on all 16 runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The group-context loop called ensureTimelineWindowParentedRows once per
iteration, and each call re-queried the children of every delegating item
in the window, including children already loaded with their turn. On
thr_u738kqjs29 the latest window read 19,463 rows for 7,665 distinct rows.

- Keep the set of tool calls whose children (and missing parents) were
  already fetched across loop iterations.
- Exclude turns the turn query already loaded from the child-row query
  (new excludedTurnIds argument; the trimmed memo source applies the
  same filter).
- Return the turn and child rows straight from the SQLite statement with
  aliased columns instead of Drizzle's per-row mapping.
- Check octet_length before the character-counting length() in the
  inline-output truncation column, so rows that are small in bytes skip
  a full UTF-8 scan.

Cold latest window, median of 3 alternating A/B harness pairs on the Nov 7
snapshot (load avg 11-40, shared machine):
- u738kqjs29: 222.8 -> 149.2 ms, rows read 19,463 -> 7,857
- kdrbtee92b: 36.1 -> 27.7 ms, rows read 2,264 -> 1,332
- avim9t7kpe: 129.2 -> 104.2 ms
- wg5iwwrezi: 60.3 -> 53.3 ms, rows read 3,358 -> 2,653
- u738kqjs29 older-page walk: 1,012 -> 678 ms

Responses are byte-identical across 1,648 replayed reads on 159 snapshot
threads, and memo-path windows after appends match fresh builds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r-many-concurrent-agents-thr_vw834vqyax

Bump HOST_DAEMON_PROTOCOL_VERSION to 265, keep the host toolchain's
loopback NO_PROXY for the taskpolicy-wrapped server and daemon, and
parse daemon messages through the contract schema in the experiment test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
listStoredEventRowsByParentToolCallIds bound every parent tool call id
plus the excluded turn ids in one unbatched statement, and
listStoredTimelineTurnEventRows assumed 32 fixed variables although the
inline-output truncation column binds more than that. Both now split
their ids with queryInSqliteVariableBatches, counting the fixed
variables from the statement built with an empty batch.

Tests cover 40,000 parent ids with 500 excluded turns and 33,002 turn
ids (both raised "too many SQL variables" before), and assert that the
parented read with excluded turns still searches
events_parent_tool_call_thread_parent_sequence_idx without a scan.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y on failure

Every daemon terminal.output chunk read its terminal_sessions row before
checking whether any browser was attached. Headless terminals, such as the
usage plugin's scans, never have one, so each chunk cost a query for nothing.
The handler also advanced the forwarded sequence for output nobody received,
so a browser reattaching during a daemon disconnect caught up from that
sequence and missed the output in between. The handler now returns before
the lookup when the terminal has no browser clients.

normalizeRpcJsonResult built a path string for every node of an RPC result
while copying it. It now keeps a segment stack and renders the path only
when it reports a problem.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Stall records named "ws:daemon heartbeat" as the longest synchronous work
in most windows because DB transactions, plugin handlers and plugin
background work were not measured. Record every bb.db transaction (labelled
by its first write), single statements of 1 ms or more, and the synchronous
part of each request, plugin invocation, plugin load and plugin service
before its first await. Name the dominant child chain and the calling work,
and add main-thread CPU and context switches to the longest unit and to the
slow timeline build log. Profile stall attribution now totals sampled time
per plugin id.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A push for one new event still re-ran several whole-window passes after the
selection memo and projection fold hit. This removes the biggest of them
without changing any output byte:

- Settled delegations: with deferContent the server dropped their child rows
  after building and mapping them. thread-view now skips building them
  (omitSettledDelegationChildRows) and only checks whether any child row
  exists, so the result stays null vs [] exact.
- bb thread tell detection: parseThreadTellCommand scanned every command
  (2 MB on u738kqjs29) several times per build. Results are now cached by
  command string, bounded like the shell intent cache.
- Interrupted turns: once any turn in the window was interrupted, every fold
  finish structuredClone'd the whole projection state. It now deep-copies only
  when interrupted-turn finalization would change something (a running call
  or a pending message in that turn).
- Decode: a selection that extends the previous one reuses its decoded
  prefix and byte count instead of re-decoding every row.
- Pagination byte budget: per-leaf and per-page JSON.stringify is replaced by
  byte counts cached per row object; unchanged latest-window rows and window
  fields are reused from the previous build when they serialize identically,
  so the tag, delta and byte counts only touch rows that changed.

Warm push after one appended event, in-process harness push scenario,
4 alternating base/fix pairs x 12 appends, load avg 14-19:

  thread                base ms  fix ms
  kdrbtee92b               4.0     2.8
  u738kqjs29 (active)     15.4     9.8
  8nnix6m53a (active)      5.9     3.0
  gyi25h9awq (active)     10.6     4.7
  wg5iwwrezi (active)     10.9     4.3
  txqr3djnmd (active)      8.0     2.5
  mwktgwihcc (active)      8.1     3.2

Parity: latest, phone, CLI, nested, nested+deferred, summaryOnly and three
older pages for all 947 snapshot threads with >=1,000 events, plus a
13-step warm-vs-cold replay with deltas on 112 threads, hash identical to
main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Phone (segmentLimit 8) and desktop (20) windows, summaryOnly, CLI log and
nested reads each paid a full build after the app's window was already
built, and with both phone and desktop watching a giant-turn thread the
two 13 MB selections evicted each other from the 16M-char memo, so every
push rebuilt both from SQL. Older pages were revisioned on the thread
head, so every append invalidated them, and no revision carried the
rewrite generation, so a gap-filled event below the head was never seen.

- Selection memo: a narrower window adopts a wider sibling's selection
  when both start at the same sequence, or trims it in memory; shared row
  arrays are counted once against the char budget.
- Projection cache keyed by the selected rows array: the event projection
  is shared across deferContent, summaryOnly and includeNestedRows; rows
  are materialized per includeNestedRows (thread-view now exposes
  projectThreadTimelineEvents and buildThreadTimelineFromProjection).
- Response cache: revisions include the rewrite generation; older pages
  are revisioned on generation and surface only (their cursor snapshot is
  already in the key); thread-deleted drops a thread's windows; the
  per-entry cap is 8 MB (was 2 MB, total cap unchanged at 64 MB).
- Decode cache: one LRU of 16M chars instead of two 4M generations, so a
  rescan of a 13M-char turn hits.

Snapshot A/B (3 alternating pairs, medians, load 17-64):
- u738 phone+desktop push after an append: 864 -> 26.5 ms
- older page re-read after an append: u738 230 -> 0.1, kdrb 108 -> 0.1 ms
- phone8 after app: u738 294 -> 5.3, avim 138 -> 2.2, kdrb 32 -> 1.8 ms
- summaryOnly after app: u738 42 -> 4.0, avim 23 -> 2.2 ms
- CLI log after app: u738 40 -> 3.9, avim 23 -> 2.0 ms
- nested after app: u738 46 -> 11, avim 59 -> 45 ms
- wg5 CLI log / nested repeat (over 2 MB): 38 -> 0.3 ms
- u738 walk pages 2-4: ~225 -> ~175 ms
- cold latest builds: unchanged (15 samples each, within noise)
Parity: 72 snapshot threads, 586 response hashes identical to main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every "load earlier" page of turn summary details re-read, decoded and
re-projected the whole turn, then paginated it, and re-expanding a turn
paid the same again. Cache the scoped projection per thread and request
shape, keyed on the cursor snapshot and the thread's rewrite generation,
and serve every page and repeat expand by paginating the cached rows with
their cached leaf sizes. Entries expire when a retained-output preview
they contain would flip to retention-expired.

Snapshot A/B (3 alternating pairs, load avg 12-69), whole walk / re-expand:
- 6e9knccemi t2 (7.6k events, 13 pages): 1913 -> 155 ms / 1914 -> 4.2 ms
- u738kqjs29 t3 (7.4k events, 4 pages): 859 -> 221 ms / 886 -> 0.7 ms
- avim9t7kpe t1 (5.9k events, 6 pages): 824 -> 140 ms / 840 -> 1.2 ms
First pages and single-page turns cost the same as before. Pages are
byte-identical across 23 turns on 12 threads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Any backgroundTask or delegation item in the projected history stopped
the outline from ever keeping a checkpoint, so every outline load of a
thread that had run one background command reprojected its whole epoch.
Treat background items like tool calls instead: their ids join the
checkpoint's referenced items, and a later event for one of them rebuilds
from scratch. The outline selection already drops a task's normal
completion, so the full build never depended on it.

Outline replay over 107 snapshot threads (4,573 append steps, incremental
vs the full builder at every step): 0 mismatches. Active outline reload,
3 alternating A/B pairs: d5ej4e2gtv 286 -> 116 ms, 6e9knccemi 34 -> 1.4 ms,
kdrbtee92b 12.6 -> 2.6 ms, ymhw6pktq4 12.1 -> 1.0 ms; replay median per
append: yvsvx8anai 18.4 -> 2.1 ms, dwzy4aij2h 16.5 -> 2.3 ms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…start test condition-based

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A reader that holds an old snapshot (for example a VACUUM INTO copy) stops
PASSIVE checkpoints from backfilling while writes keep growing the WAL. The
worker treated that as write starvation: it paused, asked the main thread to
checkpoint the tail, resumed, and repeated on every write, logging one
"Sustained writes" line each time (about 2,000 lines per 15 s pin on a bb.db
snapshot). The main-thread checkpoint could not help either, since the same
reader blocks it.

The worker now only reports starvation, and only re-runs immediately, when the
previous pass made checkpoint progress or the WAL restarted. A pinned WAL falls
back to the normal interval until the reader finishes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eader test

A fixed 1.5 s write window depends on runner speed, and stopping just past the
threshold let the unpatched worker pass before its starvation messages landed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Usage and turn-diff snapshot prunes no longer advance the thread's rewrite
generation or send history-compacted: timeline, outline and turn-detail
reads never load those rows beyond the kept snapshots. The settled sweep
now sends one history-compacted per thread pass instead of one per
ten-second run, and the timeline response cache keys on the rewrite
generation so reads between runs still match a fresh build. A history
rewrite on one thread now forgets only that thread's grouping contexts
instead of clearing them for every thread.

Replay of the production pruning schedule on 5 busy snapshot threads
(163 turn ends, deltas and usage rows reconstructed into pruned sequence
holes, 3 alternating A/B pairs, medians):
- history-compacted notices: 344 -> 121 (2.1 -> 0.74 per turn end)
- rewrite-generation bumps: 275 -> 156
- served timeline build time: 133 s -> 63 s; refetch builds 44 s -> 12 s
- u738kqjs29: 30 -> 9 notices, build time 78.8 s -> 32.5 s
- every post-prune read equalled a fresh build in both variants

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A timeline page fetched every turn it touched from the start of history,
plus every turn its delegation parents lived in, so a 17-row latest page on
thr_u738kqjs29 read a 7,407-event turn (7,663 rows, 13.4 MB) because one
background task in the window had a parent in that turn.

A turn whose rows render flat (a running turn, or any turn under the flat
display) is now read only inside the page window. The selection adds the
complete events of items that cross the window edges, delegation parents,
children of delegations the page owns, the turn's lifecycle, accepted input,
compaction and provider rows, and on older pages the turn's events up to the
furthest event those items reach, since the projection fold depends on them.
Turns that start inside the window are still read whole with no extra
queries. Finished turns under the collapsed display are still read whole.
The latest-selection memo appends to windowed turns and checks the store
before accepting an event for an item it has not seen.
olderRowsSourceSeqEnd is at least a windowed turn's last event before the
window, so the client merge never keeps a gap.

thr_u738kqjs29 cold latest page (in-process, snapshot): 7,663 -> 779 rows
read, ~210 -> ~32 ms. Rendered rows are unchanged: merged walks over 119
snapshot threads x 3 variants and the 12 harness threads x 4 variants are
byte-identical to main.

Refs #4674

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A window started at a user message, so a turn with no message inside it
was one page however long it ran: thr_kdrbtee92b's oldest page owned a
7,335-event turn.

When no message start fits the event budget, the window now starts on a
grid of half the budget at or below the budget floor, on the first
lifecycle event there (pruning never deletes those, so cursors stay
valid), moved back to the start of the item it lands in so the latest
page is never left holding only a streaming item's tail. The latest start
then moves once per half budget of appends, so the selection memo keeps
appending. The grid is skipped inside a finished collapsed turn, which is
read whole anyway. Cursors stay timeline-v3: their fields keep their
meaning, and the projection of a window is unchanged.

Harness, snapshot, two alternating A/B pairs, median of 3 per run, load
6-10:
- u738kqjs29 latest: 218 -> 24 ms, rows read 7,663 -> 772; push with one
  new event as active: 12.2 -> 1.6 ms; phone layout 188 -> 14 ms
- wg5iwwrezi latest: 53 -> 42 ms
- app walk: u738 918 -> 337 ms (34.7k -> 15.4k rows), 6e9knccemi
  958 -> 544 ms (56.7k -> 26.6k)
- thread log --all: d5ej4e2gtv 3.98 -> 3.04 s (157k -> 115k rows),
  u738 1.55 -> 0.57 s, kdrbtee92b 764 -> 466 ms, 6e9knccemi 1.07 -> 0.65 s
- costs: small-turn cold latest +0.5-1.5 ms (2-9%); app walk kdrbtee92b
  226 -> 292 ms and d5ej4e2gtv 2.04 -> 2.24 s, from the extra pages and
  the tail reads that keep older pages exact
Rows are unchanged: merged walks of 119 snapshot threads x 3 variants and
12 harness threads x 4 variants, plus latest-page head fields, are
byte-identical to main.

Refs #4674

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd-plugin-main-thre-thr_aemxuhadwf' into ru2/integration-wip
…-code-off-core-s-ev-thr_jbvai7bpud' into ru2/integration-wip

# Conflicts:
#	apps/server/src/services/plugins/plugin-api.ts
#	apps/server/src/services/plugins/plugin-runtime.ts
#	apps/server/src/services/system/periodic-sweeps.ts
#	packages/db/src/data/maintenance.ts
…aves-its-branch-beh-thr_rfnkcrag5v' into ru2/integration-wip
…urrent-agents-thr_vw834vqyax' into ru2/integration-wip
@ymichael ymichael changed the title Timeline perf integration (do not merge: verification branch for #7238 #7239 #7245 #7244 #7246 #7243) Timeline perf integration (do not merge: verification branch for #7238 #7239 #7245 #7244 #7246 #7243 #7254 #7249 #7241 #7108 #7240 #7248 #7242 #6215) Nov 7, 2026
ymichael and others added 6 commits November 7, 2026 14:35
The previous commits made some reads slower than main:
- Older pages re-read a turn's later events up to the furthest event their
  items reached. That guarded against a projection dependency that turned
  out to be a missing background-task start, already fixed, so the tail
  read is gone. On kdrbtee92b's app walk the turn rows read fall from
  15.4k back to main's 9.4k.
- Grid cuts split finished turns into more pages, each paying fixed
  per-page costs. Grid cuts now apply only inside running turns, and only
  when the turn has more than one budget of events before the cut. Pages
  over finished history keep main's boundaries.
- A turn that started before the window paid for context, item-closure and
  count queries. On the latest page each touched turn's first sequence now
  comes from one index-only query. A turn that starts within 256 sequences
  of the window is read whole in the same single query as the window, as
  main does. On older pages a turn with at most 256 events outside the
  window is read whole.
- A child-row exclusion subquery cost about 11 ms on kdrbtee92b's CLI walk
  and has been removed.

ymhw6pktq4 cold latest, the worst small case before this change, went
from +0.35 ms to +0.07 ms in turn loading (180 fresh-connection builds per
side). Merged walks are still byte-identical to main.

Refs #4674

Co-Authored-By: Claude Opus 5.5 <[email protected]>
S4's decoded-selection cache kept up to 4 decoded selections per thread for
64 threads per connection, bounded by count only, and nothing dropped them on
thread delete, history rewrite or idle. It retained row data the selection
memo and the stored-event decode cache had already let go: reading the 12
harness threads in 4 page shapes kept 261 MB alive in it.

The decoded rows now live on the selection memo entry whose rows they decode.
A memo hit hands the entry's decoded rows to the build as the prefix to
extend, and the build stores the extended result back on the new entry. The
decoded cache therefore has exactly the memo's bounds (16 entries, 4 idle,
16M data chars) and is forgotten wherever the memo forgets an entry: thread
delete, rewrite generation or data_version change, context-clear epoch change
and eviction. The separate per-thread map and its prefix scan are gone.

Retained heap after reading app, phone, CLI and nested windows (forced GC):

  scenario                     main     #7244 c381f52   this
  12 harness threads           +63 MB   +321 MB            +67 MB
  12 harness + 293 recent      +109 MB  +295 MB            +108 MB

Warm push after one appended event (harness push scenario, 9 alternating
pairs x 12 appends, median of per-run medians): kdrbtee92b 2.5 -> 2.4 ms,
u738kqjs29 (active) 8.8 -> 9.1 ms; the last 3 interleaved pairs were 8.8 vs
8.8 ms. Rows read, decoded and folded per push are identical. Warm cache-hit
reads stay at 0.0-0.1 ms on all 12 threads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A page that touched a finished turn under the collapsed display (Codex's
default) read the whole turn, because its summary rows depend on every
message in it: thr_avim9t7kpe's latest page read 5,888 rows to render 6.

The first time a page reads such a turn of at least 1,000 events whole, it
stores the turn's row plan in thread_turn_timeline_plans: the summary rows,
and the id and source range of each message the turn shows ungrouped.
Later pages take the summary rows from the plan and read only the events
of the ungrouped messages they show, plus the turn's context events.

A plan is keyed by a projection version, the in-process rewrite
generation, the thread status and the display settings that change the
output, following the thread_conversation_outlines precedent. It is used
only while the greatest sequence of the turn's events, its delegations'
children and its open items is unchanged. Rewriting the history suffix
deletes a thread's plans. The latest-selection memo rebuilds on any append
that touches a planned turn. Nested-row reads (bb thread log --format
verbose) still read the turn whole.

Harness, snapshot, three alternating A/B pairs, fresh DB clone per run,
median of 3 per run, load 6-10:
- avim9t7kpe latest page 105 -> 14 ms (5,888 -> 40 rows), app walk
  227 -> 15 ms, thread log --all 211 -> 15 ms
- 9h3n4aiax8 app walk 146 -> 52 ms (13.9k -> 1.5k rows)
- the first read of a turn materializes its plan at main's cost
- nested-row reads right after an app read of the same thread no longer
  share the app's whole-turn selection: avim 45 -> 144 ms, which is
  main's own cold nested read (143-150 ms; branch 137-140 ms)
Merged walks are byte-identical to main across 357 broad-sample walks,
208 walks of 104 Codex threads whose finished turns span pages, and 48
harness walks, each with plans being created and with all plans stored.

Refs #4674

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ized-costs-thr_jn4p352bnn' into bb/timeline-perf-integration
Stored per-turn plans and conversation outlines were keyed on the
in-process rewrite generation, which restarts at zero. A rewrite before a
restart could leave a stored plan or outline that still looked valid. A
gap-fill insert into a finished turn does not move the plan's watermark
(the turn's greatest sequence), so after a restart the stale plan was used
and the walk rendered the turn without the inserted message.

thread_event_rewrite_generations (migration 0156) holds a per-thread
generation. bumpThreadEventRewriteGeneration increments it in the same
transaction at every rewrite: suffix deletes, inserts at or below the
high-water mark, completed-output migrations, and pruning that removes
rows (moved inside the pruning transaction). The in-memory generation stays
the fast key for process-local caches. Turn plans and persisted outlines
key on the stored value, one primary-key read per build.

The new restart test seeds a plan and an outline, gap-fills an agent
message into the turn, reloads the server modules, and checks that the
walk and outline equal a rebuild with no stored artifacts. It fails when
the keys use the in-memory generation. The rewrite-generation DB tests now
also assert the stored value on every bump path.

Refs #4674

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-turn-pagination-46-thr_pgx4x6ezq6' into bb/timeline-perf-integration

# Conflicts:
#	apps/server/src/services/threads/timeline-pagination.ts
#	apps/server/src/services/threads/timeline-selection-memo.ts
#	apps/server/src/services/threads/timeline.ts
#	packages/db/src/data/events.ts
#	packages/db/src/data/thread-pruning.ts
#	packages/thread-view/src/build-thread-timeline.ts
@ymichael ymichael changed the title Timeline perf integration (do not merge: verification branch for #7238 #7239 #7245 #7244 #7246 #7243 #7254 #7249 #7241 #7108 #7240 #7248 #7242 #6215) Timeline perf integration (do not merge: verification branch for #7238 #7239 #7245 #7244 #7246 #7243 #7247 #7254 #7249 #7241 #7108 #7240 #7248 #7242 #6215) Nov 7, 2026
ymichael and others added 2 commits November 7, 2026 15:56
…n one pass

Evicting one entry per insert from the front of the Map walked every
tombstone left by earlier deletes, so each insert over budget cost
O(evicted entries) and 600k inserts took 16 s instead of 85 ms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…visit after it

The turn-end live prune now removes rows, and each removal sent its own
history-compacted notice before the sweep's pass over the same thread sent
another. A live step on a settled thread now leaves its notice to the
sweep's next visit to that thread, with a one-minute fallback, and the
timeline response cache revision includes the rewrite generation so
server reads never depend on the notice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael and others added 5 commits November 7, 2026 16:13
…aring-thr_curdrpgt2c' into bb/timeline-perf-integration
…29ek' into bb/timeline-perf-integration

# Conflicts:
#	apps/server/src/services/system/thread-pruning-sweep.ts
#	apps/server/src/services/threads/timeline-cache.ts
#	apps/server/test/services/threads/timeline-cache.test.ts
#	docs/events-table-pruning.md
timelinePage.olderRowsSourceSeqEnd depended on whether a turn's plan
was stored and on read order. The page folded in the latest event of
every windowed or planned turn before the window. A whole read of the
same turn instead reports the greatest sourceSeqEnd of the rows it
projected and did not return, leaving out rows sent as olderRowUpdates.
thr_avim9t7kpe's latest page reported 1 on a fresh database and 1925
once its plan was stored. A nested read first left a plan-less memo
entry that later app reads reused, so those reported 1 again.

The page now adds only what a whole read would have projected:
- a planned turn: the end of each stored ungrouped message that ends
  before the window. Plans keep only messages that render a row, and a
  stored message matches its projected message by id and source range.
- a turn read only inside the window: its latest event before the
  window, skipping context events (already read) and events whose
  top-level row reaches the window. A metadata-only backward scan
  finds it and usually stops after one page.

A windowed read also reads the turn-scoped start of an item whose
thread-scoped completion is in the window. Without it,
thr_u738kqjs29's older pages gave a delegation row a later
sourceSeqEnd than main.

#7247's new queries hardcoded SQL-variable counts and used Drizzle row
mapping. They now batch with queryInSqliteVariableBatches on the
query's exact fixed-variable count, and turn and item rows read raw
rows through the same helpers #7239 adds.

Snapshot parity against main 55135d1, 162 threads, every response
including olderRowsSourceSeqEnd and tag: 4,652 hashes, 0 differences.
Reverse read order: 2,462 hashes, 0 differences. Append replay: 1,024
steps, 5,120 deltas, 0 warm-vs-cold mismatches.

Refs #4674

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-turn-pagination-46-thr_pgx4x6ezq6' into bb/timeline-perf-integration

# Conflicts:
#	packages/thread-view/src/build-thread-timeline.ts
…dget

The latest-window row reuse kept the pageable rows of the last 32 windows
per connection in a separate map. The bound was a count, not a size, and
the map never dropped a thread's windows on history rewrite, compaction or
memo eviction.

The kept rows now live on the selection memo entry for their selection,
one set per (deferContent, includeNestedRows) variant. Their JSON bytes
count toward the memo's 16M budget along with the selection's data chars.
They go away wherever the memo drops an entry: forget on rewrite or
compaction, context-clear epoch change and eviction. A rewritten
generation doesn't carry them over. After pagination, only rows whose JSON
size pagination already measured are kept. Those are the only rows reuse
helps, and their size costs nothing extra. Charging every pageable row
instead stringified the older context rows pagination never touches,
which doubled u738kqjs29's first CLI read after an app read
(27 -> 57 ms).

Retained heapUsed after reading app, phone, CLI and nested windows of each
thread (forced GC; kept rows = heap freed by dropping them once the
windows instance is gone):

  read set                          49f4151        this
  12 harness threads                +66.5 MB (5.9)    +66.5 MB (1.0)
  305 threads                       +108.3 MB (3.2)   +108.4 MB (1.2)
  305, harness threads read last    +128.6 MB (5.9)   +112.4 MB (1.0)
  318, 17 largest threads last      +149.1 MB (14.4)  +140.3 MB (0.0)

Responses are identical to 49f4151: 4,652 forward and 2,462
reverse-order hashes over 162 threads, and 0 warm-vs-cold mismatches over
1,024 append-replay steps. Harness timings, 4 alternating pairs, are within
1% in total, and every rows-read and bytes metric is identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael and others added 3 commits November 7, 2026 16:49
A deferred notice was sent by whichever sweep visit came next, usually a
pass that removed nothing, so the rewriting pass after it still sent its
own and the count didn't drop. A live step's notice now rides on the
sweep's next real notice for the thread, with the one-minute fallback,
and active-turn live steps defer the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ized-costs-thr_jn4p352bnn' into bb/timeline-perf-integration

# Conflicts:
#	apps/server/src/services/threads/timeline-selection-memo.ts
The batched queries rendered every query twice: once with an empty
batch to count its fixed variables, then again for the batch. The
inline-output truncation column makes that render expensive, so
listStoredTimelineTurnContextRows cost 650 us against 410 us before
batching. queryRawRowsInSqliteVariableBatches now renders the query
once with the whole list, takes the exact fixed-variable count from
that render, and runs it directly when it fits. Only lists above the
SQLite limit pay for per-batch renders. The aggregate and start-lookup
queries keep their raw SQL text, rendered through SQLiteSyncDialect.

The older-row scan starts with 16 events and grows, and the thread-scope
start lookup is skipped when the page reads no turn in part.

Micro-benchmark on thr_u738kqjs29, per call against the PR head:
turn context rows 409 vs 408 us, first sequences 28.6 vs 28.3 us,
outside counts 26.7 vs 26.4 us.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…29ek' into bb/timeline-perf-integration

# Conflicts:
#	apps/server/src/services/system/thread-pruning-sweep.ts
#	docs/events-table-pruning.md
…-turn-pagination-46-thr_pgx4x6ezq6' into bb/timeline-perf-integration
ymichael added a commit that referenced this pull request Nov 9, 2026
…tly (#7245)

## Human comments

## What was wrong

Timeline window caches were keyed on the request's page shape and on the
thread head, not on what actually determines the output. The selection
memo was keyed by `segmentLimit`. So the phone (8) and desktop (20)
windows each ran their own SQL selection, decode and projection, even
when both started at the same sequence. On a giant-turn thread the two
~13M-char selections could not both fit the memo's 16M-char budget: with
phone and desktop both watching, every push evicted the other entry and
rebuilt both windows from SQL. summaryOnly, CLI log and nested reads
shared the selection but re-ran the whole projection. In the response
cache, older pages used the current `maxSeq`/status as their revision,
even though their content is fixed by the cursor's snapshot, so every
append on an active thread invalidated them. No revision carried the
rewrite generation, so an event gap-filled below the head (same
`maxSeq`) was served stale. `thread-deleted` never dropped cached
windows. Windows over 2 MB were never cached. The decode cache's two
4M-char generations thrash on a rescan of any turn larger than one
generation (the largest recent turns are 11–13M chars).

## What changed

- `timeline-selection-memo.ts`: a narrower window adopts a wider
sibling's selection (same thread, budget, epoch, head and generation)
when its computed start equals the sibling's. If the start is later, it
trims the sibling's rows in memory instead of running SQL. A wider
window whose start equals a narrower sibling's adopts that selection
too. Row arrays shared between entries count once against the char
budget. A memo hit with no appended rows keeps the same row array.
- `timeline-projection-cache.ts` (new), `timeline.ts`: the projection is
cached per selected row array (a `WeakMap`, so it lives exactly as long
as the memo's rows). The event projection is shared across
`deferContent`, `summaryOnly` and `includeNestedRows`, and rows are
materialized per `includeNestedRows`. Output after projection (previews,
deferral, pagination, shortening, tag) is still computed per request.
`@bb/thread-view` now exports `projectThreadTimelineEvents` and
`buildThreadTimelineFromProjection`; `buildThreadTimelineFromEvents`
composes them. Profiles have a new `thread-view-rows` stage for
materialization.
- `timeline-cache.ts`, `thread-timeline-windows.ts`: revisions include
the rewrite generation. Older pages are revisioned on generation and
surface only, because the anchor id in the key already encodes the
cursor snapshot. `thread-deleted` invalidates the thread's windows. The
per-entry cap is now 8 MB (was 2 MB). The 64 MB total is unchanged, and
cached responses measured 1.3–1.6× their JSON size in heap.
- `stored-event-decode-cache.ts`: one LRU of 16M chars replaces two
4M-char generations, so a rescan of a turn up to 16M chars hits. Once
the cache goes over either cap, it evicts the oldest entries down to 90%
of both caps in one pass. Evicting one entry per insert from the front
of the `Map` would walk every slot deleted before it (V8 keeps deleted
slots until the next rehash): 600k inserts take 14.6 s that way and 82
ms with batch eviction.

No wire, CLI or SDK changes. Every response is byte-identical to main
(parity below).

## How you verified

Benchmarked on a prod snapshot clone with the shared in-process harness
(cold/variants/walk/push) plus S2 scenarios (older pages after an
append, phone+desktop push, parity, memory). Three alternating base/new
pairs, medians of medians. Load average was 17–64 because other
benchmarks shared the host; row and parity metrics are deterministic.

| case | main | this PR |
|---|---|---|
| u738 phone+desktop latest after one append | 864 ms | 26.5 ms |
| older page re-read after an append (u738 / kdrb) | 230 / 108 ms,
rebuilt | 0.1 / 0.1 ms, hit |
| phone8 after app (u738 / avim / kdrb / wg5) | 294 / 138 / 32 / 52 ms |
5.3 / 2.2 / 1.8 / 7.7 ms |
| summaryOnly after app (u738 / avim / wg5) | 42 / 23 / 29 ms | 4.0 /
2.2 / 15 ms |
| CLI log after app (u738 / avim / kdrb) | 40 / 23 / 22 ms | 3.9 / 2.0 /
13.5 ms |
| nested after app (u738 / avim) | 46 / 59 ms | 11 / 45 ms |
| repeat of a window over 2 MB (wg5 CLI log, avim nested) | 38 / 55 ms |
0.3 / 0.2 ms |
| u738 older-page walk, pages 2–4 (decode cache) | ~225 ms each | ~175
ms each |
| cold latest, 12 threads (5 repeats × 3 pairs, load ~17) | — | within
−10%/+7%, minima overlap |
| module-cache heap after app+summary+CLI+nested+phone on 12 threads |
29.7 MB | 42.2 MB |

The extra heap is mostly the decode cache (16M vs 8M chars, about 3.1
heap bytes per cached char when it holds the only copy of the row data).

**Parity.** On 72 snapshot threads (the 12 harness threads plus 60
threads with ≥1,000 events), each of 6 variants (app, summaryOnly, CLI
log, nested, phone8, CLI log at segment limit 100) was built cold, plus
the latest and up to three older pages. All 586 response hashes,
including rows, tags and cursors, are identical to main. On this branch,
1,008 reads in two warm sharing orders (wide first and narrow first)
each equal the cold build. After appends, the older-page and
phone/desktop scenarios showed zero mismatches against fresh builds.

**Decode-cache eviction** (23d0283, found by the integration branch
#7250). Per-insert front eviction made the `capacity` scenario (one
instance opens 712 threads, then re-reads them) 14–17% slower than main.
Harness `capacity,cold`, 9 repeats, three alternating pairs on fresh
snapshot clones, load 4–8:

| case | dc75c40 (per-insert eviction) | 23d0283 (batch eviction)
|
|---|---|---|
| capacity reopen, median cold open | 23.8 ms (23.8 / 24.3 / 22.9) |
19.8 ms (19.8 / 19.9 / 19.1), −17% |
| capacity first miss from newest / retained windows | 403 / 402 | 403 /
402 |
| cold latest, 12 threads (medians of medians) | — | −2% to +8% per
thread, ranges overlap. A cold read uses a fresh connection, and no
thread exceeds the cap, so it never evicts. |

The PR's other bounded `Map`s are fine. The response cache (512 entries)
and the selection memo (16 entries) also evict from the front, but at
those sizes 600k inserts take 108 ms and 49 ms (vs 45 / 44 ms with batch
eviction). Both predate this PR. The projection cache is a `WeakMap`
with at most 4 entries per selection.

Parity of the fix: the 162-thread parity replay (12 harness threads plus
150 sampled threads with ≥1,000 events, 8 latest variants, older pages,
repeats, turn details, outline), with one connection per arm so the
decode cache evicts. All 4,652 response hashes are identical between
dc75c40 and 23d0283 (and against a second dc75c40 run). The 8
errors are the same on both arms: details requests for 2 turns that the
route rejects on main too.

**Tests** (they fail on main, pass here):
- `test/services/threads/timeline-window-sharing.test.ts`: a gap-filled
event below the head is served. Older pages stay cached while the thread
grows and are rebuilt after a rewrite. Phone reuses desktop's selection
and projection. summaryOnly, CLI and nested reuse the app's projection.
`thread-deleted` drops cached windows. All 5 fail on main.
- `stored-event-decode-cache.test.ts`: a rescan of a turn at 75% of the
cap hits on every row. Going over the cap evicts down to 90% at once, so
the next inserts evict nothing; this one fails on dc75c40 (`expected
15987023 to be less than or equal to 14400000`).
- `timeline-cache.test.ts`: older-page revision ignores the head and
includes the generation; a 3 MB window is cached by default.
- `timeline-selection-memo.test.ts`: the randomized warm-equals-cold
replay also builds a narrower window before and after the wider one.

Commands: `pnpm exec turbo run typecheck lint --filter=@bb/server
--filter=@bb/thread-view` passes. `pnpm exec turbo run test
--filter=@bb/server --filter=@bb/thread-view`: thread-view 510/510;
server 3,947 passed and 1 failed, in
`test/app/install-machine-script.test.ts`. That file also fails on main
on this host (a different test each run, timing under load) and is
unrelated.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 9, 2026
## Human comments

## What was wrong

With the selection memo and projection fold both hitting, a push for one
new event still ran several passes over the whole latest window
(timeline perf audit, REPORT #5). On the snapshot threads the biggest
were:
- **Settled delegations.** Their child rows were built and mapped
bottom-up, then thrown away by `deferSettledTimelineRow` (572 of 634
rows on kdrbtee92b).
- **Sent-message detection.** `parseThreadTellCommand` scanned every
command's text several times per build (2 MB per pass on u738kqjs29,
about 14% of a push).
- **Interrupted turns.** Once any turn in the window had been
interrupted, every fold finish ran `structuredClone` on the whole
projection state, because `pendingFinalizationByTurnId` is never cleared
(6 of 150 sampled active threads, 1–1.8 ms per push).
- **Decoding and byte counts.** Every row was decoded and its bytes
counted again.
- **Byte-budget pagination.** It ran `JSON.stringify` on every leaf,
then on every returned segment.
- **Tag and delta.** Every row object was fresh each build, so the tag
and delta hashed and stringified all of them again.

## What changed

- **thread-view.** `buildThreadTimelineFromEvents` takes a new
`omitSettledDelegationChildRows` option. The server sets it when
`deferContent` is on, and settled delegations then skip building their
child rows. Emptiness is still checked lazily, so the output keeps the
exact `null` vs `[]` that deferral produced.
- **thread-view.** `parseThreadTellCommand` results are cached by
command string, bounded the same way as `shellIntentCache` (16k entries,
8M chars), and every call returns a fresh object.
- **thread-view.** `copyProjectionStateForFinish` deep-copies only when
interrupted-turn finalization would actually change something: a running
call, or a pending message or cell scoped to that turn.
`interruptedTurnFinalizationChangesState` implements the check.
- **server.**
- `timeline-selection-decode.ts` / `timeline-selection-memo.ts`: when a
selection extends the previous one, it reuses the decoded prefix and its
byte count. The decoded rows live on the selection memo entry whose rows
they decode, so they have exactly the memo's bounds (16 entries, 4 idle,
16M data chars) and go away wherever the memo drops an entry: thread
delete, rewrite generation or `data_version` change, context-clear epoch
change, and eviction.
- `timeline-content-pagination.ts` / `timeline-pagination.ts`: JSON byte
counts are cached per row object, and array and parent sizes are derived
from their parts (exact for any UTF-8).
- `timeline-window-reuse.ts`: unchanged latest-window rows, and window
fields like todos and provider commands, are reused from the previous
build when they serialize identically, key order included. The tag,
delta and cache accounting then only touch rows that changed.
`getOrBuild` now passes the stale response to the builder for this.
- `timeline-selection-memo.ts`: the previous build's pageable rows,
which the next build reuses rows from, live on the selection memo entry,
one set per `deferContent`/`includeNestedRows` variant. Their JSON bytes
count toward the memo's 16M budget along with the selection's data
chars, and they go away wherever the memo drops an entry. Only rows
whose JSON size pagination already measured are kept, so the size costs
nothing extra (e515883).
- **server, after rebasing onto #7245.** #7245's projection cache shares
built rows between windows and keyed them only by `includeNestedRows`.
Deferred reads now leave out settled delegations' child rows, so a CLI
read after an app read could reuse the app's rows and lose a subagent's
children. `timeline-projection-cache.ts` now keys rows by
`includeNestedRows` and `omitSettledDelegationChildRows`. The first
non-deferred read after an app read builds its own rows; the projection
is still shared. In the selection memo, a selection shared by several
entries counts its data once, and kept pageable rows count per entry. An
entry that adopts a sibling's selection starts with no kept rows instead
of sharing the sibling's map.
- **No contract change.** No wire, CLI, SDK or plugin surface changes.
Output is byte-identical to main.

Not changed:
- **Push pacing** still waits the last build's duration (capped at 1 s).
Cheaper builds shorten it directly.
- **Remaining u738kqjs29 cost.** Most of its remaining push cost is the
fold finish over completed turn t3 (7.4k events). The window loads t3
only as context and the page doesn't return it. Removing that needs
page-bounded reads (#4674 / S6), not hit-path work.
- **kdrbtee92b grouping-context SQL.** About 10% of its push is still
`getTimelineGroupingContext` running again whenever child (parented)
events are appended.

## How you verified

**Before/after.** Harness push scenario: warm latest read with
`afterTag` after appending one `item/started`. In-process on a clone of
the Nov 7 snapshot. 4 alternating main/branch pairs × 12 appends, load
average 14–19 (other slices were benchmarking at the same time). Median
of per-run medians:

| thread | main ms | branch ms | Δ |
|---|---|---|---|
| kdrbtee92b (active) | 4.0 (3.5–4.4) | 2.8 (2.8–3.0) | −30% |
| u738kqjs29 (forced active) | 15.4 (14.3–16.2) | 9.8 (9.4–10.6) | −36%
|
| 8nnix6m53a (forced active) | 5.9 | 3.0 | −48% |
| gyi25h9awq (forced active) | 10.6 | 4.7 | −56% |
| wg5iwwrezi (forced active) | 10.9 | 4.3 | −61% |
| txqr3djnmd (forced active, interrupted turn) | 8.0 | 2.5 | −69% |
| mwktgwihcc (forced active, interrupted turn) | 8.1 | 3.2 | −60% |

An earlier round of 3 pairs at load average 37–58 showed the same
direction, with −16% to −61% and much wider spread.

**Memory.** The first version of this PR kept decoded selections in a
separate per-connection cache: 4 per thread for 64 threads, bounded by
count only, never dropped on thread delete, rewrite or idle. It retained
rows the memo and the stored-event decode cache had already released.
They now live on the memo entries (49f4151). Retained `heapUsed`
after one instance reads the app, phone, CLI and nested windows of each
thread, after a forced GC, on a clone of the snapshot:

| scenario | main | c381f52 | 49f4151 |
|---|---|---|---|
| 12 harness threads | +63 MB | +321 MB (261 MB in the decoded-selection
cache) | +67 MB |
| 12 harness + 293 most recent threads | +109 MB | +295 MB | +108 MB |
| 12 harness threads, forced active | – | – | +74 MB |

Push and warm timings for 49f4151 vs c381f52: harness `push` +
`warm`, 9 alternating pairs × 12 appends (3 of them reversed-order, 3
interleaved), load average 7–9. Median of per-run medians:

| case | c381f52 | 49f4151 |
|---|---|---|
| warm push, kdrbtee92b | 2.5 ms | 2.4 ms |
| warm push, u738kqjs29 (forced active) | 8.8 ms | 9.1 ms (last 3
interleaved pairs: 8.8 vs 8.8) |
| cold after append, kdrbtee92b / u738kqjs29 | 33.4 / 207.8 ms | 34.0 /
207.4 ms |
| warm cache hit, all 12 threads | 0.0–0.1 ms | 0.0–0.1 ms |

Rows read, decoded and folded per push are identical, and
`event-json-decode` stays under 0.1 ms on both, so the prefix is still
reused.

**Memory, kept pageable rows (e515883).** Before this commit the
reused rows sat in a separate per-connection map of the last 32 windows.
The bound was a count, and nothing dropped a thread's windows on
rewrite, compaction or memo eviction. Same measurement as above. In
brackets: heap freed by dropping the kept rows once the windows instance
is gone.

| read set | 49f4151 | e515883 |
|---|---|---|
| 12 harness threads | +66.5 MB (5.9) | +66.5 MB (1.0) |
| 305 threads (12 harness + 300 most recent) | +108.3 MB (3.2) | +108.4
MB (1.2) |
| the same 305, harness threads read last | +128.6 MB (5.9) | +112.4 MB
(1.0) |
| 318 threads, the 17 largest read last | +149.1 MB (14.4) | +140.3 MB
(0.0) |

On this branch alone the old map stayed small in the default read order,
because the last 32 windows read were small threads. With the larger
merged integration branch (#7250) it measured 33 MB at 305 threads.

The first version of this commit charged every pageable row. That
stringified the older context rows pagination never measures, and it
doubled u738kqjs29's first CLI, nested and summary reads after an app
read (27 → 57 ms). Keeping only measured rows removed that cost.

Timings for e515883 vs 49f4151: harness `cold`, `warm`,
`variants`, `capacity` and `push`. Push threads were kdrbtee92b plus
u738kqjs29, wg5iwwrezi and txqr3djnmd forced active, 12 appends, 5
repeats. 4 alternating pairs, each started at load below 8 (4.3–6.3).
Median of per-run medians:

| case | 49f4151 | e515883 |
|---|---|---|
| warm push, kdrbtee92b / txqr3djnmd / wg5iwwrezi / u738kqjs29 | 1.9 /
2.05 / 3.55 / 8.6 ms | 1.9 / 2.1 / 3.6 / 8.15 ms |
| cold after append, u738kqjs29 | 205.8 ms (202.5–212.5) | 210.8 ms
(206.6–220.3) |
| cold app latest, sum of 12 threads | 567.7 ms | 570.7 ms |
| first variant read after app, sum of 48 | 782.8 ms | 788.5 ms |
| u738kqjs29 CLI log after app | 26.85 ms | 27.15 ms |
| capacity reopen | 19.3 ms | 19.35 ms |
| warm cache hit, all 12 threads | 0.0–0.1 ms | 0.0–0.1 ms |

Every rows-read, decoded, bytes and response-bytes metric is identical
between the two.

**Parity.** Responses were hashed on main and on the branch over a
read-only clone of the snapshot:
- All 947 threads with ≥1,000 events, six window variants each: app
latest, phone (segmentLimit 8), CLI, nested, nested+deferred,
summaryOnly.
- Up to three older pages per thread.
- A 13-step incremental replay on 112 threads (the 12 harness threads
plus 100 sampled), app and CLI params. Each step compares warm memo,
fold and row-reuse builds against a cold build at the same maxSeq, and
also hashes the delta from the previous step.

Result: 9,723 / 9,723 hashes identical to main, and warm equals cold at
every replay step. Retained-output availability, which depends on
`Date.now()`, was normalized before hashing. Re-run on 49f4151 with
the same script on a fresh clone: 9,723 / 9,723 identical to main and to
c381f52, warm equals cold at every replay step.

e515883 vs 49f4151, using the integration's parity and
append-replay scripts on fresh clones:
- 162 threads × 8 variants, older pages, turn details and outlines:
4,652 forward-order and 2,462 reverse-order hashes, all identical.
- Append replay over 64 thread-runs: 1,024 steps and 5,120 deltas, 0
warm-vs-cold mismatches on both.

**Tests added.** I ran the `structuredClone` test against the old
condition, where it fails. The others test code paths that don't exist
on main, so they weren't run there.
- `thread-view/test/settled-delegation-child-rows.test.ts`: omitted
child rows equal deferring the full rows, including nested, childless
and pending delegations.
- `thread-view/test/event-projection-fold.test.ts`: fold matches cold
after every event for an interrupted turn with nothing pending, and
finishing does not call `structuredClone`.
- `thread-view/test/tool-call-parsing*.test.ts`: cached results are
independent objects, repeated parses are reused, and the existing
linearity benchmarks now use unique commands so the cache can't mask
them.
- `server/test/services/threads/timeline-selection-decode.test.ts`:
prefix reuse and byte count. The memo entry carries the decoded rows and
a reused selection extends them. Decoded rows are dropped on history
rewrite and thread forget, and when the memo evicts the entry for its
data-char budget or its entry cap.
- `server/test/services/threads/timeline-selection-decode.test.ts`, kept
pageable rows (e515883). A build reuses no row objects after the memo
forgets the thread. Kept rows count toward the memo budget, so a second
thread of the same size evicts the first. Both tests fail on 49f4151,
where the rebuilt rows are still the old objects.
- `server/test/services/threads/timeline-window-reuse.test.ts`:
unchanged rows keep identity across an append and serialize like a fresh
build; reuse only happens on exact JSON equality, including key order.
- `server/test/services/threads/timeline-content-pagination.test.ts`:
derived byte counts equal `Buffer.byteLength(JSON.stringify(rows))` for
nested multibyte rows.
- `server/test/services/threads/timeline-window-sharing.test.ts`: the
CLI window built after the app window keeps a settled subagent's child
rows. It fails without the cache-key change (`[null]` instead of `[1]`).
The existing sharing test now expects a row rebuild for each new row
shape (`includeNestedRows` × `deferContent`).

**Commands run.**
- e515883: `turbo run typecheck lint --filter=@bb/server`, plus
vitest on `test/services/threads` and `test/provider-corpus` (34 files,
293 tests pass, 1 skipped). All with `env -u BB_ACCOUNT_POOL_PARENT_URL
-u BB_SERVER_URL -u BB_CLI`.
- `pnpm exec turbo run typecheck test --filter=@bb/server
--filter=@bb/thread-view --filter=@bb/provider-parity`
- 49f4151: `turbo run typecheck lint --filter=@bb/server`, plus
vitest on `test/services/threads/timeline*`, `thread-events`,
`conversation-outline*`, `test/provider-corpus`, `event-pruning` and
`internal-event-append-ownership` (25 files, 241 tests pass, 1 skipped)

**After rebasing onto main at 226d128** (#7245, #7238, #7254, #7284):
`turbo run typecheck lint --filter=@bb/server`, `turbo run typecheck
test --filter=@bb/thread-view --filter=@bb/provider-parity`, and vitest
on `test/services/threads` and `test/provider-corpus` (38 files, 312
tests pass, 1 skipped). Push harness, 4 threads × 12 appends, rebased
branch vs main at be3ca2c: warm push −37% to −64%, identical response
bytes (load average 12–38, so the exact numbers are noisy).

Refs #4674 (does not fix it)

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@ymichael ymichael closed this Nov 9, 2026
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