Repository navigation
test(chat): wait for the queued-prompt writer to settle, not its file - #20433
iamwhatever merged 1 commit into
Conversation
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] e9056dc Description read[DESCRIPTION-READ] 2506ad0da0488679fe7bfa6b012f592e402ef3419758ec54b8643696ed71bd47 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
a9fa746 to
a251fba
Compare
|
Disposition for the independent review of a9fa746. New head: a251fba. Test-only; production is unchanged. S1, no test exercised the owed follow-up pass: fixed. N1, release timeout raised on the executor thread: fixed. Both held writers now append to a N2, the body implied nothing observes the commit-to-witness window: fixed. "Why it is not a production race" now names the four loop-side readers that can see Mutation re-runs on the new head (8 tests in the two classes):
Determinism: 30/30 default and 30/30 one-thread, and the same under 32 CPU spinners on a 32-core host (spinners killed and confirmed gone). Whole file plus the wait-discipline and flake-pattern ratchets: 211 passed, also on the merge with current main; The First-pass check: R1-R8 OK. |
a251fba to
86befed
Compare
|
New head 86befed (rebased onto main 3d09514). Light-check NIT (named release-timeout assertion unreachable): fixed. The held write now waits half the settle's budget, so it gives up first and Rebased onto main 3d09514, which carries the fix for the Rulings on this PR: light-check NIT DONE ( First-pass check: R1-R8 OK |
86befed to
98ef278
Compare
98ef278 to
c81ec89
Compare
c81ec89 to
a5372b0
Compare
|
New head a5372b0 (rebased onto main b4135f1). Still one test-only commit; Reds on the previous head c81ec89, none from this diff:
Rulings on this PR, checked on the new head:
Body, edited before the push: one inaccurate clause fixed (the held write waits half of Re-proved on the new head:
AUTOSDE rules that match the file:
First-pass check: R1-R8 OK. |
mbriones98
left a comment
There was a problem hiding this comment.
Checks green and readiness passed at a5372b0; no new feature.
…file TestOneWriterPerSlot polled the transcript until both queued prompts were on disk, then asserted queue_persist_pending was false. The save commits the file and only then records the queue witness, so a read in between sees the new queue while pending is still true. On a slow Windows runner the poll landed in that window and the last assertion failed. The tests in this class and in TestEnqueueStartsTheWriteImmediately now wait for the single-flight flag to clear. The writer's done callback clears it on the loop after the executor thread returned, and a follow-up pass sets it again in the same callback, so a clear flag means the whole chain is done. The writer tests count starts as well as overlap, so a second writer queued behind the first on a one-thread executor still fails the class. A new test covers the follow-up pass itself: the held writer commits "first" and then blocks, "second" arrives, and only the follow-up can land it. The held writers record a release timeout for the test to assert, instead of raising it on the executor thread where only the done callback's log would see it. Closes kirodotdev#20430
a5372b0 to
e9056dc
Compare
|
[operator: bolichen97] Rebased onto main ed975d7 to clear the merge conflict: a5372b0 -> e9056dc. Still one test-only commit.
This push dismissed @mbriones98's approval of a5372b0. A re-approval on e9056dc is welcome once CI is green. |
|
@mbriones98 I rebased this onto current main to clear the merge conflict (mechanical, no behaviour change). That dismissed your approval on a5372b0. The new head e9056dc is green with [operator: bolichen97] |
Problem / Motivation
Goal: The queued-prompt one-writer tests wait for the writer to settle, so they pass on every runner and still fail when a second writer starts.
test_a_send_during_a_write_does_not_start_a_second_writerfailed onBackend Tests (Windows) (7)withassert True is Falseonslot.queue_persist_pending, on a pull request that does not touch the queued-prompt writer (#20430 has the run). Only its pending-flag assertion failed.Why it matters
An unrelated red shard costs every open pull request a rerun or a fresh head. The test also guards a real property: a prompt typed during a turn reaches disk with one writer at a time.
Not a goal
What changed (motivation → approach → change)
Symptom: the test polled the file until both prompts were on disk, then asserted
queue_persist_pending is False, which on Windows was still true.Cause, test-only: the file is not the barrier. The save commits the file and only then records the queue witness (
_queue_persisted_sig) under the transcript lock. The test reads the file without that lock, so a read between the two sees both prompts on disk while the witness still holds the old value. The forced interleaving under Tests reproduces the CI assertion.Why it is not a production race: the writer's done callback runs on the loop after the executor thread returns, so it always reads
queue_persist_pendingafter the witness is recorded, and a second immediate writer cannot start from this window. Recording the witness after the commit is the intended order: the witness must never claim a write that has not landed.Four other loop-side readers can see
queue_persist_pendingstill true there, and each errs to "still owed":chat_persistence.py:3023, the resumed-slot skip guard in the save: it does not skip, so one extra save runs.dashboard_persistence.py:137, the periodic flush gate: one redundant flush, and the stale-snapshot guard orders the commits.chat_api/handover_drain.py:258, the hand-over "nothing unsaved" check: it takes the save path instead of the no-write path.channel_handoff.py:316, the close classification: it reportsREFUSED_UNSAVED_CLOSEinstead ofQUEUED_BY_CLOSE, the documented fail-closed choice.None starts an immediate writer: the window costs at most a redundant save or a refused close.
Change, in
test/test_queued_prompt_durability.py:_queue_writer_settled(slot)helper waits, throughasync_wait_until, forslot._queue_persist_inflightto clear. The done callback clears it on the loop after the thread returns, and a follow-up pass sets it again in that callback, so a clear flag means the whole chain is done.TestOneWriterPerSlottests and the three asyncTestEnqueueStartsTheWriteImmediatelytests use it in place of fixed-count polls and asleep(0.1)barrier.async_wait_until(entered.is_set), not by parkingentered.wait, 5on the executor the write itself needs.releaseis set in afinally.test_a_send_after_the_snapshot_gets_a_follow_up_pass, covers the follow-up pass: the held writer commits "first" and blocks, "second" arrives, and only the follow-up can land it before the periodic flush.never_released, asserted on the loop side (raised on the executor thread, it reached only the done callback's log). The hold waits half the settle's budget, so that assertion fails first, and the settle helper prints the list too.Why not hold the transcript lock in the test's read: that couples the test to the save's locking, and the property under test is the slot's own settlement, which the single-flight flag signals.
Backwards compatibility
Compatible: test-only change. No production module is touched.
Tests
assert True is Falseonqueue_persist_pending. The new barrier passes with the same hold.max(concurrent) == 1fails on the default executor, and on a one-thread executor, where the old overlap-only check would pass, the start counts fail it (see below)._finish_queue_persist: the new test fails withassert 1 == 2on both executors. Before it, this mutation passed the whole file.assert 3 == 2). The one-writer test's start count catches it in most runs but not all (7 of 10 in the eight-test selection), because a writer queued behind the first may not have started yet when the flag clears.finallythat setsreleaseremoved in both held-writer tests): both fail withAssertionError: the held write timed out waiting for release, 6 of 6 runs.-n 4, and 30 of 30 serially with the two classes in reverse order.test/test_queued_prompt_durability.pyin full plustest/test_wait_discipline_ratchet.pyandtest/test_flake_pattern_ratchet.py: 216 passed with-n 4on main b4135f1.--write-baselinechanges nothing. Everytest/test_*ratchet*.pyplustest/test_agent_refactor_facade.py: 303 passed.-n 2;test/test_flake_pattern_ratchet.pyplustest/test_wait_discipline*.py: 99 passed.semgrep/rules against the merge-base: 0 findings on this diff.Manual verification
N/A — unit coverage sufficient: test-only change, proven by the forced interleaving and the mutation runs.
Related Issues
Closes #20430
Pattern harvest
Rule candidate: review
Pattern: a test waits on a durable side effect (a file on disk) and then asserts in-memory settlement that the writer records after that effect. The barrier should be the writer's own completion signal.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)