Repository navigation
ADFA-7249 | AI-Core: fix the races in three ChatViewModel test classes - #176
Open
davidschachterADFA wants to merge 3 commits into
Open
davidschachterADFA wants to merge 3 commits into
davidschachterADFA wants to merge 3 commits into
Conversation
…mpactionTest A failed run sets AgentState.Error, adds its error message, and clears its in-flight flag last. send() and retry() stopped waiting at the error state, so the next step could read before the message existed, or retry while the run was still in flight, which ignores the retry. Both now wait on canChangePrompts, which turns true only after the flag is cleared. With a 300 ms sleep added before the flag is cleared (proof only), the old helpers fail and the new ones pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…ditTest A run sets AgentState.Idle before it clears its in-flight flag. The waits stopped at Idle, so editPrompt could return BUSY, a fork never started, or sendMessage returned false. They now also wait on canChangePrompts. The hunks are the same as in #154 (ADFA-6767), so both merge cleanly. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…eueTest The title request runs on Dispatchers.IO. Two tests verified the generateCompletion call without waiting for it; they now verify with a timeout. With a 300 ms delay at the start of the request (proof only), the old checks fail and the new ones pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
Contributor
Author
|
Thanks. On the three risks in the summary:
|
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.
Jira: ADFA-7249
What: three AI-Core test classes failed now and then, more often under CPU load, because a test went on before the work it checks had finished. This changes only the tests: no production code, and the
.cgpis unchanged.Why they failed
ChatViewModelCompactionTest: a failed run setsAgentState.Error, then adds its error message, and clears its in-flight flag last, in afinally(ChatViewModel.kt, the end of the run). Thesend()andretry()helpers stopped waiting atAgentState.Error. The next step could then read before the message existed, or callretryLastRun()while the run was still in flight, which ignores it, and the next wait timed out.ChatViewModelPromptEditTest: a run setsAgentState.Idlebefore itsfinallyclears the in-flight flag.sendAndAwaitand the other waits stopped atIdle.editPromptcould then returnBUSYinstead ofSTARTED, a fork never started and the next wait timed out, orsendMessagereturned false.ChatViewModelTitleQueueTest: the title request runs onDispatchers.IO. Two tests checked thatgenerateCompletionwas called without waiting for it.The fix
ChatViewModelCompactionTest: both helpers wait oncanChangePrompts, which turns true only after the in-flight flag is cleared.AgentState.Errordoesn't count as running, so a failed run still ends the wait.ChatViewModelPromptEditTest: the waits useagentState == Idle && canChangePrompts. These hunks are line for line the ones in ADFA-6767 | Put prompt actions beside the bubble and add a full-screen chat #154 (ADFA-6767), so the two PRs merge cleanly in either order.ChatViewModelTitleQueueTest: the two checks useverify(timeout = WAIT_MS).Tests
Each fix was proved by widening its race on purpose, with a 300 ms sleep added to
ChatViewModelfor the proof only, never committed:ChatViewModelCompactionTestandChatViewModelPromptEditTest, with a sleep before the in-flight flag is cleared: at main, 12 of the 30 tests in the two classes fail; with this PR, none.ChatViewModelTitleQueueTest, with a delay at the start of the title request: at main, both tests fail; with this PR, neither.Without any added sleep:
taskset -c 0,1): main failed in 3 of 3 runs, and this PR passed 5 of 5.testDebugUnitTestat the head: 10 runs in a row, 1,342 tests each, 0 failures, 5 of the runs pinned to 2 cores. Before the title fix, 3 of the 5 pinned runs failed one title test; that is how the third race was found.assemblePluginandaddons checkpass.Version: no bump. Only tests change, and the
.cgpis the same; #152 (ADFA-6795), a test-only fix to these classes, merged without one.🤖 Generated with Claude Code
https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn