Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .opencode/configuration/documentation-review/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: documentation-review
description: Provide documentation-focused review feedback for pull requests
mode: primary
model: openrouter/deepseek/deepseek-v4-flash
model: deepseek/deepseek-v4-flash
temperature: 0.1
permission:
edit: deny
Expand Down
2 changes: 1 addition & 1 deletion .opencode/configuration/documentation-review/hashes.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"agent.md": "e41076ae306ce89ba9c7d1b58a48d1435bcb6aef59a612794c8b7ca9d463503f",
"agent.md": "c1627f63e6d213b0123d4bbb7e3f28dc903d9454d41f79a2ba1c488b1eb8fd04",
"prompts/review.md": "fdf01efc28af41a5a61b6575f3953c5c0708c6f9f4155b5e5b1e924e8b83fdf2",
"skills/documentation/SKILL.md": "f5540417be9a2fd2a9b7e21c91e64ad65744a9f9b66e76e8c1b73487527621a1"
}
29 changes: 25 additions & 4 deletions scripts/run_agentic_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,12 @@ def _run_opencode_integrated(
provider_timeout=provider_timeout,
)
if result.returncode:
print(result.stderr, file=sys.stderr)
detail = (result.stderr or result.stdout or "").strip()
print(
f"::error::OpenCode exited with status {result.returncode}. "
f"{detail or 'No diagnostic output was returned.'}",
file=sys.stderr,
)
return result.returncode, result.stdout
finally:
import shutil
Expand Down Expand Up @@ -991,10 +996,26 @@ def review_with_context_loop(*, args: argparse.Namespace, resolved_bundle: dict,
prompt = _compose_integrated_prompt(resolved_bundle=resolved_bundle, feedback_kind=args.feedback_kind, output_contract="pr-review-json-v1", repository=args.repository or "", author_login=args.author, pull_number=args.pull_number, target_title=None, focus=args.focus, max_comments=effective_max_comments, allowed_locations=format_changed_locations(changed_lines), untrusted_content=transcript + ("\n\nNo more context is available. Return final review JSON now." if final_only else ""))
rc, output = _run_opencode_integrated(resolved_bundle=resolved_bundle, agent_name=resolved_bundle.get("agent_name") or "default-agent", prompt=prompt, provider_timeout=provider_timeout)
if rc: return rc, output, audit
try: kind, parsed = PROMPTS.parse_pr_review_response(output, changed_lines=changed_lines, max_comments=effective_max_comments)
except PROMPTS.ContractError: return 1, output, audit
try:
kind, parsed = PROMPTS.parse_pr_review_response(
output,
changed_lines=changed_lines,
max_comments=effective_max_comments,
)
except PROMPTS.ContractError as error:
print(
f"::error::OpenCode response violated the PR review contract: {error}",
file=sys.stderr,
)
return 1, output, audit
if kind == "final": return 0, output, audit
if final_only: return 1, output, audit
if final_only:
print(
"::error::OpenCode requested additional context after the "
f"configured limit of {limits.max_rounds} round(s).",
file=sys.stderr,
)
return 1, output, audit
audit.rounds += 1; supplied, manifest = _requested_context(parsed, diff_files=files, manifest=manifest, base_ref=args.base_ref, head_ref=args.head_ref, policy=effective_policy, limits=limits, audit=audit)
transcript += f"\n\nContext request {audit.rounds}: {parsed['reason']}\nContext response:\n{supplied}"
return 1, "", audit
Expand Down
46 changes: 46 additions & 0 deletions tests/test_run_agentic_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
from __future__ import annotations

import importlib.util
import argparse
import contextlib
import io
import json
from pathlib import Path
import unittest
from unittest import mock


SCRIPT_PATH = Path(__file__).parents[1] / "scripts" / "run_agentic_feedback.py"
Expand Down Expand Up @@ -137,6 +141,48 @@ def test_rejects_unsafe_context_path(self) -> None:
self.assertFalse(RUNNER._safe_context_path("../secret", ()))
self.assertFalse(RUNNER._safe_context_path("/secret", ()))

def test_context_loop_reports_invalid_model_output(self) -> None:
"""Malformed context-loop output must not fail without diagnostics."""
args = argparse.Namespace(
max_context_rounds=None,
max_context_files=None,
max_context_bytes=None,
feedback_kind="pr-documentation-review",
repository="owner/repository",
author="octocat",
pull_number=1,
focus=None,
base_ref="base",
head_ref="head",
)
bundle = {
"agent_name": "documentation-review",
"limits": {"max_comments": 10},
"prompt_template_text": "Review documentation.",
}
policy = {"context": {"max_context_rounds": 0}}
with mock.patch.object(
RUNNER,
"_run_opencode_integrated",
return_value=(0, "not valid JSON"),
):
stderr = io.StringIO()
with contextlib.redirect_stderr(stderr):
rc, _, _ = RUNNER.review_with_context_loop(
args=args,
resolved_bundle=bundle,
effective_policy=policy,
changed_lines={},
input_text="",
pr_metadata={},
effective_max_comments=10,
provider_timeout=1,
)
self.assertEqual(rc, 1)
self.assertIn(
"OpenCode response violated the PR review contract", stderr.getvalue()
)


if __name__ == "__main__":
unittest.main()
37 changes: 37 additions & 0 deletions tests/test_run_agentic_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from __future__ import annotations

import contextlib
import importlib.util
import io
import json
import os
import sys
Expand Down Expand Up @@ -536,6 +538,41 @@ def fake_run(cmd, **kwargs):
# "documentation impact").
self.assertIn("documentation impact", captured["prompt"])

def test_integrated_path_reports_opencode_failure(self):
with tempfile.TemporaryDirectory() as tmp:
tmp_path = Path(tmp)
bundle_path, policy_path, diff_path = self._write_inputs(tmp_path)
stderr = io.StringIO()
with (
mock.patch.object(
RUNNER.subprocess,
"run",
return_value=FakeSubprocessResult(
"", returncode=1, stderr="Error: Model not found: provider/model"
),
),
mock.patch.object(RUNNER, "github_request"),
mock.patch.object(RUNNER, "_has_v2_marker_match", return_value=False),
mock.patch.object(RUNNER, "has_marker", return_value=False),
contextlib.redirect_stderr(stderr),
):
rc = RUNNER.main(
[
"--input", str(diff_path),
"--comments-url", "https://api.github.com/repos/o/r/issues/1/comments",
"--repository", "o/r",
"--pull-number", "1",
"--head-sha", "abc123",
"--feedback-kind", "pr-documentation-review",
"--author", "octocat",
"--resolved-config", str(bundle_path),
"--effective-policy", str(policy_path),
]
)
self.assertEqual(rc, 1)
self.assertIn("OpenCode exited with status 1", stderr.getvalue())
self.assertIn("Model not found", stderr.getvalue())

def test_untrusted_diff_is_delimited_single_channel(self):
with tempfile.TemporaryDirectory() as tmp:
tmp_path = Path(tmp)
Expand Down
Loading