Skip to content

chore(platform): module-scope disarm import; re-arm a foreign alarm when execv fails - #22651

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
kc-wt-14358
Nov 1, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
kc-wt-14358

Conversation

@dodgeblaster

@dodgeblaster dodgeblaster commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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_REAL alarm 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 gateway dispatch in cli.py imported disarm_inherited_alarm locally beside the dispatch's deferred imports even though the import is cheap and cycle-free. Second, reexec_launcher / reexec_python_module cancel ITIMER_REAL unconditionally right before os.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

  • No change to the cancel-on-success behavior, the loop-stall watchdog, or the exit mechanism.
  • No new behavior on Windows, which has no ITIMER_REAL; both paths stay a no-op there.

What changed (motivation → approach → change)

  1. Module-scope import. cli.py imports disarm_inherited_alarm at module scope. The watchdog's import closure (dashboard.stall_enrichment → acp.liveness, and platform_compat) has no module-scope import of cli, so this creates no cycle; acp is already loaded when cli imports session, so only the two small watchdog modules are new to the graph. The dispatch keeps its order (faulthandler.enable() before disarm_inherited_alarm()).
  2. Re-arm on failed exec. Cancelling ITIMER_REAL before execv is correct only when the exec succeeds — the successor image never armed it. _disarm_process_alarm_before_exec now reads and returns the pre-cancel itimer value and repeat interval; both exec seams restore both via the new _rearm_process_alarm_after_failed_exec when os.execv raises, then re-raise the OSError. The code lives in src/kiro_crew/platform_compat_runtime.py, forwarded through src/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 from None to tuple[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 failed os.execv restores 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-in ITIMER_REAL and 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 binding kiro_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.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 7b6ab8112b73ccc33ae6933cedda6dc87823c2de touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 7b6ab8112b73ccc33ae6933cedda6dc87823c2de — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 7b6ab8112b73ccc33ae6933cedda6dc87823c2de — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • Item 1 — inherited: its only support is "the local import obscures the dispatch". That is a preference, not a defect. Shipping nothing would cost no user anything. The move also makes every kiro_crew.cli import load dashboard.loop_watchdog up front. Subtraction: delete the module-scope from kiro_crew.dashboard.loop_watchdog import disarm_inherited_alarm in cli.py and keep the local import where it was, which also leaves the test patch target as it was.

What this change ships

Inventory (3 items) — 2 justified

Intent: 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.

  1. The gateway's inherited-alarm disarm import moves from inside the dispatch to the top of cli.py, so any CLI import now loads the watchdog modules — inherited
  2. A failed os.execv in reexec_launcher / reexec_python_module now restores the alarm's remaining time and repeat interval, then re-raises — justified
  3. New private helper _rearm_process_alarm_after_failed_exec, forwarded through the platform_compat facade — justified

[FIRST-PRINCIPLES-REVIEWED] 7b6ab81

Description read

[DESCRIPTION-READ] 6ed96d4e234e5df69d3dd8feed4c47a9f60e5b008cd6583fa85800a907f8b2fe

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 7b6ab8112b73ccc33ae6933cedda6dc87823c2de — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 7b6ab81

Verdict parsed from the review's SHA-scoped output markers for commit 7b6ab8112b73ccc33ae6933cedda6dc87823c2de.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 7b6ab8112b73ccc33ae6933cedda6dc87823c2de false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 7b6ab8112b73ccc33ae6933cedda6dc87823c2de and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 7b6ab81

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 7b6ab8112b73ccc33ae6933cedda6dc87823c2de false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 21, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 29, 2026
…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
@dodgeblaster

dodgeblaster commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: restore of the pre-exec ITIMER_REAL after a failed os.execv

  • span=8940c6011ac4 Failed exec converts a repeating alarm into a one-shot

fixed in 7b6ab81: _rearm_process_alarm_after_failed_exec now restores both saved fields with signal.setitimer(signal.ITIMER_REAL, value, interval) instead of arm_process_alarm(value), which zeroed the interval.
regression test test_a_failed_exec_restores_a_repeating_alarms_interval (both seams) arms (25.0, 5.0), fails the exec, and asserts the timer reads (25.0, 5.0); it fails on the previous head with (25.0, 0.0) == (25.0, 5.0) and passes on the fix.
class sweep: getitimer has one caller in src/kiro_crew (the disarm); the restore is the only site that writes a saved timer back.

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

acknowledged PASS: both fixes stay contained; the widened _disarm_process_alarm_before_exec return type has only its two in-module callers, both updated. No change needed.

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

acknowledged PASS: the import move is the readability half of the deferred #14302 findings and is reversible; the restore covers both exec seams that cancel the alarm, value and interval. No change needed.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 29, 2026
@dodgeblaster
dodgeblaster marked this pull request as ready for review October 29, 2026 23:53
@dodgeblaster
dodgeblaster requested review from a team and KiroCrewCaptain as code owners October 29, 2026 23:53
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 30, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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 returns None when the cancel was a no-op, and _rearm_process_alarm_after_failed_exec says None means nothing was pending. With no pending alarm, getitimer returns (0.0, 0.0). The behaviour is harmless, but the docstrings should say so.
  • docs/system-specs/common/platform-compat.md (the arm_process_alarm row) describes the cancel-before-exec rule and should add that a failed exec restores the cancelled alarm.

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on behalf of the watch holder (bolichen). Lanes pass on 7b6ab81, checks green, no conflict, no open change request.

@KiroCrewCaptain
KiroCrewCaptain merged commit 417c7f1 into main Nov 1, 2026
97 of 98 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the kc-wt-14358 branch November 1, 2026 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(platform): follow-ups deferred from #14302 (module-scope disarm import; re-arm a foreign alarm when execv fails)

3 participants