[Fix] ACA Sandboxes wake-loop fix and improved suspend state management - #1018
Merged
mrubens merged 5 commits intoAug 3, 2026
Merged
Conversation
- Finalize runs when Azure instance is missing instead of retrying forever - Re-suspend orphaned Azure standby instances during retention job - Kill stale worker processes before launching new Azure worker - Terminate worker when heartbeat reports run finalized - Use Manual port activation to prevent unintended sandbox wakes
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
standby retention logic, and remove redundant ESLint disable comments for explicit any usage.
Contributor
|
No new code issues found. See task
Reviewed d760153 |
On a 409 from ports/add, remove and re-add the port with Manual activation instead of silently accepting the conflict. Ports persist across stop/resume, so legacy OnDemand ports keep waking suspended sandboxes on any inbound traffic. Ports already on Manual are left untouched.
tebieshi
marked this pull request as ready for review
August 3, 2026 16:58
tebieshi
requested review from
brunobergher,
daniel-lxs and
mrubens
as code owners
August 3, 2026 16:58
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses an Azure Container Apps sandbox suspend/wake “death loop” by preventing out-of-band wakes, cleaning up zombie worker processes on resume, re-suspending orphaned retained standbys, and finalizing runs when the underlying Azure instance has been deleted.
Changes:
- Switched Azure sandbox port exposure to Manual activation and added a conflict-time migration to recreate legacy OnDemand ports.
- Made workers self-terminate when the control plane reports their run is finalized; added a pre-launch reaper for leftover workers on resume/restore.
- Enhanced BullMQ jobs to re-suspend retained standbys found running without an owning run and to finalize runs on definitive Azure 404 instance-not-found errors (with tests).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/compute-providers/src/adapters/azure.ts | Change port activation to Manual and migrate legacy ports on conflict. |
| packages/compute-providers/src/tests/azure.contract.test.ts | Update contract expectations and add tests for port-migration behavior. |
| apps/worker/src/run-task/polling/worker-heartbeat.ts | Exit worker on terminal run-token guard heartbeat failure. |
| apps/worker/src/run-task/polling/worker-heartbeat.test.ts | Add unit test ensuring terminal-run heartbeat triggers worker exit. |
| apps/controller/src/compute-providers/spawn-azure-worker.ts | Reap leftover worker processes before launching a new worker on resume/restore. |
| apps/bullmq/src/scheduled-jobs/standby-retention.ts | Re-suspend orphaned retained standbys that are running, with active-run guards. |
| apps/bullmq/src/scheduled-jobs/sleep-check.ts | Finalize runs when Azure definitively reports instance-not-found (404). |
| apps/bullmq/src/scheduled-jobs/tests/standby-retention.test.ts | New tests for orphan re-suspend behavior and guard conditions. |
| apps/bullmq/src/scheduled-jobs/tests/sleep-check.test.ts | Tests for 404 finalization + transient error retry behavior. |
| apps/bullmq/src/jobs/snapshot.test.ts | Update eslint-disable comment to match tooling behavior. |
| .changeset/aca-sandboxes-sleep-wake-remediation.md | Changeset describing the end-user visible remediation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+74
to
+77
| if ( | ||
| heartbeatError instanceof Error && | ||
| heartbeatError.message.includes(RUN_TERMINAL_HEARTBEAT_MESSAGE) | ||
| ) { |
Comment on lines
+412
to
+417
| .runCommand({ | ||
| instanceId: machine.machineId, | ||
| cmd: 'pkill', | ||
| args: ['-f', '/sandbox/worker/dist/worker.js'], | ||
| signal: AbortSignal.timeout(15_000), | ||
| }) |
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.
Related issue
N/A
Why this PR exists
in the linked issue or discussionWhat changed
Fixes an Azure Container Apps Sandboxes sleep/wake death loop: after a task was suspended (standby), every wake attempt died on "waking up" and the sandbox never stayed suspended.
Four interlocking defects, verified live against sandbox + DB event timelines:
→ Workers now terminate themselves when the server reports their run as finalized (heartbeat rejects with the terminal run-guard message), and resume launches reap leftover workers (
pkill) before booting the new one.snapshotId IS NULL, so a retained standby sandbox left Running (failed wake, portal stop/start, legacy port wake) was never re-suspended.→ Standby-retention (5-min cadence) now re-suspends azure retained handles whose instance reports
running, guarded so it never touches a sandbox an active run owns.OnDemandactivation resumes a suspended sandbox on any inbound traffic, but standby runs are always Completed at suspend time, so traffic-driven wakes could only orphan.→ All Roomote-added sandbox ports now use
Manualactivation; wake is deliberate-only (wake prompt / message send).getInstanceStatus(sandbox deleted out-of-band) went down the generic retry path and re-failed every minute indefinitely.→ Definitive not-found now finalizes the run (idle → complete; otherwise fail/cancel).
How it was tested
Manualport activation.pnpm lintandpnpm check-typespass on all four touched packages.Stoppedat the keepalive deadline, and the standby handle was recorded for the next wake.Checklist
[Fix],[Feat],[Improve],[Refactor],[Docs], or[Chore]followed by a user-facing descriptionpnpm lintandpnpm check-typespass locallypnpm changeset