Skip to content

fix(fs): detect an unwritable directory from the write, not from mkdir - #510

Merged
HugoRCD merged 2 commits into
mainfrom
fix/fs-drain-probe-the-write
Aug 7, 2026
Merged

fix(fs): detect an unwritable directory from the write, not from mkdir#510
HugoRCD merged 2 commits into
mainfrom
fix/fs-drain-probe-the-write

Conversation

@HugoRCD

@HugoRCD HugoRCD commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Follow-up to #509, which shipped a check that does not hold. CodeRabbit caught both problems after the merge and it was right on both.

mkdir does not prove write access. With { recursive: true } it is a no-op on a directory that already exists, so it succeeds on a read-only one. Verified directly:

$ chmod 500 logs
mkdir({recursive:true})  -> OK
appendFile               -> EACCES

A deployment whose log directory is baked into the image therefore passed the probe and kept throwing on every batch, which is the exact failure #509 set out to remove.

The probe was not concurrency-safe. It cached only after awaiting, so simultaneous batches each ran it and each warned.

Both go away by making the write the check. The first append that fails with EROFS, EACCES or EPERM marks the directory and warns once; resolve returns null from then on. markUnwritable is synchronous, so its check-then-add cannot interleave no matter how many batches arrive together. Anything else still surfaces through the drain's own error path.

Also applies the two wording fixes from that review: "an HTTP adapter", and "disables itself in the Edge runtime" in the changeset.

Testing

packages/evlog/test/adapters/fs.test.ts — 25 passing, three new cases: a directory that exists but rejects the write, three concurrent batches warning once, and ENOSPC still reported rather than silenced. Full package suite 1788 passing, pnpm api:snapshot unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • Improved filesystem drain handling for read-only or inaccessible directories.
    • Drains now disable after the first permission-related write failure and issue only one warning per directory.
    • Other write failures continue to be reported normally.
    • Improved behavior for concurrent failed writes and existing read-only directories.

@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0ac99e6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
evlog Patch
@evlog/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
evlog-telemetry Ready Ready Preview Aug 7, 2026 8:34pm
4 Skipped Deployments
Project Deployment Actions Updated (UTC)
evi Ignored Ignored Preview Aug 7, 2026 8:34pm
evlog-docs Ignored Ignored Preview Aug 7, 2026 8:34pm
evlog-render-lab Ignored Ignored Preview Aug 7, 2026 8:34pm
just-use-evlog Ignored Ignored Preview Aug 7, 2026 8:34pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@HugoRCD, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 97af9355-30cf-4ae8-83d9-3a8ce8994b5e

📥 Commits

Reviewing files that changed from the base of the PR and between 377effd and 0ac99e6.

📒 Files selected for processing (4)
  • .changeset/fs-drain-probe-the-write.md
  • .changeset/fs-drain-readonly-directory.md
  • packages/evlog/src/adapters/fs.ts
  • packages/evlog/test/adapters/fs.test.ts
📝 Walkthrough

Walkthrough

The filesystem drain now detects unwritable directories during append operations. It caches permission-related failures, warns once per directory, skips future writes, and continues reporting other failures.

Changes

Filesystem drain behavior

Layer / File(s) Summary
Write-time unwritable directory handling
packages/evlog/src/adapters/fs.ts
The adapter replaces directory probes with append-time detection. It caches unwritable directories, warns once, skips cached directories, and suppresses only read-only or permission errors.
Behavior validation and changesets
packages/evlog/test/adapters/fs.test.ts, .changeset/*
Tests cover read-only, permission, concurrent, and non-permission append failures. Changesets document the updated detection and disabling behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • HugoRCD/evlog#509: Revises the same filesystem drain writability logic, tests, and changeset.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the conventional fix(fs) format and clearly states that writability is detected from the write instead of mkdir.
Description check ✅ Passed The description explains the bug, concurrency fix, error handling, wording updates, and test results, but omits the template checklist.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/fs-drain-probe-the-write

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@pkg-pr-new

pkg-pr-new Bot commented Aug 7, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@evlog/cli@510
npm i https://pkg.pr.new/evlog@510
npm i https://pkg.pr.new/@evlog/nuxthub@510
npm i https://pkg.pr.new/@evlog/telemetry@510

commit: 0ac99e6

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/fs-drain-probe-the-write.md:
- Line 7: Update the release-note wording to replace “baked in” with an explicit
statement that the log directory already existed, while preserving the
surrounding explanation of the probe and warning behavior.

In @.changeset/fs-drain-readonly-directory.md:
- Line 14: Update the changeset wording to avoid promising that only one append
is attempted: state that concurrent batches may each call appendFile until the
drain observes a matching EROFS, EACCES, or EPERM error, after which it disables
itself and warns once.

In `@packages/evlog/src/adapters/fs.ts`:
- Around line 178-196: Update the JSDoc for createFsDrain with a short `@remarks`
sentence stating that EROFS, EACCES, and EPERM errors mark the configured
directory unavailable and disable the filesystem drain for the current process.

In `@packages/evlog/test/adapters/fs.test.ts`:
- Around line 404-414: Rename the test case around createFsDrainFresh to state
that a non-permission write failure is logged rather than propagated, matching
the await drain(createDrainContext()) behavior and console.error assertion.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3ac37b29-ba69-458a-854a-aefebf945cac

📥 Commits

Reviewing files that changed from the base of the PR and between 2dfde11 and 377effd.

📒 Files selected for processing (4)
  • .changeset/fs-drain-probe-the-write.md
  • .changeset/fs-drain-readonly-directory.md
  • packages/evlog/src/adapters/fs.ts
  • packages/evlog/test/adapters/fs.test.ts

Comment thread .changeset/fs-drain-probe-the-write.md Outdated
Comment thread .changeset/fs-drain-readonly-directory.md Outdated
Comment thread packages/evlog/src/adapters/fs.ts
Comment thread packages/evlog/test/adapters/fs.test.ts Outdated
@HugoRCD HugoRCD self-assigned this Aug 7, 2026
@HugoRCD
HugoRCD merged commit 68b05fa into main Aug 7, 2026
18 checks passed
@HugoRCD
HugoRCD deleted the fix/fs-drain-probe-the-write branch August 7, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant