← Back to Pull requests

fix(agent): give task trace correlations a complete lifecycle (issue #228) #380

Open
unknown opened this pull request with 499 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 21, 2026 08:20 UTC
Author

Describe what this PR does / why we need it

Issue #228 reports that TaskTraceCorrelation — the in-memory store linking the TaskTool delegation site to the TaskOutputTool receive site of background tasks — has no lifecycle at all: it has a forget method with zero production callers, entries are recorded before the repository submission so a rejection strands the record, and the map grows without bound. This PR gives the store a three-layer lifecycle and adds regression tests for the rejection, terminal-delivery, running-task and repository-lifecycle paths.

Root cause

TaskTool.apply records the correlation facts before calling taskRepository.putTask unguarded, so a rejected submission — the bounded repository throws RejectedExecutionException on full capacity, a duplicate task id or a closed repository — leaves a stranded record that nothing ever removes. On the happy path, TaskOutputTool returns terminal results without releasing the entry either, and the store itself has no retention, so with the default repository (which has no capacity or TTL at all) entries accumulate for the life of the process.

The fix

Three layers, all inside the tools/task package, plus one repository hook. First, TaskTool wraps putTask in a try/catch and rolls the record back with forget before rethrowing, which covers every rejection mode of the bounded repository plus executor submission failures; the record-then-submit ordering already guarantees the task cannot start before its correlation exists. Second, retention follows the task instead of the submission: a recorded entry has no expiry while its task runs, and the delegation site calls refresh when the task finishes, so the window is measured from completion and a task that runs longer than the retention keeps its delegation link for the first poll. Polls of a completed entry slide the window, correlation() never serves an expired completed entry, and record()/forget() lazily sweep those entries, so the store converges without a janitor thread; running entries are never swept by intervening submissions or polls. Third, no sweep can observe a task that leaves the repository through removeTask, clear, clearCompletedTasks, shutdown or the bounded repository's close, so TaskRepository gains a default addLifecycleListener(TaskLifecycleListener): both implementations notify listeners with the affected task ids outside their monitors, and both TaskTool and TaskOutputTool register the shared store as a listener. An idle shared store therefore drops removed, cleared or shut-down tasks immediately instead of retaining them until the next poll; retention now only has to cover results that leave the repository through internal expiry.

Testing

The TaskTraceCorrelationLifecycleTest drives retention with a mutable clock: a completed entry is never served after its window and is swept by the next record, a completed entry slides on polls and lapses when idle, a running entry survives the retention window plus intervening record/poll/refresh/forget traffic (and an eight-thread concurrent record/poll/refresh/forget loop), forgetAll releases only the given ids, and forget stays idempotent. The new TaskTraceCorrelationRepositoryLifecycleTest asserts cleanup without any subsequent poll: removeTask, clear and shutdown on the default repository and removeTask, clear and close on the bounded repository release the correlations, and both tools wire the listener. TaskToolTraceCorrelationTests covers the tool chain: a 31-minute task keeps its link for the first poll after completion, a poll of an unknown task sweeps expired completed entries, a capacity-full bounded repository rejects the background submission with RejectedExecutionException and leaves zero retained records, and a poll of a removed task releases its correlation. The task package is 91 tests green, and checkstyle plus spring-javaformat are clean.

Fixes #228

Diff: 499 lines (+374 / -125) across 6 files Reviewer: yuluo-yx Review duration: 13635m
All Vouch review confidence checks passed
Residual risk 0.25 = Change Risk (0.47) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 499 lines diff across 6 files
0.47
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.372
Shallow Review Depth shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #380"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 47.5% (MEDIUM) · Higher = larger blast radius
47.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 25.3% · Safe to merge
25.3%