Repository navigation
refactor(sel): route the restart path's SEL drain through flush_audit_queue_before_hard_exit - #22396
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The restart exit's worst-case wait grows from 3s to 4s (3s inner drain plus 1s outer margin). Confirm that is acceptable before What this change shipsInventory (4 items) — 3 justifiedIntent: the restart command drains the SEL audit queue through the same single helper as every other gateway hard exit. FIX (#18938), a removed duplicate.
The duplicate is gone: a grep for [FIRST-PRINCIPLES-REVIEWED] e1c49ba Description read[DESCRIPTION-READ] c0151b7c65dd8ab3e2e65846565403acc786b56688ab717947c865f13117567c That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Worth confirming: the restart path's worst-case drain goes from 3s to about 4s (inner [DESIGN-REVIEWED] e1c49ba Description read[DESCRIPTION-READ] 072d48c029c2e7d7ea9c69d87d316a60b92a6c020a9fedaf74c8a8ce9365e4f2 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: |
1c7de60 to
ac2411a
Compare
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: |
|
span=8ffa878c35ae — needs-a-decision — self-added: no — mechanism: GPT
|
|
span=67e2ef5946f5 — needs-a-decision — self-added: no — mechanism: verified-real race between the off-loop force-exit thread and the graceful
|
ac2411a to
b5732ba
Compare
b5732ba to
8a8e11d
Compare
|
needs-a-decision — self-added: yes — mechanism: verified-real NEW concurrency angle on the force-exit span; it trips the conductor's circuit-breaker, so this is escalated rather than patched in a third design pass.
|
…_queue_before_hard_exit The gateway restart path (`_handle_restart` in src/kiro_crew/slack/events_slash.py) drained the SEL audit queue before its `os._exit(1)` with its own inline `run_in_executor(subprocess_executor(), sel().flush)` block. Route it through the shared `flush_audit_queue_before_hard_exit()` helper instead, so every gateway hard exit that drains SEL does it by one spelling: the helper offloads the blocking drain to the teardown pool under an outer deadline (a wedged writer cannot hang the loop or block `os._exit`), and drains only an existing singleton so it never creates a trust root on the way out. Fixes #18938
8a8e11d to
e1c49ba
Compare
|
Conductor narrowing after the circuit-breaker tripped. This PR originally carried both #18938 (restart-path SEL drain → shared helper) and #19042 (second-signal force-exit SEL drain). The #19042 force-exit work hit a conductor-set circuit-breaker when GPT 6.1 Review (Opus-adjudicated UPHOLD, data-loss class) raised a new concurrency angle on the force-exit span: with the Option-A sole-exiter guard, Per the conductor's ruling, the force-exit half (#19042) has been reverted out of this PR and deferred to a tracking issue; this PR now carries only the #18938 restart-drain refactor, and its Goal / Why / Not-a-goal sections were narrowed to match. #19042 stays open. |
|
rebutted — self-added: no — mechanism: the +1s is the shared helper's standard outer margin; the bound is acceptable on a rare operator restart.
|
|
rebutted — self-added: no — mechanism: same as the Design punchline — the ~4s worst-case bound is the shared helper's standard margin and is acceptable on an operator restart.
|
|
HOLD (reserved for a human reviewer) at e1c49ba. The change routes the approved-restart path's SEL audit drain, right before I found no defect. The restart audit event is logged through What clears it: a maintainer review of the restart-path drain. — crew-pr-reviewer (r116) |
Problem / Motivation
Goal: Every gateway hard exit that drains the SEL audit queue does it by one spelling. The restart path drained SEL with its own inline block; route it through the shared helper the other hard exits use.
The gateway restart path (
_handle_restartinsrc/kiro_crew/slack/events_slash.py) callsplatform_compat.hard_exit(1), which isos._exit: it runs no atexit handler and does not join the SEL daemon writer. Before that exit it drained the SEL audit queue — so the approved-restart audit event is not dropped — but with its own inlinerun_in_executor(subprocess_executor(), sel().flush)block, a second spelling of the drain that #18089 had already centralised intoflush_audit_queue_before_hard_exit()for the other hard-exit paths.Why it matters
Two spellings of the same shutdown drain drift apart: a fix to the bound, the trust-root guard or the error handling made in the shared helper does not reach the inline copy. Routing the restart path through the one helper keeps the SEL drain contract in a single place for every gateway hard exit.
Not a goal
os._exit(1), in the same order (SEL before the gateway.log tail).What changed (motivation → approach → change)
_handle_restart's inlinerun_in_executor(subprocess_executor(), sel().flush)+asyncio.wait_forblock is replaced byawait flush_audit_queue_before_hard_exit().flushto the teardown pool under an outer deadline, so a wedged writer (disk full, unreachable sink) cannot block the loop indefinitely or preventos._exit(1)from being reached, and it drains only an existing singleton so it never creates a trust root on the way out — the same guarantees the inline block carried, now shared.Backwards compatibility
Removes nothing: one restart-path drain is swapped for an equivalent shared helper; no field, type, key, record or public function is changed, rejected or removed.
Tests
test/test_restart_command.py: the three restart tests assert the sharedflush_audit_queue_before_hard_exit()helper is awaited (mock_flush_sel.assert_awaited_once_with()) instead of the removed inlinesel().flush, across the owner-with-supervisor, hung-session-close, and slot-save-raises paths — so the restart path still drains SEL beforeos._exit(1)even when session close hangs or the slot save raises.Manual verification
N/A — unit coverage is sufficient; the restart path is exercised deterministically with
os._exitreplaced, and the SEL drain helper is asserted awaited.Related Issues
Fixes #18938
Pattern harvest
Not generalizable: this folds one remaining inline SEL drain into the shared
flush_audit_queue_before_hard_exit()helper; thetest_sel_hard_exit_flush.pyratchet already enforces the class (everyos._exit/hard_exitin the scanned modules must drain), so no new rule is needed.