Repository navigation
fix(antigravity): run multiple sessions in parallel - #446
Merged
Merged
Conversation
Antigravity sends held a global gate for the whole response, so a second chat could not start until the first finished (up to ten minutes). The gate exists because two agy processes launched in quick succession hang under PRoot, which is a startup-window problem: the official CLI's own guest-state initialization is not safe to race. Keep that startup window serialized, then let each session's already-started process stream alongside the others. The session records and process table are now safe for concurrent sessions: records keep insertion order under an explicit monitor, and record persistence serializes its snapshot.
Register a turn's process before the startup grace begins so the stop button can reach it during that window, and remove (and terminate) a process that dies on a read/parse failure instead of leaving a stale entry that blocks title summarisation for every session.
Contributor
|
Debug APK built successfully Download APK artifact Commit: |
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.
概要
Antigravity で複数セッションを開くと、1つの応答が終わるまで他のセッションが送信できない問題を修正します。
原因は
AntigravityProcessGateが応答完了までグローバルロックを保持していたことです。このロックは「PRoot/Android 上でagyを短時間に連続起動すると停止する」という実機観測への対策ですが、実際に危険なのは CLI 自身のゲスト状態初期化が競合する起動ウィンドウだけです。recordsを insertion-order の synchronized map にし、永続化を直列化Claude Code / Codex / OpenCode には同等の全セッション共通送信ロックがないことも確認済みです(Codex は単一 app-server が複数スレッドを多重化、Claude Code はセッションごとにプロセス、OpenCode V2 はセッション単位の Mutex)。
検証
./gradlew :app:testGithubDebugUnitTest --tests 'com.yugahashimoto.andcode.runtime.local.Antigravity*'成功./gradlew detekt spotlessCheck成功Pre-PR review
再レビュー完了。HEAD
aee50033、差分 4 ファイル(AntigravityProcessGate.kt/AntigravityRuntime.kt/AntigravityTarget.kt/AntigravityProcessGateTest.kt)、working tree はクリーン。origin/mainの先行 5 コミットはいずれも Antigravity に非接触で、origin/main...HEADは本ブランチ分のみを正しく反映しています。全 hunk と、追加されたtry/finally・二引数removeの前後コードを確認しました。判定: APPROVE
ブロッカー
なし
提案(非ブロッキング)
app/src/main/java/com/yugahashimoto/andcode/runtime/local/AntigravityRuntime.kt:296— 新規のerror("Antigravity is busy and the turn could not be scheduled")はSessionError経由でChatViewModelのerror = message(ChatViewModel.kt:2477-2483)として生表示されます。同ファイル既存の"Antigravity is not installed"/"agy exited with ..."と同じ生英語パターンで CI の i18n-check(ロケールキー一致のみ)は落ちませんが、*Messages注入方針からは外れたままです(前回指摘から変更なし・既存踏襲のため非ブロッキング)。ローカライズするなら本サブシステム全体をまとめて寄せるのが妥当です。AntigravityRuntime.kt:408— 念のための整合確認:processes.remove(sessionId, process)は「自分が登録した値のときだけ」false を返し得るため、同一セッションの後発 send が先にエントリを差し替えた場合に後発プロセスを巻き添え終了しないことを確認しました(&&短絡でterminateも回避)。実装は正しいです。なおabort()とfinallyが同時刻にterminateを呼ぶ可能性は残りますが、いずれもkillProcessTreeで実害はなく、finally側はrunCatchingで包まれており問題なし。チェック済み項目
ProcessBuilder(...).start().also { processes[sessionId] = it }がacquireThenReleaseブロック内に入り、猶予 2.5 秒+ロック待ちの間もabort()/abortAll()/remove()がプロセスを検知・停止できることを確認。block()がstart()前に例外を投げた場合は未登録のまま伝播しリークしないこと、start()成功後の登録なので中止時にmarkIntentionalが正しく立つことも確認。finallyがprocesses.remove(sessionId, process)で自身のマップエントリを除去し、isAliveのときのみterminateする構造を確認。正常終了・意図的 abort・クラッシュ(require(exitValue==0)例外)の各経路で finally が走り、旧コードのprocesses.remove(sessionId)(正常系のみ)によるマップ残留=summarizeTitle()恒久停止の問題が解消されていることを確認。二引数removeにより後発プロセスを誤殺しないこと、terminateの二重呼び出しが無害化されていることも確認。try内のreturn@runCatching(turnFinished / wasKilledIntentionally)は finally 実行後に戻り、旧return@serializeと同じ結果(finalText.orEmpty())になること。process.waitFor()後のconsumeIntentional順序が変わっていないこと。records=Collections.synchronizedMap(linkedMapOf())で全イテレーション(listSessions 432, workspacePaths, archive, persistRecords)がsynchronized(records)下、単一 get/put のみロック外。processes=ConcurrentHashMap。persistRecordsのsynchronized(recordsFile)とAntigravityMessageStore.flush()の@Synchronized(別 tmp ファイル)で永続化が直列化され破損しないこと。acquireThenRelease lets a second session start while the first is runningが「ストリーミング中でも 2 本目が 5 秒以内に取得できる」ことを検証し、旧 serialize 相当(60 秒待ち)を確実に落とせることを確認。refreshRateLimits/summarizeTitle/AntigravityTargetのコメントが新挙動(並行ストリーミング・processes.isNotEmpty()ガードは「視聴中チャットの容量を奪わない」意図)に更新され、実装と一致。AntigravityProcessGateのserialize削除・doc 更新も整合。java.io→java.util.Base64/Collections/concurrent.ConcurrentHashMap)は ktlint 規約内、行長.editorconfig140 以内、try/finally追加による return 数は 2(閾値 4 以内)。※当環境は./gradlew実行不可のため detekt/spotless は手確認に留めています。origin/main先行分とファイル重複なし=マージ競合なし。working tree クリーン(aee50033)。