Skip to content

fix(crash-dumps): take the PID-reuse identity from the persisted-identity routine - #8160

Merged
NicholasRBowers merged 2 commits into
kirodotdev:mainfrom
leonlaiyc:fix/crash-dump-pid-reuse-guard-cross-platform
Sep 13, 2026
Merged

NicholasRBowers merged 2 commits into
kirodotdev:mainfrom
leonlaiyc:fix/crash-dump-pid-reuse-guard-cross-platform

Conversation

@leonlaiyc

@leonlaiyc leonlaiyc commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

crash_dump_store._pid_start_id supplies the start identity that decides whether a crash dump's recorded owner is still the process holding its fd. Two readers act on that answer destructively:

  • sweep_stale_dumps treats a mismatch as "owner is gone" and unlinks the dump — while the owning gateway is alive and faulthandler still holds that file's fd, so its future stall evidence goes to an unreachable inode. There is no recovery path.
  • cron_inflight.RunningMarker.owner_alive reads the same identity to conclude a run was abandoned, and the breaker then parks the job.

#8282 (merged after this PR was opened) gave the function a fallback to platform_compat.process_start_time so it could answer off Linux. That routine has two legs, and only one of them is suitable here:

  • Its Windows leg is the process creation FILETIME read through a query-only handle — a machine integer at 100-ns resolution, no locale or timezone in it. Sound.
  • Its remaining POSIX leg is ps -o lstart=: 1-second, locale- and TZ-rendered. Its own docstring calls it safe precisely because "a format or resolution drift can only make the guard decline to act, never act on the wrong process."

That sentence states a kill-guard contract, where a mismatch means do nothing. Both readers above do the opposite — they act on a mismatch — so the same drift deletes a live gateway's dump rather than declining. Two gateways sharing one data home (an overlapping restart, an isolated pod — cases sweep_stale_dumps documents) need only differ in TZ or LC_TIME to render the same start instant as two different strings. The 1-second granularity is the milder half: it cannot separate two processes that started in the same second.

Why it matters

The dump this can delete is the only artifact of a loop-stall wedge, and the failure is silent and self-concealing: the file disappears while the gateway that will need it is still running, so the loss is only discovered when someone goes looking for evidence that no longer exists.

It also lands on #8282's own new feature. That PR built the cron circuit breaker to answer "which job was in flight when the gateway died" from exactly this identity — so a drifted render both destroys the dump the breaker joins against and can mark a live run abandoned.

What changed (motivation → approach → change)

Root cause is the direction of the fail-safe, not the probe. A drift-tolerant helper is safe only where a mismatch means decline to act; routed into a caller that unlinks, the same tolerance becomes a deletion.

1. The source. The identity now comes from platform_compat.get_process_start_id — the routine this repository already uses everywhere a start identity is written down and compared back later (mcp_gateway.claim, session_pid, metrics.sessions). It is in-process on every platform it covers, and on macOS it reads libproc's microsecond start instant, so macOS keeps the coverage #8282 gave it, at a resolution that also separates two processes started in the same second. Its win32 arm is the process creation FILETIME read through a query-only handle, so Windows is covered by the same routine — one source for the recorded identity on every platform.

The read goes through platform_compat; neither the procfs read nor any process probe is re-implemented locally, so the shim-table row in AGENTS.md ("Process start time (PID-reuse guard)", whose NOT column names raw /proc/<pid>/stat and raw ps -o lstart=) is satisfied. Its stated concern — that both raw probes answer None on Windows — is covered by get_process_start_id's win32 arm, the creation FILETIME read.

