Skip to content

fix: prevent watch process crash on invalid template and improve sync test reliability#8652

Merged
bnusunny merged 1 commit intodevelopfrom
fix/sync-watch-crash-and-timeouts
Feb 13, 2026
Merged

fix: prevent watch process crash on invalid template and improve sync test reliability#8652
bnusunny merged 1 commit intodevelopfrom
fix/sync-watch-crash-and-timeouts

Conversation

@bnusunny
Copy link
Copy Markdown
Contributor

Problem

Four sync integration tests were failing:

  1. TestSyncWatchInfraWithInvalidTemplate::test_sync_watch_infra - ValueError: The watch process crashed when an invalid template was applied during sam sync --watch.
  2. TestSyncAdlWithWatchStartWithNoDependencies::test_sync_watch_code - TimeoutError (60s): Layer sync operations exceeded the 60s timeout.
  3. TestSyncInfraNestedStacks_0::test_sync_watch_infra_nested_stack - TimeoutError (600s): Nested stack infra sync exceeded the 600s timeout.
  4. TestSyncInfraNestedStacks_1::test_sync_watch_infra_nested_stack - TimeoutError (600s): Same as above.

Root Cause

The ValueError was caused by an unhandled exception in watch_manager.py. When infra sync fails (e.g., invalid template), the error handler calls _add_template_triggers() to re-register file watchers. However, _add_template_triggers() calls SamLocalStackProvider.get_stacks() which can also throw if the template is unparseable. This unhandled exception propagated up and crashed the watch process's main loop, causing the process to exit.

The TimeoutError failures were due to timeouts that were too tight for the operations being performed.

Fix

  • samcli/lib/sync/watch_manager.py: Wrap _add_template_triggers() in try/except within the infra sync error handler so the watch process survives and can recover when the template is fixed.
  • tests/testing_utils.py: Add descriptive message to the bare raise ValueError() in read_until, and catch ValueError in read_until_string to include expected output context for better debugging.
  • tests/integration/sync/test_sync_adl.py: Increase layer sync timeouts from 60s to 120s.
  • tests/integration/sync/test_sync_watch.py: Increase nested stack infra sync timeout from 600s to 900s.

Testing

Verified with real AWS deployments on fork — all 4 tests passed in two consecutive runs:

  • Run 1: 4 passed in 8m34s
  • Run 2: 4 passed in 8m18s

… test reliability

- 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
@bnusunny bnusunny requested a review from a team as a code owner February 13, 2026 05:10
@bnusunny bnusunny added this pull request to the merge queue Feb 13, 2026
Merged via the queue into develop with commit f92e9df Feb 13, 2026
46 checks passed
@bnusunny bnusunny deleted the fix/sync-watch-crash-and-timeouts branch February 18, 2026 16:48
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.

3 participants