On Postgres, setting the current tenant and fetching its rows can take more time going back and forth than running the queries. In the upcoming Effect 4.2 release, the PostgreSQL driver lets you send both statements in one round trip. When the wait is inside your program instead, a supervisor can tell you what a blocked fiber is waiting for.
Effect UI
Effect UI is a frontend library for Effect.
Its core APIs live under effect/ui, with a browser host under effect/ui/html
and a terminal host in @effect/ui-opentui. The API is unstable and may change
in minor releases.
Each component has its own model, messages, and pure update function. The runtime runs side effects described by commands and subscriptions. The same component logic can power a browser view or a terminal interface, with a separate view for each host. Try the interactive walkthrough.
SQL batching
On PostgreSQL, setting transaction-local context and then querying with it
normally means four round trips: begin, set, query, commit. With
SqlClient.batch, you can do all four in one. For example, if your row-level
security policy reads the current organization from a setting:
import { Effect } from "effect"import { SqlClient } from "effect/sql"
const itemsFor = (org: string) => Effect.gen(function* () { const sql = yield* SqlClient.SqlClient const [, items] = yield* sql.batch([ sql`SELECT set_config('app.organization_id', ${org}, true)`, sql`SELECT * FROM item`, ]) return items })The statements run in order on the same connection. The result is a typed
tuple, so items has the row type of the second statement. PostgreSQL and
libSQL execute the batch atomically in one round trip. Drivers without native
batching execute one statement at a time; use withTransaction if those
statements need to succeed or fail together.
See what a fiber is waiting for
The experimental Supervisor module lets you observe when a fiber starts,
blocks, unblocks and ends, and what a blocked fiber is waiting on. Install a
supervisor around one effect with Effect.withSupervisor, or add one to a
runtime with Supervisor.layer. If you build your own synchronization
primitive on Effect.callback, its new blockedOn option tells the
supervisor what the fiber is waiting on.
Two smaller additions help distinguish waiting from working.
Semaphore.withPermitsTraced creates a span for the time spent waiting to
acquire permits, not for the work that holds them. And Pool.stats and
PgClient.poolStats now report acquiring separately from waiting
borrowers, so you can see how many acquisitions are already in flight.
Reusable path filters
In 4.1, FileSystem.glob took a glob pattern and a separate set of options.
In 4.2, it takes a single PathFilter.Input: a pattern, a list of patterns
and rules, or a PathFilter. The new unstable PathFilter module lets you
write ordered rules and test them without walking the file system. For
example, you can ignore build output but keep a published declaration file:
import { PathFilter } from "effect"
const filter = PathFilter.make([ PathFilter.exclude("dist", { subtree: "inherit" }), PathFilter.include("dist/index.d.ts"),])
PathFilter.excludes(filter, "dist/index.js") // => truePathFilter.excludes(filter, "dist/index.d.ts") // => falseLater rules take precedence. If the project already defines its exclusions,
the experimental IgnoreFile parsers can build filters from .gitignore and
.dockerignore sources.
Reading and writing YAML
Yaml.parse from effect/encoding returns a Result instead of throwing.
Handle an EncodingError on failure, or use the parsed value on success. For
files containing multiple documents separated by ---, use Yaml.parseAll;
anchors are scoped to each document. Going the other direction,
Yaml.stringify and Yaml.stringifyAll write block-style YAML.
Parsing now resolves plain scalars and keys using YAML 1.2 core rules. Quote
text such as "true" if you need a string rather than a boolean. Unsupported
tags and ambiguous collection syntax now fail instead of silently becoming
text.
More highlights
- Pattern matching:
Match.whenFilterruns a filter once and passes the extracted value to the handler, or falls through with the original input if the filter fails.Filter.maptransforms passing values without changing failures. - HTTP: A sub-app built with
HttpRouter.toHttpEffectgets its own router, so its routes and middleware no longer register on the outer server. Cookies with the same name but different domains or paths now coexist instead of overwriting one another. - AI and MCP: A tool can declare
failure: McpSchema.InputRequiredto request input from the client rather than report a tool error, and handlers can set the model-facing output viaToolkit.HandlerContext.modelOutput. Anthropic batch result endpoints now return the JSON Lines response as bytes, with streaming variants for large batches. - Processes and stdio: Child processes accept numeric file descriptors,
and
ChildProcessHandle.exitStatusdistinguishes an exit code from a terminating signal. RPC and MCP stdio servers can opt intoonStdinEnd: "interrupt"to stop active requests when the client closes stdin. - PostgreSQL: Supply a
connectRetryScheduletoPgClientorPgPoolto retry a failed connection checkout before any statement is sent. - Configuration:
Toml.parsesupports TOML 1.1 syntax, including multiline inline tables and times without seconds, so13:37parses as"13:37:00".String.hasNonWhitespacetests for a nonblank string.
Upgrade notes
This release includes breaking changes. Expand the notes for the APIs you use before upgrading.
OpenTelemetry
@effect/opentelemetrynow targets JS SDK 3.x (stay on 4.1.x for SDK 2.x), with peers@opentelemetry/api1.10 or later and 3.x ofresources,sdk-logs,sdk-metricsandsdk-trace, which replacessdk-trace-base,sdk-trace-nodeandsdk-trace-web.@opentelemetry/api-logsis no longer a peer; see the SDK migration notes for details.- Import span processors, exporters and samplers from
@opentelemetry/sdk-trace, andSeverityNumberfrom@opentelemetry/api. Pass the exporter asnew BatchSpanProcessor({ exporter }). - In both
NodeSdkandWebSdk,tracerConfigtakesTracerProviderOptionsfrom@opentelemetry/sdk-traceinstead ofTracerConfig, andloggerProviderConfigtakesLoggerProviderOptionsfrom@opentelemetry/sdk-logsinstead ofLoggerProviderConfig.OtelLogger.layerLoggerProvidertakesLoggerProviderOptionstoo. BatchSpanProcessorno longer readsOTEL_BSP_*, so pass those settings as options.NodeSdkno longer readsOTEL_TRACES_SAMPLER,OTEL_TRACES_SAMPLER_ARGor theOTEL_SPAN_*/OTEL_ATTRIBUTE_*span limits, so settracerConfig.samplerandtracerConfig.spanLimitsin code instead. The built-inOtlpTracer.layerFromConfig, by contrast, now reads both sampler variables.- Metric descriptors from
OtelMetricsno longer include thetypeandadvicefields.
HTTP and cookies
Cookies.cookiesand theSchema.Cookiesencoding are now arrays, socookies.cookies[name],in,Object.hasOwn,Object.keysandObject.entriesno longer go by cookie name. UseCookies.getorCookies.getValueto read or test for a cookie, andCookies.toRecordfor names and values.- To replace or expire a cookie, pass its original
domainandpath. HttpRouter.servealways builds its own router instead of reusing anHttpRouter.layerbuilt outside it, so itsrouterConfigoption always applies.HttpClient.withRateLimiternow infers bothRateLimiterErrorandHttpClientErrorunless you passfailsWith. PassfailsWith: "RateLimiterError"to keep the previous error type, or"HttpClientError"to receive HTTP transport errors instead.
File systems and YAML
FileSystem.globtakes a singlePathFilter.Inputinstead of a pattern and options. Itsexcludeanddotoptions are gone: replacefs.glob("src/**/*.ts", { exclude: ["**/*.test.ts"] })withfs.glob(["src/**/*.ts", "!**/*.test.ts"]), or passPathFilterrules, which take adotoption.Yaml.parsereturns aResultand fails with anEncodingErrorinstead of throwing. Input with more than one document still fails; useYaml.parseAll.Yaml.parseandYaml.parseAlluse YAML 1.2 core scalar, tag and key resolution. Quote values and keys to keep them as literal text.- Input the parser used to accept now fails: unsupported tags and key
properties, invalid or ambiguous collection syntax, any directive other
than
%YAML 1.2, a directive without a following---, plain scalars starting with%, and nesting or merge expansion beyond the new limits. Non-YAML whitespace is preserved.
AI, MCP, RPC and Solid
- The
McpSchema.InputRequiredconstructor validates its fields and throws when they are invalid. Declarefailure: McpSchema.InputRequiredrather thanSchema.instanceOf(McpSchema.InputRequired), which has no JSON codec. messageBatchesResultsandbetaMessageBatchesResultsin@effect/ai-anthropicreturn the raw JSON Lines bytes. Decode each line withMessageBatchIndividualResponseorBetaMessageBatchIndividualResponse.RpcServer.layerProtocolStdioandRpcServer.makeProtocolStdioare now functions. CallRpcServer.layerProtocolStdio()andRpcServer.makeProtocolStdio().@effect/atom-solidrequires Solid 2: replaceuseAtomResourcewithuseAtomValueand match on theAsyncResult. Use<RegistryContext value={registry}>or<RegistryProvider>instead ofRegistryContext.Provider.
Custom implementations and test doubles
- Custom
ChildProcessSpawner.makeHandleimplementations must provideexitStatus. - Manually constructed
Pool.Statssnapshots must includeacquiring(use0when no acquisition is running). - Manually constructed
Toolkit.HandlerContextvalues must includemodelOutput, for example() => Effect.void.
For all additions and fixes, see the 4.2 release queue.
Join our Discord Community to follow the latest updates and discuss the release!