Platform On origin/main (post-#8282) Here
Linux procfs field 22 procfs field 22 — byte-identical
macOS ps -o lstart=, 1 s, locale/TZ libproc, microsecond, machine
Windows creation FILETIME creation FILETIME — same read, one routine
other POSIX ps -o lstart= None → plain PID liveness

Because Linux is byte-identical, Linux headers written before this change still compare equal. A None is "identity unknown", never a mismatch, so the last row degrades to plain PID liveness, which only ever protects a file.

2. The migration guard. Changing the representation is itself a hazard, and it is guarded rather than ignored. A macOS gateway that wrote its header under the previous build recorded a ps render; it can never equal what is read now, and comparing the two as though they were one kind of identity would unlink the dump of a gateway still running across the upgrade — the overlapping restart sweep_stale_dumps documents a live PID as protecting.

_start_ids_comparable therefore treats a value that is not in the current representation as unknown rather than different, and both destructive readers consult it — _owner_alive and pid_identity_alive. Patching only the sweep would leave the cron marker path open.

There is a third comparison site, RunningMarker.same_process, and it deliberately gets no guard: it joins a marker to a dump, so its mismatch answer is "not the same process" and the breaker then attributes nothing and pauses nothing. That is already the declining direction.

Two deliberate choices in that predicate:

  • It is an allowlist of what this build writes (digits, optionally one . — a Linux jiffy count, a Windows FILETIME, or macOS's <seconds>.<microseconds>), not a denylist of the retired render. The ps text depends on the writer's locale and TZ, so no property of it — not even the HH:MM:SS colon — is reliable across locales.
  • A legacy token is never converted into the new representation. The timezone and locale it was rendered under are not recoverable, and guessing them would re-introduce the misjudgement this exists to prevent.

#8282's other additions to this module are untouched: the bounded _read_dump_bytes / _read_dump_lines readers, and dump_owner_identity / current_process_identity / pid_identity_alive / dump_wedged_frames. _pid_start_id does not consult process_start_time at all — get_process_start_id's win32 arm performs the same FILETIME read, so a separate fallback could never answer differently than the call above it.

Residual, stated plainly. The guard fixes the direction this build controls: a new gateway reading an old header. The reverse — a gateway still running the previous build reading a header this build wrote — cannot be fixed from here, because that code is already deployed and compares with its own ps render. It is bounded to the macOS upgrade overlap window and is inherent to any identity-format migration; against it stands a permanent removal of the locale/TZ misjudgement on every subsequent restart.

Tests

test/test_crash_dump_store.py. The two platform routines are stubbed apart so each assertion names a source rather than merely observing a value, and the stub also pins IS_WINDOWS so every case asserts the same contract on every CI host. The stub patches the source module and any name the module bound directly, so the tests pin behaviour rather than import style — re-adding a from platform_compat import process_start_time and calling it stays visible.

Red on origin/main at this PR's base (control = main's crash_dump_store.py in-tree with these tests):

  • test_start_id_comes_from_the_persisted_identity_routine — assert 'Wed_Sep_3_10:00:00_2026' == 'stable-id'
  • test_posix_start_id_is_none_rather_than_the_ps_render — assert 'Wed_Sep_3_10:00:00_2026' is None
  • test_header_records_start_id_on_a_non_procfs_platform — the header carries no token
  • test_pid_reuse_detected_without_procfs — assert True is False
  • test_rotation_reclaims_recycled_pid_dumps_without_procfs — assert 0 == 2

Red on the pre-guard head 3aa7f839a, for the migration mechanism itself (not merely because a helper is absent):

  • test_legacy_ps_header_does_not_sweep_a_live_gateways_dump — assert False is True; the sweep unlinks a live gateway's dump.
  • test_legacy_ps_header_is_not_a_rotation_victim — assert 2 == 0; rotation's never-a-victim rule stops protecting it, so two more live-owner dumps are sacrificed. This consequence is beyond the reported one.
  • test_legacy_cron_marker_is_not_reported_abandoned — assert False is True; a still-executing run reports abandoned.
  • test_legacy_cron_marker_falls_back_to_liveness_not_the_own_pid_shortcut — assert False is True; the same on another gateway's PID, so the green answer comes from the liveness fallback rather than pid_identity_alive's own-PID shortcut.

Two further tests (test_windows_filetime_is_a_comparable_current_identity, test_comparability_is_an_allowlist_of_the_current_representation) are direct unit tests of the new predicate and fail on that head with AttributeError — helper-absence, listed separately because that is not mechanism evidence.

Green on both sides, pinning what is preserved rather than changed:

  • test_windows_start_id_comes_from_the_persisted_identity_routine — on Windows the recorded identity comes from get_process_start_id (its win32 arm is the creation FILETIME); the kill-guard routine is not consulted even when it has an answer.
  • test_windows_unknown_identity_is_none_not_a_fallback_render — an unknown identity reads as unknown on Windows exactly as on POSIX, and readers fall back to plain PID liveness.
  • test_real_start_id_round_trips_through_the_header also binds _CURRENT_START_ID_RE to the routine's real output on the running host, so a platform_compat value outside the allowlist is a red test on every CI platform rather than a silent degradation to plain liveness.
  • test_current_format_mismatch_still_detects_pid_reuse and test_current_format_mismatch_still_detects_a_recycled_cron_marker — the guard does not blunt the check it protects; two current-format values that differ are still proof of reuse, on both readers.
  • test_legacy_token_does_not_resurrect_a_dead_owner — the guard turns different into unknown, never confirmed-dead into alive; a dead PID's dump is still swept.

Local runs (Linux): test_crash_dump_store.py + test_stall_attribution.py + test_subagent_stall_attribution.py — 125 passed. isort, flake8, and mypy are clean, and scripts/check_comment_history.py passes against the base. The Windows and macOS CI shards carry the platform evidence; the tests stub the platform routines apart and pin IS_WINDOWS, so each case asserts the same contract on every host.

Manual verification

N/A — unit coverage sufficient: the change is a source swap plus a comparability predicate inside one module, and every divergence it turns on is between two platform_compat routines that the tests stub apart deterministically. The real macOS libproc and Windows FILETIME legs are platform_compat's own, already covered there.

Related Issues

None — found by source review while confirming the PID-reuse guard off Linux.

no linked issue: found by source review, no tracked issue

Interacts with #8282 (merged): this PR is not a revert of it. All four of its new module APIs are preserved; _pid_start_id's identity source becomes one routine covering Linux, macOS, and Windows, and the Windows value is the same creation FILETIME #8282 read.

Pattern harvest

Rule candidate: review-prompt
Pattern: a drift-tolerant identity/liveness helper is safe only where a mismatch means decline to act; routing one into a caller that deletes, kills, or otherwise acts on a mismatch inverts its documented fail-safe direction. When a helper's docstring justifies its coarseness with "drift can only make the guard decline", that sentence is a contract on the caller, and reusing the helper elsewhere must re-check it. Corollary, and the second half of this PR: changing the representation of a persisted identity is a migration — a recorded value in the retired representation must read as unknown, never as a mismatch, on every reader that acts destructively.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|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

🤖 Generated with Claude Code

@leonlaiyc
leonlaiyc requested review from a team and cixuuz September 3, 2026 12:52
@github-actions github-actions Bot added readiness: checking Automated validation is still running fork Pull request from a fork (external contributor) labels Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed ead3cd535aa5d43131a6aabd64ba1b526ea3d584 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] ead3cd5

