Repository navigation
fix: prevent reviewer sessions from cluttering chat history - #51
Conversation
dyoshikawa
left a comment
There was a problem hiding this comment.
Thanks for this — linking the reviewer session to its parent and cleaning it up afterwards is a good idea, and I'd like to take it.
It can't be merged as-is though: main has moved 23 commits since this branch and src/agent-reviewer.ts now conflicts (the agent reviewer gained a runtime option, so create now passes (agent.runtime === "opencode" ? agent.model : undefined) ?? input.model). Could you rebase onto main? Please keep parentID/remove limited to the V2 OpenCode client so the Claude/Codex runtimes and V1 stay unchanged.
While you're there, two things I'd like changed (see the inline comment): remove should not be able to hold up the verdict, and since the reviewer transcript is currently the only record of why something was allowed, I'd rather not delete it unconditionally. A follow-up for V1 (its SDK also has parentID and session.delete) would be welcome but isn't required here.
| try { | ||
| // V2 removes temporary sessions; V1 keeps its existing behavior. | ||
| // Cleanup must never replace the review verdict or error. | ||
| await this.#client.remove?.({ sessionID }); |
There was a problem hiding this comment.
This await isn't covered by withTimeout, so if session.remove hangs (or waits for the run that abort just interrupted without awaiting) the permission hook stays blocked past reviewer.timeoutMs. I'd make this best-effort and non-blocking, e.g. void this.#client.remove?.({ sessionID }).catch(() => undefined) after the verdict is settled (dropping the ID from #reviewerSessionIDs once it finishes), or wrap it in a short timeout. A test where remove never resolves and review() still returns in time would pin it down.
Also, with the audit log off by default and it only recording verdict/category, the reviewer session is the only place you can see what the reviewer read and why it allowed something. Could removal be opt-in, or at least skipped for allow verdicts and errors? Otherwise it gets hard to investigate a bad approval after the fact.
| await this.#client.remove?.({ sessionID }); | ||
| } catch { | ||
| // The parent relationship still keeps an orphan out of the top-level list. | ||
| } finally { |
There was a problem hiding this comment.
Small thing: this comment only holds for V2 — V1 ignores parentID, so there an orphan still shows up at the top level.
737bfd2 to
306e4d9
Compare
|
Thanks for the review! I've rebased the PR onto the current main (v0.10.0) and addressed your feedback:
Validation passed in my fork's CI: 378 tests, lint, typecheck, formatting, and build. I'd appreciate another review when you have time! |
|
@thisfilipe Thank you! I've collected the remaining small follow-ups in #64. |
Keep both config tests: the cleanupSessions one from dyoshikawa#51 and the allToolsNativeAsks one from this PR. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QUBBebviXSBQtiRAmDopZ7
Summary
Fixes #50.
The V2
agentreviewer currently creates a new top-levelAuto-approval reviewsession for every operation, cluttering the chat history and leaving persistent reviewer sessions behind.This PR fixes the reviewer session lifecycle:
parentID.Tests
Validated on Linux against version 0.7.0:
pnpm cicheck— passed.pnpm build— passed (ESM and CommonJS).Added regression tests covering parent session association, temporary session removal, cleanup after failures, and preservation of reviewer results.
Compatibility
No configuration changes are required. The fix applies to newly created reviewer sessions; existing sessions are unaffected.