fix(agent): give task trace correlations a complete lifecycle (issue #228) #380
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
yuluo-yx
Describe what this PR does / why we need it
Issue #228 reports that
TaskTraceCorrelation— the in-memory store linking theTaskTooldelegation site to theTaskOutputToolreceive site of background tasks — has no lifecycle at all: it has aforgetmethod 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.applyrecords the correlation facts before callingtaskRepository.putTaskunguarded, so a rejected submission — the bounded repository throwsRejectedExecutionExceptionon full capacity, a duplicate task id or a closed repository — leaves a stranded record that nothing ever removes. On the happy path,TaskOutputToolreturns 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/taskpackage, plus one repository hook. First,TaskToolwrapsputTaskin a try/catch and rolls the record back withforgetbefore 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 callsrefreshwhen 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, andrecord()/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 throughremoveTask,clear,clearCompletedTasks,shutdownor the bounded repository'sclose, soTaskRepositorygains a defaultaddLifecycleListener(TaskLifecycleListener): both implementations notify listeners with the affected task ids outside their monitors, and bothTaskToolandTaskOutputToolregister 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
TaskTraceCorrelationLifecycleTestdrives 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),forgetAllreleases only the given ids, andforgetstays idempotent. The newTaskTraceCorrelationRepositoryLifecycleTestasserts cleanup without any subsequent poll:removeTask,clearandshutdownon the default repository andremoveTask,clearandcloseon the bounded repository release the correlations, and both tools wire the listener.TaskToolTraceCorrelationTestscovers 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 withRejectedExecutionExceptionand 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