Skip to content

fix(write): report descriptor exhaustion accurately - #742

Merged
steipete merged 2 commits into
mainfrom
codex/fix-write-emfile-20260927
Sep 28, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/fix-write-emfile-20260927

Conversation

@steipete

@steipete steipete commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Native writes under descriptor pressure could preserve a stage correctly while throwing invalid-path: path is not a regular file under root. The native error had also collapsed EMFILE into EIO.

Retain EMFILE/ENFILE in the POSIX binding and report descriptor exhaustion as helper-failed / operational, including across aggregate and suppressed failures. The outer message explicitly names indeterminate publication and the preserved stage, and retains the original cause chain and cleanup receipt. Boundary failures remain primary. Publication classification, cleanup decisions, descriptor ownership, and stage contents are unchanged.

The regression fills a subprocess's descriptor table under ulimit -n 64 on Linux and macOS. On macOS, three and four spare descriptors reproduce preserved complete stages; five through eight allow publication. Before: invalid-path: path is not a regular file under root, with an inner EIO. After: helper-failed: filesystem write failed: too many open files (EMFILE); publication outcome is indeterminate; staged file preserved, with the inner EMFILE and a preserved/closed cleanup receipt.

Validation: 73 focused tests passed on macOS, including the real descriptor-limit harness, existing staging failures, and guarded write diagnostics. TypeScript/native builds and diff checks passed. Full local checks encountered unrelated watch/copy/queue timeouts under host load and were stopped; hosted full checks provide the complete-suite proof. Independent Codex review is clean through P2. Exact-head hosted CI and coverage are green for 7f7ff48ea5ac71c5d06465716bb71450e7b30779: CI, coverage. The full rollup is 41 successful checks and six conditional skips, with no pending/failing checks; the Linux and macOS native coverage lanes execute the real descriptor-limit regression. No changelog edit; leave unmerged.

@steipete
steipete requested a review from a team as a code owner September 28, 2026 02:41
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 27, 2026, 11:24 PM ET / September 28, 2026, 03:24 UTC.

ClawSweeper review

What this changes

The PR preserves POSIX descriptor-limit error codes and changes guarded writes to report them as operational failures while retaining the original causes and staged-file receipts.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep open: current main still misclassifies descriptor exhaustion, and this focused PR has credible native-path validation. It remains a useful merge candidate.

Priority: P2
Reviewed head: e3f2d64e200e31c7ecc014dd673a874afb5a09dd
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused correction has credible production-path proof and focused tests; the release note and public error-contract decision remain before merge.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The changed native errno map and Root write normalizer are exercised through root().write in a native-required descriptor-limited subprocess on macOS, with the PR reporting the improved EMFILE error, complete preserved stage, closed-resource receipt, and successful writes when more descriptors remain. The cited Linux and macOS CI runs succeeded on the earlier head, and the later merge left the reviewed paths unchanged. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed native errno map and Root write normalizer are exercised through root().write in a native-required descriptor-limited subprocess on macOS, with the PR reporting the improved EMFILE error, complete preserved stage, closed-resource receipt, and successful writes when more descriptors remain. The cited Linux and macOS CI runs succeeded on the earlier head, and the later merge left the reviewed paths unchanged. No stored-data contract changes.
Evidence reviewed 9 items Current-main behavior: Current main maps an unclassified write failure to invalid-path; the same normalization is present in the v0.21.1 source.
Introduced diagnostic: The branch searches error causes, suppressed errors, and aggregate errors for EMFILE or ENFILE, then returns helper-failed with the original cause and selected cleanup details.
Native errno source: The POSIX binding now passes through EMFILE and ENFILE instead of collapsing them to EIO.
Findings 1 actionable finding [P3] Document the public error-code change in Unreleased
Security None None.

How this fits together

The Root write API checks paths and identities before staging and publishing files. Native POSIX operations feed errors back through the write-error normalizer, which determines the public error and recovery receipt.

flowchart LR
A[Root write request] --> B[Path and identity checks]
B --> C[Native staged write]
C --> D{Native outcome}
D -->|Descriptor limit| E[Operational error and stage receipt]
D -->|Success| F[Published file]
D -->|Other failure| G[Existing error classification]
Loading

Decision needed

Question Recommendation
Should guarded writes change their public error code from invalid-path to helper-failed when EMFILE or ENFILE occurs? Adopt the corrected code: Approve helper-failed for descriptor exhaustion and document the catch-by-code change in Unreleased.

Why: Error codes are a documented compatibility surface, and the desired diagnostic necessarily changes what existing catch-by-code consumers observe.

Before merge

  • Document the public error-code change in Unreleased (P3) - This changes a public write error from invalid-path to helper-failed, while CHANGELOG.md has an empty Unreleased section. The repository policy calls for an Unreleased entry for user-visible fixes and compatibility changes; add a concise note for consumers that branch on the error code.
  • Resolve merge risk (P1) - Callers that catch invalid-path for descriptor exhaustion will now receive helper-failed and a different category. The intended public error-code change needs explicit owner acceptance before release.
  • Complete next step (P2) - Confirm the EMFILE/ENFILE error-code migration and add the Unreleased note before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P3] Document the public error-code change in Unreleased — src/root-errors.ts:62-64
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Line growth production +31, tests +120, docs +10 The runtime change is bounded and is accompanied by a native descriptor-limit harness and diagnostic coverage.

