Skip to content

fix(core): 🐛 converge orphaned subagents and account final turns for judge-completed goals#226

Open
HayWolf wants to merge 1 commit into
masterfrom
fix/orphaned-helpers-turn
Open

fix(core): 🐛 converge orphaned subagents and account final turns for judge-completed goals#226
HayWolf wants to merge 1 commit into
masterfrom
fix/orphaned-helpers-turn

Conversation

@HayWolf

@HayWolf HayWolf commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add backstop to converge orphaned non-terminal run helpers (e.g. Judge subagents) to interrupted when a run finishes, preventing them from lingering at running forever after interrupt/cancel
  • Account the final turn for goals that are judge-completed within the same run, so the finished turn count matches what was shown while the run was active
  • Add helper_judge to the frontend helper kind formatter so Judge Agent shows correctly in the UI

Test Plan

  • Verify orphaned helpers are converged on run cancel/interrupt
  • Verify turn count stays consistent when Judge completes a goal
  • Verify turn accounting is idempotent (no double count on re-evaluation)

🤖 Generated with TiyCode

…judge-completed goals

When a run finishes while a subagent (e.g. a Judge) is still active in the
DB, its helper row can linger at `running` forever because only live
SubagentCompleted/Failed events flip the status. This adds a backstop in
the run-finalization path that:

- Marks all non-terminal helpers for the run as `interrupted`
- Emits matching `SubagentFailed` events so the DB and live stream converge

Additionally, a Judge can flip a goal to `complete` within the same run,
but the normal turn-accounting path is skipped for non-active goals,
causing the finished turn count to drop by one. A new
`account_turn_if_unevaluated` function idempotently bills that final
turn so the running-vs-finished display stays consistent.

The frontend now also maps `helper_judge` to "Judge Agent".
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

AI Code Review Summary

PR: #226 (fix(core): 🐛 converge orphaned subagents and account final turns for judge-completed goals)
Preferred language: English

Overall Assessment

No blocking issue was detected in the reviewed diff; keep focused regression testing before merge.

Major Findings by Severity

No major issues identified from the reviewed diff.

Actionable Suggestions

  • Replace get_active() with a direct goal fetch by id to avoid stale turns_used in outcome payloads.
  • Consider removing COALESCE for error_summary in interrupt_non_terminal_by_run to guarantee consistency between DB and events, or propagate the DB value into the SubagentFailed event.

Potential Risks

  • If get_active() returns None, the frontend may show an incorrect turn count after a goal is completed.
  • A helper with a pre-existing error_summary that is interrupted may display a different error message in the frontend than what is stored in the database.

Test Suggestions

  • Integration test verifying SubagentFailed events for orphaned helpers.
  • Goal lifecycle test for missing active goal after turn accounting.
  • Run helper repo test for a helper that already has error_summary while being interrupted.

File-Level Coverage Notes

  • src-tauri/src/core/agent_run_event_handler.rs: Adds a clean-up backstop that converges orphaned run helpers to interrupted and emits matching SubagentFailed events. The implementation is correct and properly idempotent.
  • src-tauri/src/core/goal_manager.rs: Introduces idempotent turn accounting for the run that completes a goal, preventing a lost turn. The logic is sound, but the re-fetch via get_active() may lead to a stale payload in edge cases.
  • src-tauri/src/persistence/repo/goal_repo.rs: New account_turn_if_unevaluated function is correctly written and idempotent; it uses a clear WHERE condition to avoid double counting.
  • src-tauri/src/persistence/repo/run_helper_repo.rs: interrupt_non_terminal_by_run is a well-tested, transactional function that converges helpers safely. The COALESCE choice is the only small design consideration.
  • src-tauri/tests/goal_lifecycle.rs: Expanded test correctly asserts that turn accounting occurs for the terminal run and is idempotent on re-evaluation.
  • src/modules/workbench-shell/ui/runtime-thread-surface-helpers.test.ts: Adds unit test for the new helper_judge kind; straightforward and sufficient.
  • src/modules/workbench-shell/ui/runtime-thread-surface-helpers.ts: Adds display mapping for helper_judge → 'Judge Agent', aligning with the backend.

Inline Downgraded Items (processed but not inline)

  • None

Coverage Status

  • Target files: 7
  • Covered files: 7
  • Uncovered files: 0
  • No-patch/binary covered as file-level: 0
  • Findings with unknown confidence (N/A): 0

Uncovered list:

  • None

No-patch covered list:

  • None

Runtime/Budget

  • Rounds used: 1/4
  • Planned batches: 1
  • Executed batches: 1
  • Sub-agent runs: 1
  • Planner calls: 1
  • Reviewer calls: 1
  • Model calls: 2/64
  • Structured-output summary-only degradation: NO

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated PR review completed.

  • Findings kept: 0
  • Findings with unknown confidence: 0
  • Inline comments attempted: 1
  • Target files: 7
  • Covered files: 7
  • Uncovered files: 0
    See the summary comment for detailed analysis and coverage details.

@@ -16,7 +16,7 @@ use crate::ipc::app_events::{
use crate::ipc::frontend_channels::ThreadStreamEvent;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review completed for this PR diff. No concrete inline issue was selected after aggregation.

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.

2 participants