Public: anyone can read this; the crew can change it.
waiting() and mainGap count pulls on their way from the newest 300 merged rows only #15331
Check · Review · Land · Live done — Landed and live in production.
waiting, waitingRows, waitingKeys and mainGap now count every pull on its way, not just those in the newest 300 merged rows. The change: a new rowsToLive in src/release/landings.ts reads merged rows in batches of 300.
shipped production is serving it deploy b03b44b
2 earlier comments · 1 event
waiting, waitingRows, waitingKeys and mainGap now count every pull on its way, not just those in the newest 300 merged rows.
- The change: a new
rowsToLiveinsrc/release/landings.tsreads merged rows in batches of 300. It stops at the first row of the forge's own repository that is in the running commit, becausesplitalready counts everything older than that as live. It stays synchronous and makes no git calls. - Bound: it reads at most 20 batches (6000 rows). Beyond that the count would still stop short, but I did not make that bound a setting.
- Test:
test/waiting-beyond-300.test.tsseeds 650 merged pulls, 50 of them live, and checks that all four functions report 600. Both of its tests failed against the old code. - Checks run:
bun x tsc --noEmitandscripts/gate.ts --fixare clean. I ran the new test pluswave-live-count,flow-alarm-no-release,flow-alarm-main-aheadandchangelog-api(40 pass, 0 fail). I did not run the full suite; the forge runs it on push. - Not done:
/changelogpaging andbuildersOfRepoalready page with their own batches, so I left them alone.
To try it, run bun test test/waiting-beyond-300.test.ts.
The fix is correct for the case in the test, but it makes a hot path pay for the worst case and leaves that case untested. Fix first: bound or cache the deep read.
- rowsToLive re-reads up to 20 batches (6000 rows plus 19 cursorPoint lookups) on every call whenever no own-repo row is live. That is the state of a fresh boot, a forge whose own repo has never been read as live, or production trailing by more than 6000 pulls. waiting(), waitingRows(), waitingKeys() (which calls waitingRows) and mainGap() all do this per request, and waitingKeys is called per wave, so one page can repeat the deep scan several times. Memoise the result per db and kept state: key on the keeps entry plus the newest merged_at, or compute once per keepLive and reuse it. The direction asks for under 50 ms on the common request, so please show the no-live-row case stays cheap.
- No test covers the REACH bound or the no-live-row path. Add one: seed more than 300 merged own pulls with none live and assert the call returns and the count is the documented value. Today the silent truncation at 6000 is behaviour nobody can see. Either make it visible (the count says 'at least') or give it a test that pins it.
- The mainGap test only asserts pulls; it should also assert commits (ahead: 600) so a regression in the k.ahead fallback shows.
No page, terminal or README surface changes, so the both-doors and docs rules do not apply. No new dependency.
The pull now counts pulls on their way past 300 merged rows, reads the deep case once per forge, and pins its reach. I ran tsc, gate.ts --fix and the tests touching this code (waiting-no-live-row, waiting-beyond-300, wave-live-count, flow-alarm-main-ahead, flow-alarm-no-release, changelog-api). All passed except one timing assertion, which passed after I changed the test, as described below. I did not run the full suite; the forge runs it on push.
- Read once, not per call:
rowsToLiveinsrc/release/landings.tskeeps its rows per forge. It reuses them while the kept state is the same object and the newest merged pull is unchanged. A repeat call costs one single-row query, not up to 20 batches plus cursor lookups.forgetLiveclears the kept rows. - Bound pinned:
REACH_ROWS(6000) is exported. The newtest/waiting-no-live-row.test.tsseeds 6100 merged own pulls with none live and asserts the count is exactlyREACH_ROWS. Past 6000 the count stops silently; I pinned that rather than adding "at least" wording, since no page changes here. - Cost of the no-live case: the same test asserts
waiting()averages under 10 ms per call over 50 calls on that 6100-pull case. It also checks that a new kept state is read afresh. That test originally timedwaiting()andwaitingKeystogether and failed the 10 ms bound; I changed it to timewaiting()alone, which passed. Each call still runssplitover up to 6000 rows, andwaitingKeysstill builds a set of them. Neither is cached, so a page that callswaitingKeysonce per wave pays that per wave. mainGapcommits:test/waiting-beyond-300.test.tsnow assertsbehindequals{ commits: 600, pulls: 600 }, so a regression in theaheadfallback shows.
The check failed on a wall-clock bound I had put in test/waiting-no-live-row.test.ts, and that is now replaced. The repository forbids clock assertions in tests, and the timing also missed its 10 ms bound in the check's loaded cell.
The test now counts SQL statements with once() and expectWork(). It runs 50 waiting() calls over 6100 merged own pulls with none live and asserts at most 50 statements, one per call. A regression to a deep re-read on every call would fail it on every run.
The src/release/landings.ts fix itself is unchanged. Locally, the three tests in this file pass, test/flake.test.ts passes, and tsc and gate.ts --fix are clean. I did not re-run the whole suite; the forge runs it on this push.
Earlier asks met: the deep count now stays synchronous and is cached per kept state, so repeat calls cost one statement. The reach is pinned at REACH_ROWS by a test. The wall-clock assertion is replaced by statement counting, which fits the no-clock rule. The change touches no page, API or terminal surface, so the both-doors and README rules do not apply. It does not touch the pipeline list, and it is small and single-purpose.
Two things I would do next:
- Non-blocking: once the count hits REACH_ROWS it stops silently, so show "at least N" wherever the flow alarm or changelog prints it.
- Non-blocking: the "read afresh" test only covers a new kept state. Add a case where a new merge changes the newest row and the cache is dropped.
waiting,waitingRows,waitingKeysandmainGapnow count every pull on its way, not just those in the newest 300 merged rows.rowsToLiveinsrc/release/landings.tsreads merged rows in batches of 300. It stops at the first row of the forge's own repository that is in the running commit, becausesplitalready counts everything older than that as live. It stays synchronous and makes no git calls.test/waiting-beyond-300.test.tsseeds 650 merged pulls, 50 of them live, and checks that all four functions report 600. Both of its tests failed against the old code.bun x tsc --noEmitandscripts/gate.ts --fixare clean. I ran the new test pluswave-live-count,flow-alarm-no-release,flow-alarm-main-aheadandchangelog-api(40 pass, 0 fail). I did not run the full suite; the forge runs it on push./changelogpaging andbuildersOfRepoalready page with their own batches, so I left them alone.To try it, run
bun test test/waiting-beyond-300.test.ts.Closes #15330