Merge-risk options

Maintainer options:

  1. Accept the corrected classification (recommended)
    Approve the targeted public code change and document how catch-by-code consumers should handle it.
  2. Preserve the old code
    Keep the existing code and category while adding a separate descriptor-limit diagnostic.

Technical review

Best possible solution:

Ship the accurate descriptor-limit classification with preserved publication receipts and a concise Unreleased migration note for code-based error handling.

Do we have a high-confidence way to reproduce the issue?

Yes. Current-main source shows the misleading fallback, and the PR describes a concrete native-required descriptor-limit run with before and after observations; this read-only review did not rerun it.

Is this the best way to solve the issue?

Yes. Passing through the native errno and correcting the shared write diagnostic is a focused repair that leaves publication and cleanup decisions in their existing owners.

Full review comments:

  • [P3] Document the public error-code change in Unreleased — src/root-errors.ts:62-64
    This changes a public write error from invalid-path to helper-failed, while CHANGELOG.md has an empty Unreleased section. The repository policy calls for an Unreleased entry for user-visible fixes and compatibility changes; add a concise note for consumers that branch on the error code.
    Confidence: 0.96

Overall correctness: patch is correct
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a883ae66a2af.

Labels

Label changes:

  • add P2: This corrects a real but conditional filesystem-write diagnostic with limited blast radius.
  • add merge-risk: 🚨 compatibility: The patch changes a documented public error code and category that existing consumers may branch on.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed native errno map and Root write normalizer are exercised through root().write in a native-required descriptor-limited subprocess on macOS, with the PR reporting the improved EMFILE error, complete preserved stage, closed-resource receipt, and successful writes when more descriptors remain. The cited Linux and macOS CI runs succeeded on the earlier head, and the later merge left the reviewed paths unchanged. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed native errno map and Root write normalizer are exercised through root().write in a native-required descriptor-limited subprocess on macOS, with the PR reporting the improved EMFILE error, complete preserved stage, closed-resource receipt, and successful writes when more descriptors remain. The cited Linux and macOS CI runs succeeded on the earlier head, and the later merge left the reviewed paths unchanged. No stored-data contract changes.

Label justifications:

  • P2: This corrects a real but conditional filesystem-write diagnostic with limited blast radius.
  • merge-risk: 🚨 compatibility: The patch changes a documented public error code and category that existing consumers may branch on.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed native errno map and Root write normalizer are exercised through root().write in a native-required descriptor-limited subprocess on macOS, with the PR reporting the improved EMFILE error, complete preserved stage, closed-resource receipt, and successful writes when more descriptors remain. The cited Linux and macOS CI runs succeeded on the earlier head, and the later merge left the reviewed paths unchanged. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed native errno map and Root write normalizer are exercised through root().write in a native-required descriptor-limited subprocess on macOS, with the PR reporting the improved EMFILE error, complete preserved stage, closed-resource receipt, and successful writes when more descriptors remain. The cited Linux and macOS CI runs succeeded on the earlier head, and the later merge left the reviewed paths unchanged. No stored-data contract changes.

Evidence

What I checked:

  • Current-main behavior: Current main maps an unclassified write failure to invalid-path; the same normalization is present in the v0.21.1 source. (src/root-errors.ts:40, a883ae66a2af)
  • Introduced diagnostic: The branch searches error causes, suppressed errors, and aggregate errors for EMFILE or ENFILE, then returns helper-failed with the original cause and selected cleanup details. (src/root-errors.ts:40, e3f2d64e200e)
  • Native errno source: The POSIX binding now passes through EMFILE and ENFILE instead of collapsing them to EIO. (native/src/unix.rs:44, e3f2d64e200e)
  • Production call path: Guarded Root writes call the shared normalizer after a staged-write failure; native rename failures remain indeterminate unless explicit pre-dispatch provenance rules out publication. (src/root-impl.ts:1142, e3f2d64e200e)
  • Real behavior evidence: The PR body reports a native-required macOS subprocess at ulimit -n 64, with a before/after error quote, preserved complete stages at three and four spare descriptors, and successful publication with more descriptors. The added harness exercises root().write through that boundary on Linux and macOS. (test/native-write-descriptor-limit.test.ts:14, e3f2d64e200e)
  • Proof revision: The cited CI and coverage runs succeeded at 7f7ff48. The later merge commit changes none of the six reviewed PR paths. (e3f2d64e200e)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add the Unreleased migration note and obtain explicit acceptance of the changed public error code.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit c7eb1a2 into main Sep 28, 2026
47 checks passed
@steipete
steipete deleted the codex/fix-write-emfile-20260927 branch September 28, 2026 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants