Skip to content

feat: add MemoryFileSystem module - #6573

Draft
lloydrichards wants to merge 48 commits into
Effect-TS:v4/next-minorfrom
lloydrichards:feat/memory-file-system
Draft

lloydrichards wants to merge 48 commits into
Effect-TS:v4/next-minorfrom
lloydrichards:feat/memory-file-system

Conversation

@lloydrichards

@lloydrichards lloydrichards commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Type

  • Feature

Description

Adds an in-memory layer for FileSystem, useful for testing filesystem-dependent code without creating and cleaning up host directories, and for dry-run or preview flows. The motivating use case is stack-effect#108.

This builds on the VirtualFileSystem in #9960 and ports the MemoryFileSystem adapter behavior from effect-vfs. VFS owns filesystem state, path resolution, links, metadata, and resource lifetimes. The adapter implements the FileSystem contract, while FileSystem.make supplies derived helpers such as globbing.

WIP

Depends on #9960. This branch includes the VFS commits and will be rebased once that PR lands, before making this ready for review.

MemoryFileSystem.layer provides an isolated volume with an empty /tmp directory. MemoryFileSystem.make is a scoped constructor. Open files and watches have their own acquisition scopes, and the filesystem inherits VFS's finite limits.

Review guide

The watcher commits come first, followed by the MemoryFileSystem adapter and its tests. Watching lives in VFS so other adapters can reuse it. The main review areas are caller lifetime, subscription cleanup, rename event ordering, and overflow recovery through MemoryFileSystem.isWatchOverflow.

The adapter tests cover the shared FileSystem and glob contracts, file cursors, copy cleanup, hard-link preservation, and scoped temporary files.

Full repository type checking currently reports unrelated dependency and type-resolution errors outside this change.

Related


This is part 2 of 2 in a stack made with GitButler:

@changeset-bot

changeset-bot Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c911454

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

This PR includes changesets to release 35 packages
Name Type
effect Minor
@effect/opentelemetry Minor
@effect/vitest Minor
@effect/ai-amazon-bedrock Minor
@effect/ai-anthropic Minor
@effect/ai-cloudflare Minor
@effect/ai-openai-compat Minor
@effect/ai-openai Minor
@effect/ai-openrouter Minor
@effect/ai-typesafe Minor
@effect/atom-react Minor
@effect/atom-solid Minor
@effect/atom-vue Minor
@effect/platform-browser Minor
@effect/platform-bun Minor
@effect/platform-cloudflare Minor
@effect/platform-deno Minor
@effect/platform-node-shared Minor
@effect/platform-node Minor
@effect/sql-clickhouse Minor
@effect/sql-d1 Minor
@effect/sql-libsql Minor
@effect/sql-mssql Minor
@effect/sql-mysql2 Minor
@effect/sql-pg Minor
@effect/sql-pglite Minor
@effect/sql-sqlite-bun Minor
@effect/sql-sqlite-do Minor
@effect/sql-sqlite-node Minor
@effect/sql-sqlite-react-native Minor
@effect/sql-sqlite-wasm Minor
@effect/docgen Minor
@effect/doctest Minor
@effect/graphql-generator Minor
@effect/openapi-generator Minor

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

@github-actions github-actions Bot added the 4.0 label Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2af3b872-1c9d-4d5f-8c06-e12c6c372df2

📥 Commits

Reviewing files that changed from the base of the PR and between a52dfd4 and cda9755.

📒 Files selected for processing (4)
  • .changeset/puny-queens-spend.md
  • packages/effect/src/MemoryFileSystem.ts
  • packages/effect/src/internal/memoryFileSystem.ts
  • packages/effect/test/MemoryFileSystem.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/effect/src/MemoryFileSystem.ts
  • .changeset/puny-queens-spend.md
  • packages/effect/test/MemoryFileSystem.test.ts
  • packages/effect/src/internal/memoryFileSystem.ts

📝 Walkthrough

Walkthrough

