Skip to content

fix(a2a): retain completed background tasks in /tasks (#691) - #701

Merged
edenreich merged 1 commit into
mainfrom
fix/691-retain-completed-a2a-tasks
Jun 30, 2026
Merged

edenreich merged 1 commit into
mainfrom
fix/691-retain-completed-a2a-tasks

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

Fixes #691 — completed background A2A tasks vanished from /tasks instead of being retained (the documented a2a.task.completed_task_retention: 5 was effectively ignored).

Root cause

The /tasks view sources completed A2A rows only from taskRetentionService.GetTasks() (it skips A2A rows from the supervisor snapshot), so a completed A2A task shows up iff something calls taskRetentionService.AddTask(...). Nothing did, for background tasks:

  • The only retention call site is the a2acoord coordinator's retainTaskFromResult, reached solely from HandleTaskCompleted — i.e. only when a domain.A2ATaskCompletedEvent is dispatched.
  • But every A2A lifecycle event (A2ATaskCompletedEvent, …) is constructed only in *_test.go; none are emitted in production. That whole coordinator → retention pipeline is unreachable.

So the issue's first guess ("retention runs with a Task-less result") isn't what happens — retention is never called at all for background tasks. The real background-completion path is the job supervisor: when an a2aJob's polling loop reaches a terminal state, Supervisor.finish() surfaces the result (enqueue → agent notification) but never populates the retention service. Tellingly, the container already calls SetRetentionCount(domain.JobKindA2A, …) — a half-wired seam.

Fix

Supervisor.finish() now populates the retention service via a small optional TaskRetainer BackgroundJob extension implemented by a2aJob — mirroring the existing JobNotifier/asNotifier pattern:

  • internal/domain/background_job.go — new TaskRetainer optional extension (sibling of JobNotifier).
  • internal/agent/tools/a2a_job.go — a2aJob.RetainedTask builds a TaskInfo from the live in-memory *adk.Task (no JSON round-trip fragility), reconstructing it from the reported state when the result carries no task (canceled). retainableA2AState whitelists completed/failed/canceled (normalizing the TASK_STATE_* enum), excluding input-required.
  • internal/services/jobs/supervisor.go — taskRetention field + late-injected SetTaskRetention setter (mirrors SetConversationRepo), an asRetainer helper, and a retain step in finish() (field read under the existing lock; retains before the BackgroundTasksChangedEvent refresh; independent of Silent).
  • internal/container/container.go — wire SetTaskRetention where the retention service is built.

The supervisor stays domain-only (no tools import). The existing result-surfacing path is unchanged, so there's no double-rendering, and the dead A2ATaskCompletedEvent pipeline is not resurrected.

Testing

  • internal/agent/tools/a2a_job_test.go — table tests for RetainedTask (completed/failed carry the full task; canceled reconstructs from state; input-required / non-A2A data / empty id opt out) and retainableA2AState (prefixed enum + bare/alternate spellings).
  • internal/services/jobs/supervisor_test.go — finish retains a TaskRetainer job's TaskInfo exactly once; non-retainer and opt-out jobs are skipped; no retention service wired → no panic.
  • task test (full suite, -race on affected packages) and task lint are green.

Scope / notes

  • Retains completed/failed/canceled terminal states. input-required (a pause) is intentionally not retained.
  • The unreachable a2acoord A2A event pipeline is left as-is (resurrecting/removing it is out of scope for this bug).
  • No cross-repo impact; no docs ticket (internal bug fix, no public surface/config change).

Completed background A2A tasks vanished from /tasks: the task view reads completed A2A rows only from the retention service, which nothing populated for backgrounded tasks. The only retention call site is the a2acoord coordinator, reached solely via A2ATaskCompletedEvent - an event constructed only in tests, so that pipeline is unreachable in production.

Populate the retention service from the job supervisor's finish() (the real background-completion path) via a new optional TaskRetainer BackgroundJob extension implemented by a2aJob, mirroring JobNotifier/asNotifier. The supervisor stays domain-only; a2aJob builds the TaskInfo from the live *adk.Task, reconstructing it from the reported state for canceled tasks. Retains completed/failed/canceled terminal states.

Closes #691
@edenreich
edenreich requested a review from a team as a code owner June 30, 2026 22:56
@edenreich
edenreich merged commit 43b8e13 into main Jun 30, 2026
1 check passed
@edenreich
edenreich deleted the fix/691-retain-completed-a2a-tasks branch June 30, 2026 23:03
inference-gateway-releaser Bot added a commit that referenced this pull request Jun 30, 2026
## [0.126.0](v0.125.0...v0.126.0) (2026-06-30)

### 🚀 Features

* add persistent memory tool for agent ([#679](#679)) ([a487b13](a487b13))
* **agent:** interactive subagent management and unified background-work tracking ([#684](#684)) ([343e083](343e083))

### 🐛 Bug Fixes

* **chat:** bind opt+backspace and ctrl+backspace to delete-word-backward ([#697](#697)) ([173fe83](173fe83)), closes [#689](#689) [#576](#576)
* **a2a:** retain completed background tasks in /tasks ([#691](#691)) ([#701](#701)) ([43b8e13](43b8e13))
* **autocomplete:** surface arguments for one-of/all-optional tool schemas ([#698](#698)) ([655b2e4](655b2e4))

### ♻️ Code Refactoring

* add .gitignore by default to the projects dir ([4717deb](4717deb))
* enable memory by default ([86c2158](86c2158))
* make infer config userspace-first ([#682](#682)) ([1e77e42](1e77e42)), closes [#680](#680)
* **tui:** single event-loop ingress - one notifier, no self-rescheduling pollers ([#700](#700)) ([2ab8854](2ab8854))
* standardize comment punctuation by replacing em dashes with hyphens ([78f53a8](78f53a8))

### 📚 Documentation

* fix docs/ drift found by the README-to-codebase audit ([#687](#687)) ([413047a](413047a)), closes [#572](#572) [#686](#686)
* sync README and reference docs with the codebase ([#685](#685)) ([c328423](c328423)), closes [#572](#572) [#684](#684) [#684](#684)

### 👷 CI/CD

* **deps:** update CLAUDE workflow to version 0.14.5 ([eaba2b3](eaba2b3))

### 🧹 Maintenance

* add .infer to .gitignore ([08ef319](08ef319))
* **deps:** bump infer CLI v0.124.0 -> v0.125.0, infer-action v0.19.0 -> v0.19.1 ([#681](#681)) ([e9e7e21](e9e7e21))
* remove agent definitions ([4f7fd7d](4f7fd7d))
* remove unused configuration and shortcut files ([4c611db](4c611db))
* update claude-code to 2.1.191 ([729e81c](729e81c))
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.126.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Completed background A2A tasks are not retained in /tasks (completed_task_retention ignored)

1 participant