Repository navigation
refactor: fold the crew log agent door's offload, re-check and respond into one helper - #13485
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify follow-up #13526 exists and carries the debug.py deferral this PR leans on — I could not confirm it from here. [DESIGN-REVIEWED] b1ca796 |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 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: |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Confirm #13526 exists and names debug.py's five deferred sibling sites (808, 1024, 1103, 1160, 1199) — the only unfixed half of the root cause. What this change shipsInventory (6 items) — 6 justifiedIntent: make "answered under a stale grant" a shape a future crew-log route cannot write, by folding the shared post-gate sequence into one helper and pinning the order — a FIX (guard-gap), no behavior change.
Counts run: [FIRST-PRINCIPLES-REVIEWED] b1ca796 |
Opus 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: |
|
Disposition of the two advisory findings on Design Review: the suspension check only detected
|
| mutation | reds asserted before | reds measured |
|---|---|---|
| drop the offload | 44 | 48 |
| drop the refusal mapping | 2 | 5 |
| drop the re-check | 9 | 9 |
| drop the shaping call | 5 | 5 |
| shape before re-checking | 1 | 1 |
The refusal-mapping row was the real error: it is the four parametrized mapping cases
plus test_a_route_reaches_the_mapping_for_its_own_read, not two cases. The offload row
was undercounted the same way. Both rows are corrected in the PR body, which now also
says the counts are a measured run and that CI cannot reproduce them, because CI runs the
tests and not the mutations.
The two rows that matter for the acceptance bar are unchanged and still discriminate
exactly as claimed: dropping the re-check reddens 9, and shaping before the re-check
reddens exactly 1 -- test_the_shaping_never_runs_when_the_grant_was_withdrawn, alone.
Two Windows shards are red and neither failure is in this diff
This diff changes two files. Both failing test files are byte-identical to main, and the
branch's own diff against its merge base is those same two files, so there is no overlap
and rebasing cannot move either red.
test/test_crew_log_crew_emitter.py::test_a_worker_report_through_the_route_records_the_answer
-- tests(crew-log): the cited-span cap leaks between tests, so shard 2 fails on every PR #13444, whose title already records that it fails on every PR. Reproduced here on two
unrelated heads: PRs fix(channels): grade the rotation boundary the splitter cannot see #13494 and fix(crew-log): reclaim a deleted crew member's crew log #13492 carry the identical
{'from': 3, ...} == {'from': 1, ...}assertion on their own shard 2.test/test_diag_procs.py::test_the_gil_hint_can_fire_through_the_read_path
-- tests(windows): test_diag_procs second-read cpu rate reads the real clock, flakes on slow runners #13134. The rate assertion reads the real clock, so runner time between the two scans
inflates the interval;85.584%here means about 0.52s of it, against a tolerance that
admits about 0.11s. Recorded on that issue with this head and the arithmetic.
Both issues are open and labelled claimed, so neither is patched from here.
|
Answering the standing Design advisory on #13444 -- PR #13502, an unrelated head, carries the byte-identical assertion: That is now three unrelated heads (#13494, #13492, #13502), which matches the issue's own #13134 -- the test red on this head has changed since the last report, and it is a One related observation, stated separately because it is not the same assertion: PR #13512 Nothing here is in this diff. The branch's own change against its merge base is two files, |
|
Disposition of the First Principles CONCERNS on
So the PR body's earlier wording -- that Taken as accepted-and-deferred, on the clearing condition the review itself named. Filed as Not folded into this diff, which stays at two files. Folding five sites whose helper needs a |
3a1ed5f to
a8e862d
Compare
|
Rebased onto main Why: #13444 was closed and its fix is in this base, so the The rebase is content-neutral. Same two files A different base-owned red appeared with the new base, and it is not in this diff: Filed as #13576 with the mechanism. Short version:
|
|
Disposition of the two advisories on First Principles: "verify the deferral is real" -- verifiedFair check, since the unfixed siblings rest on that pointer. #13526 is open and read back Design:
|
|
Final state on Checks: 91 lanes, 79 success, 11 skipped, 1 failure. Nothing queued, nothing in Reviews: all four clean on this head -- Design PASS, First Principles PASS, GPT 5.6 no PR Readiness: Eleven lanes passed, nothing pending, and the one failure is The only red is not in this diff: What the rebase bought: Remaining blocker is a human approval -- One incidental observation from driving this, recorded here rather than as a fourth issue in |
|
Correction to my earlier comment on this red. Two things in it were wrong. #13576 was a duplicate and is closed. The live tracking is #13528 ("concurrent My dedup missed #13528 even though it was in the issue list I fetched: every term I searched My mechanism attribution named the wrong frame. I said the unlocked write was namespace What I had right stays right: the destination ( PR #13551's own diff states the underlying point better than I did: it adds a cross-process Effect on this PR: none of the state changes. |
…d into one helper Three of the four unit-keyed reads on the agent's door run the same sequence after the gate admits the caller: build the payload off the loop, map a storage refusal, re-check that the grant still holds, answer. The three middle segments were identical apart from the callable they offload, the operation they audit under and the one keyword the re-check takes, so the sequence is now one helper, ``_offload_then_recheck``, and each route hands it the read and its own payload shaping. The shaping is passed in rather than done after the call, so a route never holds a payload before the re-check has passed and cannot answer out of order. The route keeps everything outside those three steps: the gate, the env flag, all pre-offload validation, and the shaping function itself. Behaviour is unchanged at all three routes. ``api_crew_log_resolve`` keeps its own shape: it answers from memory rather than suspending, so it owes no re-check. The source-scan guard is restated against the choke point -- the re-check has exactly one caller, and no agent-door route suspends by itself -- which also refuses a route that re-checks by hand in an order of its own. New cases pin the storage-refusal mapping, which had no cover, and pin that a withdrawn grant stops the route's shaping from running at all. Closes #12360
a8e862d to
dd6cf3f
Compare
dd6cf3f to
4bce0e0
Compare
…spelling The source scan asserted that no agent-door route reaches storage by `asyncio.to_thread`. Suspension has three spellings -- `await`, `async with`, `async for` -- so a route that offloads through `run_in_executor`, awaits a storage coroutine, or gathers one satisfies that assertion while still being able to answer under a grant taken before the read. State the rule from the other side: the gate and `_offload_then_recheck` are the only two suspension points a door route may hold, and anything else that suspends is named back in the failure. A route that genuinely needs a third has to add it here, which is where somebody decides whether it owes a re-check. `api_crew_log_resolve` stays the control: it awaits the gate alone, so it is admitted by every rule in the pin while appearing in none of them.
|
Disposition of the two advisory PASS verdicts on Both reviewers: "confirm the two red Windows shards are red on base, not introduced by this diff"That ask is now answered by the board rather than by argument: there are no red Windows shards. All eight The reason is a rebase, not a change to this diff. The two shards were owned by two base defects:
So the shards were base-owned, and the evidence is that they cleared without this diff changing. Design Suggestion: door detection escaped by an attribute-form gate call -- FIXEDThis one was a real hole and I have closed it rather than deferred it. The fail-closed treatment I gave suspensions covered only the The call collector now matches an attribute tail as well as a bare name, so both spellings name the same gate. Measured, not argued. Against a synthetic route whose gate call is attribute-form and which then suspends on its own via
Once the route is recognised, the existing suspension rule names its Same widening also strengthens the single-re-check-caller assertion, since an attribute-form call to the re-check would now be counted too. What this costs
Note on the seven reds that appeared and cleared on this headDesign, GPT 5.6, Opus 5, First Principles, UX, |
4bce0e0 to
b1ca796
Compare
|
Final state on The required gate passed
Board: Every substantive lane is green, including all four reviewers on this exact head (Design PASS, First Principles PASS, GPT 5.6 and Opus 5 no blocking findings), Security Scope Review, PR Hygiene, CodeQL, and all eight The one red row is a stale publisher attempt, not a check result
Readiness had published a truthful The self-heal sweep then did the job properly: its 07:34:27Z run republished the status as Why I am not re-running it againRe-running would likely turn the row green, but the downside has reversed since my first attempt. Then, the status was That trade is not worth taking, so the row stays red and is explained here instead. Scope unchangedTwo commits, two files: |
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed the full diff. Required gate PR Readiness is green on the current head, all CI shards pass, no blocking reviews. Approving.
1. What is the problem?
The crew log agent door has four unit-keyed read routes. Three of them run the same
sequence once the gate has admitted the caller: build the payload off the loop, map a
storage refusal to a response, re-check that the grant still holds, then answer. That
sequence was written out three times in
src/kiro_crew/dashboard/handlers/crew_log.py,and the three copies differed only in the callable they offload, the operation name
they audit under, and the one keyword the re-check takes (
listing=Trueagainstunit=unit).Two of the four steps had no cover at all.
CrewLogErrordid not appear once intest/test_crew_log_routes.py, so the mapping from a storage refusal to a 400 / 409 /422 was unguarded at all three routes. And nothing asserted the ORDER of the last two
steps -- only that a withdrawn grant produces a 403, which a route that shaped its
answer first and returned the refusal afterwards would also produce.
The guard that was there scanned the module's source for the re-check's presence inside
each route that suspends. It caught an omitted line, but it could not catch a route that
calls the re-check in an order of its own, because such a route passes the scan.
2. Why this issue matters to the user
Nothing is open today: all three routes do all four steps, in order. What is at risk is
the next route. The re-check exists because the payload read is a suspension point, so a
caller can acquire a channel link while its read is in flight and receive another
session's log content into a published thread. A route added later that suspends and
answers without re-checking reads correctly in review -- the defect is an absent line --
and the same is true of one that re-checks after it has already shaped the answer.
The unguarded refusal mapping has a smaller but live cost: a route that lost it would
answer a malformed unit id or an unparseable log line with a 500 and no code, and the
agent proxying the read has nothing to branch on.
3. How our fix solves it
The three steps after the gate are now one helper,
_offload_then_recheck, and thechain from symptom to cause runs like this.
The symptom is a sequence a future route can get wrong. The cause is that the sequence
lived at the call sites, so getting it right was each route's own responsibility and
"answered without re-checking" was a shape a route could write. The fix removes the
shape: the helper takes the read (bound with
functools.partial) and the route'spayload shaping as arguments, and calls the shaping only after the re-check has held. A
route therefore never holds the payload, and the order is not its to get wrong.
Folding the shaping in is a deliberate step past what the issue sketched, which left the
shaping at the call site after a two-value return. A two-value return leaves a route
holding a payload alongside a refusal it must remember to return first -- a mistake the
code today cannot make. The shaping function still belongs to the route; the helper only
calls it.
Each route keeps everything outside those three steps, unchanged: the gate, the env-flag
check, all pre-offload validation (
bad_rangeon the listing and the page,unknown_projection/ the owner-served refusal /slot_projectionon the fold), and itsown shaping -- the page's 404
unknown_unitfor a unit with no log, the fold'ssession_idwrapper key, and the listing's bare pass-through. The three routes behaveverbatim as before.
api_crew_log_resolveis the fourth agent-door route and is untouched. It authorizes andthen answers from memory without suspending, so it has no payload read to re-check
after and no step missing -- worth stating plainly, because the route reads like the one
outlier in the set.
The cookie-gated browser routes (
api_session_crew_logand its two siblings) are alsountouched. They stand on a different authorization model --
require_owner_dashboard_requeston the owner's own cookie -- and never call
_authorize_crew_log_read, so they are not inthis helper's set.
debug.pyis a deliberate deferral, and an earlier draft of this section understated it.Its
_stale_grant_refusalis a different function over a different store, but the shapeand the risk are the same: five debug read handlers run authorize, offload, re-check,
answer, and the only thing holding that order is a string-presence scan asserting the
re-check's name appears in each handler's source -- the weak form this PR replaces, and
debug.py:578states the same channel-mirror window in its own words. They are not foldedhere because the contract differs: that re-check is synchronous, it takes a per-route
reads_past_ownpolicy flag the crew-log version has no equivalent of, and one of the fiveoffloads at four different points depending on mode, so "the read" is not one callable
there. Tracked as #13526, which carries the five call sites, the presence scan, and the
suggested shape.
4. What tests we did
The acceptance bar for a refactor is that behaviour does not move and that every folded
step is still provably present, so each step was deleted in turn and the file re-run.
One mutation, one intended detector:
The last row is the one the file could not see before: shaping first and returning the
refusal afterwards turns exactly one test red, and it is new. The counts above are a
measured run of each mutation against this revision, not an estimate -- each entry is
applied to
_offload_then_recheck, the one file is re-run with-n0, and the source isrestored and checked back against its digest before the next entry. CI cannot reproduce
them, because CI runs the tests and not the mutations.
New cases, in
TestTheOffloadHelperOwnsTheOrder:invalid_id-> 400,unknown_entry_type->409, another code -> 422, and an empty code -> 422 with
crew_log_error;offloading through the helper would not keep that cover.
The source scan is restated as two rules a new route cannot satisfy by accident: the
re-check has exactly one caller, and the gate and that helper are the only two places an
agent-door route may suspend. The second rule is stated as the allowed suspension points
rather than as the storage calls to look for, because suspension has three spellings --
await,async with,async for-- and a rule namingasyncio.to_threadadmits a routethat offloads through
run_in_executor, awaits a storage coroutine, or gathers one. Bothrules were tested by writing the route they exist to refuse: one that offloads on its own,
one that re-checks by hand, and one that suspends through
run_in_executor. All three arerefused, and the last is measured against both forms of the rule -- the call-spelling form
admits it, the suspension-point form names it back.
api_crew_log_resolveis the control:it is in the agent-door set, awaits the gate alone, appears in none of the rules, and is
still admitted.
test/test_crew_log_routes.py: 186 passed (179 before, 7 added), run with-n0.flake8,isort,mypyon the handler, the black gate, the sync-IO-in-async gate, thebrand gate and the comment-history gate all pass on this diff.
Two Windows backend shards are red on this revision and neither failure is in this diff.
test/test_crew_log_crew_emitter.py::test_a_worker_report_through_the_route_records_the_answeris #13444, reproduced on unrelated heads (PRs #13494 and #13492 carry the identical
assertion).
test/test_diag_procs.py::test_the_gil_hint_can_fire_through_the_read_pathis#13134, a rate assertion that reads the real clock and drifts on a slow runner. This diff
changes two files; both failing files are byte-identical to
main, so rebasing cannotmove either one.
5. Any other suggestions on the work
The re-check's caller count is now load-bearing, which the scan states but the helper's
own docstring is the better place for a reader to meet it. If a later route needs the
payload before it can decide the response -- something none of the three needs today --
the honest move is to widen the shaping function's contract rather than to return the
payload to the route, because returning it is what reopens the order.
Closes #12360