Skip to content

fix(lifecycle): snapshot a stack in the region it declares (#1261) - #1262

Merged
lex00 merged 1 commit into
mainfrom
fix/lifecycle-snapshot-region
Jul 31, 2026
Merged

lex00 merged 1 commit into
mainfrom
fix/lifecycle-snapshot-region

Conversation

@lex00

@lex00 lex00 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Fixes #1261.

The bug

chant lifecycle snapshot <env> observed every stack against the ambient region. On a multi-region estate only the stacks sharing that region were recorded; the rest failed with:

aws: no valid resources or artifacts returned

Because the command still wrote the stacks it could reach and exited 0, the failure read as a per-stack quirk rather than a systematic region miss. A later diff would read the missing stacks back as absent rather than unobserved.

The cause

config.stacks[].region is declared, and is already honored everywhere else:

  • cli/handlers/search.ts maps stacks to { name, region, src }, which is why search --live covers a multi-region estate correctly.
  • The AWS lexicon's describeResources accepts region?: string and builds --region args from it, with the comment "Multi-region estates: target this stack's region, not the ambient one."

Only the snapshot path dropped it. resolveStackTargets mapped config.stacks to { stack, root } and discarded s.region, and takeSnapshot had no option to carry one, so the plugin never received a region and fell back to the ambient one.

The change

Thread the declared region through the two layers that dropped it:

  • StackTarget gains region, and resolveStackTargets carries s.region.
  • takeSnapshot's options gain region, forwarded to describeResources.

No new concept — the region a stack deploys to is the region it is read from.

listArtifacts deliberately does not take a region. Artifacts are registry and chart objects (docker, helm), not regional cloud resources.

Verification

Against a four-stack estate spanning us-east-1 ×2, us-west-1 and us-west-2, with AWS_DEFAULT_REGION=us-east-1.

Before — 2 of 4 stacks, 21 resources:

ec2-multiregion-EC2-ks84v1fh12-us-east-1: Snapshot saved (aws(17))
error: aws: no valid resources or artifacts returned
error: aws: no valid resources or artifacts returned
ec2-multiregion-QARoles-us-east-1: Snapshot saved (aws(4))

After — 4 of 4 stacks, 37 resources:

ec2-multiregion-EC2-ks84v1fh12-us-east-1: Snapshot saved (aws(17))
ec2-multiregion-EC2-ls9fuhb522-us-west-1: Snapshot saved (aws(8))
ec2-multiregion-EC2-ls9fuhb522-us-west-2: Snapshot saved (aws(8))
ec2-multiregion-QARoles-us-east-1: Snapshot saved (aws(4))

Tests

Four added, covering both layers and both directions:

  • takeSnapshot forwards a declared region to describeResources, and leaves it undefined when none is declared (so the ambient-region default is preserved for single-region projects).
  • The snapshot handler passes each stack's own region, and undefined for a stack that declares none.

just build, npx eslint packages/, and the full lifecycle + cli/handlers suites pass (458 tests).

Follow-up, not in this PR

runLifecycleDiffLive is reached from the same resolveStackTargets loop and is passed only stack: target.stack, so lifecycle diff looks like the same shape. observeResources already accepts stacks: Array<{ name, region, src }>, so the plumbing exists. I left it alone because I only reproduced the snapshot path; noted in #1261.

🤖 Generated with Claude Code

https://claude.ai/code/session_01J3xEUD47xeEX2AK9xSvBug

`chant lifecycle snapshot` observed every stack against the ambient region, so
a multi-region estate recorded only the stacks that happened to share it. The
rest failed with "aws: no valid resources or artifacts returned" — and because
the command still wrote the stacks it could reach, the result read as a
per-stack quirk rather than a systematic miss. A later diff would then read
those stacks back as absent rather than unobserved.

`config.stacks[].region` was already declared and already honored elsewhere:
`chant search --live` maps stacks to `{ name, region, src }`, and the AWS
lexicon's `describeResources` takes a `region` and builds `--region` args from
it. Only the snapshot path dropped it — `resolveStackTargets` discarded
`s.region`, and `takeSnapshot` had nowhere to put one.

Thread it through those two layers. No new concept: the region a stack deploys
to is the region it is read from.

`listArtifacts` deliberately does not take one. Artifacts are registry and
chart objects (docker, helm), not regional cloud resources.

Verified against a four-stack estate across us-east-1, us-west-1 and
us-west-2: 2 of 4 stacks captured before, 4 of 4 after.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J3xEUD47xeEX2AK9xSvBug
lex00 added a commit that referenced this pull request Jul 31, 2026
…1267)

A snapshot recorded identity — logical name, type, physical id, status — plus
the stack's CloudFormation exports. It carried no per-resource properties, so
nothing that folds over topology could be answered from one. `webServer`,
`publicSubnet` and `webSecurityGroup` in the same snapshot all held an
identical `attributes` blob of stack exports.

`observeResourcesDeep` already existed and was already wired into
`lifecycle diff --live`. Only the snapshot path never called it.

`chant lifecycle snapshot <env> --deep` now records each resource's normalized
property tree beside the identity it already kept. Thin stays the default: a
deep read is more provider calls and a larger record, so it is asked for.

Depth is recorded, not inferred. `depth` is absent on a thin snapshot, because
every snapshot written before this was thin and treating a missing field as
unknown would invalidate them all. `lifecycle show` states it, so a reader
knows what a snapshot can answer before asking.

Degradation is explicit at every step, following #1089's rule that an unread
resource is a hole with a reason and never a clean empty answer:

  - a lexicon with no deep reader warns and records identity
  - a deep read returning nothing warns and keeps the identity snapshot rather
    than discarding one that was already good
  - a type outside the Cloud Control allowlist is recorded unobserved, per
    entity, with the kind named

The deep path was region-blind — `observeResourcesDeep` took no region at any
layer, so a multi-region estate read every stack against the ambient one and
the out-of-region stacks came back empty. Thread it the same way #1262 did for
thin, through DeepObserveOptions, the lexicon interface, and the AWS reader's
describe-stack-resources and cloudcontrol get-resource calls.

Verified against a four-stack estate across three regions. Coverage is now the
constraint rather than the mechanism: the allowlist holds four types and the
EC2 topology types are not among them, so the folds still cannot be answered
from a snapshot. Filed as #1269.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J3xEUD47xeEX2AK9xSvBug
@lex00
lex00 force-pushed the fix/lifecycle-snapshot-region branch from c28f957 to 0e55bfe Compare July 31, 2026 03:49
@lex00
lex00 merged commit 7985937 into main Jul 31, 2026
9 checks passed
@lex00
lex00 deleted the fix/lifecycle-snapshot-region branch August 3, 2026 19:22
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.

lifecycle snapshot observes every stack against the ambient region

1 participant