Skip to content

fix: report a lifecycle script that cannot start as failed - #34507

Merged
RohanK6 merged 1 commit into
mainfrom
crew/conductor/lifecycle-script-spawn-failure
Nov 10, 2026
Merged

RohanK6 merged 1 commit into
mainfrom
crew/conductor/lifecycle-script-spawn-failure

Conversation

@RohanK6

@RohanK6 RohanK6 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An app lifecycle script whose process cannot be started is reported as a failed script, so enable rolls back and uninstall finishes instead of stopping half done.

run_lifecycle_script returns {output, failed}, and every caller acts on failed. When the spawn itself raised OSError (no /bin/bash, EAGAIN from a process limit, ENOMEM), the error escaped instead. Enable was left with the backend started and no rollback, the post-update onEnable re-run failed a route that must not fail, and uninstall stopped after its crons were already removed. Teardown already caught it.

Why it matters

These are the moments a host is most likely to be short of processes or memory. An uninstall that stops after deleting the app's crons leaves an app that is still installed but no longer runs its schedules, and every retry stops at the same place.

Not a goal

  • Changing what a failed script does at any caller.
  • Catching TypeError, ValueError or RuntimeError from the spawn helper; those are not raised for a script that merely cannot start.

What changed (motivation → approach → change)

Symptom: enable answers 500 with the app half enabled; uninstall answers 500 with its crons gone. Cause: create_subprocess_limited raising OSError was not caught in run_lifecycle_script, so it skipped the failed path every caller already has. Change: catch OSError around the spawn only, log it, and return {"output": "script could not be started: ...", "failed": True}. The existing finally still removes the sandbox wrapper's temp file.

Backwards compatibility

Compatible: a script that starts behaves exactly as before; a spawn that used to raise now returns the failed result the function already documents.

Removes nothing: no input, key, route or behavior is taken away.

Tests

test/test_lifecycle_script_spawn_failure.py: a spawn that raises FileNotFoundError or BlockingIOError returns failed: True with a "could not be started" message, and the sandbox wrapper's temp file is still removed. Both cases fail on main (the OSError escapes) and pass with the fix. 1,055 tests in the 41 lifecycle, enable, uninstall and teardown test files pass.

Proof: not provable -- other: prove.py ended inconclusive (collection-only error); run by hand against the origin/main copy of lifecycle_scripts.py, both new cases fail and pass with the fix.

Manual verification

N/A — unit coverage sufficient: the change is one except clause around the spawn, exercised directly by the test.

Related Issues

Fixes #34502

Open PR #10599 also edits lifecycle_scripts.py; it already conflicts with main, so whichever lands second rebases.

Sibling sweep

Swept: git grep -n "run_lifecycle_script(" -- src/kiro_crew/
Sibling: src/kiro_crew/apps/teardown.py -- not affected -- already catches an exception from the runner
Sibling: src/kiro_crew/apps/routes_uninstall.py -- not affected -- fixed through the shared runner, no change needed here
Sibling: src/kiro_crew/apps/routes_lifecycle.py -- not affected -- fixed through the shared runner, no change needed here

Pattern harvest

Not generalizable: the defect is one helper that promises a result dict but let its spawn error escape; the fix lives in that helper.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the Apache-2.0 license of this project.

run_lifecycle_script returns {output, failed}, and every caller acts
on failed: enable rolls the app back, an update notes it, and
uninstall and teardown carry on. When the spawn itself raised (no
shell, EAGAIN, ENOMEM), the OSError escaped instead. Teardown caught
it, but enable was left with the backend started and no rollback, an
update re-run failed a route that must not fail, and uninstall
stopped after its crons were already removed.

Catch the spawn's OSError and return a failed result, so each caller
takes the failure path it already has.
@RohanK6
RohanK6 requested review from a team and KiroCrewCaptain as code owners November 10, 2026 11:31
@RohanK6
RohanK6 requested a review from buluoray November 10, 2026 11:31
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

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

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks. The fix sits in the shared helper, which already promises a failed result to every caller, so it removes the root cause once for enable, update and uninstall. The outer finally still cleans up the wrapper.

Notes

  • The logger.warning call drops exc. Add it, or exc_info, so an operator can tell an EAGAIN failure from a missing-bash failure in the logs and not only in the response body.

[DESIGN-REVIEWED] a20e80d

Description read

[DESCRIPTION-READ] 6cf68728b1d052c35d143ee85641a31ad64e3b79c5f6c7a0a8702d90912bd900

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of a20e80df5d58820aff2d6522df3fe6e75cd6fd5a — 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

Nothing to check.

What this change ships

Inventory (2 items) — 2 justified

Intent: when an app script can't even start, its enable, update or uninstall should finish or roll back cleanly instead of stopping half done. FIX.

  1. A lifecycle script that cannot start now reports as failed with a "could not be started" message, so enable rolls back and uninstall finishes. It used to stop with a 500. — justified
  2. A warning is now logged when a lifecycle script cannot start. — justified

[FIRST-PRINCIPLES-REVIEWED] a20e80d

Description read

[DESCRIPTION-READ] 9287a4bc2b34b67e6aef6dbb9ad014d72542fcd527439224fa040e5d18fb4ed6

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] a20e80d

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

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

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] a20e80d

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

@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 Nov 10, 2026
@RohanK6
RohanK6 enabled auto-merge (squash) November 10, 2026 13:04

@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.

Tier 1 auto-approve: fix (2 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: returns a failed result when a lifecycle script's process cannot be started, so callers roll back as for any failed script; regression test added.

@RohanK6
RohanK6 merged commit c132a1f into main Nov 10, 2026
98 checks passed
@RohanK6
RohanK6 deleted the crew/conductor/lifecycle-script-spawn-failure branch November 10, 2026 13:06
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 10, 2026

@bolichen97 bolichen97 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.

Approving a20e80d. run_lifecycle_script now catches an OSError from create_subprocess_limited (no shell, EAGAIN, ENOMEM). It logs one warning and returns {"output": "script could not be started: ...", "failed": True}, the result shape every caller already handles. Before, the raise skipped that handling: an enable was left half done, and an uninstall stopped after its crons were already gone (#34502).

Nothing new is refused. A spawn that fails was already a failure. Now it goes down the existing failed path instead of escaping. The test covers FileNotFoundError and BlockingIOError and checks that the sandbox wrapper's temp file is still cleaned up. No regex. All 98 checks are green. Auto-merge is left to the author.

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.

An app lifecycle script that cannot start raises instead of failing, leaving enable and uninstall half done

3 participants