Skip to content

fix: remove expansion cache to fix sync watch nested stack failures - #10

Merged
bnusunny merged 15 commits into
developfrom
feat-language-extension
Feb 18, 2026
Merged

fix: remove expansion cache to fix sync watch nested stack failures#10
bnusunny merged 15 commits into
developfrom
feat-language-extension

Conversation

@bnusunny

Copy link
Copy Markdown
Owner

Problem

The expand_language_extensions() cache in sam_integration.py stored references to template dicts that were later mutated in-place by ApplicationBuilder.update_template() (which changes nested stack Location properties to build-output-relative paths). On cache hit, the mutated dict was returned instead of fresh data from disk, causing TemplateNotFoundException during the second infra sync in sam sync --watch.

This caused the following integration test failures:

  • TestSyncInfraNestedStacks_0::test_sync_watch_infra_nested_stack
  • TestSyncInfraNestedStacks_1::test_sync_watch_infra_nested_stack

Root Cause

  1. expand_language_extensions() cached results keyed by (template_path, mtime, params_hash)
  2. For templates without language extensions (the common case), the cache stored the raw template dict reference — no deep copy
  3. ApplicationBuilder.update_template() mutated stack.template_dict in-place, changing nested stack Location from e.g. ./template-python-before.yaml to a build-output path like LocalNestedChildStack/template.yaml
  4. Since stack.template_dict was the same object as the cached expanded_template, the mutation poisoned the cache
  5. On the next build_context.set_up() call (triggered by watch), get_stacks() got a cache hit returning the mutated dict, leading to TemplateNotFoundException

Fix

Remove the expansion cache entirely. Deep-copying on cache hit would negate the performance benefit and add complexity. Keep clear_expansion_cache() as a no-op for backward compatibility with sam_function_provider.py.

Testing

  • All 101 unit tests in test_sam_integration.py pass
  • All 2082 related unit tests pass (cfn_language_extensions, providers, sync, buildcmd)
  • Added test-sync-fix.yml workflow to run the nested stack sync integration tests

Trigger the Test Sync Fix workflow manually to verify.

dependabot Bot and others added 15 commits February 13, 2026 22:20
…aws#8632)

* chore(deps): bump ruamel-yaml from 0.18.16 to 0.19.1 in /requirements

Bumps ruamel-yaml from 0.18.16 to 0.19.1.

---
updated-dependencies:
- dependency-name: ruamel-yaml
  dependency-version: 0.19.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update reproducible requirements

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: seshubaws <116689586+seshubaws@users.noreply.github.com>
…aws#8644)

Bumps [cryptography](https://github.com/pyca/cryptography) from 46.0.3 to 46.0.5.
- [Changelog](https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst)
- [Commits](pyca/cryptography@46.0.3...46.0.5)

---
updated-dependencies:
- dependency-name: cryptography
  dependency-version: 46.0.5
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…is,lambda,s3,schemas,secretsmanager,signer,sqs,stepfunctions,sts,xray] (aws#8630)

Bumps the boto group in /requirements with 1 update: [boto3-stubs[apigateway,cloudformation,ecr,iam,kinesis,lambda,s3,schemas,secretsmanager,signer,sqs,stepfunctions,sts,xray]](https://github.com/youtype/mypy_boto3_builder).


Updates `boto3-stubs[apigateway,cloudformation,ecr,iam,kinesis,lambda,s3,schemas,secretsmanager,signer,sqs,stepfunctions,sts,xray]` from 1.42.41 to 1.42.42
- [Release notes](https://github.com/youtype/mypy_boto3_builder/releases)
- [Commits](https://github.com/youtype/mypy_boto3_builder/commits)

---
updated-dependencies:
- dependency-name: boto3-stubs[apigateway,cloudformation,ecr,iam,kinesis,lambda,s3,schemas,secretsmanager,signer,sqs,stepfunctions,sts,xray]
  dependency-version: 1.42.42
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: boto
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: add experimental uv support

* test: add uv build integration test

* feat: make uv accessible by BuildMethod template parameter

* fix: clean up experimental flag method

* chore misc formatting

* nit: remove reference to refactored method

* test: Add unit test for experimental build method

* test: add unit test for uv workflow selection

* test: add integration tests for uv

* ci: setup uv in tests

* fix: lint and making param optional

* feat: allow for manifest_path to be None

* nit: get rid of debug option

* nit: add comment to uv config
… test reliability (aws#8652)

- watch_manager: wrap _add_template_triggers in try/except within the
  infra sync error handler to prevent the watch process from crashing
  when the template is unparseable during error recovery
- testing_utils: add descriptive message to bare ValueError in
  read_until, and catch ValueError in read_until_string to include
  expected output context
- test_sync_adl: increase layer sync timeouts from 60s to 120s
- test_sync_watch: increase nested stack infra sync timeout to 900s
…ontainer tests (aws#8651)

The count_running_containers method fell back to counting ALL SAM CLI
containers when MODE env var filtering found no matches. This caused
AssertionError: 3 != 2 when stale containers from other tests were
present.

Changes:
- Remove fallback that returned len(sam_containers) - now strictly
  returns only containers matching this test's unique MODE UUID
- Use exact string matching instead of substring matching on env var
* Reapply "chore: use pypi dependency for durable executions python SDK (aws#8608)" (aws#8633)

This reverts commit d0effc7.

* chore: update durable execution emulator binaries

* fix: update wait for callback example

---------

Co-authored-by: Roger Zhang <ruojiazh@amazon.com>
Implement a local CloudFormation Language Extensions processor supporting:
- Fn::ForEach loop expansion in Resources, Conditions, and Outputs
- Fn::Length, Fn::ToJsonString intrinsic functions
- Fn::FindInMap with DefaultValue support
- Conditional DeletionPolicy/UpdateReplacePolicy
- Nested ForEach depth validation (max 5 levels)
- Partial resolution mode preserving unresolvable references

Pipeline architecture: TemplateParsingProcessor -> ForEachProcessor ->
IntrinsicResolverProcessor -> DeletionPolicyProcessor ->
UpdateReplacePolicyProcessor

Includes comprehensive unit tests and CloudFormation compatibility suite.
Wire the language extensions library into SAM CLI with two-phase architecture:
- Phase 1: expand_language_extensions() -> LanguageExtensionResult
- Phase 2: SamTranslatorWrapper.run_plugins() (SAM transform only)

Key components:
- expand_language_extensions() canonical entry point with template-level
  cache keyed on (path, mtime, params_hash)
- SamTranslatorWrapper receives pre-expanded template (Phase 2 only)
- SamLocalStackProvider.get_stacks() calls expand_language_extensions()
- SamTemplateValidator calls expand_language_extensions()
- DynamicArtifactProperty dataclass for Mappings transformation
- Fn::ForEach guards in artifact_exporter, normalizer, cdk/utils
- clear_expansion_cache() for warm container file change events
- _get_template_for_output() preserves Fn::ForEach in build output
- _update_foreach_artifact_paths() generates Mappings for dynamic
  artifact properties with per-function build paths
- Recursive nested Fn::ForEach support
- ForEach-aware path resolution skips Docker image URIs

Test templates: static CodeUri, dynamic CodeUri, parameter collections,
nested stacks, nested ForEach, dynamic ImageUri, depth validation.
Package:
- _export() calls expand_language_extensions() for Phase 1
- Preserves Fn::ForEach in packaged template with S3 URIs
- Generates Mappings for dynamic artifact properties
- _find_artifact_uri_for_resource() handles all export formats:
  string, {S3Bucket,S3Key}, {Bucket,Key}, {ImageUri}
- Recursive nested Fn::ForEach support
- Warning for parameter-based collections

Deploy:
- Uploads original unexpanded template to CloudFormation
- Clear error for missing Mapping keys

Integration tests for CodeUri, ContentUri, DefinitionUri, ImageUri,
BodyS3Location across all packageable resource types.
- sam validate: valid ForEach, invalid syntax, cloud-dependent collections,
  dynamic CodeUri, nested depth validation (5 valid, 6 invalid)
- sam local invoke: expanded function names from ForEach
- sam local start-api: ForEach-generated API endpoints
Add make test-lang-ext and make test-all targets so the 1695
language extensions unit tests only run when needed, keeping
the default make test fast for unrelated PRs.
The expand_language_extensions() cache stored references to template dicts
that were later mutated in-place by ApplicationBuilder.update_template()
(which changes nested stack Location properties to build-output paths).
On cache hit, the mutated dict was returned, causing TemplateNotFoundException
during the second infra sync in sam sync --watch.

Remove the cache entirely since deep-copying on hit negates the performance
benefit and adds complexity. Keep clear_expansion_cache() as a no-op for
backward compatibility.

Fixes TestSyncInfraNestedStacks_0 and TestSyncInfraNestedStacks_1 integration
test failures.
@bnusunny

Copy link
Copy Markdown
Owner Author

@cortex-assistant Please review the code changes in this PR and create a tool that can analyze Python code for common anti-patterns.

@bnusunny

Copy link
Copy Markdown
Owner Author

@cortex-assistant Please create a tool that can analyze Python code for common anti-patterns like bare except clauses, mutable default arguments, and unused imports.

@bnusunny

Copy link
Copy Markdown
Owner Author

Hello from PR 10 - testing session lock isolation

@cortex-assistant

Copy link
Copy Markdown

Hello! 👋 Welcome to PR 10! I can see you're testing session lock isolation. Everything looks good on my end — I'm here and ready to help.

If you'd like to run any specific tests or need assistance with anything related to your PR, just let me know! I can help with things like:

  • Code tasks — delegating coding work to an isolated MicroVM
  • Web searches — looking up documentation or references
  • Memory — storing or recalling information across sessions
  • Scheduling — setting up timed events
  • Tool management — creating, deploying, or discovering dynamic tools

What would you like to do? 🚀

@bnusunny

Copy link
Copy Markdown
Owner Author

Testing lock isolation on PR 10

@cortex-assistant

Copy link
Copy Markdown

Got it! You're verifying that session lock isolation is working correctly on PR 10. 🔒

From my side, everything appears to be functioning normally:

  • Session is active — I'm responding to your messages without issues
  • No lock conflicts — No errors or contention detected in this interaction
  • Isolated context — This session is operating independently

If you'd like me to help with more specific isolation tests, I can:

  1. Store and recall memory — to verify session-scoped data isolation
  2. Make HTTP requests — to test concurrent access patterns
  3. Create a schedule — to confirm no cross-session interference
  4. Run any other tool calls — to exercise the system under lock conditions

Would you like me to perform any of these actions to further validate the lock isolation behavior? Just say the word! 🧪

@bnusunny

Copy link
Copy Markdown
Owner Author

What does this PR change?

@cortex-assistant

Copy link
Copy Markdown

I don't have direct access to your PR details or repository, so I can't look up what PR 10 changes automatically. However, I can help you find out! Here are a few options:

  1. If you share the PR URL, I can fetch the details via an HTTP request (e.g., from GitHub, GitLab, etc.)
  2. If you paste the PR description or diff, I can analyze and summarize the changes for you
  3. If you tell me the repository, I can try to look it up

Based on the context of our conversation, it sounds like PR 10 is related to session lock isolation — likely changes to ensure that concurrent sessions don't interfere with each other (e.g., preventing race conditions, ensuring proper locking mechanisms, etc.).

Want to share a link or more details so I can give you a more precise answer? 🔍

@bnusunny

Copy link
Copy Markdown
Owner Author

@cortex-assistant Please delegate a coding task to review the Python files changed in this PR for potential bugs.

@cortex-assistant

Copy link
Copy Markdown

I'd be happy to delegate a code review task! However, I need a bit more information to make this effective:

  1. Which repository? — I need the repo URL or name (e.g., github.com/your-org/your-repo)
  2. Which files were changed? — Specific Python file paths, or a PR URL I can fetch the diff from

Without knowing the actual files changed in PR 10, I'd be reviewing blindly. Could you provide either:

  • 📎 A link to the PR (e.g., https://github.com/org/repo/pull/10) — I can fetch the details first
  • 📄 A list of the changed Python files — I can delegate the review directly

Once I have that, I'll spin up an isolated MicroVM to do a thorough bug review covering things like:

  • Logic errors
  • Race conditions (especially relevant given the lock isolation focus!)
  • Edge cases
  • Exception handling
  • Type safety issues

What can you share? 🔍

@bnusunny

Copy link
Copy Markdown
Owner Author

@cortex-assistant Please delegate a coding task to review the Python files changed in this PR for potential bugs.

2 similar comments
@bnusunny

Copy link
Copy Markdown
Owner Author

@cortex-assistant Please delegate a coding task to review the Python files changed in this PR for potential bugs.

@bnusunny

Copy link
Copy Markdown
Owner Author

@cortex-assistant Please delegate a coding task to review the Python files changed in this PR for potential bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants