Repository navigation
fix(monetization): split bootstrap() to stop test deadlock (RCA Fix B) - #135
Merged
Merged
Conversation
…top test deadlock (RCA Fix B)
Applies Fix B from meetings/2026-05-25_swift-test-hang-rca.md.
Root cause (RCA H1): MonetizationStateController.bootstrap()
unconditionally spawned a `Task { for await event in
iapClient.purchaseUpdates() }` whose lifetime ran until controller deinit.
swift-testing keeps suite instances alive for the full run, and
FakeIAPClient.finishUpdates() was never called — so 19 tests each
leaked a long-lived @mainactor task, deadlocking the suite under
default parallelism against 17 @mainactor snapshot suites.
Fix:
- bootstrap() now does one-shot reads only (no Task spawn)
- New startListeningForLifetimeOfApp() owns the lifecycle subscription
- AppComposition.live calls startListeningForLifetimeOfApp() eagerly at
composition; Views continue calling bootstrap() from .task
- 3 purchaseUpdates tests start the listener explicitly + tear down via
`defer { Task { await iap.finishUpdates() } }` (defer cannot await
directly; combined with deinit cancellation, the for-await terminates)
- 2 tap-only tests intentionally do NOT start the listener (proves split)
Validation:
- `swift test --filter MonetizationStateControllerUpdatesTests` → 6/6 pass in 0.059s
- Full `swift test` no-filter → exit 0, all suites pass (RCA H1 empirically confirmed)
--no-verify note: lefthook pre-commit deadlocked on parallel `mise exec
swiftlint` + `mise exec gitleaks` — exact RCA H4 mode. Validated manually:
swiftlint shows only pre-existing warnings on these files (no new
violations from this diff); gitleaks clean. Follow-up: serialize lefthook
pipeline per RCA prevention.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
This was referenced May 25, 2026
wei18
added a commit
that referenced
this pull request
May 25, 2026
…ps resolution (#142) Captures the day's outcome (10 PRs merged into main) and the infrastructure crisis that drove the methodology iteration: - RCA H1 (swift-test no-filter hang) → Fix B #135 - RCA H4 (lefthook parallel mise deadlock) → #136 - 4 subagent sandbox limits discovered the hard way - 3 lost-work events (worktree wipe before commit) - Methodology §派發契約 §9-12 + patterns + anti-patterns codified in #137 Plus end-to-end records of: #67 (error funnel), #64 (wire-or-delete with REJECT → APPROVE-WITH-NITS round trip), #139 (Settings UX redesign via UI Designer subagent), AdMob banner wiring still in flight. Per docs/methodology.md backlog-routing convention (collaboration patterns → meetings/{date}_{topic}.md). Co-authored-by: Claude Opus 4.7 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Applies Fix B from
meetings/2026-05-25_swift-test-hang-rca.md.Unblocks recurring `swift test` hang that has bitten this repo multiple sessions and was forcing subagents to either kill stuck procs or use `--filter` workarounds.
Root cause (RCA H1)
`MonetizationStateController.bootstrap()` spawned a long-lived `Task { for await event in iapClient.purchaseUpdates() }` that ran until controller `deinit`. swift-testing keeps suite instances alive for the full run; `FakeIAPClient.finishUpdates()` was never called by tests. 19 tests × 1 leaked `@MainActor` task → main-actor deadlock under default parallelism vs 17 `@MainActor` snapshot suites.
Fix
Validation
`--no-verify` note
Lefthook pre-commit deadlocked twice on parallel `mise exec swiftlint` + `mise exec gitleaks` — exact RCA H4 mode reproduced. Validated manually: swiftlint shows only pre-existing warnings on these files; gitleaks 0 leaks. Follow-up should serialize the lefthook pipeline (RCA prevention bullet 2).
Test plan
🤖 Generated with Claude Code