Skip to content

Effect v4 port #68

Closed
11 of 11 issues completed
Closed

Description

@allisonmahmood

Charted on the Effect v4 port map (2026-08-28). This issue is the migration spec: every shape decision the port implements, assembled from the map's Notes and the closed tickets, which hold the detail. The build runs from the sub-issues below, one PR and one agent session each; main stays green throughout. Mid-port decisions go back to the map as grilling tickets, not into PR threads.

What the port is

Move the server, packages and CLI from Fastify / hand-rolled pg / commander onto Effect 4 (4.0.0-rc.112, pinned through the pnpm catalog, HTTP/HttpApi/SQL/CLI from effect/unstable/*), and re-cut the monorepo into packages by capability so each can be swapped or extended on its own — above all serving, which the tier 1 and 2 runtimes will build on.

Faithful means: how readers experience served pages and how agents experience the CLI and HTTP API is preserved. Internals are free to be simpler; the port is also a clean-up. Self-hosting is over: Patchy Cloud is the only deployment, and everything that existed for an operator goes.

Target layout

Decided on Package decomposition by capability.

package owns
core shared kernel: html-policy, ids. No services.
api wire schemas (Schema.Class), the HttpApi definition, the bearer-middleware definition, the derived HttpApiClient. Imports only core + Effect.
sql @effect/sql-pg layer, Effect Migrator + ledger, embedded-Postgres test layer. Owns no tables.
auth tokens, principals, self-service mint + mint quota, revocation, bearer parsing; migrations 1–2; the tokens/mint/me API group.
content-store put/get/delete objects; filesystem (dev) and Azure blob layers. Renamed from storage — "storage" is reserved for the later per-patch file primitive.
patches records, versions, upload contract, visits, retention/expiry, the expiry sweep, pins, moderation, patch quota; migrations 3+; the patches API group.
serving serving guarantees, headers, CSP, cache-control, page routes (/, /d/*, /healthz) as HttpRouter, trusted-proxy CIDR schema. Reads content through patches, never bytes.
analytics the event service (emitters: auth, patches), PostHog layer, finalizer flush under 3 s.
limits the fixed-window limiter as an Effect service whose interface mirrors RateLimiter.consume. Quotas are not here (mint quota is auth's, patch quota patches').
cli unchanged scope; imports api + core.
apps/server wiring only: per-capability Config, the layer stack, the forked sweep, listen.

Deleted: packages/config (Effect Config per capability), packages/db (split into sql + auth + patches), packages/storage (renamed). Imports:

cli ──▶ api ──▶ core
auth ──▶ api, sql, analytics, limits
patches ──▶ api, sql, analytics, content-store
serving ──▶ patches (+ limits only if a page rate limit survives reports removal)
apps/server ──▶ all

patches never imports auth: handlers receive the principal from the bearer middleware. A capability with one consumer stays a module unless it has two implementations (content-store).

Vocabulary: execution is a runtime with tiers (tier 0 = static page); serving is serving a patch to the user; a patch is runtime-agnostic (id, owner, versions, retention clock, pin, quota). draft → patch is renamed wherever the port touches.

Shape decisions

Settled while charting (map Notes) and on the closed tickets. Each build ticket names the ones it implements.

  1. HTTP. /api/* is an HttpApi defined in packages/api; each capability implements its own group with HttpApiBuilder.group. Pages are plain HttpRouter routes owned by serving. The observable status contract of the pre-routing target classification (400/404/414) and of auth-before-body (no double rate-limit debit) is kept, implemented as one raw middleware plus one API-group middleware; Fastify's rewriteUrl/Symbol-marked request/preBody* flags are dropped. The 401 body stays { ok: false, error } — a plain Schema.Struct + HttpApiSchema.status(401), no _tag on the wire (vertical slice).
  2. SQL. @effect/sql-pg + SqlSchema; sql.withTransaction for the four manual transactions; row decoding through Schema in one module per capability so the pending native-client type change (int8→bigint, timestamps→epoch ms) lands in one place. Effect's Migrator (Migrator.make({}) from effect/unstable/sql, not PgMigrator.layer) with fromRecord composing per-package records: one global integer id sequence, duplicates fail, all pending steps in one transaction under ACCESS EXCLUSIVE, ledger schema_migrations(migration_id integer, name, created_at). prepare: false reserved for the Neon pooler (vertical slice).
  3. Postgres only. The JSON-file driver is deleted; embedded-postgres is the dev and test store. No production database exists, so the baseline migrations are rewritten by owner with patches/patch_versions naming and integer ids (auth 1–2, patches 3+); draft_reports never exists. ADR.
  4. Reports are removed (scope change on #56): PatchPage's free-service valve, nothing later builds on it, and it leaks a reader-facing surface into serving. Mint, pins, expiry and quotas stay as foundations.
  5. CLI (CLI contract on Effect cli): effect/unstable/cli; exit-code ladder by who has to act — 0 ok, 1 local, 2 rejected, 3 unreachable, 130 interrupted, nothing else; --json and --api-url are global flags; JSON failure is { ok: false, error, kind } on stderr, success one stdout document in the api wire shape; --api-url > .local/dev/env (walk up from cwd) > PATCHY_API_URL > ~/.patchy > default, resolved by one Instance service; Effect's signal mapping, terminal restore as a scope finalizer; defects are one Unexpected error: line, stack only at --log-level debug. esbuild bundle needs the createRequire banner. One ADR CLI contract for agents.
  6. Config. Effect Config per capability, Redacted secrets, fail on the first missing key. Trusted-proxy CIDRs stay a Schema in serving (HttpMiddleware.xForwardedHeaders has no allow-list). The Config PascalCase rename is a known upcoming RC break.
  7. Tests. @effect/vitest: it.layer shares one fresh, migrated embedded-Postgres database per block, it.effect per case, HttpApiTest.groups for API routes, NodeHttpServer.layerTest for what a socket sees, TestClock for the clock, Scope for anything closed by hand, faults injected by an alternate layer, never a mock. Template: packages/effect-slice/src/slice.test.ts on prototype/effect-slice (README lists the gotchas). app.test.ts splits by capability as each ports.
  8. Limiter, sweep, analytics. Limiter semantics kept (Retry-After, fails closed at 10k keys) behind an interface mirroring RateLimiter.consume, so a Redis-backed swap is a layer change. Sweep is Effect.repeat(job, Schedule.spaced("1 hour")) forked in the server scope. Analytics is a service whose finalizer flushes under 3 s; PostHog stays.
  9. Wire schemas and docs. Schemas live in packages/api; docs/API.md is rendered from OpenApi.fromApi by a small local renderer and pinned by a test.
  10. Guardrails (landed): Effect pinned via catalog + overrides, Dependabot RC PRs labelled effect-rc-bump (#57); @effect/language-service diagnostics fail typecheck, with the whole-file Node rules (nodeBuiltinImport, globalConsole, globalDate, globalRandom, globalTimers, globalFetch, cryptoRandomUUID) left at warning for each port ticket to promote for its package (#58); the two review specs are repo skills /code-review loads (#59); AGENTS.md has the ## Effect section (#61, PR docs(agents): tell agents how Effect is written here #67). Still to land: the two t3code ESLint rules written locally (namespace imports for service modules, no manual runtimes in tests, no schema compile in hot paths) — with the serving ticket.
  11. Dev runner (Local dev environment, supervisor prototype): an Effect 4 CLI under scripts/, pnpm dev; per-worktree ports from a path hash and state in .local/dev/; idempotent, daemonised start that migrates and seeds; status/stop/logs/reset; --dry-run --json prints the Plan; each service spawned with effect/unstable/process in one scope; seed = one dev company + one token written to .local/dev/env.

Rules every port PR follows

  • Service conventions: .agents/skills/effect-service-conventions/SKILL.md — one file per service (errors/schemas, Context.Service tag with the interface inline, make, layer); namespace imports at service boundaries; Schema.TaggedError with structured fields and cause; dependencies from the environment, never constructor arguments; runPromise / ManagedRuntime only at the server and CLI entrypoints and at the thin seam between a ported package and one not yet moved.
  • Seams: a ported package is consumed by unported code through a thin Effect.runPromise adapter, deleted by the PR that ports the consumer. No long-lived port branch.
  • Glossary follows the code: the PR that moves a capability moves its terms out of apps/server/CONTEXT.md into packages/<name>/CONTEXT.md and writes packages/<name>/docs/adr/ where a decision meets the ADR tests. Nothing is written ahead of code. Expected system-wide ADRs (root docs/adr/): Postgres-only, the api contract package, CLI contract for agents.
  • Lint: promote the language-service warnings to error for each package as it ports; the two Effect ESLint rules land with serving.
  • Rename what you touch: draft → patch — on the wire when packages/api is created (one wire break, not two; decided on filing), in tables and code when patches ports.
  • Read first: node_modules/effect/AGENTS.md and ai-docs/; upstream MIGRATION.md; ~/Dev/t3code for conventions.
  • Review: /code-review with the effect-service-conventions spec on every port PR; ui-consistency when rendered HTML or CSS moves.

Build order

One sub-issue each, filed ready-for-agent, blocking wired as native dependencies (the real ones, so independent tickets can run in parallel; the numbering is the recommended order).

  1. Remove reports (pre-port, plain TS)
  2. Dev runner — the first Effect 4 code and the harness every later PR is smoked on
  3. packages/api + --json on every command (Fastify decodes through Schema as the interim adapter)
  4. packages/sql — Pg layer, Migrator, test layer
  5. packages/analytics + packages/limits
  6. packages/auth
  7. packages/content-store
  8. packages/patches
  9. packages/serving + apps/server on HttpApi/HttpRouter; delete config, db; Effect lint to error
  10. packages/cli on effect/unstable/cli
  11. Redraw CONTEXT-MAP.md, remaining CONTEXT.md/ADRs, wipe self-hosting artefacts, retire ADR-0000/0001

Known unknowns (not blocking)

  • A shared rate-limiter store for multi-replica production — surfaces with deployment work.
  • Neon specifics once production points at it: transaction-mode pooler (prepare: false), scale-to-zero dropping sessions.
  • Two merged-but-unreleased Effect breaks are planned for: the @effect/sql-pg native client types and the Config PascalCase rename. RC bumps follow the runbook in AGENTS.md.

Out of scope

Feature-by-feature keep/drop of PatchPage-isms (except reports); deployment target, replicas, hosting, release channel; auth replacement, tier 1/2 runtimes, the integration layer; self-hosting in any form.

Sub-issues

Sub-issues

11 of 11 Issues completed
Loading 11 sub-issues

Activity

  1. added
    area:server
    area:ci
    area:cli
    area:docs
    on Aug 28, 2026
  2. allisonmahmood commented on Sep 2, 2026

    @allisonmahmood
    OwnerAuthor

    migration done

  3. allisonmahmood commented on Sep 2, 2026

    @allisonmahmood
    OwnerAuthor

    Built. All eleven build tickets (#69–#79) are closed and their PRs merged on main: #80–#90. The known unknowns above (multi-replica limiter store, Neon pooler and scale-to-zero, the two unreleased Effect breaks) are not blocking and move to whichever map takes on deployment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:ciarea:cliarea:docsarea:server

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions