Skip to content

fix(net): a JS fill answers what the cache holds whole instead of asking its handler - #9771

Merged
kixelated merged 2 commits into
mainfrom
quest/m0/test-flakes-5/copy-fill-accept-after-close
Nov 27, 2026
Merged

kixelated merged 2 commits into
mainfrom
quest/m0/test-flakes-5/copy-fill-accept-after-close

Conversation

@kixelated

@kixelated kixelated commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m0/test-flakes-5/copy-fill-accept-after-close.md (deleted here).

Problem

js/net/src/lite/copy_fill.test.ts threw expected a value from defined(fill.accept(key)) as an unhandled error between tests, knocking PRs out of the merge queue. Only the lite-07 case of "reads back what a finished copy evicted" triggers it: 20 errors in 200 isolated runs, 5 in 560 whole-file runs.

The race is in the library, not the teardown. The copy asks the publisher for the evicted run twice: once by group (a run fill that lands groups 2 and 3) and once by time (a time start for time 2). Below the eviction watermark the publisher's cache cannot place the time by the groups it holds, so it asks a time-start fill. When that ask comes after group 2 already landed, no arrival answers it, and JS FillGroups.wanted() handed the handler key 2 anyway. accept(2) then answered the lookup but returned undefined because the track already held the group. Rust's FillGroups::wanted answers such a key from the cache instead of asking the handler.

Approach

  • FillGroups.wanted() answers a key the track holds whole from the cache (as an arrival would: a time start gets { kind: "group" }, a run resolves the key) and moves on, mirroring Rust. A handler serving wanted() is never asked for a group it already has.
  • copy_fill.test.ts drops its closed guard (if (!group && closed) break), added in feat(net)!: remove FETCH from lite-07 and serve fetches via bounded SUBSCRIBE #9687 against this same symptom; defined(fill.accept(key)) holds again.
  • New fill.test.ts case drives a FillState over a fake track holding group 2: a time start and a run both get no held key from wanted(). It fails on main (wanted() returns 2n).

Rust already does this (rs/moq-net/src/model/track/fill.rs, wanted_except), so no Rust change.

Impact

  • Public API: none. FillGroups.wanted() no longer returns a key the track caches whole (behavior change, matching its doc and Rust).
  • Wire: none.

Alternatives

  • Treat undefined from accept as "already held" in the harness: matches accept's doc, but leaves every JS handler doing work Rust's never does, and hides the divergence. Rejected.

Decisions

  • Fixed in the library (wanted()) rather than the harness, per the quest's plan ("If accept can return undefined while a case is still running, the fix belongs in the fill path"). Taken as my recommendation while the maintainer was away.
  • accept keeps returning undefined for a held key without resolving a run fill: with wanted() answering held keys, a handler following wanted() never reaches it, and the relay handlers that iterate runs already check isWanted/undefined.

Caused by

  • moq-dev/moq#9228 - added JS time-start fills, which only an arrival answers, without wanted() answering a group the cache already holds as Rust does (found by check)
  • moq-dev/moq#9687 - the lite-07 SUBSCRIBE fill path exposed it, and its closed guard masked the symptom only after teardown (found by check)

Validation

  • Before (main 541c0839bf): bun test src/lite/copy_fill.test.ts --rerun-each 200 -t "moq-lite-07-wip reads back what a finished copy evicted": 200 pass, 20 errors. --rerun-each 20 on the whole file: 560 pass, 5 errors.
  • After: the same isolated case --rerun-each 400: 400 pass, 0 errors. The whole file --rerun-each 100: 2800 pass, 0 errors.
  • New unit test fails before the fix, passes after; src/fill.test.ts 82 pass.
  • just ci (scoped) passed, including test js (@moq/net 3982 pass, 0 fail).

Follow-ups

None.

Models

  • Size: S
  • Implementer: Claude Code, claude-opus-5-5, unknown (arm A)

(Written by Claude Opus 5.5)

Review

