Skip to content

fix(agent): handle clean recovered exits#1630

Open
konard wants to merge 4 commits into
mainfrom
issue-1629-00cbc78f8c9d
Open

fix(agent): handle clean recovered exits#1630
konard wants to merge 4 commits into
mainfrom
issue-1629-00cbc78f8c9d

Conversation

@konard

@konard konard commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds the issue 1629 case study under docs/case-studies/issue-1629, including PR 1833 metadata, comments/reviews/timeline data, 16 Actions logs, 5 solution-draft logs, related issue 1826 data, and related PR 1839 data.
  • Fixes Agent CLI error classification so {"type":"log","message":"Agent exiting","hasError":false} marks the run as successfully recovered.
  • Clears post-hoc type:error detection when the agent exits with code 0 and a success marker, preventing recovered internal usage errors from failing the solution draft.
  • Adds a regression test for the exact issue 1629 stream: internal usage.inputTokens.total TypeError followed by clean Agent exiting.

Case Study Findings

  • External PR 1833 was closed unmerged even though the final commit had green GitHub Actions checks.
  • The decisive Hive Mind failure was not CI; it was a recovered Agent CLI internal error being treated as fatal after hasError:false and exit code 0.
  • The raw evidence and timeline are in docs/case-studies/issue-1629/README.md; the artifact inventory is in docs/case-studies/issue-1629/data/data-inventory.tsv.
  • No external issue was opened in Jhon-Crow/godot-topdown-MVP because the project issue was later resolved by PR 1839; the actionable fix is Hive-side.

Verification

  • node tests/test-agent-error-detection.mjs
  • npx prettier --check src/agent.lib.mjs tests/test-agent-error-detection.mjs docs/case-studies/issue-1629/README.md docs/case-studies/issue-1629/research/online-sources.md
  • npm run lint
  • npm test
  • git diff --cached --check -- src/agent.lib.mjs tests/test-agent-error-detection.mjs .changeset/issue-1629-agent-exit.md docs/case-studies/issue-1629/README.md docs/case-studies/issue-1629/research/online-sources.md

Note: dependency installation completed with an expected local engine warning because this environment runs Node 20 while package.json requires Node >=24.

Fixes #1629

Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: #1629
@konard konard self-assigned this Apr 17, 2026
@konard konard changed the title [WIP] Hive Mind stuck in a loop that lead to no changes in pull request fix(agent): handle clean recovered exits Apr 17, 2026
@konard
konard marked this pull request as ready for review April 17, 2026 21:03
@konard

konard commented Apr 17, 2026

Copy link
Copy Markdown
Contributor Author

Solution summary

Implemented, pushed, and finalized PR 1630: #1630

What changed:

Verification:

  • node tests/test-agent-error-detection.mjs
  • npx prettier --check ...
  • npm run lint
  • npm test
  • CI run 24586577572 on commit 9243e77f41ab45a2215cbaf19193635c79eaa4dd passed; PR merge state is CLEAN.
  • Working tree is clean.

Online references used for the case-study collection are documented in docs/case-studies/issue-1629/research/online-sources.md, including GitHub CLI gh run view, GitHub workflow-runs API, issue timeline API, issue comments API, and pull request review comments API.

Useful follow-ups:

  1. Add deterministic auto-restart recovery for already-staged changes.
  2. Fix the PR monitoring/comment-counting cwd path that produced fatal: not a git repository noise in the captured logs.

This summary was automatically extracted from the AI working session output.

@konard

konard commented Apr 19, 2026

Copy link
Copy Markdown
Contributor Author

Double check all conclusions from previous analysis and implemented solution. Do we really log everything, found real root cause and have actually fixed it?

We need to ensure all changes are correct, consistent, validated, tested, logged and fully meet each and all discussed requirements (check issue description and all comments in issue and in pull request). Ensure all CI/CD checks pass.

@konard

konard commented Apr 19, 2026

Copy link
Copy Markdown
Contributor Author

🤖 AI Work Session Started

Starting automated work session at 2026-04-19T19:00:10.206Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback.

@konard
konard marked this pull request as draft April 19, 2026 19:00
…enarios

Add Test 28 and Test 29 to tests/test-agent-error-detection.mjs covering
the real NDJSON event shape observed in the Hive Mind case study log at
docs/case-studies/issue-1629/logs/solution-draft-6aeb182b868a97770a8ed3ff525819f6.log:

- Test 28 exercises the full gate chain (streaming → post-hoc → fallback)
  against the actual production payload where the TypeError is nested at
  error.data.message inside a type:"error" event, followed by the clean
  Agent exiting event with hasError:false.
- Test 29 independently verifies that the raw NDJSON fullOutput would match
  the fallback pattern if the gate were not in place, confirming the Issue
  #1629 fix is actually necessary rather than redundant.

Addresses the maintainer's request in PR #1630 to double-check that the
implemented solution validates against the real logs and fully meets
the requirements discussed in the issue.
@konard

konard commented Apr 19, 2026

Copy link
Copy Markdown
Contributor Author

Double-check summary (per #1630 (comment))

Verified each link in the chain:

Logs

  • solution-draft-6aeb182b868a97770a8ed3ff525819f6.log line 52583 confirms the real payload: {"type":"error",...,"error":{"name":"UnknownError","data":{"message":"TypeError: undefined is not an object (evaluating 'usage.inputTokens.total')"}}} followed by {"type":"log","message":"Agent exiting","hasError":false}.
  • solution-draft-0717628d22607598cd694e9fceffba00.log shows the same loop signature, matching the issue's "no changes in PR" symptom.
  • Case study in docs/case-studies/issue-1629/README.md accurately cites these lines — re-verified with LC_ALL=C grep after an earlier encoding-related false negative on my side.

Root cause

  • The Agent CLI's internal usage telemetry threw TypeError but the process continued and exited cleanly (exitCode=0, hasError:false).
  • detectAgentErrors plus the fallback "type":"error" matcher in src/agent.lib.mjs misread that transient event as a terminal failure, causing hive-mind to restart and loop without producing changes.

Fix (already in this PR)

  • src/agent.lib.mjs:594-598 / :667-671: set agentCompletedSuccessfully=true when Agent exiting + hasError:false arrives on stdout or stderr.
  • src/agent.lib.mjs:731-738: clear a post-hoc outputError when exitCode===0 && agentCompletedSuccessfully.
  • src/agent.lib.mjs:756: existing Issue There is no report on auto-restart session finish for --tool agent #1290 gate already skips the fallback pattern when the agent completed successfully — now reachable for this scenario because of the flag above.
  • .changeset/issue-1629-agent-exit.md documents the behavior change.

Tests

  • tests/test-agent-error-detection.mjs passes all 29 tests (node tests/test-agent-error-detection.mjs).
  • Latest commit adds Test 28 (nested error.data.message shape end-to-end across streaming → post-hoc → fallback) and Test 29 (raw NDJSON, proves the fallback would have fired without the gate).
  • Full npm test → 41/41 pass. npm run lint → clean.

CI

  • Previous run on 9243e77: success (run 24586577572).
  • New run on 16f1a66 (test additions): in progress at comment time — will report back if anything regresses.

All conclusions re-verified against real logs, and the fix now has explicit production-shape test coverage.

@konard
konard marked this pull request as ready for review April 19, 2026 19:15
@konard

konard commented Apr 19, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost: $5.359954

📊 Context and tokens usage:

Claude Opus 4.7: (2 session segments)

  1. 165.3K / 1M (17%) input tokens, 27.4K / 128K (21%) output tokens
  2. 46.8K / 1M (5%) input tokens, 4.6K / 128K (4%) output tokens

Total: (202.6K + 6.3M cached) input tokens, 37.2K output tokens, $5.359954 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: opus
  • Model: Claude Opus 4.7 (claude-opus-4-7)

📎 Log file uploaded as Gist (2517KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard

konard commented Apr 19, 2026

Copy link
Copy Markdown
Contributor Author

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hive Mind stuck in a loop that lead to no changes in pull request

1 participant