Skip to content

refactor: Effect Crypto replaces node:crypto inside Effect - #1000

Merged
allisonmahmood merged 3 commits into
mainfrom
refactor/effect-crypto
Oct 29, 2026
Merged

allisonmahmood merged 3 commits into
mainfrom
refactor/effect-crypto

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

What changed

TypeScript 7's Effect checker (@effect/tsgo) flags node:crypto imports that the TypeScript 6 language service let through. Effect 4 has a Crypto service, so code that already runs inside Effect now takes it from its environment instead of importing Node's. Nothing anyone sees changes: every id, token, digest and stored fingerprint keeps its format.

Part of #985 (step 3 of 5). Stacked on #994.

Look at

  • Moved to Crypto, formats unchanged:
    • Fleet task ids and wake origins: UUIDv4.
    • Each company database's file-handle secret: still 32 random bytes in hex. Both company database constructors take Crypto and hand it to Inventory.initialize.
    • Table row ids: UUIDv7 on the Effect clock, the same layout the hand-rolled ones had.
    • File tokens and SHA-256 digests: Effect's Hex and Base64Url encode exactly as Node's hex and base64url. Checked on 32 random bytes.
    • The deployment config's revision, stored with every limit change in deployment_revision: still the SHA-256 hex of the values. main and this branch both print af2b298c…2724e for PATCHY_LIMITS_JSON='{"company.connections":9}'.
  • DeploymentConfig.load keeps its ripple small. revision is now an Effect, so only OperatingLimits and the exec entrypoint, the two that record it, need Crypto. The services that only read values don't. The server gets Crypto from NodeHttpServer, exec provides NodeCrypto, and so do the test layers that build fleets, table writers or operating limits.
  • Kept on node:crypto, each with its reason:
    • What Effect has no equivalent for: AES-256-GCM in CredentialKeys, and HMAC with a constant-time compare in Files.
    • Synchronous helpers callers outside Effect use: core sha256, tokens and ids, which the CLI uses too; table index names; and the look preview's CSP hash, a module constant.

How it was verified

  • pnpm build, pnpm typecheck and pnpm typecheck:tests (exit 0), pnpm lint and pnpm format:check pass. The TypeScript 7 Effect checker reports nothing in the touched packages.
  • Suites that build what moved pass: limits (deployment config and operating limits), table operations, files and the files API, wakes over Postgres, the fleet controller, client documents and OAuth endpoints (163 tests); company databases on Postgres and PGlite, and tables (89 tests).
  • The deployment revision matches between main and this branch, as above.

Release impact

  • Breaking — requires action from anyone already running this
  • Not breaking — no action required

An internal refactor: every id, token, digest and stored revision keeps its format.

  • What does a revert leave behind? Nothing new. Rows written in between carry the same id, token, digest and revision formats as before.
  • Does the release before it still work with that? Yes.

Made by Claude Opus 5.5 (Claude Code in T3 Code); reviewed by GPT 6.1 Sol.

@github-actions github-actions Bot added area:server Touches the server area area:cli Touches the cli area area:core Touches the core area area:primitives Patch tables and files area:integrations Company connections and integration implementations size:m 100-500 changed lines labels Oct 29, 2026
@allisonmahmood

allisonmahmood commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner Author

Review (GPT 6.1 Sol, xhigh) and what changed:

  1. pnpm typecheck:tests exited 2. OperatingLimits.layer now needs Crypto, which NodeServices.layer supplies, and in the integration runtime harnesses both sat in one Layer.mergeAll. A merge member can't feed its siblings, so the Effect checker's layerMergeAllWithDependencies warning failed the run. The four harnesses and the Pidgeon live tier now provide NodeServices around the merge (17b0280). pnpm typecheck and pnpm typecheck:tests exit 0, and the four runtime suites pass.

Everything else Sol checked held: UUIDv7 layout and TestClock behaviour, token length and alphabet, digest hex, revision bytes, and revisions staying stable when a registry default changes after load. Production and packed patchy dev wiring provide Crypto, and orDie keeps the old defect semantics.

Rebased onto #994's head (5a2df1d). Since the review, 3aecc51 also moves each company database's file-handle secret to Crypto, still 32 random bytes in hex.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked 17b02802f4c31eee7245dee211c9d9626386208d (base 5a2df1d63e7483285ab2b80b7a756ce499a13abc, origin/refactor/cli-parse-without-typescript) on fresh brightline and disposable Postgres/PGlite/fleet fixtures, by GPT-6.1 Sol in Codex (T3 Code).

Done means

This checks #1000's step of #985: replacing crypto inside Effect while preserving behavior and formats. The later TypeScript 7 migration steps are outside this PR.

  • IDs, tokens, digests and secrets keep their formats: passed. The row contract passed on Postgres and PGlite: 128 UUIDv7s at a fixed Effect clock, all random bits varying, correct version/variant, and lexical ordering after advancing the clock. File contracts passed on both backends. Independently compared Effect Hex/Base64Url against Node at byte lengths 0, 1, 2, 3, 32 and 257. Fresh company databases successfully generated and used their handle keys; UUIDv4 fleet/wake paths ran successfully.
  • Deployment revisions and limit-change records: passed. Ran the base's DeploymentConfig.load and the head's against the same unchanged registry for defaults and two override sets: identical SHA-256 hex in all three. {"company.connections":9} gives af2b298cfaf75f9a6dcc2c0f97af91b71386684e73997325ac19d4bee5d2724e. OperatingLimits tests also passed, including audit rows retaining the deployment revision across override changes.
  • Crypto wiring: passed. pnpm typecheck passed (24 tasks, including the tests program), and standalone pnpm typecheck:tests exited 0. The focused suites passed 129 tests across 10 files, including a fresh EXECUTION_PROVIDER=local-fleet cloud server executing an action with nested callbacks, plus CLI dev startup, row/file writes, restart persistence and reset.
  • Packed local runtime: passed. pnpm test:packed-tier2-e2e exited 0: clean offline CLI install, bundled PGlite, both local viewer mounts, local row writes and staged file adoption/download, then publish, two-viewer sync, keyed retry, sharing, files, members, CSV and tier changes on the built cloud server.
  • Server image path: passed. node scripts/build-server-image.mjs --stage … succeeded with pinned Node 24.20.0/pnpm 12.9.1. Started both entrypoints from the staged production dependency tree: dist/start.js migrated fresh Postgres and /healthz/deep returned 200; dist/exec.js started and authenticated /stats returned 200. Both were stopped.

Golden journeys

  • Use a tier 1 tool live: passed. On fresh Brightline, Jordan sent kudos to Priya; it appeared on Priya's already-open page without reloading.
  • Use a tier 2 tool: passed. Sample deals loaded; Jordan moved a Lead to Discovery and back, with both changes appearing on Allison's already-open board. Jordan submitted a Spend request with a staged PDF receipt; the action adopted it and created the request. Approving his own request returned “You can't approve your own request.” Downloading through its viewer-bound handle produced the exact uploaded bytes.
Focused commands and observed output
pnpm exec vitest run packages/limits/src/DeploymentConfig.test.ts packages/limits/src/OperatingLimits.test.ts packages/primitives/src/TableOperations.test.ts packages/primitives/src/Files.test.ts packages/company-database/src/PgliteCompanyDatabases.test.ts packages/runtime/src/WakesPostgres.test.ts packages/execution/src/Fleet.test.ts packages/patchy/src/devResources.test.ts --maxWorkers 1
Test Files  8 passed (8)
Tests       112 passed (112)

pnpm exec vitest run apps/server/src/DevelopmentExecution.test.ts packages/patchy/src/devLifecycle.test.ts --maxWorkers 1
Test Files  2 passed (2)
Tests       17 passed (17)

pnpm test:packed-tier2-e2e
PASS: packed init, both dev mounts, publish, two-viewer sync, keyed retry, sharing, files, members, CSV and tier changes

Direct Playwright checks on pnpm dev up brightline:
PASS tier 1: Jordan sent kudos; Priya saw it without reload
PASS tier 2: sample deals loaded; Jordan moved a Lead to Discovery and back; Allison saw both without reload
PASS tier 2: submit action adopted receipt and created request; own approval refused
PASS files: uploaded PDF downloaded byte-for-byte through viewer-bound handle

Rollback answers: match the diff. No migrations, wire contracts or infrastructure changes; generated data retains the prior formats, and the stored deployment fingerprint is byte-identical for the same effective values. No one-way label needed.

Not run

  • Real ECS/Fargate execution and live third-party services: used the disposable local-fleet provider and dev personas; no production or daily-driver instance was touched.

Notes

  • At posting, CI image, rollback-rehearsal and clerk-live are green; other jobs remain queued/running (including live-service checks). Full CI completion is not part of this verdict; those pending jobs are not counted as passes. No product failure was observed locally.
  • All local instances and child processes started by this run were taken down; the detached checkout stayed clean. No PR code, branch, body or labels were changed.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Rebased onto #994's final head (dc83ce9), which changed only editUses.ts and its test. git range-diff shows every commit of this PR unchanged (=): 45206b9..17b0280 → f1dbb45..d9759cf. The acceptance verdict above covers the same patches. At the top of the stack, pnpm build, pnpm typecheck and pnpm lint pass on the rebased branches.

@allisonmahmood
allisonmahmood force-pushed the refactor/cli-parse-without-typescript branch from dc83ce9 to 3df1a74 Compare October 29, 2026 09:45
Base automatically changed from refactor/cli-parse-without-typescript to main October 29, 2026 10:00
allisonmahmood and others added 3 commits October 29, 2026 11:00
TypeScript 7's Effect checker (@effect/tsgo) flags node:crypto imports
the TypeScript 6 language service let through. Effect 4 has a Crypto
service, so code that already runs in Effect takes it from its
environment; the formats stay byte for byte:

- Fleet task ids and wake origins are Crypto UUIDv4s; table row ids are
  Crypto UUIDv7s on the Effect clock, the layout the hand-rolled ones had.
- File tokens and SHA-256 digests use Crypto with Effect's Hex and
  Base64Url, which encode exactly as Node's hex and base64url.
- The deployment config's revision, stored with every limit change, is
  still the SHA-256 hex of its values. It is now an Effect, so only
  OperatingLimits and the exec entrypoint, which record it, need Crypto;
  the services that only read values don't.

NodeHttpServer already provides Crypto to the server; exec provides
NodeCrypto, and the test layers that build these services provide it too.

What Effect has no equivalent for keeps node:crypto with its reason:
AES-256-GCM, HMAC with a constant-time compare, and the synchronous
helpers (core sha256/tokens/ids, index names, the look preview's CSP
hash) that callers outside Effect, the CLI included, use.

Part of #985.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rypto

Inventory.initialize drew each company database's file-handle secret
from node:crypto inside Effect; TypeScript 7's Effect checker flags it.
Both company database constructors take Crypto from their environment
and hand it to initialize. The secret is still 32 random bytes in hex.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ses' merge

OperatingLimits now needs Crypto, which NodeServices supplies, and a
Layer.mergeAll member can't feed its siblings: the Effect checker's
layerMergeAllWithDependencies warning failed typecheck:tests. The four
integration runtime harnesses and the Pidgeon live tier now provide
NodeServices around the merge, which also covers Crypto.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit ac41203 into main Oct 29, 2026
38 of 39 checks passed
@allisonmahmood
allisonmahmood deleted the refactor/effect-crypto branch October 29, 2026 10:22
allisonmahmood added a commit that referenced this pull request Oct 29, 2026
## What changed

Patchy now compiles with TypeScript 7, the native compiler, and nothing
in the repo reads TypeScript 6 any more. Type-checking the workspace is
6–12× faster, building it 6.5× faster, and new patch repos start on
TypeScript 7.

Part of #985 (step 4 of 5). Stacked on #1000.

## Look at

- **Effect diagnostics come from `@effect/tsgo`.** Builds and `pnpm
typecheck` run `effect-tsgo tsc`, TypeScript 7 with the Effect checker
built in, so `prepare` no longer patches a compiler in the shared pnpm
store. That patching was the trap where one worktree's install silently
turned Effect rules off in another.
- The rule set is unchanged, and a canary proved `nodeBuiltinImport`,
`globalDateInEffect`, `globalConsoleInEffect` and `preferSchemaOverJson`
still fail the build.
- Turned off, each with a reason: tsgo's default `unstableApiUsage`,
since `effect/http` and `effect/sql` are used on purpose (about 5,700
hits); suggestions in `tsc` output; and the new
`schemaClassObjectLiteral` warning, until #1002.
- The deliberate missing-`PatchLock` test keeps its suppression; its two
comments swapped order for the Go checker.
- **The CLI's declarations (`scripts/build-patchy-package.mjs`).**
- TypeScript 7 emits them, reading workspace packages from source, and
Rolldown bundles them. Only the files the bundle publishes must emit
cleanly. The dev runtime's internals infer types TypeScript can't name
in a declaration, and no published type reaches them.
- The release's own dependencies (Preact, signals, PGlite) are
explicitly external, so pnpm's `NODE_PATH` can't pull them inline.
- The published `.d.ts` files import exactly what `main`'s do: `preact`,
`preact/compat`, `preact/jsx-*` and `@preact/signals`. `server.ts` and
`csv.ts` joined the build's entries.
- **Tests that read TypeScript's API.** The generated-client type tests
and the client facade test run the real `tsc` on a temp directory
(`test/typescript.ts`), and esbuild strips the types the
generated-client tests execute.
- **New patch repos scaffold `typescript@^7.0.2`.** The offline test
registry packs TypeScript 7's platform binary for this machine and skips
the other platforms'. TypeScript 7 exits 1, not 2, on type errors.
Publishing still accepts TypeScript 6 until the next PR.

Same 16-core machine and script as the baseline in #985, medians,
uncached, with equal or higher load during these runs:

| | TS 6 + ESLint (`main`) | TS 7 + Oxlint (this stack) |
|---|---|---|
| Type-check every project | 151 s | 25.5 s |
| Type-check the tests program | 87 s | 7.1 s |
| `pnpm typecheck` | 142 s | 20.9 s |
| `pnpm build` | 75 s | 11.6 s |
| `pnpm lint` | 38 s | 11.6 s |
| `patchy --version` | 0.35 s | 0.20 s |
| CLI tarball | 35.1 MB | 22.5 MB |
| Patch repo `tsc --noEmit` (3 real repos) | 2.4 / 2.9 / 1.2 s | 0.39 /
0.35 / 0.24 s |
| Patch repo lint | 1.3 / 1.1 / 0.6 s | 0.06 / 0.05 / 0.06 s |

## How it was verified

- `pnpm typecheck` exits 0, and `pnpm build`, `pnpm lint` and `pnpm
format:check` pass.
- The lockfile holds only `[email protected]`: no TypeScript 6,
typescript-eslint, `@effect/language-service` or rollup-plugin-dts.
- `pnpm test:packed-cli-e2e` and `pnpm test:packed-preact-e2e` pass
locally. Real scaffolded repos install `typescript@^7.0.2` from npm and
type-check with it.
- Passing suites: the TypeScript-sensitive ones (125 tests: scaffold,
publish, client and generated-client types, generated server, parsers,
lint rules), plus the offline tier 1 init that runs a TypeScript 7
typecheck.
- Three real patch repos type-check under TypeScript 7 and lint clean
under the scaffold's Oxlint with no code changes.
- The full CLI suite has the same stray-`GET /` stub-server failures on
this loaded machine as `main`, so CI is the oracle for those.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

Build tooling, plus the scaffold's TypeScript range for new repos.
Existing patch repos and their publishing are untouched here.

- **What does a revert leave behind?** Patch repos created in between
scaffold TypeScript 7, which the release before still publishes: it
never gated TypeScript.
- **Does the release before it still work with that?** Yes.

Made by Claude Opus 5.5 (Claude Code in T3 Code); reviewed by GPT 6.1
Sol.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
allisonmahmood added a commit that referenced this pull request Oct 29, 2026
…1041)

## What changed

#1000 moved the crypto that Effect's own `Crypto` covers. The rest still
called `node:crypto` directly: sealing integration credentials, signing
file links, HKDF for agent connections, the management secret check, and
reading Clerk's JWT key. Now those take `Cryptography` from the
environment. It's a new `@patchy/core` service, and its
`NodeCryptography.layer` is the one place they reach Node. Nobody using
Patchy sees a difference.

Part of #1039. Stacked on #1010.

## Look at

- **Stored values still open, through the code that reads them:**
- An integration credential sealed by the old code decrypts through
`CredentialKeys`.
- A retry copy sealed the old way, with HKDF info, connection-id AAD and
layout as before, refreshes through `AgentConnections.refresh`.
- The file handle `Files` issues equals the old HMAC of the same key and
binding, cut to 24 bytes.
- Changing the HKDF info or the truncation fails these tests. I checked
both.
- HMAC-SHA256 and HKDF also match the RFC 4231 and RFC 5869 test
vectors.
- **Errors keep their shape:**
- A failed seal is still `CredentialEncryptionFailed` with a redacted
cause.
- A failed open is still `CredentialDecryptionFailed`, with no cause,
and still a 503.
  - A retry copy that won't open is still a defect.
  - A bad `CLERK_JWT_KEY` still fails at boot as that setting.
- **One change from #1039's plan:**
- `NodeCryptography.layer` requires nothing, the way Effect splits
`Crypto` from `NodeCrypto`. Entrypoints and test layers provide it
beside `NodeCrypto`, with no ordering between them.
  - The plan had it built on Effect's `Crypto`.
- **One behaviour gets stricter.** A file handle whose MAC is the wrong
length is now refused. Before, Node's `timingSafeEqual` threw on it.

## How it was verified

- `pnpm check`: format, lint, typecheck and synth pass.
- Tests:
- Every suite passes except the CLI suites' stray `GET /` flake on this
shared machine, which also fails on the base branch. CI decides those.
- The affected suites pass: auth, credentials, files, management and
`Cryptography` (309 tests).

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

This is an internal refactor. Every stored format is unchanged, and the
known-answer tests above prove it for the sealed ones.

- **What does a revert leave behind?** Nothing new. Values sealed or
signed in between use the same formats as before.
- **Does the release before it still work with that?** Yes.

Made by Claude Opus 5.5 (Claude Code in T3 Code); reviewed by GPT 6.1
Sol.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
allisonmahmood added a commit that referenced this pull request Oct 29, 2026
… 7 (#1046)

## What changed

This adds release 22's What's new entry, written from `a2d1331`. It
covers everything merged since release 21's `through` (`f30d8fe`), and
sets the `patchy` release to `0.22.0` in `packages/patchy/package.json`
and `CURRENT_RELEASE`. With this release, patch repos move to TypeScript
7 and Oxlint, and Patchy's crypto runs through one Effect service.

| Change | PRs |
| --- | --- |
| Improved: Your agent checks patches several times faster. New repos
use TypeScript 7 and Oxlint, the patchy download is a third smaller, and
an existing repo's next publish asks it to move over | #989, #994,
#1009, #1010 |
| Behind the scenes: Patchy itself builds with TypeScript 7 and Oxlint |
#989, #1009 |
| Behind the scenes: Encryption, signing and ids go through one place,
with tests proving stored values still open | #1000, #1041, #1042 |

One merged PR gets no line: #971 is release 21's own entry.

## Look at

- **The entry**, at the top of `releases` in
`packages/core/src/whatsNew.ts`. It tells builders that their next
publish of an existing repo will ask them to move to TypeScript 7, and
that live patches keep working. That's the one behaviour change people
will meet.
- **Rollback safety, from the live commit `2f9f7c1` (release 21) to
`a2d1331`:**
- No PR in the range is labelled `one-way`, and none has a migration or
an infrastructure change.
- Every stored format is unchanged: ids, tokens, digests, sealed
credentials, file handles and index names. The crypto PRs prove this
with known-answer tests.
- #1010 is Breaking for builders: publishing a TypeScript 6 repo is
refused, with the command to fix it. A rollback lifts that refusal, and
doesn't strand anyone.
  - `rollback-rehearsal` passed on every landed head.

**Rollback line:** If this release misbehaves, roll back to `2f9f7c1`
(release 21).

## How it was verified

- **Tests.** `whatsNew.test.ts`, `WhatsNewPages.test.ts` and
`schemas.test.ts` pass (21 tests), and prettier passes on the changed
files.
- **The stack.** All seven PRs were Sol-reviewed with every finding
fixed, and each got an acceptance PASS or PASS with notes. Each landed
after a rebase onto `main` that left it unchanged (range-diff `=`), with
all 12 required checks passing. #1000's one red run was the known Fleet
flake #1012, and it passed on rerun.
- **Deploy state.** The live commit, pinned from `/healthz/deep`, is
`2f9f7c1` (release 21). The Deploy run updated last succeeded, and none
is unfinished.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

Text and version numbers only. The `0.22.0` bump tells CLIs and patch
repos installed before this deploy to upgrade, as every release does.

- **What does a revert leave behind?** Nothing.
- **Does the release before it still work with that?** Yes.

Made by Claude Opus 5.5 (Claude Code in T3 Code).

Co-authored-by: Claude Opus 5.5 <[email protected]>
allisonmahmood added a commit that referenced this pull request Oct 29, 2026
…loop can add (#1049)

## What changed

A Fleet test failed often in CI: a refused call reported waiting 40,500
ms instead of 40,000. The call arms its 40-second wait just after it
reads the clock, and the test's loop moves the clock in 500 ms steps
alongside it. When a step lands between those two, the wait arms one
step late. The test now accepts exactly that one step. The product code
is unchanged.

Closes #1012

## Look at

- **`packages/execution/src/Fleet.test.ts`, the refused call.** `found`
and `refused` are still exact, and `waitedMs` must be 40,000 or 40,500,
never shorter than the pool wait. This is the "asserts within one step"
option from the issue.
- **Why now.** This failed on `test (24)` twice in a row on #992 (run
40897302040, both attempts), with the same diff as on #1000:
  ```
  -   "waitedMs": 40000,
  +   "waitedMs": 40500,
  ```
Neither #992 nor any of the speed PRs queued behind it touch this test
or `fleet.ts`'s wait. They each run it on three Node versions, so it
would keep blocking them.

## How it was verified

- The case passes 3 of 3 locally: `pnpm vitest run
packages/execution/src/Fleet.test.ts -t "says how a call found"`.
- `pnpm typecheck:tests`, oxlint and prettier pass on the file.
- CI on this PR runs the full suite on Node 22, 24 and 26.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

Test only.

- **What does a revert leave behind?** Nothing.
- **Does the release before it still work with that?** Yes.

Made by Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, running in
T3 Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli Touches the cli area area:core Touches the core area area:integrations Company connections and integration implementations area:primitives Patch tables and files area:server Touches the server area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant