Repository navigation
Fix kept-order byte accounting after concurrent page reads - #111
Merged
Merged
Conversation
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.
Summary
Fix M1 from #108: after SQL returns, a kept-order reader only touches or forgets the exact order it read. This prevents it from resurrecting an uncounted entry or changing the entry another page admitted. SQL, stamp validation, and ranking are unchanged. Fork CI adds one named self-host step for kept orders, the search walk, and the new races.
Invariants and coverage
ordersBytesandoversizedHeldequal their respective map sums. The identity check andtouchrun synchronously; a successful touch changes recency only.forget,admit, andrememberuse current entries and update counters synchronously. The eviction test observes the pre-ranking room check incorrectly finding room by subtracting an uncounted order; the separate oversized accounting is unchanged and the existing kept-orders scenario exercises oversized isolation.admitcan insert a new order; it recalculates room after ranking and evicts only sufficiently idle entries. The eviction test uses four ~1.52 MB orders: it tests byte pressure well below 32 entries. The count bound follows from the synchronous admission check and the no-resurrection guard; the existing 40-search scenario also checks that active orders are retained under count pressure.kept; the stamp miss fills the active cache past the pre-ranking threshold so the resumed miss must rank without dropping the replacement. A new ranking, when room allows, can still perform an ordinary fresh admission.Test host only
The existing statement-hold fixture intercepts just the kept-page SQL fragment and signals after the reply, with no SQL connection held. The scenario owns the waiting MCP call and releases the hold on failure as well as success. Its separate monotonic-clock Layer offsets only Effect's monotonic readings; wall time, tracing timestamps, and live
sleepare delegated unchanged. Checked call sites: kept-order recency is the only product consumer of that reading; the CodeMode deadline Clock forwards it and delegates other sleeps, and Effect timeouts race aClock.sleep. The controls are mounted only by the loopback self-host test entry point, never by a production entry point. The app's public cache invalidation changes the listing in place; a redeploy would change the listing ID and miss the same-key race.Verification
On shuvdev with Node 24 (matching fork CI),
nice -n 19 bun run e2e:self-host --test-name '^A held kept-order read' --workers 1against the original7193e6a51store and the new tests failed on all three intended assertions (exit 1):With the fix restored, all three race scenarios passed. The same named self-host run also passed
mcp-search-kept-orders,mcp-search-walk,mcp-search-statements, and both the named held-check case and the access case that exercises the shared SQL hold (8 passed total). The named localmcp-search-conciserun passed (1 passed). No full E2E suite ran. The runs usednice -n 19, four CPUs and one E2E worker, one run at a time.bun run format,nice -n 19 bun run check(9/9 typecheck projects), ande2e:preparepassed.actionlintandgit diff --checkpassed. The upstream-stylee2e:check-descriptioncommand reaches a pre-existing fork/v2 coverage error forcloudOAuthProxyRefusal(pc_b9c87aaf36d5), before it can check the selection. Fork CI runs explicit title filters; no Cloud or production runs were made.Review notes
e2e/sdk/scenario.ts:91–108starts a fresh process per self-host scenario; the kept-orders and walk scenarios do not share its map.keptBytes − keptOrderBytes(4 MB), even if there are fewer than 32 orders.admit()note:forget(key)before the fit check can drop a same-key entry if its replacement cannot fit. That is a cache miss, not an accounting error; deliberately unchanged. M2, M3, N3, and N4 are outside this PR.Rat-stack pages followed:
skills/model-a-protocol(controlled interleavings and failing/passing twins; no committed model under Executor's E2E-only rule),lore/model-based-testing,skills/test-behaviour,lore/concurrent-work-needs-an-owner,lore/cache-completed-values,lore/testing-ladder, andlore/tests-that-earn-their-place.Refs #108