Repository navigation
fix(android): guard AlphaLocalAgentRunner phase transitions against stop races - #2398
Open
NubsCarson wants to merge 1 commit into
Open
NubsCarson wants to merge 1 commit into
NubsCarson wants to merge 1 commit into
Conversation
…top races Guard lifecycle phase, epoch, and failure-detail transitions in AlphaLocalAgentRunner under lifecycleLock so an in-flight async launchLocked(), failLocked(), markReadyLocked(), watchExit(), or failOrScheduleRestartLocked() task on the serial executor cannot flip statusJson() back to starting, running, or failed after stop() sets desiredRunning = false or restart() advances activeEpoch. Make statusJson() and isRunning() read lifecycle state atomically under lifecycleLock (always reporting stopped with epoch 0 whenever !desiredRunning), track childEpoch separately so queued stop teardown retires only the child it tears down, and add deterministic async-stop and stress-cycle regression tests in AlphaAgentServiceLocalHandoffTest.
NubsCarson
requested a deployment
to
turbo-cache-read
December 4, 2026 20:05 — with
GitHub Actions
In progress
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
This branch was successfully deployed
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
Fixes the thread race in
AlphaLocalAgentRunnercaught onmain(Resident Android exact sourcerun47400748049,AlphaAgentServiceLocalHandoffTest.localRunnerLifecycleTransitionsAreSynchronousAndRaceFreeatAlphaAgentServiceLocalHandoffTest.java:113):start()queuedlaunchLocked(targetEpoch, ...)onserial, which mutatedphase(Phase.STARTING/Phase.FAILEDviafailLocked) andactiveEpochwithout holdinglifecycleLockor re-checkingdesiredRunning && activeEpoch == epochafterstop()synchronously setdesiredRunning = false; phase = Phase.STOPPED.statusJson()also readphasewithout holdinglifecycleLockand lacked a!desiredRunningguard, so a racinglaunchLocked/failLockedcausedisActive()to returnfalsewhilestatusJson().optString("state")reverted to"starting"or"failed".apps/app/android/app/src/main/java/ai/alphacompute/alphaphone/AlphaLocalAgentRunner.java):phase,activeEpoch,failureReason, anderrorDetailreads/writes acrosslaunchLocked,failLocked,markReadyLocked,watchExit,failOrScheduleRestartLocked,stop,isRunning,onReady, andstatusJsonunderlifecycleLock, verifyingdesiredRunning && activeEpoch == epochbefore mutating state or spawning a child process.statusJson()captures an atomic snapshot underlifecycleLockand always reportsstate: "stopped"andepoch: 0(with nofailure/errorfields) whenever!desiredRunning.childEpochseparately onserialsoteardownChildLocked()retires only the torn-down child's epoch instead of a neweractiveEpochreserved by a subsequentstart().failOrScheduleRestartLockedfrom callingfailLockedwhen!desiredRunningor when superseded by a newer epoch, and reserve retry epochs atomically underlifecycleLock.apps/app/android/app/src/test/java/ai/alphacompute/alphaphone/AlphaAgentServiceLocalHandoffTest.java):stopDuringAsyncLaunchFailureNeverRevertsStatusFromStopped(stops immediately upon the async launch observer callback right before Robolectric's async launch failure path runs, drainingserialvia a FIFO barrier and verifyingstate == "stopped",epoch == 0, and nofailure/error).repeatedStartRestartStopCyclesKeepStoppedStateAndMonotonicEpochs(60 rapidstart/restart/stopcycles with varying micro-delays and a linearizable seqlock observer verifying atomic snapshots and monotonic epochs).Verification
./gradlew --no-daemon -PelizaParadeeApiOnly=true -PelizaSpeechBridgeCapacitor=true :app:testLauncherDebugUnitTest --rerunagainst pinnedeliza@8dc9b2db6def:33test suites,133/133tests PASS (0failures,0errors,0skipped)AlphaAgentServiceLocalHandoffTest(6/6tests) repeated 3 consecutive--rerunruns:18/18PASS (0flakes)pnpm no-bun(via Boatvibestack-remote) andgit diff --check: PASS