Skip to content

fix(apps): start the gateway when an app pidfile row is not an object - #29159

Merged
RohanK6 merged 1 commit into
mainfrom
crew/conductor/r92-pidfile-row
Nov 3, 2026
Merged

RohanK6 merged 1 commit into
mainfrom
crew/conductor/r92-pidfile-row

Conversation

@RohanK6

@RohanK6 RohanK6 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The gateway starts even when one row of app_backends.pids.json is not an object, instead of crash-looping on every restart.

On every start, _reap_stale_app_backends in src/kiro_crew/apps/backend_runtime/stale_reap.py calls entry.get("pid") on each pidfile row and catches only TypeError/ValueError. A row like {"some-app": 4242} or {"some-app": null} raises AttributeError out of dashboard startup, which nothing on that path catches. The file is reread and never repaired, so every restart fails the same way.

Why it matters

A gateway that will not start takes the dashboard, channels and crons down with it, and the cause is a one-line edit in a state file most people never look at.

Not a goal

What changed (motivation → approach → change)

Symptom: AttributeError at startup. Root cause: the reap assumed every row is a dict. Change: a row that is not a dict is recorded as handled and skipped in the scan, exactly like a row whose pid does not parse, so the final merge drops it. The final merge calls windows_tree_cleanup_pending only for dict rows, so it no longer calls .get on a non-dict. The other readers of this file (_forget_app_pid_if, retire_windows_app_tracking, the port lookup) already check isinstance(entry, dict).

Backwards compatibility

Compatible: every writer (_record_app_pid) writes dict rows, which take the same path as before; only rows that crash startup today are dropped.

Removes nothing: the dropped rows name no process the reaper can identify; no field or path is taken away.

Tests

  • test_reap_drops_a_row_that_is_not_an_object (int, null, string, list): the reap returns 0, does not raise, and the row is gone from the pidfile afterwards.

All four cases fail on main with AttributeError. The app-backend stale-reap, composition contract, characterization, boot coverage, lenient-read ratchet, Windows cleanup and spawn-env suites pass: 645 tests.

Proof: not provable -- other: prove.py mutated run errors at test collection; reverting stale_reap.py to main by hand fails all four cases with AttributeError

Manual verification

N/A — unit coverage sufficient: the test writes the malformed rows to the real pidfile path and runs the real reap.

Related Issues

Fixes #29156

Overlaps #13650 (another author, conflicting since 2026-10-29), which edits the final merge of the same function but does not handle non-object rows.

Sibling sweep

Swept: git grep -nE "_read_pidfile()|entry.get("(pid|start_time)"" -- src/kiro_crew/apps/backend_runtime/
Sibling: src/kiro_crew/apps/backend_runtime/stale_reap.py:_reap_stale_app_backends final merge -- changed here
Sibling: src/kiro_crew/apps/backend_runtime/pidfile.py:_forget_app_pid_if -- not affected -- already checks isinstance(entry, dict)
Sibling: src/kiro_crew/apps/backend_runtime/ports.py:recorded_backend_port -- not affected -- already checks isinstance(entry, dict)

Pattern harvest

Rule candidate: review-prompt
Pattern: a reader that validates only the top level of a hand-editable JSON file and then calls methods on each value crashes on one bad row; check each row type where it is read.

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

Contributions are accepted under the Apache-2.0 license of this project.

The startup stale-reap reads app_backends.pids.json and calls .get() on
every row, catching only TypeError and ValueError. A row that is not an
object, such as {"some-app": 4242} or null from a hand edit, raised
AttributeError out of dashboard startup, so the gateway crash-looped on
every restart and never repaired the file.

Drop such a row like an unparseable pid, in the scan and in the final
merge, as the other pidfile readers already do.
@RohanK6
RohanK6 requested review from a team and KiroCrewCaptain as code owners November 3, 2026 12:22
@RohanK6
RohanK6 requested a review from CrysisDeu November 3, 2026 12:22
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 3c81577fee68995763fa6d0d6b200047c161b0cf 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 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the fix handles the bad row in the one reader that crashed and drops it through the existing handled-row merge, and no other reader depends on such rows.

[DESIGN-REVIEWED] 3c81577

Description read

[DESCRIPTION-READ] 5b690da1ca0c64918d19340dc13918319afe2a7cfbde62f2df8cbb2c4289edb0

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 Nov 3, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

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

The fix removes the startup crash reported in #29156. One note: the guard sits in the reaper, not in the pidfile reader whose type is wrong.

Notes

  • Item 1 — symptom-level: _read_pidfile() (pidfile.py:60) is typed -> dict[str, dict[str, Any]] but returns non-dict rows unchanged. Its callers each repeat the isinstance(entry, dict) check: pidfile.py:137 and ports.py:371 before this PR, and now stale_reap.py:184 and :420. Subtraction: drop non-dict rows once inside _read_pidfile and delete the per-caller checks.

What this change ships

Inventory (3 items) — 2 justified

Intent: keep the gateway starting when one app-pidfile row has been hand-edited into a non-object. FIX.

  1. Gateway no longer crash-loops at startup on a non-object pidfile row — symptom-level: the guard sits at the crash site, not in the reader
  2. Such rows are removed from app_backends.pids.json on the next start — justified
  3. The final merge skips the Windows cleanup-pending check for non-dict rows — justified

[FIRST-PRINCIPLES-REVIEWED] 3c81577

Description read

[DESCRIPTION-READ] a5cd704803cdbac65da0a9b8fa8df9ff624bdf246b1138b8af2408a5fa3bc5ec

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 Nov 3, 2026

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 3c81577

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

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

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 3c81577

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 3c81577fee68995763fa6d0d6b200047c161b0cf 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 3, 2026
@RohanK6
RohanK6 enabled auto-merge (squash) November 3, 2026 13:29

@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: the stale app-backend reaper skips a pidfile row that is not an object instead of raising on every gateway start; adds a parametrized test.

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.

Gateway crash-loops at startup when an app_backends.pids.json row is not an object

2 participants