Repository navigation
fix(opencode): implement Work and Code distinct Review subagents - #201
Conversation
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Code Review SummaryStatus: 4 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)CRITICAL
WARNING
SUGGESTION
Files Reviewed (14 files)
Fix these issues in Kilo Cloud Previous Review Summaries (2 snapshots, latest commit 32ae7f4)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 32ae7f4)Status: 4 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)CRITICAL
WARNING
SUGGESTION
Files Reviewed (14 files)
Fix these issues in Kilo Cloud Previous reviewThis review did not finish. The model reached its output limit before it Reviewed by free · Input: 0 · Output: 0 · Cached: 0 |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
ea76f20 to
32ae7f4
Compare
| * here is itself a member of `REVIEW_AGENTS`, so a routed request still passes | ||
| * the report gate. | ||
| */ | ||
| export const REVIEW_ROUTING: Record<string, string> = { |
| * here is itself a member of `REVIEW_AGENTS`, so a routed request still passes | ||
| * the report gate. | ||
| */ | ||
| export const REVIEW_ROUTING: Record<string, string> = { |
There was a problem hiding this comment.
SUGGESTION: REVIEW_ROUTING is typed as a plain Record<string, string> with no exhaustiveness guard, so adding a new runtime (e.g. desktop) without a routing entry silently falls back to the generic review agent — the same silent-degradation failure mode the file's own docblock warns about for REVIEW_AGENTS. Since every value must itself be a member of REVIEW_AGENTS, a discriminated-union type keyed on the known parent agents (e.g. Record<'work' | 'code', (typeof REVIEW_AGENTS)[number]>) would make a missing entry a compile error rather than a runtime fallback. The guard test in review-specialization.test.ts only checks the three existing entries, so this gap is currently unproven either way.
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
| // it is the CHILD's agent, so it would select a reviewer by the child's | ||
| // identity. Hydration is deferred into the fallback so a pinned session | ||
| // never pays for it. | ||
| const resolveParentAgent = Effect.fnUntraced(function* (session: { agent?: string }) { |
There was a problem hiding this comment.
CRITICAL: resolveParentAgent swallows the parent session's NotFound error. sessions.get(ctx.sessionID) at line 122 already throws NotFound for a missing parent, but the fallback at lines 151-153 catches all causes with Effect.catchCause(() => Effect.succeed([])) and then returns undefined from findLast(...)?.info.agent. A task dispatched against a deleted/invalid parent session therefore resolves parentAgent to undefined, resolveReviewer falls back to the generic review agent, and the subagent runs with the wrong prompt and permissions instead of failing loudly. The original code at line 344 also used catchCause, but it had ?? ctx.agent as a final tier, so a missing session still resolved to a real agent. That tier was dropped in this change. Either rethrow NotFound (let the session-get failure propagate) or catch only the specific not-found cause and fail the task explicitly.
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
| // grants and user config rules (`permission.task.review`) are written | ||
| // against it. Re-keying on the runtime routing decision would silently | ||
| // re-prompt returning users and silently drop their `deny` rule. | ||
| patterns: [params.subagent_type], |
There was a problem hiding this comment.
WARNING: The permission prompt is keyed on params.subagent_type (the requested name, e.g. "review") while the metadata.subagent_type sent in the same prompt carries the resolved reviewer (work-review / code-review). The comment at lines 181-185 argues this is correct because user grants and permission.task.review rules are written against the requested name — but the metadata field is what UIs, audit logs, and any consumer of part.state.input.subagent_type read (see subagent-data.ts:312, tool.ts:381, session-data.ts:413). A user who configured an always-allow or deny rule against work-review or code-review directly will see it silently never match, and the stored tool input will disagree with the rule that actually gated it. Align the two: either send the requested name in metadata too, or document explicitly why the divergence is intentional and update the comment.
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
| currentParent.agent ?? parentMessages.find((message) => message.info.role === "user")?.info.agent ?? ctx.agent | ||
| // path, so it is not a candidate; the shared resolution above reads the | ||
| // parent session and its newest user message instead. | ||
| const parentAgent = yield* resolveParentAgent(currentParent) |
There was a problem hiding this comment.
WARNING: The background delivery path re-resolves the parent agent via resolveParentAgent(currentParent) here, but the child run itself is launched with agent: next.name (the resolved reviewer) at line 275. So a background review's delivery agent is decided by two different mechanisms: the child session row's pinned agent for its own turns, and a fresh parent-agent read for the synthetic notification injected into the parent. If the parent session's pinned agent and its newest user message ever disagree (mid-session agent switch, the exact case this routing exists to handle), the background notification can be written under a different agent than the one that dispatched it. Pick one resolution site and reuse it for both the child agent and the notification agent.
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
Issue #113. The generic `review` subagent becomes a request rather than an identity: the task tool resolves which reviewer runs from the parent agent, so `work` dispatches work-review, `code` dispatches code-review, and any other parent keeps the existing generic `review`. Every routing target is itself a member of the reviewer set, so a routed request still passes the report gate. All three reviewers share one `reviewPermissions` block, extracted from the existing `review` definition, so they keep the plan-equivalent inspection permissions including `bash` for reproducing and verifying runtime behaviour, with edit denial enforced at the permission seam. The split is domain focus only: identical capability, identical standard, no description implying a weaker bar. The report gate is keyed on agent name, and a name missing from the set completes a review without a verdict rather than failing loudly. The names therefore live in one module, `REVIEW_AGENTS` for the gate and `REVIEW_ROUTING` for dispatch, with a `ReviewAgent` union making "a routed target is itself a reviewer" a compile error. Centralising reduces the failure mode; it does not remove it, and the module says so. Parent-agent resolution reads the session row, then the newest user message naming an agent, because a session row's `agent` is null for the default session. `MessageV2.page` returns messages oldest-first, so this uses `findLast`; reading the oldest message would invert the routing in exactly the mid-session agent switch it exists to handle. `ctx.agent` is deliberately not consulted, because on the subtask path it is the child's agent. The read is memoized and yielded only when a review routes or a background result is delivered, so other delegations never pay for it. An unreadable parent fails the dispatch explicitly instead of resolving to no agent and silently falling back to the generic reviewer with the wrong prompt and permissions. The catch is narrowed to `NotFound` so any other cause stays a defect rather than being reinterpreted. The task permission prompt is keyed on the requested `subagent_type` together with the resolved name, because stored always-allow grants and user config rules are written against either, and a deny on one name must not be bypassed by an allow on the other. Stale read-only wording that #165 made false is corrected, and the two new reviewer prompts no longer claim they cannot run commands.
32ae7f4 to
d412f67
Compare
Issue for this PR
Closes #113
Type of change
What does this PR do?
Adds distinct Review subagents for the Work and Code runtimes.
The generic
reviewsubagent becomes a request rather than an identity. The task tool resolves which reviewer actually runs from the agent that made the request: aworkparent dispatcheswork-review, acodeparent dispatchescode-review, and any other parent keeps the existing genericreview. Every value in the routing table is itself a member of the reviewer set, so a routed request still passes the report gate.Why they are not read-only. The reviewers share one
reviewPermissionsblock, extracted from the existingreviewdefinition, so they keep the plan-equivalent inspection permissions includingbashfor reproducing and verifying runtime behaviour, with edit denial enforced at the permission seam. An earlier version of this PR defined both new reviewers with a blanket"*": "deny", which would have silently reverted #165. The split is domain focus only: all three reviewers are identical in capability and in the standard they apply, and none of their descriptions advertise a weaker bar.Why the reviewer names are centralised. The report gate that requires every reviewer to deliver a parseable
<alphacode-review>envelope is keyed on agent name. A name missing from the set completes a review without a verdict rather than failing loudly. The names therefore live in one module (REVIEW_AGENTSfor the gate,REVIEW_ROUTINGfor dispatch) instead of being compared inline at each of the four call sites. Centralising reduces the failure mode; it does not remove it, and the module says so.Parent-agent resolution. A session row's
agentis null for the default session, so the newest user message naming an agent is the fallback that actually identifies what is driving the session.MessageV2.pagereturns messages oldest-first, so this usesfindLast; reading the oldest message would invert the routing in exactly the mid-session agent switch it exists to handle.ctx.agentis deliberately not consulted, because on the subtask path it is the child's agent.Permission keying. The task permission prompt stays keyed on the requested
subagent_type, not the resolved reviewer, because stored always-allow grants and user config rules are written against that name. Re-keying on the runtime routing decision would silently re-prompt returning users and silently drop apermission.task.reviewdeny rule.Stale "read-only" wording that #165 made false is corrected, and the two new reviewer prompts no longer claim they cannot run commands.
How did you verify your code works?
bun typecheckclean inpackages/opencode.test/session/review-specialization.test.ts15/0test/session/review-loop.test.ts28/0test/session/review-delegation.test.ts5/0test/session/review-stagnation.test.ts58/0test/tool/task.test.ts35/0test/tool/finish.test.ts19/0test/tool/finish-reason.test.ts15/0test/tool/review-finish-history.test.ts1/0One pre-existing failure in
test/agent/work-code.test.ts("permission-denied tools are hidden while finish remains available") reproduces unchanged ondev; it exercises only theplanagent and ToolRegistry, neither of which this PR touches.The ordering fix is mutation-verified: reverting
findLasttofinddrops the mixed-agent routing cases to 12 pass / 3 fail, and restoring returns 15/0.The four findings raised by the Kilo Code review bot on this PR are being addressed; see the PR conversation.
Screenshots / recordings
Not a UI change.
Checklist