Skip to content

fix(process): count one unreadable child once during cleanup - #2928

Closed
CodeAlex52 wants to merge 5 commits into
morluto:mainfrom
CodeAlex52:fix/process-cleanup-count-dedupe
Closed

CodeAlex52 wants to merge 5 commits into
morluto:mainfrom
CodeAlex52:fix/process-cleanup-count-dedupe

Conversation

@CodeAlex52

Copy link
Copy Markdown

Summary

Fixes #2540.

Cleanup now reports one unreadable live child once: the reason names one live process and the failure list keeps one entry per PID.

Problem and expected behavior

The cleanup plan seeded its unresolved list with the sweep failures (ProcessOwnership.ts:459) and then appended the per-group validation failures, which describe the same member again (:492-510), so cleanupValidationFailure counted the same PID twice:

process ownership token could not be read for 2 live process(es): environment_unavailable=2; live candidates 101=environment_unavailable, 101=environment_unavailable

Expected (per the issue's restoration check): one failure for PID 101, a count of one, cleanup still unsuccessful, and no signal to the unverified group. A control with two distinct unreadable live children must still report each PID once and count two.

Change and scope

src/process/ProcessOwnership.ts: when merging the per-group validation failures into the unresolved list, skip PIDs that the sweep already recorded. One observation per PID is kept; distinct PIDs are unaffected, and the signalability decision (failures.length === 0 && scanFailures.length === 0) is unchanged.

Verification

Added src/process/cleanup-count.regression.test.ts with the issue's reproduction and its control:

  • one unreadable child → failures has length 1, reason contains 1 live process(es), zero signal calls;
  • two distinct unreadable children → one failure per PID, reason contains 2 live process(es), zero signal calls.

I traced both fixtures through the cleanup plan and the failure merge by hand; I could not run Vitest in this environment (no local checkout), so please let CI run npm run test:focused -- src/process/cleanup-count.regression.test.ts and the static checks.

The cleanup plan seeded its unresolved list with the sweep failures and then
appended the same member's validation failure, so one live process that could
not expose its run token was reported twice: the reason counted two live
processes and listed the same PID twice.

Keep one failure per PID when merging the per-group validation failures into
the sweep's unresolved list. Distinct unreadable children still report once
each, and cleanup remains unsuccessful without signaling.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T18:51:33.566412Z e46862d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with a non-blocking gap in the one-failure-per-PID fix.

Findings

  1. P2 One child still appears twice ▶
Fix with agent prompt
### Issue 1
src/process/ProcessOwnership.ts:510-511
The sweep can record both an unreadable token and a changed or unreadable identity for one live PID. `unresolved` starts with both entries, and `mergeProcessOwnershipFailure` only replaces the first match. Cleanup callers therefore still get duplicate failures, leaving the one-entry-per-PID fix incomplete.

Build the initial list through the same merge helper, and add a test with both failures for one PID.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR merges cleanup failures by PID and keeps the more useful explanation.

  • Cleanup reports one ownership failure for each live process.

Reviews (4) · Last reviewed commit: "Merge branch 'main' into fix/process-cle..." · Reviewed by Greptile

Comment thread src/process/ProcessOwnership.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 70a18934e6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/process/ProcessOwnership.ts Outdated
// diagnostic. Keep one observation per PID.
unresolved.push(
...failures.filter(
({ pid }) => !unresolved.some((entry) => entry.pid === pid),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retain later failure evidence when deduplicating by PID

When a sweep records a PID as environment-unreadable but the subsequent per-group read returns a foreign run token, processOwnershipFailures emits run-token-mismatch; because unresolved was seeded from sweep failures, this PID-only predicate discards that newer result. The group is still not signaled, but cleanupValidationFailure now falsely reports the older unreadable-token diagnosis and callers lose the definitive mismatch, so one-entry-per-PID needs to merge or replace changed observations rather than always retaining the first.

AGENTS.md reference: AGENTS.md:L29-L29

Useful? React with 👍 / 👎.

morluto and others added 2 commits October 14, 2026 02:07
The cleanup plan seeded its unresolved list with the sweep failures and then
appended the same member's validation failure, so one live process that could
not expose its run token was reported twice: the reason counted two live
processes and listed the same PID twice.

Keep one failure per PID when merging the per-group validation failures into
the sweep's unresolved list. Distinct unreadable children still report once
each, and cleanup remains unsuccessful without signaling.
@morluto
morluto force-pushed the fix/process-cleanup-count-dedupe branch from 70a1893 to 89d36df Compare October 13, 2026 18:07

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 89d36dfbb0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/process/ProcessOwnership.ts Outdated
Comment on lines +515 to +516
...failures.filter(
({ pid }) => !unresolved.some((entry) => entry.pid === pid),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Deduplicate failures returned in the same validation batch

Even with no sweep failure already in unresolved, if an owned member's identity becomes unavailable during revalidation and its token read is also unavailable, processOwnershipFailures returns both process-identity-unavailable and environment-unreadable for that PID. This filter evaluates both entries before unresolved.push changes the array, so both pass and the cleanup result still reports one PID twice; normalize these failures at their producing boundary or update a seen-PID map while merging.

AGENTS.md reference: AGENTS.md:L23-L25

Useful? React with 👍 / 👎.

…codex/maintenance-pr-2928

# Conflicts:
#	src/process/ProcessOwnership.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 014ce9fd1b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +510 to +511
for (const failure of failures)
mergeProcessOwnershipFailure(unresolved, failure);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Normalize failures before every cleanup consumer

When an owned member's identity becomes unavailable and its token read is also unavailable during the final pre-signal check, processOwnershipFailures returns both process-identity-unavailable and environment-unreadable for the same PID. The remaining revalidateOwnedProcessGroup path passes that array directly to cleanupValidationFailure at lines 591–597, so this new merge loop is never applied and cleanup still reports one PID twice; normalize at the producing boundary rather than only in createOwnedCleanupPlan.

AGENTS.md reference: AGENTS.md:L23-L25

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e46862dc3a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

failures: ProcessOwnershipValidationFailure[],
next: ProcessOwnershipValidationFailure,
): void => {
const index = failures.findIndex(({ pid }) => pid === next.pid);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Normalize failures emitted by the sweep

When a sweep first reads a stable identity, keeps getting an unreadable token, and then sees the identity change or become unavailable in its post-read check, scanTokenOwnedProcesses emits both environment-unreadable and process-identity-unavailable for the same PID. Both entries seed unresolved, and this findIndex updates only the first one, so the final cleanup result still reports that PID twice. This is a separate producer from the already-reported final-revalidation path; normalize the sweep output (or seed the plan through a PID-keyed merge) as well.

AGENTS.md reference: AGENTS.md:L23-L25

Useful? React with 👍 / 👎.

Comment on lines +510 to +511
for (const failure of failures)
mergeProcessOwnershipFailure(unresolved, failure);

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.

P2 One child still appears twice

The sweep can record both an unreadable token and a changed or unreadable identity for one live PID. unresolved starts with both entries, and mergeProcessOwnershipFailure only replaces the first match. Cleanup callers therefore still get duplicate failures, leaving the one-entry-per-PID fix incomplete.

Build the initial list through the same merge helper, and add a test with both failures for one PID.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/process/ProcessOwnership.ts
Line: 510-511

Comment:
**One child still appears twice**

The sweep can record both an unreadable token and a changed or unreadable identity for one live PID. `unresolved` starts with both entries, and `mergeProcessOwnershipFailure` only replaces the first match. Cleanup callers therefore still get duplicate failures, leaving the one-entry-per-PID fix incomplete.

Build the initial list through the same merge helper, and add a test with both failures for one PID.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@morluto morluto added area: runtime Process capture and runtime observation bug Something isn't working labels Oct 14, 2026
morluto added a commit that referenced this pull request Oct 14, 2026
Retain unresolved process identity and launch evidence through retryable cleanup. Share capture path normalization and preserve failed filesystem observations. Bound child output and drain Windows pipes without one-chunk throttling.

Reviewed fixes include #1628, #2632, #2644, #2784, #2928, #2931, #2965, #2992, and #3011.

Validation: 92 focused source tests passed; four platform-specific skips. Real Windows and Hopper lifecycle coverage was not rerun.
@CassieFox23

Copy link
Copy Markdown
Contributor

Heads up: main covers this in its own way in 599a8ee. The code is in src/process/ProcessOwnership.ts, and counts each unreadable live member once shows it. It is listed on tracker #3582. If this PR still adds something main doesn't have, please say so here and I'll take it off the list. Thanks for the fix!

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@CodeAlex52

Copy link
Copy Markdown
Author

Verified against 599a8ee: mergeProcessOwnershipFailure keeps one diagnosis per PID (with priority replacement, which is strictly better than my keep-first version), and the counts each unreadable live member once coverage pins the issue's scenario. Nothing in this PR that main doesn't already have — please take it off the tracker list. Closing as superseded.

@CodeAlex52 CodeAlex52 closed this Oct 15, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

@CodeAlex52, thanks for noticing that one unreadable child could be counted more than once in cleanup reporting. The current ownership path counts unreadable live members once and keeps the later identity-validation case distinct (main).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(process): report one unreadable child as one live process

3 participants