Skip to content

fix(state): destroy removes the persisted stack output instead of writing an empty husk - #965

Merged
sam-goodwin merged 1 commit into
mainfrom
claude/issue-961-regression-test-708e55
Jul 27, 2026
Merged

sam-goodwin merged 1 commit into
mainfrom
claude/issue-961-regression-test-708e55

Conversation

@sam-goodwin

Copy link
Copy Markdown
Member

Destroying a stack left a stale persisted output record: the destroy plan was built with output: {}, so apply re-persisted an empty {} husk for the stage. state.getOutput then returned non-null while state stages no longer listed the stage, and cross-stack Output.stackRef consumers crashed at plan time reading fields off the husk instead of getting the typed InvalidReferenceError.

Fix: destroy plans now carry no output and apply deletes the stage's persisted state once the destroy converges.

// Plan.ts — realizes the old "Plan.destroy" TODO
export const destroy = (stack: { name: string; stage: string }) =>
  make({ ...emptySpec(stack), output: undefined })
    .pipe(Effect.map((plan) => ({ ...plan, destroy: true })));

// Apply.ts
if (plan.destroy) {
  // every resource row was already deleted; drop the rest of the stage —
  // notably the stack output record written by the last deploy
  yield* state.deleteStack({ stack: stackName, stage });
  return undefined;
}
  • All three destroy paths (engine destroy, alchemy destroy, test scratch stacks) now go through Plan.destroy.
  • InMemoryService.deleteStack also drops the stage's outputs (the other stores already did).
  • Regression test: destroy-output.test.ts covers both the scratch-stack path and the real deploy/destroy entry points; both failed with expected {} to be undefined before the fix.

Fixes #961

🤖 Generated with Claude Code

…ting an empty husk

Destroying a stack planned with `output: {}`, so `apply` re-persisted an
empty `{}` output record for the stage. `state.getOutput` then returned a
non-null, field-less husk while `state stages` no longer listed the stage,
and cross-stack `Output.stackRef` consumers crashed reading fields off the
husk at plan time instead of getting the "Have you deployed?" error.

- Add `Plan.destroy(stack)`: empty spec, `output: undefined`, and a
  `destroy` marker on the plan (realizes the old Plan.destroy TODO).
- `apply` finishes a destroy plan by deleting the stage's remaining
  persisted state (the stack output record) via `state.deleteStack`.
- Route all three destroy paths (engine `destroy`, `alchemy destroy`,
  test scratch stacks) through `Plan.destroy`.
- `InMemoryService.deleteStack` now also drops the stage's outputs.

Fixes #961

Co-Authored-By: Claude Fable 5 <[email protected]>
@alchemy-version-bot

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

alchemy

bun add alchemy@https://pkg.ing/alchemy/061cb1c

@alchemy.run/better-auth

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

@alchemy.run/pr-package

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

@sam-goodwin
sam-goodwin merged commit 663d467 into main Jul 27, 2026
9 checks passed
@sam-goodwin
sam-goodwin deleted the claude/issue-961-regression-test-708e55 branch July 27, 2026 23:09
DavidJFelix added a commit to DavidJFelix/alchemy-effect that referenced this pull request Aug 7, 2026
Resolves conflicts between the dashboard work (deployment journal in
apply, --ui deploy flow, delete-node pending reporting) and main's
Plan.destroy + aggregated destroy failures (alchemy-run#973), destroy stack-state
cleanup (alchemy-run#965), and local/live provider modes (alchemy-run#963):

- apply: keep the journal exit-mapping; run state.deleteStack after the
  deployment journal closes on a successful destroy
- collectGarbage: adopt main's outcome-based blocked/failed delete
  aggregation, keep the pending status report for queued deletions
- deploy/destroy/test harness: Plan.destroy + apply command option
- Cloudflare Workers ui: domains attr became singular domain
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.

Destroyed stack leaves a stale persisted output record: getOutput returns a field-less husk while 'state stages' omits the stage

1 participant