Repository navigation
Conversation
Contributor
Author
|
Note on the failing |
…gentic-ai-java#228) TaskTraceCorrelation recorded entries at the TaskTool delegation site before taskRepository.putTask, so a rejected submission (bounded repository capacity, duplicate id, closed repository) stranded the record forever; and nothing in production ever called forget, so even happy-path entries outlived their tasks and the map grew without bound. The correlation now has a three-layer lifecycle: TaskTool rolls the record back when putTask throws; TaskOutputTool releases the entry once a terminal (completed or failed) result has been delivered - after the receive span was linked, never before, so the polling window keeps working and non-terminal outcomes (still-running, timeout, interrupted) retain the entry for the next poll; and a retention window with an injectable clock lazily sweeps whatever survives, independent of the repository type, so default, bounded and injected repositories all converge without new repository lifecycle APIs. Tests: a capacity-rejected submission leaves zero retained records; a terminal poll releases the correlation while the repository result stays pollable; expired entries are never served and swept on the next record; forget stays idempotent.
konlue
force-pushed
the
fix/issue228-task-trace-correlation-lifecycle
branch
from
November 21, 2026 08:41
09c7700 to
aeb62a5
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 and retention 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. 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,TaskOutputToolreleases the entry once a terminal result (completed or failed) has been delivered — deliberately after the receive span was created and linked, so the polling window still establishes the link facts; non-terminal outcomes (still-running, timeout, interrupted) keep the entry so the next poll can link, matching the existing timeout contract test. Third, entries now carry an expiry stamp driven by an injectable clock with a configurable retention (30 minutes by default):correlation()removes and never serves an expired entry, andrecord()lazily sweeps stale ones, so a store with no consumers still converges without a janitor thread. The retention is independent of the repository type — the default, bounded and any injected repository all converge, and repositoryclear()/shutdown()simply leave no new records behind — so no new repository lifecycle listener API is needed, and the builder-owned store outlives a repository shutdown without being closed.Testing
The new
TaskTraceCorrelationLifecycleTestdrives retention with a mutable clock: an expired entry is never served and is swept by the next record, a live entry is served until its window elapses, andforgetstays idempotent and safe for unknown ids. Two tool-chain tests extendTaskToolTraceCorrelationTests: a capacity-full bounded repository rejects the background submission withRejectedExecutionExceptionand leaves zero retained records (red before: one stranded record), and a terminal poll releases the correlation while a second poll still returns the full repository result (red before: the entry survived the delivery). The existing timeout-retains-correlation contract, the bounded repository rejection semantics and the whole task package pass unchanged (36/36 in the package, 1423 in the module with only the known Windows filesystem/ripgrep baseline failures), checkstyle and spring-javaformat clean.Fixes #228