Adds an isolated in-memory FileSystem implementation with POSIX-style operations, descriptors, globbing, temporary resources, watch streams, public constructors, and comprehensive behavior tests.

Changes

MemoryFileSystem

Layer / File(s) Summary
Volume model and state transitions
packages/effect/src/internal/memoryFileSystem.ts
Defines inode variants, descriptors, path resolution, linking, reclamation, watch state, and semaphore-guarded volume commits.
Filesystem operations and descriptors
packages/effect/src/internal/memoryFileSystem.ts
Implements directory and file mutations, copying, descriptor operations, metadata APIs, and scoped temporary resources.
Globbing, watching, and service wiring
packages/effect/src/internal/memoryFileSystem.ts, packages/effect/src/MemoryFileSystem.ts, .changeset/puny-queens-spend.md
Adds glob matching, watch subscriptions, public make and layer exports, and a minor release changeset.
Filesystem behavior validation
packages/effect/test/MemoryFileSystem.test.ts
Tests path semantics, isolation, concurrency, metadata, globbing, and ordered watch events including hard-link aliases.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant FileSystem
  participant Volume
  participant WatchStream
  FileSystem->>Volume: mutate filesystem state
  Volume->>Volume: commit normalized transition
  Volume->>WatchStream: publish filesystem event
  WatchStream-->>FileSystem: emit watched path event
Loading

Suggested labels: enhancement

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
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.

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

@coderabbitai coderabbitai Bot added the enhancement New feature or request label Jul 24, 2026

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

Actionable comments posted: 1

🤖 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 `@packages/effect/src/internal/memoryFileSystem.ts`:
- Around line 769-810: Update the recursive makeDirectory creation flow to
accumulate every newly created path instead of overwriting createdPath on each
iteration. Emit a Create event for each created directory in creation order,
including intermediate paths such as /a and /a/b, while preserving the existing
empty-event behavior when no directory is created.
🪄 Autofix (Beta)

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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 054f14df-a2f1-4ce3-8637-2eefbe37f869

📥 Commits

Reviewing files that changed from the base of the PR and between 5101e92 and a52dfd4.

📒 Files selected for processing (4)
  • .changeset/puny-queens-spend.md
  • packages/effect/src/MemoryFileSystem.ts
  • packages/effect/src/internal/memoryFileSystem.ts
  • packages/effect/test/MemoryFileSystem.test.ts

@lloydrichards
lloydrichards force-pushed the feat/memory-file-system branch from a52dfd4 to cda9755 Compare July 24, 2026 12:54
@github-actions

github-actions Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 40.19 KB 40.19 KB 0.00 KB (0.00%)
basic.ts 7.35 KB 7.35 KB 0.00 KB (0.00%)
batching.ts 11.30 KB 11.30 KB 0.00 KB (0.00%)
brand.ts 7.00 KB 7.00 KB 0.00 KB (0.00%)
cache.ts 11.83 KB 11.83 KB 0.00 KB (0.00%)
config.ts 23.19 KB 23.19 KB 0.00 KB (0.00%)
differ.ts 22.30 KB 22.30 KB 0.00 KB (0.00%)
http-client.ts 27.70 KB 27.70 KB 0.00 KB (0.00%)
http-router.ts 37.72 KB 37.70 KB +0.02 KB (+0.05%)
logger.ts 12.28 KB 12.28 KB 0.00 KB (0.00%)
metric.ts 9.74 KB 9.74 KB 0.00 KB (0.00%)
optic.ts 7.21 KB 7.21 KB 0.00 KB (0.00%)
pubsub.ts 16.34 KB 16.34 KB 0.00 KB (0.00%)
queue.ts 13.20 KB 13.20 KB 0.00 KB (0.00%)
schedule.ts 12.08 KB 12.08 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.33 KB 14.33 KB -0.00 KB (-0.01%)
schema-binary.ts 42.58 KB 42.58 KB +0.00 KB (+0.01%)
schema-class.ts 22.06 KB 22.06 KB 0.00 KB (0.00%)
schema-codegen.ts 30.80 KB 30.80 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 30.67 KB 30.67 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 28.36 KB 28.36 KB +0.00 KB (+0.01%)
schema-string-transformation.ts 15.64 KB 15.64 KB 0.00 KB (0.00%)
schema-string.ts 12.53 KB 12.53 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.51 KB 16.51 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 39.75 KB 39.75 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 21.21 KB 21.21 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 21.38 KB 21.38 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.47 KB 21.47 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.51 KB 26.51 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.55 KB 21.55 KB 0.00 KB (0.00%)
schema.ts 21.14 KB 21.14 KB 0.00 KB (0.00%)
stm.ts 14.56 KB 14.56 KB 0.00 KB (0.00%)
stream.ts 10.66 KB 10.66 KB 0.00 KB (0.00%)
supervisor.ts 11.61 KB 11.61 KB 0.00 KB (0.00%)

@lloydrichards

Copy link
Copy Markdown
Contributor Author

Used the changes to the test suite (#6555) to align the behavior of File.seek and the missig watch target with Node and Deno impl

@lloydrichards

Copy link
Copy Markdown
Contributor Author

Not necessarily useful for the review, but could be interesting in context: I've written an article on the process I used to build out this PR

Human in the loop: Building a filesystem with LLMs

@spencerbeggs

Copy link
Copy Markdown
Contributor

@lloydrichards I borrowed the code from this PR, built it out as a temporary package in my effect utilities monorepo. I have started using it in tests in a couple projects: tsdoctor, vitest-agent and savvy-web.

These are just my initial attempts at using it to clean up my tests. There are some quirks with integrating with actual file IO, mainly I often use async file handling and there are some visibility problems but, overall, it let me stop writing a bunch of verbose and brittle fixtures for parts of my programs and sped up test runs a lot.

I tailored the implementation to my specific needs, but having a base construct for this in the core would be helpful, imo.

Thanks for building this out.

@lloydrichards

lloydrichards commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor Author

@lloydrichards I borrowed the code from this PR, built it out as a temporary package in my effect utilities monorepo.

Glad to hear its been useful 😄 If you have any feedback or suggestions, especially around the issues you had with async, do let me know. I was working mostly off the test suite in #6555 which still had some open questions on the direction so it would be good if your use case covers some of this ambiguity.

@fubhy I'm gonna give you a gentle nudge as well to see if there is anything I can do to help with getting this reviewed. Like I mentioned there are some open questions in the #6555 with the test suite, but this might be more down to reinforcing behavioral conformance between the different FileSystem implementations across Node and Deno

@lloydrichards

Copy link
Copy Markdown
Contributor Author

I'm going to be pausing development on this PR for the time being in favour of building a community package so I can explore a few side-quests:

https://github.com/lloydrichards/effect-virtual-fs

This is a bit of a step in complexity from the FileSystem implementation but unlocks some really interesting possibilities for integrations, permissions and virtual builds. I'll make this PR as draft for now and if anyone want to help contribute or has wishes for what is possible they are welcome to submit issues or PRs

This does mean though that you can use this right away with:

npm install @effect-vfs/memory
import { MemoryFileSystem } from "@effect-vfs/memory"
import { Effect, FileSystem } from "effect"

const program = Effect.gen(function*() {
  const fs = yield* FileSystem.FileSystem
  yield* fs.writeFileString("/settings.json", JSON.stringify({ mode: "preview" }))
  return yield* fs.readFileString("/settings.json")
})

const settings = await Effect.runPromise(
  program.pipe(Effect.provide(MemoryFileSystem.layer))
)

console.log(settings)

@spencerbeggs Still looking for feedback so if you feel like trying this out instead of your package, let me know whats still missing

@effect-bot
effect-bot force-pushed the v4/next-minor branch 30 times, most recently from 3fb0cd3 to 36519eb Compare November 23, 2026 23:19

This branch is waiting to be deployed

1 waiting (outdated) deployment
fork — 922dfc48 Waiting Nov 17, 2026 by lloydrichards via approval-gate #26472
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request v4/next-minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.