-
Notifications
You must be signed in to change notification settings - Fork 0
fix(core): 🐛 converge orphaned subagents and account final turns for judge-completed goals #226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ use crate::ipc::app_events::{ | |
| use crate::ipc::frontend_channels::ThreadStreamEvent; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| use crate::model::errors::{AppError, ErrorSource}; | ||
| use crate::model::thread::{MessageRecord, RunStatus, ThreadStatus}; | ||
| use crate::persistence::repo::{message_repo, run_repo, thread_repo}; | ||
| use crate::persistence::repo::{message_repo, run_helper_repo, run_repo, thread_repo}; | ||
|
|
||
| use super::agent_run_manager::{AgentRunManager, StartRunOptions}; | ||
|
|
||
|
|
@@ -415,6 +415,17 @@ impl AgentRunManager { | |
| } | ||
| } | ||
| ThreadStreamEvent::ThreadUsageUpdated { usage, .. } => { | ||
| // `usage` here is a `RunUsageDto` populated by tiycore via | ||
| // `From<tiycore::types::Usage>`. Its `context_size` field is | ||
| // the cross-protocol unified "context occupancy" value | ||
| // (`Usage::context_size()` = input + output + cache_read + | ||
| // cache_write), NOT the wire-level `total_tokens` (which is | ||
| // per-response and provider-dependent). We round-trip the | ||
| // whole struct (input/output/cache fields + total_tokens) | ||
| // through `tiycore::types::Usage` because the persistence | ||
| // layer is typed against `Usage`; `context_size` is | ||
| // re-derived inside the `From` impl on read, so storing only | ||
| // the raw fields is sufficient and forward-compatible. | ||
| let usage = tiycore::types::Usage { | ||
| input: usage.input_tokens, | ||
| output: usage.output_tokens, | ||
|
|
@@ -913,6 +924,55 @@ impl AgentRunManager { | |
| }); | ||
| } | ||
|
|
||
| // Backstop: converge any helper that is still non-terminal in the DB now | ||
| // that the run is finishing. A subagent (e.g. a Judge) whose own cleanup | ||
| // future was dropped during an interrupt/cancel can otherwise linger at | ||
| // `running` forever, since the frontend only flips helper status from | ||
| // live SubagentCompleted/Failed events. We mark them `interrupted` and | ||
| // emit a matching SubagentFailed so both the DB snapshot and the live | ||
| // event stream converge. | ||
| let helper_interrupt_reason = match status { | ||
| RunStatus::Cancelled => "Subagent interrupted because the run was cancelled.", | ||
| RunStatus::Interrupted => "Subagent interrupted because the run was interrupted.", | ||
| _ => "Subagent interrupted because the run finished while it was still active.", | ||
| }; | ||
| match run_helper_repo::interrupt_non_terminal_by_run( | ||
| &self.pool, | ||
| run_id, | ||
| helper_interrupt_reason, | ||
| ) | ||
| .await | ||
| { | ||
| Ok(orphaned) => { | ||
| if !orphaned.is_empty() { | ||
| tracing::warn!( | ||
| run_id = %run_id, | ||
| count = orphaned.len(), | ||
| "converged orphaned non-terminal run helpers to interrupted" | ||
| ); | ||
| } | ||
| for helper in orphaned { | ||
| let _ = frontend_tx.send(ThreadStreamEvent::SubagentFailed { | ||
| run_id: run_id.to_string(), | ||
| subtask_id: helper.id, | ||
| helper_kind: helper.helper_kind, | ||
| started_at: helper.started_at, | ||
| error: helper_interrupt_reason.to_string(), | ||
| snapshot: | ||
| crate::core::subagent::orchestrator::SubagentProgressSnapshot::default( | ||
| ), | ||
| }); | ||
| } | ||
| } | ||
| Err(error) => { | ||
| tracing::warn!( | ||
| run_id = %run_id, | ||
| %error, | ||
| "failed to converge orphaned run helpers while finishing run" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| finalize_run( | ||
| &self.pool, | ||
| self.app_events.as_ref(), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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