@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

Reviewed ead3cd535aa5d43131a6aabd64ba1b526ea3d584 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] ead3cd5

@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — 🟡 CONCERNS

Premise-level review of ead3cd535aa5d43131a6aabd64ba1b526ea3d584 via the fork AI-review pipeline — 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/CONCERNS are advisory.

All verification is done. Every factual premise in the description checks out against the trusted base — the kill-guard docstring, the two routines' platform arms, both destructive readers — and my grep over every process_start_time persist-and-compare site found exactly one unfixed sibling of the named root cause, in connections/warm.py. Final review:

First-Principles-Verdict: CONCERNS

Root cause is fixed here but has one counted unfixed sibling: warm.py persists the same ps render and deletes on mismatch.

What this change ships

Inventory (4 items) — 4 justified

Intent: stop a locale/TZ-drifted start-time render from deleting a live gateway's crash dump or parking a live cron run — a FIX.

  1. macOS dump/marker identity is now libproc's microsecond value, not a TZ/locale ps render — justified
  2. Other-POSIX hosts record no start token; reuse detection degrades to plain PID liveness — justified
  3. Pre-upgrade ps-format headers and cron markers read as "unknown", never swept or abandoned on format mismatch alone — justified
  4. Existing reuse-sweep test's fabricated token rewritten into the current representation — justified

Watch

  • Same root cause, 1 unfixed sibling (grepped every process_start_time persist-and-compare site in src/): connections/warm.py:785 persists the macOS ps render and _process_identity_live (warm.py:996) treats mismatch as dead, letting _scavenge_warm_generation_dirs remove a live owner's generation dir on TZ/LC_TIME drift. Every other site (run_marker, registry, ssh_tunnel, daemon_control, pod, apps/backend) declines on mismatch. Genuinely out of this module's scope — accepted-and-deferred.
    Clears when: warm.py's owner identities route through get_process_start_id with their own legacy-token guard, or a linked issue records the deferral.

[FIRST-PRINCIPLES-REVIEWED] ead3cd5

@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of ead3cd535aa5d43131a6aabd64ba1b526ea3d584 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

