Repository navigation
chore(platform): module-scope disarm import; re-arm a foreign alarm when execv fails - #22651
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: each of the two deferred findings gets a small, contained fix, and the only widened return type has two callers, both in this module and both updated here. [DESIGN-REVIEWED] 7b6ab81 Description read[DESCRIPTION-READ] f1a5c50b74474554c6895e032806017481ec2835a1da78f357098b3917bd1421 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Item 1's only stated harm is readability, but it is a reversible two-line move with a linked issue, so it stays a note. The alarm restore fixes the mechanism at both exec seams that cancel the alarm. Notes
What this change shipsInventory (3 items) — 2 justifiedIntent: when the gateway fails to re-exec itself, a pending alarm owned by someone else (a test timeout, an embedding host) survives. This is a FIX, plus a tidy-up of where one import lives.
[FIRST-PRINCIPLES-REVIEWED] 7b6ab81 Description read[DESCRIPTION-READ] 6ed96d4e234e5df69d3dd8feed4c47a9f60e5b008cd6583fa85800a907f8b2fe That sha256 names the PR description this verdict read. 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: |
4eaf102 to
148067f
Compare
…hen execv fails Two follow-ups deferred from #14302. 1. cli.py imports disarm_inherited_alarm at module scope. The watchdog's import closure (dashboard.stall_enrichment -> acp.liveness, and platform_compat) contains no module-scope import of cli, so this creates no cycle, and acp is already loaded when cli imports session, so only the two small watchdog modules are new. The gateway dispatch keeps its order (faulthandler.enable() before disarm_inherited_alarm()). 2. The two exec seams re-arm a pre-existing ITIMER_REAL alarm when os.execv fails. Cancelling the alarm before execv is correct only when the exec succeeds: a successor image never armed it. When execv raises and the process keeps running, a foreign owner's pending deadline must be put back. _disarm_process_alarm_before_exec now returns the pre-cancel itimer value, and reexec_launcher / reexec_python_module restore it via _rearm_process_alarm_after_failed_exec before re-raising the OSError. Fixes #14358
148067f to
7b6ab81
Compare
|
self-added: yes
|
|
|
buluoray
left a comment
There was a problem hiding this comment.
🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:
Approving at 7b6ab81.
This fixes a real loss: when os.execv fails and returns, the process keeps running, but the ITIMER_REAL deadline a foreign owner had pending (a test worker's timeout, an embedding host) was already cancelled and never came back. Both exec seams now restore the value and the interval, so a periodic alarm stays periodic, and then re-raise. The disarm_inherited_alarm import moves to module scope with the gateway dispatch order unchanged. Main still has neither change.
Checked: removing the re-arm call in reexec_python_module reddens test_a_failed_exec_restores_a_foreign_owners_alarm[reexec_python_module] and test_a_failed_exec_restores_a_repeating_alarms_interval[reexec_python_module].
Non-blocking follow-ups:
_disarm_process_alarm_before_exec's docstring says it returnsNonewhen the cancel was a no-op, and_rearm_process_alarm_after_failed_execsaysNonemeans nothing was pending. With no pending alarm,getitimerreturns(0.0, 0.0). The behaviour is harmless, but the docstrings should say so.docs/system-specs/common/platform-compat.md(thearm_process_alarmrow) describes the cancel-before-exec rule and should add that a failed exec restores the cancelled alarm.
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved on behalf of the watch holder (bolichen). Lanes pass on 7b6ab81, checks green, no conflict, no open change request.
Problem / Motivation
Goal: Land the two review findings deferred from #14302 so the gateway's inherited-alarm disarm import sits at module scope and a foreign owner's
ITIMER_REALalarm is not silently lost when an in-app re-exec fails.Two review-lane findings on #14302 were accepted and deferred once that head froze. First, the
gatewaydispatch incli.pyimporteddisarm_inherited_alarmlocally beside the dispatch's deferred imports even though the import is cheap and cycle-free. Second,reexec_launcher/reexec_python_modulecancelITIMER_REALunconditionally right beforeos.execv; when the exec fails and returns (OSError), the process keeps running with a foreign owner's pending alarm gone.Why it matters
The disarm import belongs at module scope because it costs nothing to defer and the local import obscures the dispatch. The alarm residue is a correctness bug: a process that owned a pending deadline (a test worker's
pytest-timeout, an embedding host) loses it after a failed re-exec and never gets it back, so a deadline that should still fire silently does not.Not a goal
ITIMER_REAL; both paths stay a no-op there.What changed (motivation → approach → change)
cli.pyimportsdisarm_inherited_alarmat module scope. The watchdog's import closure (dashboard.stall_enrichment→acp.liveness, andplatform_compat) has no module-scope import ofcli, so this creates no cycle;acpis already loaded whencliimportssession, so only the two small watchdog modules are new to the graph. The dispatch keeps its order (faulthandler.enable()beforedisarm_inherited_alarm()).ITIMER_REALbeforeexecvis correct only when the exec succeeds — the successor image never armed it._disarm_process_alarm_before_execnow reads and returns the pre-cancel itimer value and repeat interval; both exec seams restore both via the new_rearm_process_alarm_after_failed_execwhenos.execvraises, then re-raise theOSError. The code lives insrc/kiro_crew/platform_compat_runtime.py, forwarded throughsrc/kiro_crew/platform_compat.py.Backwards compatibility
Removes nothing: no field, key, kind, validator, or public function is removed, renamed, or tightened.
_disarm_process_alarm_before_exec's return type widens fromNonetotuple[float, float] | None, and its sole callers are the two seams in this same module, both updated here.Tests
test/test_platform_compat_process_alarm.py: red-first parametrized tests (both seams) that a failedos.execvrestores the foreign owner's alarm value and, for a repeating alarm, its interval (so it does not become a one-shot), plus a no-process-alarm (Windows) no-op test. Both use a stand-inITIMER_REALand leave no real alarm armed, bounded without the per-item deadline.test/test_cli_main_entry.py: the gateway-dispatch pin now patches the module-scope bindingkiro_crew.cli.disarm_inherited_alarm, locking in the module-scope import and the disarm-before-gateway order.test/test_platform_compat_refactor_facade.py: the facade forwarding invariant includes the new_rearm_process_alarm_after_failed_exec.Manual verification
N/A — unit coverage sufficient; backend-only change with no UI or external-service surface.
Related Issues
Fixes #14358
Refs #14302
Pattern harvest
Not generalizable: both are one-off follow-ups to a specific prior change — a single misplaced local import, and a single exec seam that cancelled a resource without restoring it on the failure path.