Skip to content

fix(a2a): unify background-job liveness, clear, and cancel on the supervisor contract - #730

Merged
edenreich merged 2 commits into
mainfrom
refactor/720-unify-background-job-liveness
Jul 3, 2026
Merged

edenreich merged 2 commits into
mainfrom
refactor/720-unify-background-job-liveness

Conversation

@edenreich

@edenreich edenreich commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Since #693 all three background job kinds - A2A tasks, background shells, subagents - implement the uniform BackgroundJob contract and run under the job supervisor, but the readers and controllers were still fragmented:

Consumer A2A Shell Subagent
Status bar / /tasks list supervisor supervisor supervisor
HasPending() supervisor ShellTracker SubagentTracker
A2A_QueryTask polling guard tracker, wrong key (silent no-op) none none
/tasks Cancel works A2A-only path, silently fails silently fails
/clear / conversation switch orphans in-flight jobs n/a n/a

This PR routes all of it through the supervisor contract:

  • Uniform per-id liveness - Supervisor.IsRunning(id), exposed as BackgroundTaskRegistry.IsJobRunning(id) and consumed by tools via the narrow JobLivenessReporter projection (mirrors JobSubmitter/JobStopper). First consumer: the A2A_QueryTask guard, now keyed by task id and sourced from the supervisor (it passed the agent URL to a task-id-keyed lookup, so it never fired).

  • JobMeta.HoldsSession - each job declares whether it keeps a headless session alive; HasPending() is now a single supervisor query for every kind, and the interactive-pane exit carve-out is declared by the job itself.

  • /tasks Cancel for every kind - the confirm gate arms for running shell/subagent rows and cancellation dispatches by kind: A2A keeps CancelBackgroundTask (the only path that cancels the remote task - a2aJob.Wind is deliberately a local no-op), shells/subagents use WindJob(id, WindStop).

  • Supervisor.DiscardKind - stops and forgets a kind's jobs (no completion note, no retention row, dropped from the snapshot synchronously). The registry's ClearAllAgents invokes it for JobKindA2A, so /clear, /new, and conversation switches no longer leave orphaned A2A pollers behind. Shells and subagents are untouched (session-scoped, not conversation-scoped).

  • Dead plumbing removed - TaskPollingState.CancelFunc (never assigned, nil-guarded no-op calls), the write-only NextPollTime/CurrentInterval/LastPollAt, and the caller-less A2ATaskTracker.IsPolling.

  • Subagent lifecycle debug logging - interactive tmux spin-up could fail with zero log output (early-exit errors went only to the model; Supervisor.Submit could silently swallow a job; teardowns killed panes silently). The lifecycle now logs end-to-end: Agent tool entry, tmux pane-creation failures (command + stderr) and empty-pane-id results, unsupervised-dispatch warnings, supervisor submit/finish/wind/discard/reap, pane-monitor start/exit, and close requests.

Closes #720
Closes #718
Closes #719

Verification

  • task test green; go test -race over internal/services/jobs, internal/services, internal/agent/tools, internal/ui/components, internal/utils.
  • task lint 0 issues; task build ok; mocks regenerated (FakeJobLivenessReporter added, FakeA2ATaskTracker loses IsPolling).
  • New regression tests: guard keyed by task id (fails against the old agent-URL impl), HasPending via supervisor + HoldsSession (interactive-pane carve-out preserved), /tasks cancel kind-dispatch, DiscardKind (no note, no retention, other kinds untouched), ClearAllAgents discard.

no docs ticket: internal-only refactor (user-visible effect is bug fixes: the polling guard fires, /tasks cancel works for shells/subagents, /clear stops in-flight A2A tasks)

@edenreich
edenreich requested a review from a team as a code owner July 2, 2026 23:08
…ervisor contract

The supervisor is the single source of truth for background jobs (a2a,
shell, subagent), but its readers and controllers were fragmented:

- Add Supervisor.IsRunning + JobLivenessReporter and key the
  A2A_QueryTask polling guard by task id via the supervisor (it passed
  the agent URL to a task-id lookup, a silent no-op).
