Repository navigation
test(acp): replace waits in session_handle_keepalive with await_until - #20150
Conversation
The oracle-check test bounded two awaits with asyncio.wait_for(..., timeout=5.0): the oracle's "entered" event and the drain task. A five-second ceiling that decides pass or fail is a bet on the runner's speed, which is the commonest source of flaky tests in this repository. Await both with await_until, which waits for the signal under a lost-run bound and fails by name when it never arrives, and drop the file's line from the wait-discipline baseline. The assertions are unchanged: they read the fake clock, not the wall clock.
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] 0724420 Description read[DESCRIPTION-READ] 6e6a5b6163cc39cf8341eb0c5f85e01d6459b341e7dedb82578ac701e2778a64 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 |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
|
Closing and reopening so CI runs on hosted runners: same-repo runs from this account queue on the fleet label without a runner (details on #19683). |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: test (2 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: test-only change; replaces fixed waits with await_until in test_acp_session_handle_keepalive and drops its wait-discipline baseline entry.
Problem / Motivation
Goal: The keepalive oracle-check test stops using a five-second wall-clock ceiling to decide pass or fail.
test/test_acp_session_handle_keepalive.py::test_a_keepalive_during_the_oracle_check_prevents_the_cancelwaits on two things the test itself sets up: the stub oracle'senteredevent and thedraintask that consumes the handle's dispatch loop. Both waits wereasyncio.wait_for(..., timeout=5.0)(lines 209 and 213 onorigin/main). The rest of the file is deterministic: the handle's clock is a fake that the polled queue advances one exact tick per poll (module docstring), so no assertion reads the wall clock. Only these two waits did.test/test_wait_discipline_ratchet.pycounts a fixedwait_for(..., timeout=N)under 30 s as a bet on the runner's speed and holds each file to its line intest/wait_discipline_baseline.txt. This file's line was2.No issue exists; burn-down of the wait-discipline baseline (precedents #19928, #20014, #19527).
Why it matters
A slow runner turns a correct test into a red
Backend Testsjob on an unrelated pull request, and the failure names a clock instead of the signal that never arrived.Not a goal
src/. The handle's watchdog, the oracle stub and the fake clock are untouched.test/wait_discipline_baseline.txtand migrated separately.What changed (motivation → approach → change)
Symptom: a ceiling that decides pass versus fail around an event and a task the test already controls. Approach: the repository's rule in
src/kiro_crew/testing/wait.py(wait on the signal; a ceiling only turns a hang into a named failure).await asyncio.wait_for(entered.wait(), timeout=5.0)becomesawait await_until(entered, what="the first oracle consult")(line 210 on this branch).enteredis anasyncio.Event.events = await asyncio.wait_for(drain, timeout=5.0)becomesevents = await await_until(drain, what="the drain finishing")(line 214).drainis anasyncio.Task, whichawait_untilaccepts as a future and whose result it returns.from kiro_crew.testing.wait import await_untilis added (line 28), the same importtest/test_acp_session_handle_skill_reads.pyuses.test/wait_discipline_baseline.txt; the file now holds no short fixed wait.A hang now fails with an
AssertionErrornamingwhat, after the helper's default lost-run bound (half the running test's timeout,default_timeout()), instead of aTimeoutErrorafter 5 s.await_untilleaves the awaited task running on expiry because the test owns it, wherewait_forcancelleddrain.Rejected: raising
5.0to a larger literal (still a clock bet, and the ratchet floor is 30 s).Backwards compatibility
Compatible: test-only change; no source file, public name or signature changes.
Reader:
test/test_wait_discipline_ratchet.py:read_baseline-- CI test run -- the file now counts zero, so its line is removed;test_the_baseline_is_not_stalepasses with it gone.Tests
In short: with the baseline line removed and the old waits in place the ratchet fails (
0 -> 2); with the change the ratchet and the file pass in 3 of 3 runs, and the file's own six tests pass before and after.pytest -n0 test/test_wait_discipline_ratchet.pyfails (1 failed, 38 passed) withtest/test_acp_session_handle_keepalive.py: 0 -> 2, naming lines 209 and 213 aswait_for(5s).pytest -n0 test/test_wait_discipline_ratchet.py test/test_acp_session_handle_keepalive.py, three separate processes: 45 passed each (45 passed onorigin/main).-n0: the changed file first, thentest/test_acp_session_handle_abandoned_turn.py,test/test_acp_session_handle_stream_command.py,test/test_taskrunner_atomic_persistence.py,test/test_taskrunner_execution_capture_async.py,test/test_unattended_slot_guardrails.py,test/test_wheel_apply.py: 147 passed.black --check --target-version py312,isort --check-onlyandflake8on the changed file,scripts/check_agent_sdk_boundary.py, andscripts/check_comment_history.pyagainst the merge-base all exit 0.Not run:
-n 4repeats;mypy(CI type-checkssrc/kiro_crew/only).Manual verification
N/A — test-only change; the RED run above is the check that the ratchet catches the undercount.
Related Issues
No issue exists; burn-down of the wait-discipline baseline (precedents #19928, #20014, #19527).
Pattern harvest
Rule candidate: lint — already enforced:
test/test_wait_discipline_ratchet.pycounts every short fixed wait per file, which is how this file's two sites were known. This change lowers its count to zero; no new rule is needed.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)