Skip to content

fix(engine): never persist unresolved Output exprs in resource state - #835

Merged
sam-goodwin merged 2 commits into
mainfrom
claude/vigilant-bassi-573370
Jul 15, 2026
Merged

sam-goodwin merged 2 commits into
mainfrom
claude/vigilant-bassi-573370

Conversation

@sam-goodwin

Copy link
Copy Markdown
Member

Both test/Planetscale/Postgres/Hyperdrive.test.ts tests died with a defect thrown from distilled's path-parameter builder:

Cannot coerce Output<HyperdriveTestDb.organization> to a string via JS coercion
    at buildRequestParts (distilled/packages/core/src/traits.ts:783)
    at GET /organizations/{organization}/databases/{database}/branches/{branch}
    at Plan.ts:1249 (plan.diff.deletion) → Planetscale/Branch.ts read

Two bugs stacked:

1. Engine: interrupted creates persisted live Output proxies

The first creating/replacing commits snapshot plan props, where upstream references are still live ResourceExpr/PropExpr proxies. Durable JSON stores drop them silently (proxies are function-typed), but the in-memory scratch store used by test.provider kept them. After a mid-deploy failure, the destroy plan handed those props back to provider.read as olds, and resolveDatabase(olds.database).organization reached getBranch as an unresolved proxy — the defect above, which also masked the real deploy error (the destroy runs inside Effect.ensuring, and defects escape Effect.ignore).

Fix: strip unresolved exprs at the state-commit boundary, keeping both store kinds consistent with the provider contract that olds is resolved Props:

// Apply.ts — both ResourceState commit helpers
value: { ...value, props: stripUnresolved(value.props), namespace } as S

stripUnresolved (Diff.ts) deep-replaces Expr/Effect leaves with undefined, preserving Redacted/Duration. Regression test in apply.test.ts covers interrupted-create → state hygiene → destroy convergence.

2. Fixture: migrationsDir was repo-root-relative

The masked failure: ENOENT: FileSystem.readDirectory('./packages/alchemy/test/...'). Tests run from packages/alchemy, so the branch reconcile failed right after the branch became ready and cascaded every dependent to fail. Now resolved cwd-independently:

const migrationsDir = yield* Effect.sync(() =>
  path.join(import.meta.url ? fileURLToPath(import.meta.url) : ".", "..", "migrations"),
);

Note: with destroy actually working now, each test really deletes and recreates the fixed-name alchemy-postgres-hyperdrive database — it previously survived only because the destroy plan died before deleting anything.

🤖 Generated with Claude Code

Early state commits (`creating`/`replacing`) snapshot plan props that can
still hold live Output proxies. Durable JSON stores drop them silently, but
the in-memory scratch store used by tests kept them — so after an
interrupted apply, a later destroy plan fed live proxies back into
`provider.read` as `olds`, exploding on first string coercion inside
distilled's path-parameter builder ("Cannot coerce Output<...>").

Strip unresolved exprs at the state-commit boundary so both store kinds
honor the provider contract that `olds` is resolved Props.

Also fix the Planetscale Hyperdrive fixture's `migrationsDir`, which was
repo-root-relative and ENOENT'd when running vitest from packages/alchemy —
the real deploy failure the coercion defect had been masking.

Co-Authored-By: Claude Fable 5 <[email protected]>
@sam-goodwin
sam-goodwin marked this pull request as ready for review July 15, 2026 21:07
@alchemy-version-bot

alchemy-version-bot Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

alchemy

bun add alchemy@https://pkg.ing/alchemy/3876830

@alchemy.run/better-auth

bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/3876830

@alchemy.run/pr-package

bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/3876830

Module-scope constant with an honest comment: the guard exists because
Stack.ts is bundled into the worker, not to defer execution.

Co-Authored-By: Claude Fable 5 <[email protected]>
@sam-goodwin
sam-goodwin merged commit fd18bf9 into main Jul 15, 2026
6 checks passed
@sam-goodwin
sam-goodwin deleted the claude/vigilant-bassi-573370 branch July 15, 2026 22:53
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.

1 participant