Skip to content

feat(shared): add Effect-idiomatic file lock (EffectFlock)#22681

Merged
kitlangton merged 1 commit intodevfrom
feat/effect-flock
Apr 16, 2026
Merged

feat(shared): add Effect-idiomatic file lock (EffectFlock)#22681
kitlangton merged 1 commit intodevfrom
feat/effect-flock

Conversation

@kitlangton
Copy link
Copy Markdown
Contributor

Summary

  • Parallel reimplementation of Flock using Effect idioms as EffectFlock
  • Service/Layer architecture: reads lock root from Global.Service, FS ops via AppFileSystem — no mutable globals, no setGlobal()
  • Automatic tracing spans via Effect.fn for motel observability
  • Scoped heartbeat fiber, declarative retry schedule, typed errors, Schema-validated metadata, dual withLock

Perf comparison

~89% overhead (1.05ms vs 0.55ms per cycle) — dominated by Effect fiber scheduling and span creation. Negligible in real usage since flock guards npm installs, plugin config writes, etc.

Files

  • packages/shared/src/util/effect-flock.ts — implementation
  • packages/shared/test/util/effect-flock.test.ts — 11 tests (perf + correctness)

Does not touch or replace the original Flock — this is a parallel implementation for evaluation.

Parallel reimplementation of the existing Flock using Effect idioms:

- Service/Layer architecture: reads lock root from Global.Service,
  filesystem ops via AppFileSystem (no mutable globals)
- Automatic spans via Effect.fn for motel observability
- Scoped heartbeat fiber (Effect.forkScoped + Schedule.spaced)
  replaces manual setInterval/clearInterval
- Effect.retry + Schedule.exponential with jitter replaces
  the manual while-loop backoff
- Typed errors: LockTimeoutError, LockCompromisedError, ReleaseError
- Schema-validated lock metadata on read (Schema.fromJsonString)
- Cached ensureDir per service instance (avoids mkdir syscall on
  every acquire)
- Dual withLock for pipeable usage

Includes 11 tests (perf comparison + correctness) using it.live.
@kitlangton kitlangton marked this pull request as ready for review April 16, 2026 00:50
@kitlangton kitlangton enabled auto-merge (squash) April 16, 2026 00:50
@kitlangton kitlangton merged commit a147ad6 into dev Apr 16, 2026
10 checks passed
@kitlangton kitlangton deleted the feat/effect-flock branch April 16, 2026 00:55
jerome-benoit pushed a commit to jerome-benoit/opencode that referenced this pull request Apr 16, 2026
xywsxp pushed a commit to xywsxp/opencode that referenced this pull request Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant