Skip to content

Confirm session scratch removal before completing shutdown - #858

Open
morluto wants to merge 1 commit into
mainfrom
codex/verify-runtime-scratch-removal
Open

morluto wants to merge 1 commit into
mainfrom
codex/verify-runtime-scratch-removal

Conversation

@morluto

@morluto morluto commented Nov 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Finish the runtime's closing transition only after an explicit scratch lookup confirms removal.
  • Replace the fixed cleanup failure example with generated retries after a real directory-removal fault and temporary status outages. The closing runtime continues to reject work throughout the retries.

Verification

  • The previous runtime reported successful shutdown on a retry while the scratch directory still existed.
  • 225 focused tests passed, with one Linux-only skip on macOS. The new shutdown property also passed on Python 3.14. Ruff, strict mypy, and the five Z3 verdicts passed.
  • Installed CLI and MCP shutdown paths detected the failed scratch lookup and completed after recovery.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T23:22:41.349809Z 4a28413 PR opened
ℹ️ 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 Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5 · The PR appears safe to merge, with a non-blocking gap in testing failed final scratch lookups.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects shutdown behavior for runtimes used by Python, CLI, and MCP callers.

The PR appears safe to merge, with a non-blocking gap in testing failed final scratch lookups.

FindingsFix All in CodexFindings

  1. P2 Unreadable lookup lacks a test ▶
Fix with agent prompt
### Issue 1
tests/test_runtime_requests.py:65-69
The generated outages replace `os.stat`, but the new final check calls `os.lstat`. These retries test scratch still being present, not the final lookup failing. A regression that treats an unreadable lookup as successful shutdown could pass.

Add a case where `os.lstat` raises `PermissionError` or another `OSError`, then recovers. Check that requests stay refused and a later `close()` succeeds.

---

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

Summary

AnalysisRuntime.close() now marks the session closed only after os.lstat confirms that scratch is absent.

  • Runtime shutdown waits for confirmed removal of session scratch.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Close requested] --> B{Work active?}
  B -->|Yes| C[Refuse close]
  B -->|No| D[Enter closing and expire handles]
  D --> E[Clean scratch]
  E --> F{Final scratch lookup}
  F -->|Absent| G[Mark closed]
  F -->|Present or unreadable| H[Raise error and remain closing]
  H -->|Retry| E
Loading

Reviews (1) · Last reviewed commit: "Confirm session scratch removal before c..." · Reviewed by Greptile

Comment on lines +65 to +69
with pytest.MonkeyPatch.context() as patch:
patch.setattr(os, "stat", unavailable)
for _ in range(retry_outages):
with pytest.raises(OSError):
runtime.close()

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 Unreadable lookup lacks a test

The generated outages replace os.stat, but the new final check calls os.lstat. These retries test scratch still being present, not the final lookup failing. A regression that treats an unreadable lookup as successful shutdown could pass.

Add a case where os.lstat raises PermissionError or another OSError, then recovers. Check that requests stay refused and a later close() succeeds.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/test_runtime_requests.py
Line: 65-69

Comment:
**Unreadable lookup lacks a test**

The generated outages replace `os.stat`, but the new final check calls `os.lstat`. These retries test scratch still being present, not the final lookup failing. A regression that treats an unreadable lookup as successful shutdown could pass.

Add a case where `os.lstat` raises `PermissionError` or another `OSError`, then recovers. Check that requests stay refused and a later `close()` succeeds.

---

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

Fix in Codex

This branch has not been deployed

No deployments
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.

1 participant