The base tree confirms the PR's premises: platform_compat.get_process_start_id (platform_compat.py:1481) is in-process on Linux/macOS/Windows with the exact semantics described, and process_start_time's docstring (platform_compat.py:3462) does state the kill-guard "drift can only make the guard decline to act" contract that the destructive readers in crash_dump_store invert. The Linux value is byte-identical across the swap, the legacy ps render can never match the digits-only allowlist, dead-PID sweeping is preserved, and the one modified pre-existing test keeps its assertion direction (mismatch → swept) while adapting the fabricated token to the current representation. The regex-drift coupling between the two modules is pinned by the round-trip test on every CI platform, and the diff contains no new platform-conditional branch, so the "Manual verification: N/A" claim is justified.

Design-Verdict: PASS

Root-cause fix: the persisted identity now comes from the repo's one persisted-identity routine, with a real migration guard on both destructive readers.

[DESIGN-REVIEWED] ead3cd5

@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 Sep 3, 2026
@leonlaiyc
leonlaiyc force-pushed the fix/crash-dump-pid-reuse-guard-cross-platform branch from 7024052 to af4aac7 Compare September 5, 2026 12:55
@leonlaiyc leonlaiyc changed the title fix(crash-dumps): confirm the PID-reuse guard off Linux fix(crash-dumps): confirm the PID-reuse guard on macOS Sep 5, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 5, 2026
@leonlaiyc
leonlaiyc force-pushed the fix/crash-dump-pid-reuse-guard-cross-platform branch from af4aac7 to 3aa7f83 Compare September 6, 2026 01:20
@leonlaiyc leonlaiyc changed the title fix(crash-dumps): confirm the PID-reuse guard on macOS fix(crash-dumps): take the PID-reuse identity from the persisted-identity routine Sep 6, 2026
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 6, 2026
@leonlaiyc
leonlaiyc force-pushed the fix/crash-dump-pid-reuse-guard-cross-platform branch 4 times, most recently from b53c93d to f6172d6 Compare September 6, 2026 02:13
@dwu96 dwu96 added the needs-pr-triage PR scanner: awaiting automated triage label Sep 13, 2026
@NicholasRBowers NicholasRBowers added drive-to-green PR claimed by drive-to-green pipeline and removed needs-pr-triage PR scanner: awaiting automated triage labels Sep 13, 2026
@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]: This PR has been inactive for 7+ days with failing CI. I've assessed the blockers and they appear resolvable — I'll push fixes directly to this branch as a co-author.

Assessment: The code is clean — every CI shard is green and GPT/Opus report no findings, Design Review is PASS, First Principles is advisory CONCERNS. The sole PR Readiness blocker is stale lane binding on head f6172d616: the readiness evaluator now requires each fork Stage-2 review check-run to carry a Fast-Gate-bound external_id, so the six lanes stamped on Sep 6 read as "(not started)", two lanes added to main since (Internal Content Scan, Security Scope Review) never ran on this head, and a superseded/cancelled Code Review run is counted as failed. Fix plan: rebase-only push onto current main to mint a new head (re-fires Fast Gate + CI + all review lanes under the new binding), post disposition comments for the two First Principles Watch items and the Design suggestion (out of scope — no diff widening), and tidy the body (no linked issue: line, drop the CLA placeholder).

If you'd prefer I don't touch this PR, add the pr-no-autofix label.

…tity routine

crash_dump_store._pid_start_id decides whether a dump's recorded owner is
still alive. Two readers act on that answer destructively: sweep_stale_dumps
UNLINKS a header-only dump whose owner it believes dead, while faulthandler
still holds that file's fd, and cron_inflight.RunningMarker.owner_alive reads
the same identity to conclude a run was abandoned.

kirodotdev#8282 gave the function a fallback to platform_compat.process_start_time so it
could answer off Linux. That routine's Windows leg is the creation FILETIME --
a machine integer at 100-ns resolution -- and it is kept here untouched. Its
remaining POSIX leg is `ps -o lstart=`: 1-second, locale- and TZ-rendered, and
documented as safe precisely because "a format or resolution drift can only
make the guard decline to act". That is a KILL-guard contract, where a
mismatch means do nothing. Under these two readers a mismatch means act, so a
drifted render deletes a live gateway's dump instead of declining -- and two
gateways sharing one data home need only differ in TZ or LC_TIME to render the
same instant differently.