Rewritten by quest review after each round.

  • Head: d47ae6f

  • Base: origin/main at ed3a269

  • Risk: medium, The change alters shipped JS fill behavior in js/net/src/fill.ts so that a time-start fill, or a run's group, the cache already holds whole is answered from the cache rather than asked of the source handler; the API and wire format are unchanged, so a bad fix would reach JS consumers of the next patch release, e.g. by a handler not being asked or a fill being answered from the cache wrongly, and it is easy to undo by reverting the commit, since the only other edits are tests and a deleted quest plan doc.

  • Classified: medium by Claude Code, claude-haiku-5-5, low effort, session eacd538f-3a82-43b8-8eca-47c3455bed94

  • Risk file: bb7b1c0de60b

  • Reviewer: Codex, gpt-6.2-sol, medium effort

  • Session: 01a21db7-c43f-7df0-bcf0-996d60dd850e, round 1

  • Score: 9/10, Source review found no blocking regression in this medium-risk fix, which lets `wanted()` and `wantedChanged()` settle cached groups before reporting work to the handler while still requesting headless copies, but no tests were run.

  • Rounds: 1; first round 0; findings 0: fixed 0, refuted 0, open 0

  • Findings: none

kixelated and others added 2 commits November 27, 2026 05:15
…ing its handler

A time start asked once its group already landed (the cache cannot place the
time below the eviction watermark) had no arrival to answer it, so
`FillGroups.wanted` handed the handler a key the track already held and
`accept` returned undefined. Answer such keys from the cache, as the Rust
`FillGroups::wanted` does. This was the copy_fill harness's "expected a value"
flake; its after-close guard, which masked the same symptom, goes too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title The copy fill harness accepts no group after its test ends fix(net): a JS fill answers what the cache holds whole instead of asking its handler Nov 27, 2026
@kixelated
kixelated marked this pull request as ready for review November 27, 2026 15:57
@kixelated
kixelated added this pull request to the merge queue Nov 27, 2026
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Fill selection now checks whether the cache holds each owed group whole and resolves cached keys before requesting another key. A new test verifies that a cached group in a time-start fill does not invoke the source. The archive fill test helper no longer uses a closed flag or breaks when acceptance returns no group. The note describing an intermittent test error and its unconfirmed cause is deleted.

Merge Risk: Minimal · up to d47ae

This change makes fills answer already-cached groups from the cache instead of asking the source again, which removes an intermittent test error. The public API and wire format are unchanged, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change: JS fill answers keys the track holds whole from the cache instead of asking the handler. This matches the raw summary (FillGroups.wanted() skips cached keys) and the PR obj…
Description check Passed The description is detailed and on-topic. It explains the problem (unhandled 'expected a value' error from defined(fill.accept(key)) in copy_fill.test.ts), the root cause in FillGroups.wanted(), the a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: JS fill answers keys the track holds whole from the cache instead of asking the handler. This matches the raw summary (FillGroups.wanted() skips cached keys) and the PR objectives (matching Rust's FillGroups::wanted). It is specific and single-sentence. The 'fix(net):' prefix is conventional, and the title is 84 characters, which is slightly long but acceptable.

Full details: Description check

Explanation

The description is detailed and on-topic. It explains the problem (unhandled 'expected a value' error from defined(fill.accept(key)) in copy_fill.test.ts), the root cause in FillGroups.wanted(), the approach (answer held keys from cache, mirroring Rust), the removed closed guard, the new fill.test.ts case, impact, alternatives, and validation numbers. It clearly relates to the changeset.

Finishing Touches

Simplify code

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6f422b66-22d0-448c-9d3d-bb20a485972d
Commits

Reviewing files that changed from the base of the PR and between 541c083 and d47ae6f.

Files selected for processing: 4

  • js/net/src/fill.test.ts
  • js/net/src/fill.ts
  • js/net/src/lite/copy_fill.test.ts
  • quest/m0/test-flakes-5/copy-fill-accept-after-close.md
Files with no reviewable changes: 1

  • quest/m0/test-flakes-5/copy-fill-accept-after-close.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

Merged via the queue into main with commit c3ea8f8 Nov 27, 2026
7 checks passed
@kixelated
kixelated deleted the quest/m0/test-flakes-5/copy-fill-accept-after-close branch November 27, 2026 16:03
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