fix(core): 🐛 converge orphaned subagents and account final turns for judge-completed goals#226
Conversation
…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".
AI Code Review SummaryPR: #226 (fix(core): 🐛 converge orphaned subagents and account final turns for judge-completed goals) Overall AssessmentDetected 1 actionable findings, prioritize CRITICAL/HIGH before merge. Major Findings by Severity
Actionable Suggestions
Potential Risks
Test Suggestions
File-Level Coverage Notes
Inline Downgraded Items (processed but not inline)
Coverage Status
Uncovered list:
No-patch covered list:
Runtime/Budget
|
| @@ -16,7 +16,7 @@ use crate::ipc::app_events::{ | |||
| use crate::ipc::frontend_channels::ThreadStreamEvent; | |||
There was a problem hiding this comment.
Automated review completed for this PR diff. No concrete inline issue was selected after aggregation.
升级 tiycore 0.2.9 → 0.2.10-rc.2,把跨协议的 `Usage::context_size()` 作为统一的上下文用量事实来源,贯通 RunUsageDto / 前端 badge / 自动压缩触发,清理原先的 `initial_context_calibration` 启发式估算路径。 主要变更: - 升级 `src-tauri/Cargo.toml` 至 tiycore 0.2.10-rc.2。 - `RunUsageDto`(`src-tauri/src/model/thread.rs`)新增 `context_size: u64` 字段;doc-comment 区分 wire-level `total_tokens` 与统一语义 `context_size`;`From<Usage>` 用 `value.context_size()` 填入。前端 `src/shared/types/api.ts` 同步暴露 `contextSize`。 - `readUsage`(`src/services/bridge/agent-commands.ts`)解析 `contextSize`,缺失时按 `input+output+cache_read+cache_write` 兜底;新增 `readUsageField` 助手。 - `agent_run_event_handler.rs::ThreadUsageUpdated` 注释说明 `context_size` 派生规则。 - 前端 `ThreadContextUsage` / `buildThreadContextBadgeData` / `onUsage` / `mapRunSummaryToContextUsage` 统一改用 `contextSize` 判定百分比与 isExceeded,`totalTokens` 保留为 wire-level 显示;对应测试 fixture / 新增用例同步。 - 删除 `AgentSession.initial_context_calibration` 与 `ContextCompressionRuntimeState`(及 `effective_prompt_tokens` / `current_context_token_calibration` / `record_pending_prompt_estimate` / `observe_context_usage_calibration` / `build_initial_context_token_calibration` / `run_summary_matches_primary_model`)。 - `context_compression.rs` 删除 `calibrate_total_tokens` / `should_compress_with_calibration`,新增 `should_compress_via_context_size(last_usage, settings)`; `run_auto_compression` 启发式兜底改为 `messages.is_empty()` fast-path;`should_compress` 保留为非 hot-path 估算。 - `AgentSession.last_observed_usage: Arc<StdMutex<Option<Usage>>>` 替代旧 `context_compression_state`;`configure_agent` / `set_transform_context` 闭包 / `agent_session_events.rs` / `agent.subscribe` 回调统一改用新字段。 - `run_repo.rs` / `run_helper_repo.rs` / `tests/frontend_integration.rs` / `agent_session_tests.rs::make_run_summary` 同步补 `context_size`。 - 删除 / 改写 calibration 相关测试;`message_end_usage_updates_*` 改为 `message_end_usage_updates_record_observed_usage_once_per_change`, `usage_calibration_*` 改为 `usage_record_observed_includes_cache_read_for_context_size`, 清理未使用的测试 helper。 验证: - `cargo fmt --check --manifest-path src-tauri/Cargo.toml` clean - `npm run typecheck` clean - `npm run test:unit -- --run` 53 文件 846 通过 / 1 跳过 - `cargo test --locked --manifest-path src-tauri/Cargo.toml` lib + integration 全通过 - `agent_review` verdict: PASS BREAKING CHANGE: 内部 `AgentSession.context_compression_state` 及其关联启发式 API 已移除,替换为 `AgentSession.last_observed_usage: Arc<StdMutex<Option<Usage>>>`; 前端 `RunUsageDto` 新增必填 `contextSize`,旧 `totalTokens` 保留 为 wire-level 显示。任何外部消费方需更新到新字段。 Refs: tiycore 0.2.10-rc.2 `Usage::context_size()`
| git2 = { version = "0.20", features = ["vendored-libgit2", "vendored-openssl"] } | ||
| similar = "2" | ||
| tiycore = "0.2.9" | ||
| tiycore = "0.2.10-rc.2" |
There was a problem hiding this comment.
[LOW] Cargo.toml depends on a release-candidate (rc) version of tiycore
The tiycore dependency now points to a pre-release (rc) version, which may be acceptable during development but should be stabilised before merging to master.
Suggestion: Change to a stable release version before promoting the branch, or justify the rc dependency in the PR description.
Risk: Using an rc in the mainline can cause unexpected churn when the crate is yanked or bumped, and may violate internal publishing policies.
Confidence: 0.85
Summary
interruptedwhen a run finishes, preventing them from lingering atrunningforever after interrupt/cancelhelper_judgeto the frontend helper kind formatter so Judge Agent shows correctly in the UITest Plan
🤖 Generated with TiyCode