Take the identity from platform_compat.get_process_start_id instead: the
routine this repository already uses everywhere a start identity is WRITTEN
DOWN and compared back later (mcp_gateway.claim, session_pid,
metrics.sessions). It is in-process on every platform it covers, and on macOS
it reads libproc's microsecond start instant -- so macOS keeps the coverage
kirodotdev#8282 gave it, at a resolution that also separates two processes started in
the same second. Both legs still route through platform_compat; neither the
procfs read nor the `ps` invocation is re-implemented locally.

Changing the representation is itself a hazard, and it is guarded rather than
ignored. A macOS gateway that wrote its header under the previous build
recorded a `ps` render, which can never equal what is read now; comparing the
two as though they were one kind of identity would unlink the dump of a
gateway still running across the upgrade -- the overlapping restart that
sweep_stale_dumps documents a live PID as protecting. _start_ids_comparable
therefore treats a value that is not in the CURRENT representation as unknown
rather than different, and both destructive readers consult it. It is an
allowlist of what this build writes (digits, optionally one '.'), not a
denylist of the retired render, whose text depends on the writer's locale and
TZ and so has no reliable property. A legacy token is never converted: the
timezone it was rendered under is not recoverable.

Only two platform arms change, both toward declining rather than acting:
macOS swaps the `ps` render for the libproc instant, and any other POSIX host
falls back to plain PID liveness (conservative -- a live PID protects a file).
Linux is byte-identical, both paths taking procfs field 22, so headers written
before this change still compare equal. Windows is unchanged.

Tests stub the two routines apart -- patching the source module and any name
the module bound directly, so they name a SOURCE rather than an import style.
Five fail on origin/main at this PR's base, where the POSIX arm answers
'Wed_Sep_3_10:00:00_2026' and the guard must answer None. Four more fail on
the pre-guard head 3aa7f83 for the migration mechanism itself: the sweep
unlinks a live gateway's dump, rotation sacrifices two more, and a live cron
run reports abandoned -- on its own PID and, separately, on another
gateway's PID so the answer comes from the liveness fallback rather than the
own-PID shortcut.

The third comparison site, RunningMarker.same_process, deliberately keeps no
guard: it JOINS a marker to a dump, and its mismatch answer is "not the same
process", so the breaker attributes nothing and pauses nothing. That is
already the declining direction.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@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 Sep 13, 2026
@NicholasRBowers
NicholasRBowers force-pushed the fix/crash-dump-pid-reuse-guard-cross-platform branch from f6172d6 to c17b86e Compare September 13, 2026 03:13
@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 Sep 13, 2026
@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

Drive-to-green: rebase-only push f6172d616 → c17b86e25. The code is unchanged.

Why a push at all. Every CI shard and all five review lanes were green on f6172d616, but PR Readiness failed on stale bindings, not code: (1) the Stage-2 review lanes ran before the evaluator started requiring Fast-Gate-bound external_ids (#9318), so their stamps read as "(not started)"; (2) two lanes added to main after this PR's base — Internal Content Scan and Security Scope Review — never ran for this head; (3) the evaluator picked a concurrency-cancelled Code Review row over its successful sibling. A rerun cannot re-stamp any of these (reruns emit no workflow_run event), so the fix is a new head sha: rebased the single commit onto current main (6eeec8338) and force-pushed with a SHA-pinned lease. Leon's authorship is preserved; the diff against main is byte-identical in shape (+438/−24, same two files).

Changes made:

  1. Rebase only — git rebase --onto origin/main f6172d616^; no source edits, no fix commits.
  2. PR body tidy (before the push, so the lanes read the current body): added an explicit no linked issue: found by source review, no tracked issue line under Related Issues (the body cites fix(security): stop a long command from taking the gateway down, and name the job #8282 with no closing keyword — that omission is intentional and is now machine-readably stated), and removed the empty ## Contribution License Agreement placeholder block. All of Leon's content and headings are otherwise verbatim.
  3. Approved the 15 fork workflow runs that parked at action_required for the new head.

Local verification on the rebased head (Linux, overlay venv): isort ✅, flake8 ✅, mypy src/kiro_crew/ ✅, pytest test/test_crash_dump_store.py test/test_stall_attribution.py test/test_subagent_stall_attribution.py → 125 passed. The Windows FILETIME and macOS libproc legs are covered by the platform CI shards, as the PR's tests stub the platform routines apart.

Advisory dispositions for the First Principles Watch items and the Design Suggestion follow once the lanes stamp this head.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

Fix round 1: c17b86e25 → f5bf26056 — comment text only, no executable change.

The rebased head's Fast Gate failed on the Comment History Gate, a gate added to main after this branch's Sep 6 base. It flags history narration on comment/docstring lines a change adds, and three of this PR's added lines carried it:

  1. src/kiro_crew/dashboard/crash_dump_store.py:284 — "a recorded value that no longer matches" → "a recorded value that differs from the live probe".
  2. test/test_crash_dump_store.py:1220 — "the recorded start id no longer matches the one the PID reports now" → "the recorded start id differs from the one the PID reports now".
  3. test/test_crash_dump_store.py:1332 — "The second destructive reader, which fix(security): stop a long command from taking the gateway down, and name the job #8282 added" → "The second destructive reader of the recorded identity" (the PR-number reference is the flagged marker; the sentence now states what the reader is rather than when it arrived).

Each rewrite states the same fact in present tense; the guard semantics, tests, and all executable code are untouched. Landed as a separate commit so Leon's original commit stays exactly his, with the fix attributed Co-authored-by: Kiro Crew.

Verified locally on the new head: scripts/check_comment_history.py self-test + gate both pass against base 6eeec8338; isort ✅ flake8 ✅ mypy ✅ pytest (crash_dump_store + stall_attribution + subagent_stall_attribution) → 125 passed. The 15 fork workflow runs for the new head are approved and running.

The other two reds on c17b86e25 (Await Fast Gate, Coverage Gate) were downstream of this same gate — a red Fast Gate skips the heavy CI matrix — so no separate fix applies.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 13, 2026
get_process_start_id covers win32 itself (platform_compat.py reads the
creation FILETIME through a query-only handle), so _pid_start_id's
retained process_start_time fallback could never answer differently
than the call above it. The branch, its sanitiser tail, and the
docstring paragraph premised on 'it declines on Windows' are deleted.
The two Windows tests pin that the persisted-identity routine is the
sole source on every platform, and the no-stub round-trip test binds
_CURRENT_START_ID_RE to that routine's real output. Comment and
docstring lines flagged by the Comment History Gate are reworded to
present tense.

Original PR author: Leon (leonlaiyc).

Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
@NicholasRBowers

Copy link
Copy Markdown
Contributor

self-added: no
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • span=73b3b5026bfc — Windows fallback branch duplicates get_process_start_id's win32 delegation

Disposition: fixed (head ead3cd535)

The fallback branch is deleted: _pid_start_id returns platform_compat.get_process_start_id(pid) directly. That routine's win32 arm performs the same creation-FILETIME read, so the branch could never answer differently than the call above it. Fixed in ead3cd5.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

self-added: no
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • span=de5c89f5d9ec — the "declines on Windows" premise is inherited from stale in-tree comments

Disposition: fixed (head ead3cd535)

The clearing condition is met: the fallback block is deleted, and the docstring now states that get_process_start_id covers Windows directly via the creation FILETIME. The two stale comments at run_marker.py:127 and metrics/sessions.py:509 live outside this PR's two-file diff; correcting other modules' comments is out of this PR's scope, and this ruling covers findings that ask this PR to edit files its intent does not touch. Fixed in ead3cd5.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

self-added: no
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • span=8690b73d9831 — warm.py is an unfixed destructive sibling of the root cause

Disposition: accepted-and-deferred — tracked in #10474 (label deferred-finding, assigned, Due: 2026-09-27)

The finding holds: _warm_generation_owner (warm.py:780,785) persists process_start_time renders and _process_identity_live (warm.py:993-997) reads a drifted render as dead, after which the scavenger rmtrees the tree. It is out of this PR's stated scope — crash_dump_store and the cron marker readers — and the fix is a whole-module mirror of this PR (source swap + comparability guard on every destructive reader), tracked in #10474. This ruling covers findings that ask this PR to also fix warm.py's readers.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

self-added: no
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • span=4699fad4dfd5 — subtraction: delete the fallback + sanitiser tail of _pid_start_id

Disposition: fixed (head ead3cd535)

The subtraction is taken verbatim: the IS_WINDOWS gate, the process_start_time call, and the whitespace sanitiser are deleted, and the body shrinks to return platform_compat.get_process_start_id(pid). The two Windows tests now pin the single-source contract (test_windows_start_id_comes_from_the_persisted_identity_routine, test_windows_unknown_identity_is_none_not_a_fallback_render). Fixed in ead3cd5.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

self-added: no
mechanism: _CURRENT_START_ID_RE bound to the real routine output by one assertion in the existing round-trip test
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • span=e5c24a20b894 — _CURRENT_START_ID_RE duplicates the output grammar with no test binding them

Disposition: fixed (head ead3cd535)

test_real_start_id_round_trips_through_the_header (no stubbing) now asserts _CURRENT_START_ID_RE.fullmatch() on the host's real get_process_start_id output, so it runs against the genuine value on the Linux, macOS, and Windows CI shards. A platform_compat shape outside the allowlist is a red test rather than a silent degradation of reuse detection to plain liveness. Fixed in ead3cd5.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

self-added: no
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • span=4120cfff3742 — the body claims fixture migrations the diff does not carry

Disposition: fixed (body regenerated)

The claim is removed: neither fabricated-mismatch nor recycled-token appears in the diff or the base (verified by grep on both), so the sentence sent reviewers hunting for a hunk that does not exist. The body is regenerated from the whole diff at head ead3cd5.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

self-added: no
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • span=bd325095e2e8 — docstring says "It declines on Windows", contradicting get_process_start_id

Disposition: fixed (head ead3cd535)

The docstring now states that get_process_start_id answers on Windows directly — the process creation FILETIME through a query-only handle — and the paragraph premised on it declining is deleted along with the dead fallback it justified. Fixed in ead3cd5.

@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 Sep 13, 2026
@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

Fix round 2: f5bf2605 → ead3cd53 — the retained Windows fallback is deleted as dead code.

The review round on f5bf2605 settled with no blocker, but three lanes converged on one real point: main (after this branch's Sep 6 base) folded the win32 creation-FILETIME read into platform_compat.get_process_start_id itself. Verified in the tree — its body opens with if sys.platform == "win32": return process_start_time(pid). So the fallback this PR retained could never answer differently than the call directly above it, and the docstring's "It declines on Windows" premise is false on the current base. This is rebase fallout, not a defect in Leon's original design — at his base the premise was true.

Changes in ead3cd53 (amended into the fix commit; Leon's commit untouched):

  1. _pid_start_id shrinks to return platform_compat.get_process_start_id(pid). The IS_WINDOWS gate, process_start_time call, and sanitiser tail are gone; the docstring states the Windows FILETIME coverage directly.
  2. The two Windows-fallback tests are replaced by two that pin the single-source contract: on Windows the identity comes from get_process_start_id (kill-guard routine not consulted even when it has an answer), and an unknown identity stays None rather than being manufactured from a second source.
  3. test_real_start_id_round_trips_through_the_header now binds _CURRENT_START_ID_RE to the routine's real output on every CI platform (the Design suggestion).
  4. One pre-existing test (test_windows_filetime_is_a_comparable_current_identity) had its stub moved to the routine that now supplies the FILETIME; its subject — FILETIME comparability — is unchanged.
  5. PR body regenerated from the whole diff: no retained-fallback claims, updated platform table and test list, and the stale fixture-migration sentence is removed (neither quoted string exists in the diff or base).

All seven review items from the round are dispositioned individually above: 6 fixed, 1 accepted-and-deferred (#10474 — warm.py's scavenger is the remaining destructive reader of ps-rendered identities; labeled, assigned, due 2026-09-27).

Local verification on ead3cd53: comment-history gate, isort, flake8, mypy all pass; the three test files run 125 passed. The 15 fork workflow runs for the new head are approved and running.

@NicholasRBowers

Copy link
Copy Markdown
Contributor

self-added: no
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

  • span=239dd9b80b62 — warm.py is the one unfixed persist-and-compare sibling of the root cause

Disposition: accepted-and-deferred — tracked in #10474 (label deferred-finding, assigned, Due: 2026-09-27)

The finding holds and is already recorded: #10474 tracks routing warm.py's owner identities through get_process_start_id with their own legacy-token guard, mirroring this PR. It is out of this PR's stated scope (crash_dump_store and the cron marker readers), and this ruling covers findings that ask this PR to also fix warm.py's readers, wherever the instance moves.

@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 Sep 13, 2026
@NicholasRBowers
NicholasRBowers enabled auto-merge (squash) September 13, 2026 05:16

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

Reviewed the full exact-head diff and tests. Destructive readers now use the persisted-identity routine and treat legacy representations as unknown, preserving Linux compatibility, macOS/Windows identity quality, dead-owner cleanup, and current-format PID-reuse detection.

@NicholasRBowers
NicholasRBowers merged commit 8e01fae into kirodotdev:main Sep 13, 2026
83 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 13, 2026
@NicholasRBowers NicholasRBowers removed the drive-to-green PR claimed by drive-to-green pipeline label Sep 13, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…tity routine (kirodotdev#8160)

* fix(crash-dumps): take the PID-reuse identity from the persisted-identity routine

crash_dump_store._pid_start_id decides whether a dump's recorded owner is
still alive. Two readers act on that answer destructively: sweep_stale_dumps
UNLINKS a header-only dump whose owner it believes dead, while faulthandler
still holds that file's fd, and cron_inflight.RunningMarker.owner_alive reads
the same identity to conclude a run was abandoned.

kirodotdev#8282 gave the function a fallback to platform_compat.process_start_time so it
could answer off Linux. That routine's Windows leg is the creation FILETIME --
a machine integer at 100-ns resolution -- and it is kept here untouched. Its
remaining POSIX leg is `ps -o lstart=`: 1-second, locale- and TZ-rendered, and
documented as safe precisely because "a format or resolution drift can only
make the guard decline to act". That is a KILL-guard contract, where a
mismatch means do nothing. Under these two readers a mismatch means act, so a
drifted render deletes a live gateway's dump instead of declining -- and two
gateways sharing one data home need only differ in TZ or LC_TIME to render the
same instant differently.

Take the identity from platform_compat.get_process_start_id instead: the
routine this repository already uses everywhere a start identity is WRITTEN
DOWN and compared back later (mcp_gateway.claim, session_pid,
metrics.sessions). It is in-process on every platform it covers, and on macOS
it reads libproc's microsecond start instant -- so macOS keeps the coverage
kirodotdev#8282 gave it, at a resolution that also separates two processes started in
the same second. Both legs still route through platform_compat; neither the
procfs read nor the `ps` invocation is re-implemented locally.

Changing the representation is itself a hazard, and it is guarded rather than
ignored. A macOS gateway that wrote its header under the previous build
recorded a `ps` render, which can never equal what is read now; comparing the
two as though they were one kind of identity would unlink the dump of a
gateway still running across the upgrade -- the overlapping restart that
sweep_stale_dumps documents a live PID as protecting. _start_ids_comparable
therefore treats a value that is not in the CURRENT representation as unknown
rather than different, and both destructive readers consult it. It is an
allowlist of what this build writes (digits, optionally one '.'), not a
denylist of the retired render, whose text depends on the writer's locale and
TZ and so has no reliable property. A legacy token is never converted: the
timezone it was rendered under is not recoverable.

Only two platform arms change, both toward declining rather than acting:
macOS swaps the `ps` render for the libproc instant, and any other POSIX host
falls back to plain PID liveness (conservative -- a live PID protects a file).
Linux is byte-identical, both paths taking procfs field 22, so headers written
before this change still compare equal. Windows is unchanged.

Tests stub the two routines apart -- patching the source module and any name
the module bound directly, so they name a SOURCE rather than an import style.
Five fail on origin/main at this PR's base, where the POSIX arm answers
'Wed_Sep_3_10:00:00_2026' and the guard must answer None. Four more fail on
the pre-guard head 3aa7f83 for the migration mechanism itself: the sweep
unlinks a live gateway's dump, rotation sacrifices two more, and a live cron
run reports abandoned -- on its own PID and, separately, on another
gateway's PID so the answer comes from the liveness fallback rather than the
own-PID shortcut.

The third comparison site, RunningMarker.same_process, deliberately keeps no
guard: it JOINS a marker to a dump, and its mismatch answer is "not the same
process", so the breaker attributes nothing and pauses nothing. That is
already the declining direction.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix: drop the dead Windows fallback and state comments in present tense

get_process_start_id covers win32 itself (platform_compat.py reads the
creation FILETIME through a query-only handle), so _pid_start_id's
retained process_start_time fallback could never answer differently
than the call above it. The branch, its sanitiser tail, and the
docstring paragraph premised on 'it declines on Windows' are deleted.
The two Windows tests pin that the persisted-identity routine is the
sole source on every platform, and the no-stub round-trip test binds
_CURRENT_START_ID_RE to that routine's real output. Comment and
docstring lines flagged by the Comment History Gate are reworded to
present tense.

Original PR author: Leon (leonlaiyc).

Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>

---------

Co-authored-by: Leon Lai <laputaca@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Nick Bowers <nrb@amazon.com>
Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants