Skip to content

refactor(core): keyed crypto goes through the Cryptography service - #1041

Merged
allisonmahmood merged 2 commits into
mainfrom
refactor/cryptography-keyed
Oct 29, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
refactor/cryptography-keyed

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

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 Patchy's crypto runs through Effect #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
  • 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.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling 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 area:ui Portal and first-party browser pages, shared rendering and styles labels Oct 29, 2026
@github-actions github-actions Bot added size:l 501-1,000 changed lines size:xl Over 1,000 changed lines; review in multiple passes and removed size:l 501-1,000 changed lines labels Oct 29, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked d43a6a11ea01f0a68833c9d7e6e23daaecca53b1 (base d77d0f77a097ebeac1ec1e6cab979ff769da2077, feat/patches-on-typescript-7) on fresh brightline scenario data, by GPT-6.1 Sol in the Codex harness through T3 Code. I did not write this change.

Done means

  • Pre-change credentials decrypt: passed. The focused suites open the fixed pre-service credential and retry-copy ciphertexts, check credential context/key binding and refusal shapes, RFC HMAC/HKDF vectors, existing file-handle signatures, RSA/SPKI normalization and management authentication.
  • Keyed formats stay compatible: passed. An additional direct check verified a new persona cookie with the old HMAC algorithm, rebuilt an old JSON/base64url/HMAC cookie and opened it against this server, and refused a truncated MAC. Receipt staging, adoption and fetching through a tier 2 file handle also worked.
  • Subscription updates remain synchronous: passed for this layer. Subscriptions.ts is unchanged; two open viewers received both tier 1 and tier 2 updates, and the tier 2 move was reversed.
  • Crypto has an environment seam: passed. Keyed consumers obtain Cryptography; entrypoints supply NodeCryptography.layer. The implementation differs from the issue's proposed Effect-Crypto-backed layer: the PR explicitly discloses that it directly wraps Node for unkeyed operations too. Bun's Node compatibility is assumed, not exercised here.
  • Import restriction, remaining ids/tokens/hashes and deletion of synchronous helpers: deferred to refactor: ids, tokens and hashes come from Cryptography #1042, as Patchy's crypto runs through Effect #1039's two-PR plan specifies. This verdict accepts the first layer, not completion of the entire issue.

Golden journeys

  • Sign in/out: passed. Signed-out /company returned 401, persona sign-in opened it, sign-out cleared the cookie and restored the door.
  • Log a machine in: passed. The isolated environment CLI emitted the consonant code, browser confirmation issued a credential, whoami named the new machine, and logout revoked it.
  • Publish a page: passed. The installed environment CLI published HTML; another person saw its content and Home entry; retirement removed the content and restore brought it back.
  • Tier 1 live: passed. Jordan sent kudos and Priya's already-open page received it without reload.
  • Tier 2: passed. Jordan's deal move appeared on Allison's open board and moving it back also propagated. Spend refused self-approval. An uploaded receipt was adopted and its file-handle image fetched successfully.
  • Invite/join: passed. Allison invited a fresh scenario address, its persona enrolled, joined Brightline and reached the signed-in portal.
  • Agent connection: passed for the dev-minted path. A new scenario connection authenticated MCP initialize successfully. This bypasses consent.

Evidence

pnpm exec vitest run <NodeCryptography, AgentConnections, DevPersonas,
  Session, CredentialKeys, Files, Management test files>
Test Files  7 passed (7)
Tests       105 passed (105)

CI on this head passed Node 24 tests, both CLI smoke jobs, browser, tier2-smoke, Clerk live, all installer platforms, lint, concurrency, release tarball and rollback rehearsal. CI run. The known shared-machine CLI stub flake was not used as a failure signal.

Rollback answers: match the diff. No migrations, new persisted formats, API shapes or infrastructure changes; the previous implementation can read the same sealed values and signatures. No one-way label is needed.

Not run

  • Real OAuth consent/refresh in a third-party agent client: the dev mint bypassed consent; retry/refresh behavior is covered by AgentConnections tests.
  • Real Clerk sign-in and invitation mail locally: this run used personas and scenario-only invitations. Head CI's Clerk live check passed.
  • Invite revocation and member deactivate/reactivate manually: covered by CI's auth/company suites, not this direct scenario run.
  • Bun runtime: not installed/exercised as a deployment target for this acceptance.

Notes

  • At posting, Node 22/26 test jobs and informational Attio live were still running; no observed check was red. This is a behavioral acceptance verdict, not a declaration that every merge gate has finished.
  • Only this run's throwaway local instance was used. Environment CLI calls cleared exported API URL/token and explicitly set its CLI state directory. The instance was taken down; tracked files remain unchanged.

@allisonmahmood
allisonmahmood force-pushed the feat/patches-on-typescript-7 branch from d77d0f7 to 294857d Compare October 29, 2026 10:36
Base automatically changed from feat/patches-on-typescript-7 to main October 29, 2026 10:46
allisonmahmood and others added 2 commits October 29, 2026 11:46
Cryptography, in @patchy/core, is Patchy's crypto as an Effect service: its
id, token and digest formats, and the keyed operations Effect's Crypto lacks.
NodeCryptography.layer implements it over node:crypto, the way NodeCrypto
implements Effect's Crypto.

Sealed integration credentials, agent connection retry copies, file-handle
MACs, persona cookies, the management secret check and Clerk's JWT key now go
through it. Known-answer tests open a credential and a retry copy sealed by
the old code, so stored values keep working.

Part of #1039.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Seal a retry copy the way the previous release did and refresh through
AgentConnections; recompute a file handle's MAC the way the previous release
did and compare it with what Files issues. Both go through the code that reads
stored values, so a changed HKDF info, associated data, binding or truncation
fails them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the refactor/cryptography-keyed branch from d43a6a1 to 16a5f67 Compare October 29, 2026 10:46
@allisonmahmood
allisonmahmood merged commit 9201472 into main Oct 29, 2026
22 checks passed
@allisonmahmood
allisonmahmood deleted the refactor/cryptography-keyed branch October 29, 2026 10:56
allisonmahmood added a commit that referenced this pull request Oct 29, 2026
## What changed

This finishes #1039. Core's synchronous crypto helpers are gone. These
now take `Cryptography` from their environment instead of calling
`node:crypto`:
- about 75 call sites of the old helpers;
- 14 modules that imported `node:crypto` directly.

Oxlint now refuses `node:crypto` everywhere except `NodeCryptography`
and four Promise-code modules on process boundaries, so new code can't
slip back. Nobody using Patchy sees a difference.

Closes #1039. Stacked on #1041.

## Look at

- **Stored formats are pinned:**
- Table index names, which name indexes in every company database, are
checked against the names earlier releases gave them.
  - Ids, tokens and digests are pinned in core's tests.
  - Setup links and device codes keep their shape tests.
- Pidgeon's address-creation Idempotency-Key equals the SHA-256 the
previous release sent for the same attempt. Swapping the hashed fields
fails the test.
  - A lost mint is asked again under the same `patchy-<uuid>` key.
- **The subscription commit stays one synchronous step.** It hashes with
`sha256Unsafe`, named after Effect's own `nextIntUnsafe`, so nothing
yields inside the commit or in `close()`.
- **Where generation moved:**
- Pidgeon's connect-form attempt is made by the page handler, not the
pure renderer.
  - An action's nested call id is made inside the Effect it returns.
- Mutation keys, Pidgeon idempotency keys and the dev seeds take
`Cryptography` from the environment.
- **The look preview** keeps its frame script's CSP hash as a constant,
with a test that recomputes it from the rendered page. No crypto runs at
runtime, and the Playwright spec stays plain.
- **The lint rule** bans `node:crypto` and `crypto`, including inside
both CLI import-boundary overrides. I checked it fires on a server file
and a CLI file:
  - Tests and scripts are exempt.
- The five files that keep the import carry an inline disable with the
reason: `NodeCryptography` itself, the offline task store, and the CLI's
dev state, owner lock and config runner.
- **Tests** get Patchy's formats from `test/crypto.ts`, computed
independently with `node:crypto`.
- **Supporting changes:**
- `@patchy/core/Cryptography` is exported as a subpath, so declaration
emit can name the type.
- AGENTS.md, the `effect-service-conventions` skill and GLOSSARY-MAP say
where crypto comes from.

## How it was verified

- Typecheck of the sources and the tests program both exit 0, with no
warnings. Lint and format pass.
- The offline suite, minus the CLI suites that flake on this shared
machine, passed 2,337 tests. Two failed with the same stray-request
flake and passed on rerun. CI runs everything.

## Release impact

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

This is an internal refactor. Every id, token, digest and index name
keeps its format.

- **What does a revert leave behind?** Nothing new. Rows and indexes
made in between have the same names and 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling 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 area:ui Portal and first-party browser pages, shared rendering and styles size:xl Over 1,000 changed lines; review in multiple passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant