Skip to content

Commit ee87e3b

Browse files
author
Andre Paat
committed
fix(tribunal-review): serialize OpenCode legs + run from non-repo cwd (v0.3.1)
Two distinct OpenCode deadlocks, both fixed in the tribunal-loop skill: 1. Concurrency deadlock (issue #31, upstream anomalyco/opencode#29395): the two `opencode run` legs were launched as parallel Bash calls and deadlocked on the shared ~/.local/share/opencode SQLite data dir, hanging ~20 min then failing. Fix: merge GLM + DeepSeek into ONE Bash call that runs them back-to-back (Codex + Gemini stay parallel -> 3 parallel calls). The call emits two JSON objects (GLM then DeepSeek). Deduped the two ~90-line blocks into a shared review_opencode_leg() helper; added a real `command -v opencode` guard. 2. git-cwd init deadlock (found this session): a SINGLE `opencode run` hangs at init when its cwd is inside a git repo (internal deadlock - 2 threads parked, no child process, log frozen at "loading internal plugin"; never reaches model selection). Reproduced ~5x: hangs from any repo, works in ~2s from a non-repo dir. Fix: after capturing the diff (which needs the repo), `cd "$TMPDIR"` so opencode runs from a non-repo scratch dir. opencode needs no repo context here -- the diff is embedded in the prompt and it runs --pure with "do NOT use tools". Verified end-to-end against real opencode: merged block run from a git repo yields two valid GLM + DeepSeek reviews (~20s) instead of hanging. Also verified serial execution (0 overlap), dual-JSON collection, and the empty-diff / not-installed paths via a stubbed opencode. bash -n clean. Closes #31
1 parent 857cf7c commit ee87e3b

4 files changed

Lines changed: 74 additions & 130 deletions

File tree

‎.claude-plugin/marketplace.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{
3232
"name": "tribunal-review",
3333
"description": "Multi-provider code review with Codex, Gemini, OpenCode (GLM + DeepSeek), and Opus arbitration",
34-
"version": "0.3.0",
34+
"version": "0.3.1",
3535
"author": {
3636
"name": "Andre Paat"
3737
},

‎plugins/tribunal-review/.claude-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tribunal-review",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "Multi-provider code review with Codex, Gemini, OpenCode (GLM + DeepSeek), and Opus arbitration",
55
"author": {
66
"name": "Andre Paat"

‎plugins/tribunal-review/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# tribunal-review
22

3-
Multi-provider code review plugin for Claude Code. Runs four reviewers in parallel — Codex (GPT-5.3), Gemini (3 Pro Preview), and two OpenCode Go models (GLM-5.1, DeepSeek-V4-Pro) — then uses Opus as the final arbiter to deduplicate findings, resolve conflicts, and issue a single authoritative verdict.
3+
Multi-provider code review plugin for Claude Code. Runs four reviewers — Codex (GPT-5.3), Gemini (3 Pro Preview), and two OpenCode Go models (GLM-5.1, DeepSeek-V4-Pro) — then uses Opus as the final arbiter to deduplicate findings, resolve conflicts, and issue a single authoritative verdict.
44

55
## Prerequisites
66

@@ -27,7 +27,7 @@ On a feature branch with changes vs `origin/main`:
2727
/tribunal-loop
2828
```
2929

30-
The skill will verify you're on a feature branch, run all four reviews in parallel, and produce an arbitrated verdict.
30+
The skill will verify you're on a feature branch, run the four reviews, and produce an arbitrated verdict.
3131

3232
When the verdict comes back `NEEDS_WORK` or `BLOCK`, the `closing-tribunal-loop` skill guides the iterative close-out: per-finding triage (fix-in-PR vs file-follow-up vs reject), committing fixes one finding at a time, and re-running the tribunal until the arbiter returns `APPROVE` with zero findings on the latest diff.
3333

@@ -37,7 +37,7 @@ When the verdict comes back `NEEDS_WORK` or `BLOCK`, the `closing-tribunal-loop`
3737
Verifies you're on a feature branch (not main) and that there are changes to review.
3838

3939
### Step 2: Parallel Review
40-
Runs Codex, Gemini, GLM, and DeepSeek as four parallel Bash calls. Each analyzes the `git diff origin/main...HEAD` and returns structured JSON findings covering logic errors, security vulnerabilities, edge cases, performance issues, and architectural concerns. The two OpenCode reviewers run read-only (`opencode run --agent plan`).
40+
Runs Codex, Gemini, and OpenCode as **three parallel Bash calls**. Each analyzes the `git diff origin/main...HEAD` and returns structured JSON findings covering logic errors, security vulnerabilities, edge cases, performance issues, and architectural concerns. The two OpenCode reviewers run read-only (`opencode run --agent plan`) and **sequentially within the single OpenCode call** — running them concurrently deadlocks on OpenCode's shared data dir (issue #31), so they are serialized (~8-15s each, back-to-back).
4141

4242
### Step 3: Inline Arbitration (Opus)
4343
Opus deduplicates findings, resolves severity conflicts (always using the highest severity), marks any issue flagged by ≥2 reviewers as CONSENSUS, evaluates each finding for validity, and issues a final verdict: **APPROVE**, **NEEDS_WORK**, or **BLOCK**.

‎plugins/tribunal-review/skills/tribunal-loop/SKILL.md‎

Lines changed: 69 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Output: "[TRIBUNAL 1/3] On branch: {branch_name}, {N} files changed"
3333

3434
## STEP 2: Parallel Review
3535

36-
Run all four scripts below as **four parallel Bash tool calls**. No Task agents -- execute directly.
36+
Run the three scripts below as **three parallel Bash tool calls**. No Task agents -- execute directly. The OpenCode call (Bash call 3) runs its two legs — GLM then DeepSeek — **sequentially within that one call**, because concurrent `opencode run` instances deadlock on the shared `~/.local/share/opencode` data dir (issue #31). It still yields four reviews total.
3737

3838
### Bash call 1: Codex Review
3939

@@ -232,126 +232,64 @@ fi
232232
# trap EXIT handles cleanup of $TMPDIR
233233
```
234234

235-
### Bash call 3: OpenCode GLM Review
235+
### Bash call 3: OpenCode Review (GLM + DeepSeek, sequential)
236+
237+
Runs both OpenCode legs **back-to-back inside a single Bash call** and prints
238+
**two** JSON objects on stdout (GLM first, then DeepSeek). The two legs must NOT
239+
overlap: concurrent `opencode run` processes deadlock on the shared
240+
`~/.local/share/opencode` SQLite data dir, hanging until the timeout (issue #31).
241+
The call also runs opencode from a non-repo scratch dir, because `opencode run`
242+
can also deadlock at init when its cwd is inside a git repo (see the `cd "$TMPDIR"`
243+
note below). Codex (Bash call 1) and Gemini (Bash call 2) stay parallel with this call.
236244

237245
```bash
238246
cd "$(git rev-parse --show-toplevel)"
239247

240248
# Parallel-safe: unique temp dir per invocation
241249
TMPDIR=$(mktemp -d) && trap 'rm -rf "$TMPDIR"' EXIT
242250

243-
DIFF=$(git diff origin/main...HEAD)
244-
245-
if [ -z "$DIFF" ]; then
246-
printf '%s\n' '{"provider": "glm", "model": "opencode-go/glm-5.1", "findings": [], "summary": {"total_findings": 0, "critical": 0, "high": 0, "medium": 0, "low": 0, "quality_score": 10.0, "verdict": "APPROVE", "note": "No changes detected vs origin/main"}}'
247-
exit 0
248-
fi
249-
250-
# Diff-size guard (GLM has large context; cap higher than Codex's 100KB)
251-
DIFF_SIZE=${#DIFF}
252-
DIFF_TRUNCATED=false
253-
if [ "$DIFF_SIZE" -gt 204800 ]; then
254-
DIFF=$(printf '%s' "$DIFF" | head -c 204800)
255-
DIFF_TRUNCATED=true
256-
fi
257-
258-
PROMPT="You are a senior code reviewer performing a thorough, comprehensive review.
259-
260-
ANALYZE THIS DIFF FOR:
261-
1. Logic errors - off-by-one, null deref, wrong comparisons, race conditions, division by zero
262-
2. Security vulnerabilities - injection, XSS, CSRF, auth bypass, secrets exposure
263-
3. Architecture - coupling, layering violations, anti-patterns
264-
4. Performance - N+1 queries, memory leaks, blocking in async, unnecessary allocations
265-
5. Edge cases - boundary conditions, empty inputs, integer overflow, unhandled error paths
266-
6. Test coverage gaps - missing edge cases, untested paths
267-
268-
RULES:
269-
- ONLY report findings with confidence >= 0.7
270-
- Use EXACT file paths from the diff headers (e.g., 'a/src/Foo.cs' -> 'src/Foo.cs')
271-
- Use the line number from the diff where the issue occurs
272-
- Each finding must have a concrete, actionable suggestion
273-
- Do NOT use any tools. Analyze ONLY the diff provided below.
274-
275-
VERDICT RULES:
276-
- BLOCK: any critical-severity finding, OR 2+ high-severity findings
277-
- NEEDS_WORK: any high-severity finding, OR 3+ medium-severity findings
278-
- APPROVE: all other cases
279-
280-
OUTPUT:
281-
Output ONLY a JSON object, wrapped EXACTLY between these markers on their own lines:
282-
===TRIBUNAL_JSON_BEGIN===
283-
{
284-
\"provider\": \"glm\",
285-
\"model\": \"opencode-go/glm-5.1\",
286-
\"findings\": [
287-
{\"severity\": \"critical|high|medium|low\", \"category\": \"logic|security|performance|quality|edge-case|architecture|testing\", \"file\": \"path\", \"line\": 42, \"title\": \"...\", \"description\": \"...\", \"suggestion\": \"...\", \"confidence\": 0.9}
288-
],
289-
\"summary\": {\"total_findings\": 1, \"critical\": 0, \"high\": 1, \"medium\": 0, \"low\": 0, \"quality_score\": 7.5, \"verdict\": \"APPROVE|NEEDS_WORK|BLOCK\"}
251+
emit_empty() { # provider, model
252+
printf '{"provider": "%s", "model": "%s", "findings": [], "summary": {"total_findings": 0, "critical": 0, "high": 0, "medium": 0, "low": 0, "quality_score": 10.0, "verdict": "APPROVE", "note": "No changes detected vs origin/main"}}\n' "$1" "$2"
290253
}
291-
===TRIBUNAL_JSON_END===
292-
$([ "$DIFF_TRUNCATED" = true ] && echo "NOTE: Diff was truncated to 200KB. Review what is provided.")
293-
294-
THE DIFF:
295-
$DIFF"
296254

297-
# Retry once on timeout (exit 124) — OpenCode Go latency can transiently spike past the cap
298-
for attempt in 1 2; do
299-
timeout -k 10 600 opencode run --agent plan -m opencode-go/glm-5.1 --variant high --format default --pure "$PROMPT" </dev/null \
300-
>"$TMPDIR/glm-raw.txt" 2>"$TMPDIR/glm-stderr.txt"
301-
OC_EXIT=$?
302-
[ "$OC_EXIT" -ne 124 ] && break
303-
done
304-
305-
if [ $OC_EXIT -eq 0 ] && [ -s "$TMPDIR/glm-raw.txt" ]; then
306-
# Extract between sentinels; fall back to first-{ .. last-} slice
307-
JSON=$(sed -n '/===TRIBUNAL_JSON_BEGIN===/,/===TRIBUNAL_JSON_END===/p' "$TMPDIR/glm-raw.txt" \
308-
| sed '/===TRIBUNAL_JSON_BEGIN===/d;/===TRIBUNAL_JSON_END===/d;s/^```json//;s/^```//')
309-
if ! printf '%s' "$JSON" | jq -e . >/dev/null 2>&1; then
310-
JSON=$(tr -d '\r' < "$TMPDIR/glm-raw.txt" | sed -n 'H;${x;s/^[^{]*//;s/[^}]*$//;p;}')
311-
fi
312-
if printf '%s' "$JSON" | jq -e . >/dev/null 2>&1; then
313-
printf '%s' "$JSON" | jq -c .
314-
else
315-
SAFE=$(jq -Rs . < "$TMPDIR/glm-raw.txt" 2>/dev/null || echo '"capture failed"')
316-
printf '{"error": "OpenCode GLM produced unparseable output", "provider": "glm", "raw": %s}\n' "$SAFE"
317-
fi
318-
else
319-
STDERR_CONTENT=$(cat "$TMPDIR/glm-stderr.txt" 2>/dev/null)
320-
SAFE_STDERR=$(printf '%s' "$STDERR_CONTENT" | jq -Rs . 2>/dev/null || echo '"stderr encoding failed"')
321-
printf '{"error": "OpenCode GLM execution failed", "provider": "glm", "exit_code": %d, "stderr": %s}\n' "$OC_EXIT" "$SAFE_STDERR"
255+
# If OpenCode is not installed, emit an error object for each leg and stop.
256+
if ! command -v opencode >/dev/null 2>&1; then
257+
printf '%s\n' '{"error": "OpenCode CLI not found. Install from: https://opencode.ai", "provider": "glm"}'
258+
printf '%s\n' '{"error": "OpenCode CLI not found. Install from: https://opencode.ai", "provider": "deepseek"}'
259+
exit 0
322260
fi
323-
# trap EXIT handles cleanup of $TMPDIR
324-
```
325-
326-
## Error Handling
327-
If `opencode` is not installed, the block emits:
328-
```json
329-
{"error": "OpenCode CLI not found. Install from: https://opencode.ai", "provider": "glm"}
330-
```
331-
332-
### Bash call 4: OpenCode DeepSeek Review
333-
334-
```bash
335-
cd "$(git rev-parse --show-toplevel)"
336-
337-
# Parallel-safe: unique temp dir per invocation
338-
TMPDIR=$(mktemp -d) && trap 'rm -rf "$TMPDIR"' EXIT
339261

340262
DIFF=$(git diff origin/main...HEAD)
341263

342264
if [ -z "$DIFF" ]; then
343-
printf '%s\n' '{"provider": "deepseek", "model": "opencode-go/deepseek-v4-pro", "findings": [], "summary": {"total_findings": 0, "critical": 0, "high": 0, "medium": 0, "low": 0, "quality_score": 10.0, "verdict": "APPROVE", "note": "No changes detected vs origin/main"}}'
265+
emit_empty "glm" "opencode-go/glm-5.1"
266+
emit_empty "deepseek" "opencode-go/deepseek-v4-pro"
344267
exit 0
345268
fi
346269

270+
# Diff-size guard (GLM/DeepSeek have large context; cap higher than Codex's 100KB)
347271
DIFF_SIZE=${#DIFF}
348272
DIFF_TRUNCATED=false
349273
if [ "$DIFF_SIZE" -gt 204800 ]; then
350274
DIFF=$(printf '%s' "$DIFF" | head -c 204800)
351275
DIFF_TRUNCATED=true
352276
fi
353277

354-
PROMPT="You are a senior code reviewer performing a thorough, comprehensive review.
278+
# Run OpenCode from a NON-REPO directory. `opencode run` can deadlock at init
279+
# when its cwd is inside a git repository (it hangs after loading internal
280+
# plugins, never reaching model selection — a single instance, no concurrency).
281+
# The diff is already captured above and embedded in the prompt (--pure, "do NOT
282+
# use tools"), so opencode needs no repo/git context. $TMPDIR (mktemp -d) is a
283+
# scratch dir outside any repo.
284+
cd "$TMPDIR"
285+
286+
# Review one OpenCode leg and print its JSON. Args: provider, label, model.
287+
review_opencode_leg() {
288+
local provider="$1" label="$2" model="$3"
289+
local raw="$TMPDIR/$provider-raw.txt" err="$TMPDIR/$provider-stderr.txt"
290+
local oc_exit json safe prompt
291+
292+
prompt="You are a senior code reviewer performing a thorough, comprehensive review.
355293
356294
ANALYZE THIS DIFF FOR:
357295
1. Logic errors - off-by-one, null deref, wrong comparisons, race conditions, division by zero
@@ -377,8 +315,8 @@ OUTPUT:
377315
Output ONLY a JSON object, wrapped EXACTLY between these markers on their own lines:
378316
===TRIBUNAL_JSON_BEGIN===
379317
{
380-
\"provider\": \"deepseek\",
381-
\"model\": \"opencode-go/deepseek-v4-pro\",
318+
\"provider\": \"$provider\",
319+
\"model\": \"$model\",
382320
\"findings\": [
383321
{\"severity\": \"critical|high|medium|low\", \"category\": \"logic|security|performance|quality|edge-case|architecture|testing\", \"file\": \"path\", \"line\": 42, \"title\": \"...\", \"description\": \"...\", \"suggestion\": \"...\", \"confidence\": 0.9}
384322
],
@@ -390,41 +328,47 @@ $([ "$DIFF_TRUNCATED" = true ] && echo "NOTE: Diff was truncated to 200KB. Revie
390328
THE DIFF:
391329
$DIFF"
392330

393-
# Retry once on timeout (exit 124) — OpenCode Go latency can transiently spike past the cap
394-
for attempt in 1 2; do
395-
timeout -k 10 600 opencode run --agent plan -m opencode-go/deepseek-v4-pro --variant high --format default --pure "$PROMPT" </dev/null \
396-
>"$TMPDIR/deepseek-raw.txt" 2>"$TMPDIR/deepseek-stderr.txt"
397-
OC_EXIT=$?
398-
[ "$OC_EXIT" -ne 124 ] && break
399-
done
400-
401-
if [ $OC_EXIT -eq 0 ] && [ -s "$TMPDIR/deepseek-raw.txt" ]; then
402-
JSON=$(sed -n '/===TRIBUNAL_JSON_BEGIN===/,/===TRIBUNAL_JSON_END===/p' "$TMPDIR/deepseek-raw.txt" \
403-
| sed '/===TRIBUNAL_JSON_BEGIN===/d;/===TRIBUNAL_JSON_END===/d;s/^```json//;s/^```//')
404-
if ! printf '%s' "$JSON" | jq -e . >/dev/null 2>&1; then
405-
JSON=$(tr -d '\r' < "$TMPDIR/deepseek-raw.txt" | sed -n 'H;${x;s/^[^{]*//;s/[^}]*$//;p;}')
406-
fi
407-
if printf '%s' "$JSON" | jq -e . >/dev/null 2>&1; then
408-
printf '%s' "$JSON" | jq -c .
331+
# Retry once on timeout (exit 124) — OpenCode Go latency can transiently spike past the cap
332+
for attempt in 1 2; do
333+
timeout -k 10 600 opencode run --agent plan -m "$model" --variant high --format default --pure "$prompt" </dev/null \
334+
>"$raw" 2>"$err"
335+
oc_exit=$?
336+
[ "$oc_exit" -ne 124 ] && break
337+
done
338+
339+
if [ "$oc_exit" -eq 0 ] && [ -s "$raw" ]; then
340+
# Extract between sentinels; fall back to first-{ .. last-} slice
341+
json=$(sed -n '/===TRIBUNAL_JSON_BEGIN===/,/===TRIBUNAL_JSON_END===/p' "$raw" \
342+
| sed '/===TRIBUNAL_JSON_BEGIN===/d;/===TRIBUNAL_JSON_END===/d;s/^```json//;s/^```//')
343+
if ! printf '%s' "$json" | jq -e . >/dev/null 2>&1; then
344+
json=$(tr -d '\r' < "$raw" | sed -n 'H;${x;s/^[^{]*//;s/[^}]*$//;p;}')
345+
fi
346+
if printf '%s' "$json" | jq -e . >/dev/null 2>&1; then
347+
printf '%s' "$json" | jq -c .
348+
else
349+
safe=$(jq -Rs . < "$raw" 2>/dev/null || echo '"capture failed"')
350+
printf '{"error": "OpenCode %s produced unparseable output", "provider": "%s", "raw": %s}\n' "$label" "$provider" "$safe"
351+
fi
409352
else
410-
SAFE=$(jq -Rs . < "$TMPDIR/deepseek-raw.txt" 2>/dev/null || echo '"capture failed"')
411-
printf '{"error": "OpenCode DeepSeek produced unparseable output", "provider": "deepseek", "raw": %s}\n' "$SAFE"
353+
safe=$(jq -Rs . < "$err" 2>/dev/null || echo '"stderr encoding failed"')
354+
printf '{"error": "OpenCode %s execution failed", "provider": "%s", "exit_code": %d, "stderr": %s}\n' "$label" "$provider" "$oc_exit" "$safe"
412355
fi
413-
else
414-
STDERR_CONTENT=$(cat "$TMPDIR/deepseek-stderr.txt" 2>/dev/null)
415-
SAFE_STDERR=$(printf '%s' "$STDERR_CONTENT" | jq -Rs . 2>/dev/null || echo '"stderr encoding failed"')
416-
printf '{"error": "OpenCode DeepSeek execution failed", "provider": "deepseek", "exit_code": %d, "stderr": %s}\n' "$OC_EXIT" "$SAFE_STDERR"
417-
fi
356+
}
357+
358+
# SEQUENTIAL — the two legs must never overlap (see issue #31). Each is ~8-15s.
359+
review_opencode_leg "glm" "GLM" "opencode-go/glm-5.1"
360+
review_opencode_leg "deepseek" "DeepSeek" "opencode-go/deepseek-v4-pro"
418361
# trap EXIT handles cleanup of $TMPDIR
419362
```
420363

421364
## Error Handling
422-
If `opencode` is not installed, the block emits:
365+
If `opencode` is not installed, the call emits one error object per leg and exits 0:
423366
```json
367+
{"error": "OpenCode CLI not found. Install from: https://opencode.ai", "provider": "glm"}
424368
{"error": "OpenCode CLI not found. Install from: https://opencode.ai", "provider": "deepseek"}
425369
```
426370

427-
Collect all four JSON outputs. Parse them. If any returned an error JSON, note it for arbitration.
371+
Collect all four JSON outputs — Codex and Gemini from their calls, GLM and DeepSeek from the single OpenCode call (which prints two JSON objects, GLM first). Parse them. If any returned an error JSON, note it for arbitration.
428372

429373
Output: "[TRIBUNAL 2/3] Reviews complete - Codex: {C}, Gemini: {G}, GLM: {L}, DeepSeek: {D} findings"
430374

@@ -531,4 +475,4 @@ The four reviewers are equal peers; a finding flagged by ≥2 is CONSENSUS. Opus
531475

532476
| Mode | Steps | Tool Calls | Agent Spawns |
533477
|------|-------|------------|-------------|
534-
| Default (review) | 3 | 4 (parallel Bash) | 0 |
478+
| Default (review) | 3 | 3 (parallel Bash; OpenCode call runs GLM+DeepSeek sequentially) | 0 |

0 commit comments

Comments
 (0)