Skip to content

fix(server): replace Layer.effectServices with Layer.scopedContext in NodeSqliteClient#9

Merged
Josh-wt merged 1 commit intomainfrom
claude/setup-server-dev-V0Pu8
Apr 12, 2026
Merged

fix(server): replace Layer.effectServices with Layer.scopedContext in NodeSqliteClient#9
Josh-wt merged 1 commit intomainfrom
claude/setup-server-dev-V0Pu8

Conversation

@Josh-wt
Copy link
Copy Markdown
Owner

@Josh-wt Josh-wt commented Apr 12, 2026

Root cause

Layer.effectServices does not exist in Effect 4.0.0-beta.43. Calling it at layer build time throws TypeError: undefined is not a function, which Effect catches as a defect and silently fails the sqlite client layer. With no SqlClient.SqlClient registered in context, the setup layer's yield* SqlClient.SqlClient throws the misleading "Service not found: effect/sql/SqlClient" error.

Fix

Replace all three Layer.effectServices(...) calls in NodeSqliteClient.ts with Layer.scopedContext(...) + Context.make(Client.SqlClient, client).

This matches the pattern used by the @effect/sql-sqlite-bun reference implementation:

  • Layer.scopedContext is the correct API for scoped resources (the sqlite connection registers a Scope finalizer to close the DB)
  • Context.make / Context.add register services in the Effect context that downstream layers can find

Test plan

  • cd apps/server && bun run dev starts without the "Service not found: effect/sql/SqlClient" error
  • Server connects and sessions can be created

https://claude.ai/code/session_01BpwxjJ9XzBeAXjRp86E9Jr


Summary by cubic

Fix server startup by replacing Layer.effectServices with Layer.scopedContext in NodeSqliteClient. This registers Client.SqlClient correctly and removes the "Service not found: effect/sql/SqlClient" error.

  • Bug Fixes
    • Use Layer.scopedContext for the sqlite scoped resource and Context.make(Client.SqlClient, client) to register the service.
    • Aligns with @effect/sql-sqlite-bun; avoids the runtime TypeError from missing Layer.effectServices in effect@4.0.0-beta.43.

Written for commit 83c09e0. Summary will update on new commits.

Summary by CodeRabbit

  • Refactor
    • Improved internal database client service layer construction for better code maintainability and clarity. No user-facing changes or behavioral impact.

… NodeSqliteClient

Layer.effectServices does not exist in Effect 4.0.0-beta.43. Calling it
throws TypeError at layer build time, which Effect catches as a defect,
silently failing the sqlite client layer. This left setup's
yield* SqlClient.SqlClient with no service in context, producing the
misleading "Service not found: effect/sql/SqlClient" error.

The correct API (confirmed from @effect/sql-sqlite-bun reference impl) is:
- Layer.scopedContext for scoped resources (sqlite conn needs Scope cleanup)
- Context.make(Client.SqlClient, client) instead of ServiceMap.make/add

https://claude.ai/code/session_01BpwxjJ9XzBeAXjRp86E9Jr
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2f99ddb0-0173-46b5-b7ab-d14ce2ddb35f

📥 Commits

Reviewing files that changed from the base of the PR and between 2f4d880 and 83c09e0.

📒 Files selected for processing (1)
  • apps/server/src/persistence/NodeSqliteClient.ts

📝 Walkthrough

Walkthrough

The PR refactors the SQL client service layer construction in NodeSqliteClient.ts. It replaces Layer.effectServices combined with ServiceMap operations with Layer.scopedContext and Context.make for providing the Client.SqlClient service. The external API and functionality remain unchanged; only the internal layer construction method is updated.

Changes

Cohort / File(s) Summary
SQL Client Layer Refactoring
apps/server/src/persistence/NodeSqliteClient.ts
Refactored layerConfig, layer, and layerMemory exports to use Layer.scopedContext with Context.make instead of Layer.effectServices with ServiceMap operations for providing Client.SqlClient service.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

codex

Poem

🐰 A context now scoped, no maps left behind,
The layers refactored, more elegant in mind,
Where ServiceMaps danced, now Context will sing,
The SqlClient flows through a simpler thing!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and specifically describes the main change: replacing Layer.effectServices with Layer.scopedContext in NodeSqliteClient.
Description check ✅ Passed The description thoroughly explains the root cause, the fix applied, and includes a test plan. It matches the template's required sections ('What Changed', 'Why') with comprehensive detail.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 claude/setup-server-dev-V0Pu8

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 and usage tips.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@Josh-wt Josh-wt merged commit 7eae27a into main Apr 12, 2026
2 checks passed
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.

2 participants