Skip to content

feat(lifecycle): marker-scoped environment teardown — delete what a stack owns in an env, statelessly #1222

Closed

Description

@lex00

Filed for review. Scope and approach not yet confirmed.

Tear down everything a stack owns in one environment, from live markers alone — no build artifacts, no source for that environment, no snapshot required.

Finding

Owned-only deletes exist today only inside ApplyOp prune, which needs the current build (it deletes what is owned and no longer declared). There is no verb for "this environment is over": when the source that produced an environment is gone (a merged branch's review copy, a retired experiment), nothing can enumerate and delete its resources. The ownership marker already carries everything needed — managed-by, stack, env — on the live resource, and describeResources() can read it.

Want

1. chant lifecycle teardown <env>

Sweep each configured lexicon via its observation capability, select resources carrying the chant marker for this stack + env, and delete them through the target's native delete path (same paths ApplyOp prune uses), in reverse dependency order where the target needs it.

  • Owned-only by construction. Unmarked resources are never candidates. A different stack's marker is never a candidate.
  • Plan first. Default prints the would-delete set and exits; --yes (or a gate when run as an Op) executes. Refuse to run when <env> is not in environments, and require an explicit extra confirmation for an env named prod/production.
  • Stateless. Reads live markers only — works with an empty snapshot branch and no dist/.

2. Op form

A TeardownOp composite (temporal lexicon) wrapping the same activity so CI can run it gated, with the existing gate/compensation grammar.

Acceptance

  • Against an emulator env (Floci): deploy stack A env x and env y, plus a foreign unmarked resource; teardown x deletes exactly env x's resources; y and the foreign resource untouched. E2E-style test, Docker-gated.
  • Plan output lists resource, type, marker identity; exit 0 with empty set is loud ("nothing owned in "), not silent.
  • Unobserved kinds (no reader, read failed) are reported as holes and never treated as absent.
  • Docs page under lifecycle; cross-linked from drift-detection's orphan section.

Depends on nothing new; complements #1221.

Activity

  1. added
    enhancement
    needs-review
    on Jul 30, 2026
  2. added
    area:lifecycle
    on Aug 23, 2026
  3. lex00 commented on Aug 24, 2026

    @lex00
    ContributorAuthor

    Scope confirmed (build). Verified against current code; two claims adjusted, one dependency dissolved.

    Adjustments: (a) readOwnership (stack+env extraction) exists but is unused — every read path checks only the managed-by key, and the k8s prune selector excludes env; marker-env-scoped selection exists nowhere and is the first thing to build. (b) aws describeResources carries no tags, so aws teardown is stack-level (DeleteStack over the env's stacks from stacks[] or the env-named default, after verifying stack tags carry the marker) — not per-resource selection. (c) The #1221 dependency dissolved: #1396 settled the shape — teardown keys on the marker env, never on parsing physical names.

    V1 = chant lifecycle teardown <env>. Plan by default (resource, type, marker identity; loud on empty), --yes executes, refuses envs not in environments (pattern entries per #1221 count), extra confirmation for prod-like names. Selection is marker-scoped by construction: managed-by + this project's stack + <env>. Enumeration/deletion via a new optional teardownOwned lexicon capability so each lexicon reuses its prune primitives; unreadable kinds report as holes (#1089 discipline), never as absent. Stateless: live markers only, no build, no snapshot. Also exported as a function so #1224's harness can call it in afterAll.

    Naming: the existing teardown Op builder (npm run teardown) keeps its name; the new activity/builder is envTeardown. CLI verb as filed.

    Out (v1): global reverse-dependency ordering (per-lexicon ordering + bounded retry, failures reported), azure emulator E2E (floci-az drops tags; unit-test selection), gcp/helm implementations (follow-on), ever deleting unmarked or foreign-stack resources, snapshot/ledger integration.

    Plan: PR 1 core ResourceMetadata.marker populated from readOwnership + conformance checks (M); PR 2 capability type + plan-only CLI verb (M); PR 3 execution: --yes, prod guard, k8s + fly implementations, retry pass, k3d/mudflaps tests (M-L); PR 4 aws stack-level path + floci E2E (M); PR 5 temporal envTeardown activity/builder + docs (S).

  4. removed
    needs-review
    on Aug 24, 2026
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:lifecycleenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions