Three real bugs + four polish items + a substantive test coverage
gap for the new monitor-task module.
## Critical (3 real bugs)
1. **BackgroundTasksDialog.tsx**: the per-entry live-refresh effect
gated on `dialogMode !== 'detail'`, silently dropping the
`detail-from-panel` path (the LiveAgentPanel → detail navigation).
Restored to `!isDetailMode` so both detail modes route through the
subscription. Same predicate sibling effects use.
2. **BackgroundTaskViewContext.tsx**: `getTaskByType(target.kind)`
was evaluated as a Promise.resolve() argument; a sync throw from
an unregistered kind escaped the .catch() chain into the React
useCallback handler. Wrap the lookup in try/catch (sync path),
keep the kill() dispatch synchronous-at-call-site (preserves the
"pressing 'x' invokes kill before the next tick" test contract).
3. **monitor-task.ts**: `monitorEmitEvent` called `registry.update`
which fires `fireChange`, churning the dialog list + footer pill
on every monitor stdout line — perf regression vs the old
`MonitorRegistry.emitEvent` which deliberately suppressed per-
event mutations from the status-change callback. Introduce
`TaskRegistry.mutateSilent` for in-place mutations whose change-
listener fanout the dialog doesn't need (id/kind/status don't
shift). Detail-view subscribers still see fresh data because
they re-read on their own tick. Also applied to
`agentAppendActivity` for the same reason (activity bursts
shouldn't churn list-mode renderers).
## Critical (test coverage gap)
4. **monitor-task.ts had zero tests** — the deleted
`monitorRegistry.test.ts` (918 lines) was not replaced. Added
`packages/core/src/tasks/monitor-task.test.ts` covering the
critical paths: cap enforcement, registration shape, silent
per-event mutation, idle-timer reset, auto-stop re-entrancy,
terminal transitions (single fireChange), notify:false /
notify:true cancel ordering, owner-routed notifications +
lifecycle wake, abortAll + reset clearing module-level callback
Maps, and the kind-narrowing helpers. 24 cases, all green.
## Suggestions (4)
1. **config.ts**: `loadPausedBackgroundAgents` /
`resumeBackgroundAgent` return-type imports now point at the
canonical `../tasks/agent-task.js` instead of the deprecated
re-export shim `../agents/background-tasks.js`.
2. **monitor.ts**: cap pre-check now uses the already-exported
`getRunningMonitorTasks(registry)` helper instead of an inline
filter.
3. **monitor-task.ts**: `monitorComplete` / `monitorFail` /
`monitorEmitEvent` (auto-stop branch) no longer issue a second
`registry.update` for status fields — the `settle()` helper
now accepts `{ exitCode, error }` so the terminal transition
fires exactly one `fireChange`. Mirrors the single-update
pattern in `shellComplete` / `shellFail`.
4. **registry.ts** / per-kind modules: added
`_resetAgentTaskModuleStateForTest` and
`_resetMonitorTaskModuleStateForTest` to clear module-level
singletons (callbacks, owner-routed Maps, the agent cap,
messageWaiters). Composed into a single
`_resetTaskKindModuleStateForTest(registry)` helper in
`tasks/index.ts` for `afterEach` use.
## Test infra
Added `mutateSilent` to the registry stubs in `agent.test.ts`,
`shell.test.ts`, `nonInteractiveCli.test.ts`, and
`clearCommand.test.ts` so the new method on `TaskRegistry` doesn't
trip mocks.
## Verification
- `npm run typecheck`: clean across all packages
- `npm run lint:ci`: clean (--max-warnings 0)
- `npm run build && npm run bundle`: clean
- Targeted core suites (`src/tasks`, `src/agents`,
`src/tools/agent`, shell, monitor, send-message, task-stop): 763
passed, 2 skipped
- New monitor-task.test.ts: 24 / 24 passed