fix(run): emit session_error for session failures#81
Conversation
|
I'll start by exploring the repository and understanding the PR changes.Let me get the PR diff and the full file contents.Let me get the surrounding context in |
Code reviewVerdict: Looks good — only minor / nit comments below. · 🔴 0 · 🟠 0 · 🟡 2 · ⚪ 1 · 0/3 resolved
🤖 Fix all 3 open findings with your agent📋 Out-of-diff findings (3)
Reviewed 4 files · 0 inline · view all 3 findings ↗ aictrl · AI code review for fast-moving teams · aictrl.dev |
- Add behavioral test (run-session-error-emit.test.ts): spawns the CLI with --format json against a failing model and asserts the session_error JSON event is emitted with a classified reason/message. Closes the source-text-grep gap flagged by the bot. - Fix brittle 1400-char window in run-schema-v1.test.ts: anchor the assertion window to the next event handler boundary instead of a magic character count, matching the pattern used in run-session-error-exit.test.ts. - Add clarifying comment in run.ts session.error handler explaining that session_error (structured/classified) and error (raw/legacy) are intentionally distinct channels serving different consumers, not a double-count bug. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0187MsfK1upr6K2BKVbmaebQ
Review response — PR #81Triaged 3 findings (2x 🟡 minor, 1x ⚪ nit). All addressed in commit Issues addressed (pushed to this PR)
Review claims verified false (no change needed)
|
Code reviewVerdict: Address the major findings before merging. · 🔴 0 · 🟠 1 · 🟡 1 · ⚪ 1 · 0/3 resolved
🤖 Fix all 3 open findings with your agent📋 Out-of-diff findings (3)
Reviewed 5 files · 0 inline · view all 3 findings ↗ aictrl · AI code review for fast-moving teams · aictrl.dev |
Finding 1 (TRUE/FIX): replace subprocess test that used nonexistent-model
(exercised pre-existing promptResult rejection handler, not the new in-loop
emit) with a mock-server --attach test that injects a session.error event
mid-stream. Test now fails if the new in-loop emit("session_error",…) is removed.
Finding 2 (TRUE/FIX): drop --conditions=browser from the test subprocess.
The flag was cargo-culted from the dev script; no packages in this repo export
browser-specific conditions, so it was harmless but unexplained and potentially
misleading. Removed without replacement.
Finding 3 (TRUE/FIX): add a shared `let sessionErrorEmitted = false` flag in
execute() scope. All three session_error emit sites (in-loop session.error
handler, loopDone.catch, promptResult rejection handler) now short-circuit on
the flag so at most one session_error is emitted per run regardless of which
failure paths fire. New test also asserts count === 1.
Round-2 code review verdict — PR #81Analyzed at: 2026-06-22T09:41:03Z
Finding 1 — TRUE / FIXEvidence: The round-1 subprocess test used Fix: Replaced the subprocess test with a mock-server Verification: Temporarily replaced the in-loop Finding 2 — TRUE / FIXEvidence: Fix: Removed Finding 3 — TRUE / FIXEvidence: Three independent
Sites 1 and 2 can co-fire: a Fix: Added {
"schemaVersion": "1",
"sourcePR": 81,
"repo": "aictrl-dev/cli",
"round": 2,
"analyzedAt": "2026-06-22T09:41:03Z",
"headSha": "58e48e420",
"fixSha": "b09fec9d3",
"findings": [
{ "id": "f1", "severity": "orange", "verdict": "TRUE", "action": "FIX", "location": "test/cli/run-session-error-emit.test.ts:31", "summary": "Behavioral test didn't cover in-loop session.error path; replaced with mock-server attach test" },
{ "id": "f2", "severity": "white", "verdict": "TRUE", "action": "FIX", "location": "test/cli/run-session-error-emit.test.ts:24", "summary": "Removed unexplained --conditions=browser from test subprocess" },
{ "id": "f3", "severity": "yellow", "verdict": "TRUE", "action": "FIX", "location": "run.ts:580", "summary": "Added sessionErrorEmitted guard flag; all 3 emit sites short-circuit so at most one session_error per run" }
]
} |
Summary
session_errorwhen the primary session publishessession.errorNamedErrorobjects without droppingdata.message/data.statusCodeRefs #63.
Validation
cd packages/cli && bun test test/cli/classify-session-error.test.ts test/cli/run-schema-v1.test.ts test/cli/run-session-error-exit.test.ts --timeout 30000cd packages/cli && bun run typecheck