- Add JobMeta.HoldsSession and route HasPending through the supervisor
  for every kind; interactive panes now declare the exit carve-out via
  the contract instead of a tracker-side mode filter.
- Dispatch /tasks cancel by kind so shells and subagents actually stop
  (WindJob) while A2A keeps the remote-cancelling path.
- Add Supervisor.DiscardKind and hook it into the registry's
  ClearAllAgents so /clear, /new, and conversation switch stop in-flight
  A2A jobs without a late completion note or retention row.
- Drop dead TaskPollingState plumbing (CancelFunc, NextPollTime,
  CurrentInterval, LastPollAt) and the caller-less tracker IsPolling.
@edenreich
edenreich force-pushed the refactor/720-unify-background-job-liveness branch from 8510410 to 76498db Compare July 2, 2026 23:10
Interactive subagent spin-up could fail with zero log output: the Agent
tool's early-exit errors went only to the model, Supervisor.Submit could
silently swallow a job, and teardown paths killed tmux panes without a
trace. Instrument the whole lifecycle:

- Agent tool: invocation entry, interactive-fallback decisions, tmux pane
  creation failures (with the command and stderr), empty-pane-id results,
  pane created, and unsupervised-dispatch warnings.
- Supervisor: submit-after-stop warning, accepted submits, finish status,
  wind signals, discard and reap teardowns.
- Subagent jobs: headless start/finish, pane monitor start/exit reasons,
  Gone/Dead detection, turn harvests, and pane-killing Close paths.
- Pane inspector: tmux state-check failures (debug, poll-frequency safe).
@edenreich
edenreich force-pushed the refactor/720-unify-background-job-liveness branch from d97f934 to b37400a Compare July 2, 2026 23:58
@edenreich
edenreich merged commit eb37fd0 into main Jul 3, 2026
1 check passed
@edenreich
edenreich deleted the refactor/720-unify-background-job-liveness branch July 3, 2026 00:12
inference-gateway-releaser Bot added a commit that referenced this pull request Jul 3, 2026
## [0.128.0](v0.127.0...v0.128.0) (2026-07-03)

### 🚀 Features

* **chat:** make status indicators selectable with /tools and /a2a views ([#732](#732)) ([6882de0](6882de0)), closes [#717](#717) [#717](#717)

### 🐛 Bug Fixes

* **agent:** drop redundant Idle transition that errored on every run ([#726](#726)) ([469ec64](469ec64)), closes [#722](#722) [#725](#725)
* **agent:** report session-cumulative total_turns in completion logs ([#728](#728)) ([0d8fb08](0d8fb08)), closes [#727](#727)
* **a2a:** route active A2A reads and HasPending through the job supervisor ([#693](#693)) ([#721](#721)) ([dcd0670](dcd0670)), closes [#718](#718) [#719](#719) [#720](#720)
* **keybindings:** stop "unknown keybinding action" log flood ([#724](#724)) ([c828426](c828426)), closes [#714](#714) [#722](#722)
* **a2a:** unify background-job liveness, clear, and cancel on the supervisor contract ([#730](#730)) ([eb37fd0](eb37fd0)), closes [#693](#693) [#720](#720) [#718](#718) [#719](#719)
* **logging:** use structured key/value form at misused call sites ([#729](#729)) ([cd96028](cd96028)), closes [#722](#722) [#724](#724) [#724](#724) [#723](#723)
* **tools:** wait for pipe readers before reaping detached bash shells ([#716](#716)) ([e1d0d84](e1d0d84)), closes [#696](#696)

### ⚡ Performance Improvements

* **tui:** cache per-entry rendering and keep the Update loop responsive ([#731](#731)) ([8c9db0d](8c9db0d))

### 📚 Documentation

* **a2a:** add SKILL.md documentation for Agent2Agent protocol ([defcd57](defcd57))

### 🔧 Build System

* **deps:** bump golang.org/x/net from 0.47.0 to 0.55.0 in /examples/mcp/mcp-server ([#715](#715)) ([990803b](990803b))

### 🧹 Maintenance

* **flox:** bump dev deps ([d0c8f6b](d0c8f6b))
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.128.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 Jul 3, 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

1 participant