Drop a grounding read that a newer one replaced - #40
Conversation
62033bf to
0cd80d6
Compare
|
The The fix is |
Go ahead. |
A file read that was still in flight committed its result whenever it landed. Picking a second JD before the first finished reading could leave the first one's snippets under the second file's name, and a resume read when Clear was pressed brought the cleared snippets back. Each document kind now counts its reads and Clear bumps both, so a read that is no longer the latest one is dropped without touching the lists or the status line.
0cd80d6 to
0f79ad5
Compare
|
rebase to the main, CI looks green! |
| message = error.message; | ||
| } | ||
| if (read !== groundingReads[kind]) return; | ||
| if (kind === "jd") grounding.requirements = parsed?.requirements ?? []; |
There was a problem hiding this comment.
This guards grounding against a stale read, but the start handler still reads it across an await: selected from checkedGrounding() and consented are captured before await recordGitHubLogin(false), while selectedGroundingPacket(grounding, selected, consented) runs after it. Nothing disables the file inputs or the consent box during that round trip, so a JD picked while login is pending lands here and leaves the old indices in selected pointing at snippets the candidate never checked, and a Clear followed by a new pick ships them under a consented captured before the box was unchecked. A follow-up should build the packet before the await, the rule the handler already applies to duration and problem.
Follow-up to #39.
Sumarry
loadGroundingFilewrote its result whenever the file read finished, even if a newer action had happened in the meantime:Fix and Change
Each document kind keeps a read counter (
groundingReads.jd/.resume). A read takes the next number before itsawaitand gives up afterwards if the number is no longer current, so it touches neithergrounding, the status line, nor the lists. Clear bumps both counters. The counters are per kind so a JD read never cancels a resume read.New test
Two
lobbyTests intests/browser/lobby.test.js. They hold the read of a file namedslow.txtopen by wrappingBlob.prototype.arrayBuffer, and release it on purpose.Summary by cubic
Fixes a race condition where a grounding file read that finished later could replace the result of a newer read, leaving the file list and snippets out of sync. Reads now use per-kind counters, and a read that is no longer the latest is dropped without touching the lists or status line.
Bug Fixes
Written for commit 0f79ad5. Summary will update on new commits.