# Bug Report: Completed background agent cannot be retrieved by Task Output

## Summary

A background agent is shown as successfully finished, but requesting its task output immediately fails with `No task found with ID`. The UI still lists other running background agents, indicating that the background-agent subsystem remains active while the completed task record is no longer retrievable.

## Observed behavior

```text
Agent "Audit remediation scope" finished · 45m 43s

Task Output a1f48b4de9ae5dc32
└ Error: No task found with ID: a1f48b4de9ae5dc32. Running background agents:
  a27796702701fc0e5 (Design execution phases)
  a17f7eceeff4ca0ec (Inspect IGHE implementation plan)
  a1ac5c814dc2f9c63 (Inspect IGHE implementation plan)
  a56a0f82f0ceea951 (Inspect IGHE plan)
  a9ef392c0167decb8 (Inspect IGHE implementation plan)
  ae027938d0de1d40c (Inspect IGHE and plan)
```

## Expected behavior

After the UI reports that a background agent has finished, its task ID should remain valid and its output should be retrievable. If output retention has expired or cleanup occurred, the UI should show an explicit lifecycle status instead of reporting that no task exists.

## Reproduction steps

1. Start one or more background agents.
2. Allow an agent to run for an extended period; the captured run lasted `45m 43s`.
3. Wait until the UI reports that the agent finished.
4. Request the output using the completed task ID.
5. Observe `Error: No task found with ID`.

## Impact

- The completed agent's result is lost or inaccessible.
- Long-running work cannot be reviewed after completion.
- Users cannot distinguish between an invalid ID, premature cleanup, state desynchronization, or output-retention expiry.
- Concurrent background-agent workflows become unreliable because completion does not guarantee result retrieval.

## Suspected failure area

The evidence is consistent with a lifecycle synchronization issue between agent completion, task registry retention, and task-output lookup. Possible causes include:

- The completed task is removed from the registry before its output is fetched.
- The completion notification and output lookup use different task identifiers.
- Completed-task state is stored in a different process or session and is unavailable to the lookup path.
- Cleanup or retention logic incorrectly treats a completed task as disposable before output consumption.

These are hypotheses; the screenshot alone does not establish the root cause.

## Diagnostic data to collect

- Task creation, completion, cleanup, and lookup timestamps for `a1f48b4de9ae5dc32`.
- Mapping between agent ID, background task ID, and output artifact ID.
- Session/process identifiers used by the completion event and output lookup.
- Retention or garbage-collection events around the completion timestamp.
- Whether the output exists on disk or in persistent storage after registry removal.
- Whether the issue reproduces only for long-running tasks or under concurrent-agent load.

## Acceptance criteria

- A completed background task remains retrievable for the documented retention period.
- The completion notification exposes the same identifier accepted by task-output retrieval.
- Cleanup does not remove output before the user or coordinator can consume it.
- Missing, expired, and invalid task IDs produce distinct actionable errors.
- Concurrent running agents do not affect retrieval of completed-agent output.

## Evidence

Source: user-provided screenshot.

Affected task ID: `a1f48b4de9ae5dc32`

Completed agent: `Audit remediation scope`

Reported duration: `45m 43s`
