fix(agy-acp): use --conversation ID + delta extraction for multi-turn#906
Conversation
This comment has been minimized.
This comment has been minimized.
Review verdict: Comment onlyContributor-only review from my side, so I'm not using approve/request-changes. I checked the diff and I think this is moving in the right direction, but there are two correctness risks worth fixing before maintainers merge it. 🔴 Suggested changes1. File: This PR replaces Why it matters: the PR claims concurrent-session safety, but this implementation can still cross-wire sessions under shared-home or interleaved usage. Suggested fix: bind the conversation ID to the specific invocation, not to the globally newest file. For example, snapshot the conversation directory before the first prompt and compare after the process exits, or preferably parse an explicit conversation/session identifier from 2. delta slicing by raw byte length is fragile and can panic on non-prefix output File: The new delta extraction assumes the latest stdout is always the previous stdout plus appended bytes. If Why it matters: this can turn a formatting mismatch into a runtime crash instead of a harmless fallback, and it makes the adapter dependent on an unstated invariant about Suggested fix: store the previous full text and use Validation checked
|
hana4u
left a comment
There was a problem hiding this comment.
Two concerns here:
-
latest_conversation_id()still guesses the session’s conversation by scanning the global conversations directory for the newest.pb. That is still race-prone under concurrency: another session can create a newer file before this code reads it, and the current session will bind to the wrong conversation ID. That can leak turn 2 into a different session. -
full_text[prev_len..]assumes the new stdout always has the exact previous stdout as a byte prefix. Ifagychanges formatting, adds any prefix noise, or the prefix differs by even one byte, this can either panic on a non-char boundary or emit a corrupted delta. A longest-common-prefix or stream-level delta would be safer.
This comment has been minimized.
This comment has been minimized.
aris-in-ur-mind
left a comment
There was a problem hiding this comment.
Reviewed the diff carefully. Two observations:
1. new_conversation_id returns only the first new file — silent failure when multiple files appear
after.difference(before).next().cloned() picks an arbitrary element if two .pb files are created between the pre/post snapshot (e.g. a fast retry or a parallel first-turn from another session sharing the same HOME). The session silently binds to the wrong ID with no warning. Consider returning an error or logging a warning when difference yields more than one result, so the caller can decide whether to fall back to no-conversation-ID mode rather than guessing.
2. prev_output_len tracks byte length of from_utf8_lossy output, but the fallback re-slices the original
full_text is produced by from_utf8_lossy, which replaces invalid sequences with the UTF-8 replacement character U+FFFD (3 bytes). If the original stdout contained invalid bytes, the stored prev_output_len (based on the lossy string) may not align with the next turn's lossy string at the same logical position. The char_indices fallback handles the panic case, but the delta content could still be slightly off. This is an edge case for non-UTF-8 output, but worth a comment in the code acknowledging the assumption.
Overall the approach is sound and the two issues from the initial review (race condition + UTF-8 panic) are properly addressed. The above are minor robustness points, not blockers.
This comment has been minimized.
This comment has been minimized.
|
Re-check result: the two original issues look addressed.
One remaining edge case: |
aris-in-ur-mind
left a comment
There was a problem hiding this comment.
Re-reviewed after commit 1ee1e5c.
Both issues raised in the initial review are now fixed:
- Race condition in conversation ID discovery: replaced mtime heuristic with pre/post snapshot diff — correctly isolates the new file per session.
- UTF-8 panic risk: replaced direct byte-index slice with
get(prev_len..)+char_indicesfallback — no longer panics on multi-byte boundaries.
LGTM from my side. ✅
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
hana4u
left a comment
There was a problem hiding this comment.
LGTM ✅
The two issues from the initial review are addressed in commit 1ee1e5c:
- race-free conversation ID discovery via pre/post snapshot diff
- UTF-8-safe delta extraction with fallback
No blocking concerns remain from my side.
Code Review — Additional findings not covered in existing discussionAfter reading the full diff and all review comments, I found one regression missed by existing reviewers, plus a minor issue. 🔴 F1: Silent context loss when
|
c7f4c8f to
c3b6a48
Compare
This comment has been minimized.
This comment has been minimized.
|
LGTM ✅ — All findings addressed. Unanimous approval (5/5 法師) at What This PR DoesFixes #905 — multi-turn How It Works
Findings (Final Status)
Addressing External Reviewer Feedback@agent-rapi (Round 1)
✅ Addressed: Replaced with pre/post directory snapshot diff.
✅ Addressed: Uses @hana4u (Round 2)
ℹ️ Accepted: Single-threaded, one agy call at a time. @CoraBot0523 (Round 3)
✅ Addressed: Logs warning to stderr. Does NOT fall back to
ℹ️ Accepted: Harmless for chat output. 擺渡法師 (Round 4)
✅ Addressed in Review Team Verdicts (Unanimous ✅ at
|
| Reviewer | Verdict | Key Contribution |
|---|---|---|
| 超渡法師 | ✅ LGTM | Coordinator, authored fix commits |
| 普渡法師 | ✅ LGTM | Confirmed UTF-8 fix, state transitions clean |
| 覺渡法師 | ✅ LGTM | Confirmed snapshot approach, defensive design |
| 口渡法師 | ✅ LGTM | Confirmed degradation behavior correct |
| 擺渡法師 | ✅ LGTM | Found degraded-mode truncation bug, confirmed fix |
| @agent-rapi | — | Identified core issues pre-fix |
| @hana4u | — | Confirmed fixes, noted HashSet edge case |
| @CoraBot0523 | — | Identified silent context loss regression |
CI Status
✅ All checks passing
Review History
- Round 1: CHANGES REQUESTED — UTF-8 panic, race condition, byte-offset fragility
- Round 2: Fix
1ee1e5c— all 法師 LGTM, @hana4u confirmed - Round 3: @CoraBot0523 found silent context loss → fix
a858a34(warning + graceful degradation) - Round 4: 擺渡法師 found delta truncation in degraded mode → fix
3c80b29(mode-aware delta) - Final: 5/5 法師 unanimous LGTM at
3c80b29
Replace --continue with --conversation <ID> to fix two bugs: 1. Full conversation history repeated on every turn (#905) 2. Concurrent sessions unsafe (--continue targets most recent globally) Now tracks per-session: agy conversation ID (from conversations dir) and cumulative output length. Only emits the delta on each turn. Fixes #905
3c80b29 to
5f985ac
Compare
Summary
Fix multi-turn responses repeating entire conversation history, restore sender context passthrough, and auto-configure workspace for steering files.
Changes
1. Replace
--continuewith--conversation <ID>+ delta extraction~/.gemini/antigravity-cli/conversations/after first prompt via pre/post snapshot diff)--continueif conversation ID discovery fails (prevents silent context loss)2. Restore sender context passthrough
Previously we filtered out
<sender_context>blocks before passing to agy, losing sender UID, thread ID, channel ID, etc. The filtering was a workaround for an earlier hang bug that has since been fixed (stdin=nullon the agy subprocess). Now all content blocks are passed through — agy receives the full context.3. Auto-configure workspace via
--add-diragy-acp now automatically passes
--add-dir <cwd>on everyagyinvocation. The working directory is inherited from openab's[agent].working_dirconfig (which sets the cwd of the agy-acp process). No env var or explicit config needed — just setworking_dir = "/home/agent"in config and steering files there will be picked up.How it works:
[agent].working_dir(e.g./home/agent)std::env::current_dir()--add-dir /home/agentto agy automaticallyAGENTS.md/GEMINI.mdfrom that directory4.
AGY_EXTRA_ARGSenv var (optional)Users can still pass additional flags via
AGY_EXTRA_ARGSif needed.Fixes
--continuetargeted the most recent conversation globally;--conversation <ID>targets the correct one per session--add-dirensures agy reads workspace context automatically--continueif conversation ID can't be discoveredTest
Turn 2 only shows the new response ✅
Fixes #905
Discord Discussion URL: https://discord.com/channels/1371474153303879740/1371474153303879743/1507205720226009108