Skip to content

fix(process): retain withheld-process observations on cleanup failures - #2931

Closed
CodeAlex52 wants to merge 2 commits into
morluto:mainfrom
CodeAlex52:fix/process-retain-withheld-observations
Closed

CodeAlex52 wants to merge 2 commits into
morluto:mainfrom
CodeAlex52:fix/process-retain-withheld-observations

Conversation

@CodeAlex52

Copy link
Copy Markdown

Summary

Fixes #2543.

Cleanup failures now retain the sweep's withheld-process observations: the revalidation-failure and signal-error returns no longer drop the PID and diagnostic that successful cleanup preserves.

Problem and expected behavior

cleanupOwnedProcessGroup returned a revalidation failure (ProcessOwnership.ts:255) and a signal error (:263-269) without the plan's observations, while the success return (:273-277) and the unresolved-failure return kept them. An unrelated process whose environment the OS withholds therefore lost its uncertainty evidence depending on which branch finished the attempt.

Expected (per the issue's restoration check): all three fixture cases retain PID 900 with platform_binary_environment_withheld, each keeping its own cleanup status, mismatch or signal-error reason, and signal-call count. A control with no withheld candidate must not invent an observation.

Change and scope

src/process/ProcessOwnership.ts: added withUnverifiedObservations, which attaches the plan's observations to a failure result that does not already carry its own, and used it on both returns. Ownership authority, reasons and signaling behaviour are unchanged.

Verification

Added src/process/cleanup-withheld.regression.test.ts with the issue's it.each fixture (revalidation / signal-error / success) plus the documented control expectations.

I traced all three fixtures through the plan, the revalidation and the signal paths 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-withheld.regression.test.ts and the static checks.

@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:53:22.358358Z efe9928 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: 3/5

[Medium impact] Adjusts process cleanup to preserve uncertainty observations.

The PR needs both TypeScript errors fixed before merging.

Findings

  1. P1 New assertion fails TypeScript checks ▶
  2. P1 TypeScript checks fail ▶
Fix with agent prompt
### Issue 1
src/process/cleanup-withheld.regression.test.ts:92-95
The signal-error assertion reads `result.reason`, but `result` is still `ProcessCleanupResult`, whose success case has no `reason`. Checking `mode` does not narrow `result`, so this blocks static checks. Check `result.cleaned === false` before reading `reason`, or use `toMatchObject` as the revalidation assertion does.

```suggestion
    if (mode === "signal-error")
      expect(result).toMatchObject({
        reason: "owned process group signal failed: signal denied",
      });
```

### Issue 2
src/process/ProcessOwnership.ts:undefined-270
`revalidation` has a return type that allows `cleaned: true`. Checking `"cleaned" in revalidation` removes the empty-group case but still allows success. The new call passes that value to `withUnverifiedObservations`, which accepts only `ProcessCleanupFailure`, so TypeScript rejects it and blocks static checks.

Give the failure-only helpers a failure-only return type, or check `revalidation.cleaned` before this call.

---

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

Summary

The PR keeps withheld-process observations when cleanup fails during revalidation or signaling.

  • Cleanup failures keep withheld-process observations.

Reviews (4) · Last reviewed commit: "test(process): assert withheld observati..." · Reviewed by Greptile

@morluto
morluto force-pushed the fix/process-retain-withheld-observations branch from 3fac873 to b5dede1 Compare October 13, 2026 18:06
);
if ("cleaned" in revalidation) return revalidation;
if ("cleaned" in revalidation)
return withUnverifiedObservations(revalidation, plan.unverified);

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.

P1 TypeScript checks fail

revalidation has a return type that allows cleaned: true. Checking "cleaned" in revalidation removes the empty-group case but still allows success. The new call passes that value to withUnverifiedObservations, which accepts only ProcessCleanupFailure, so TypeScript rejects it and blocks static checks.

Give the failure-only helpers a failure-only return type, or check revalidation.cleaned before this call.

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

Comment:
**TypeScript checks fail**

`revalidation` has a return type that allows `cleaned: true`. Checking `"cleaned" in revalidation` removes the empty-group case but still allows success. The new call passes that value to `withUnverifiedObservations`, which accepts only `ProcessCleanupFailure`, so TypeScript rejects it and blocks static checks.

Give the failure-only helpers a failure-only return type, or check `revalidation.cleaned` before this call.

---

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

@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: b5dede162c

ℹ️ 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 +269 to +270
if ("cleaned" in revalidation)
return withUnverifiedObservations(revalidation, plan.unverified);

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 Carry scan observations through planning failures

When a token sweep sees an unrelated withheld PID and a launcher descendant has moved into a group whose leader is absent or not rooted and no member carries the run token, createOwnedCleanupPlan takes its direct cleaned: false return after the scan has already collected the withheld observation. cleanupOwnedProcessGroup then returns that planning failure before this revalidation wrapper runs, and the planning result does not carry tokenOwned.unverified, so this cleanup-failure branch still drops the same PID and diagnostic; carry the scan observations on that planning failure (or on every post-scan result).

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@morluto
morluto force-pushed the fix/process-retain-withheld-observations branch from b5dede1 to e62ec0b Compare October 13, 2026 18:24
CodeAlex52 and others added 2 commits October 14, 2026 02:49
The revalidation-failure and signal-error returns omitted the plan's withheld
observations, while the success and unresolved-failure returns kept them, so the
documented uncertainty evidence depended on which cleanup branch finished the
attempt. Thread the plan's observations through both returns; a result that
already carries its own observations is unchanged.
@morluto
morluto force-pushed the fix/process-retain-withheld-observations branch from e62ec0b to efe9928 Compare October 13, 2026 18:49
Comment on lines +92 to +95
if (mode === "signal-error")
expect(result.reason).toBe(
"owned process group signal failed: signal denied",
);

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.

P1 New assertion fails TypeScript checks

The signal-error assertion reads result.reason, but result is still ProcessCleanupResult, whose success case has no reason. Checking mode does not narrow result, so this blocks static checks. Check result.cleaned === false before reading reason, or use toMatchObject as the revalidation assertion does.

Suggested change
if (mode === "signal-error")
expect(result.reason).toBe(
"owned process group signal failed: signal denied",
);
if (mode === "signal-error")
expect(result).toMatchObject({
reason: "owned process group signal failed: signal denied",
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/process/cleanup-withheld.regression.test.ts
Line: 92-95

Comment:
**New assertion fails TypeScript checks**

The signal-error assertion reads `result.reason`, but `result` is still `ProcessCleanupResult`, whose success case has no `reason`. Checking `mode` does not narrow `result`, so this blocks static checks. Check `result.cleaned === false` before reading `reason`, or use `toMatchObject` as the revalidation assertion does.

```suggestion
    if (mode === "signal-error")
      expect(result).toMatchObject({
        reason: "owned process group signal failed: signal denied",
      });
```

---

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. 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: the same withUnverifiedObservations helper now threads the plan's observations through the revalidation-failure and signal-error returns, and it additionally merges them into successful revalidation — a superset of this PR. The issue's three fixture cases are covered. Nothing here 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 finding that cleanup failures could discard the sweep’s withheld-process observations depending on which branch returned. The cleanup owner now preserves those observations across its failure outcomes (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): retain withheld-process observations after cleanup errors

3 participants