Repository navigation
fix(taskq): take a memory park's span from one clock read - #17217
Conversation
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The exact-span promise only holds for whole-second waits on an epoch clock. Check that no caller passes a fractional What this change shipsInventory (4 items) — 4 justifiedIntent: make a parked sub-agent get its terminal answer on the re-check that reaches the max-wait bound, not one admit wait later. FIX (#17216).
[FIRST-PRINCIPLES-REVIEWED] eccb63a Description read[DESCRIPTION-READ] 4e2f57c8014d8feb3e184d720031dc25ba52015e936b01fc740ae5cfdd0b089e That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Confirm that [DESIGN-REVIEWED] eccb63a Description read[DESCRIPTION-READ] c0596824bde877325209b9ab7d66f94043f14bad2a4d3cacc382819b7b98be7c 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 (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
a755c4c to
e15b414
Compare
|
First Principles BLOCK on a755c4c (items 2-4, "the count still rests on two clock reads"): upheld, fixed in e15b414.
|
e15b414 to
67d43a2
Compare
|
67d43a2 to
5b972ec
Compare
|
First Principles "Check that the epoch-sized
Also in this head: rebased onto origin/main e1999e4 to clear the merge conflict. #17017 moved the runner's pressure deferral into |
|
|
Design note "rows parked before this change still count a few microseconds short per park" (reviewed b5dc2db): agreed, and accepted as is. It costs one admit wait, once, on a row that was already parked when the upgrade landed; every park written after it spans exactly its wait. Rewriting stored events to correct it would be a migration for a one-time 30 s difference. The description's Backwards compatibility section now states this. |
|
Head 42e8d87: every review lane passes (First Principles, Design, Opus 5.5, GPT 6.1, UX, Security Scope). The remaining reds are outside this PR's taskq diff:
I will rebase once #17339 lands. |
42e8d87 to
aa9cd06
Compare
aa9cd06 to
11dec34
Compare
|
Head 11dec34 (rebased onto origin/main ffd9136). A read-through of aa9cd06 found no blocking issue and raised one test-robustness point and three nits. All are in this head:
The 10 listed test files on base ffd9136: 650 passed. black gate, isort, flake8, mypy ( |
11dec34 to
ad2ffa2
Compare
|
Head ad2ffa2 (11dec34 rebased onto origin/main 5b2aee2; The one red there, |
TaskStore.deferred_longer_than ends a memory-parked row once its parked time reaches agent.subagent_queue_max_wait_secs, counting each park from its deferred event's ts to its until. The bridge computed until as now() + wait from its own clock read, and defer then read the clock again for the event's ts, so every park counted a little under its admit wait. Three 30 s parks summed under a 90 s bound, and the row waited one more admit wait. defer(task_id, *, wait, reason) now computes until = ts + wait from the one read it also stamps the event with, and every caller (the three bridge paths and the task runner's admission) passes wait. The admit and max waits are whole seconds, so with one read ts + wait - ts is exactly wait and the sweep's float sum is unchanged. Follow-up to kirodotdev#17106. Closes kirodotdev#17216
ad2ffa2 to
eccb63a
Compare
|
Head eccb63a is ad2ffa2 rebased onto origin/main 397f4be. |
iamwhatever
left a comment
There was a problem hiding this comment.
Approving (crew-pr-reviewer). defer now takes wait= and stamps both the deadline and the event from one now() read. A parked row therefore ends on the re-check that reaches the configured max wait, not one admit wait later. Every caller is switched over. CI is green and the base is main.
Follow-up to #17106.
Problem / Motivation
Goal: The durable memory-wait sweep ends a parked row on the re-check that reaches
agent.subagent_queue_max_wait_secs, not one admit wait later.TaskStore.deferred_longer_thancounts eachdeferredevent's park from itststo itsuntil. The bridge computeduntil = store.now() + waitfrom its own clock read, andTaskStore.deferthen read the clock again for the event'sts, so on a clock that moves between reads every park counted a little under its admit wait. Three 30 s parks summed just under a 90 s bound, the re-check that should end the row kept it, and it waited one more admit wait. #17106 fixed the same off-by-one in the gate's in-memory ledger for starts with no durable row; its First Principles review pointed at this sibling.Why it matters
The bound is how a sub-agent stuck behind a short host gets a terminal answer. Ending it a whole admit wait late is small, but the durable path and the in-memory path should agree on when a wait has run out.
Not a goal
What changed (motivation → approach → change)
TaskStore.deferdefer(task_id, until, *, reason); the event'stsis a later clock readdefer(task_id, *, wait, reason)computesuntil = ts + waitfrom the one read it also stamps the event withtaskq_defer,taskq_defer_posted, the admission-path deferral,RunnerAdmission.admit)now() + waitwait=waitThe sweep's float sum is unchanged.
agent.admit_wait_secsandagent.subagent_queue_max_wait_secsare read as whole seconds (_safe_intinconfig/loader.py), and a whole-second wait lands on the float grid of an epoch-sizedts, so with one clock read(ts + wait) - tsis exactly wait and three 30 s parks sum to exactly 90 s._append_event_in_txtakes an optionaltsso the event carries the same read asuntil.Backwards compatibility
Compatible:
TaskStoreis internal and every caller moves towait=here; events already in a store are read the same way. A row parked by older code still counts each of those parks a few microseconds short, so its first sweep after the upgrade can end it one admit wait late, once.Reader:
src/kiro_crew/taskq/store.py:deferred_longer_than(unchanged) -- entry: subagent admission pump -- events written by older code are counted the same way;test_deferred_longer_than_counts_the_time_a_row_was_parkedandtest_deferred_longer_than_bounds_every_state_defer_parksstill pass.Tests
test/test_taskq_store.py:test_a_bound_of_whole_admit_waits_ends_the_row_on_the_recheck_that_reaches_it: a clock that moves 1 µs on every read, a row re-checked at the end of each of three parks, and a sweep in the third re-check's own clock tick, which must return the row for a bound of three waits. Two cases: 30 s waits from start 100000.123 and from an epoch-sized start. Both starts sit far enough inside their power-of-two range thatts + 30stays in the same binade, which is the condition the exact span needs; a start just below a power of two (such as 1000.123, wherets + 30crosses 1024) would pass or fail on its bits alone. With the calls written the old way (store.now() + 30) against origin/main's store, both fail (assert [] == ['w']).test/test_overload_integration_glue.py::test_admitting_id_is_held_until_the_posted_defer_landednow checks the posted deferral passes the admit wait and that the row'snext_run_atequals thedeferredevent'stsplus that wait, which pins the single clock read end to end. The tests that passed an absoluteuntilnow pass the equivalentwait.Run on base 397f4be:
test_taskq_store.py,test_taskq_claim_fencing.py,test_taskq_runner_adapter.py,test_subagent_queue_max_wait.py,test_subagent_queued_visibility.py,test_fairness_lanes.py,test_overload_integration_glue.py,test_queue_depth_reconcile.py,test_published_queue_depth.py,test_admission_gate.py: 650 passed. black (--target-version py310), isort, flake8 and mypy on the changed files;docs_lint.pyandcheck_comment_history.pyagainst origin/main pass.Manual verification
N/A -- unit coverage sufficient: the tests drive the real store on a moving clock.
Related Issues
Closes #17216
Pattern harvest
Rule candidate: review-prompt
Pattern: a duration measured between two separate clock reads (the caller's
now() + waitand the callee's ownnow()), so a span that ran to its planned end is counted short of the plan.Checklist