Skip to content

provider-pi: expose background-task lifecycle events to extensions - #5290

Draft
yteruel31 wants to merge 1 commit into
get-bb:mainfrom
yteruel31:feat/pi-background-task-events
Draft

yteruel31 wants to merge 1 commit into
get-bb:mainfrom
yteruel31:feat/pi-background-task-events

Conversation

@yteruel31

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

The Pi provider forwards extension dialogs, but has no generic path for a third-party Pi extension to publish the lifecycle of its own background work. Pi event-bus notifications remain inside the Pi process, and terminal UI status/widget requests are intentionally dropped. An extension can therefore have active subagents while BB has no native background-task cards or active-agent count for them.

What changed

  • Add experimental v1 bb:background-task events and a bb:background-task:request snapshot hook to the injected Pi extension. Transport the selected, bounded fields over the existing private child/bridge pipe; validate at the receiving boundary and translate to existing native backgroundTask deltas.
  • Support source namespaces, publisher lifetimes, ordered upserts, complete snapshots, and clear. Reject malformed, oversized, duplicate, and stale data without changing the projection. Source, task, and retired-lifetime state have explicit admission bounds; no prompts, arbitrary output, or thread IDs are accepted.
  • Open native cards once, update them after the parent turn settles, and close them exactly once. Use count-eligible native items without injecting telemetry into model context. Hold pre-turn snapshots until the first real agent turn instead of fabricating turns or invoking the model.
  • Reconcile observer shutdown, removed reload sources, stop, crash, and replacement. Recover returning sources with fresh observer identities so old completion records do not suppress current counts. Keep the previous session authoritative while a replacement candidate starts; preserve it when construction fails.
  • Document the contract, an extension example, bounds, and observation-only semantics in the provider README and skill. No new CLI command: existing Pi threads from UI, SDK, and CLI share the path.

Changes stay in plugins/provider-pi: no Pi Toolbox dependency, additional tools/workers, automatic model continuation, core/Plugin SDK exports, dependencies, SDK version bump, server/daemon wire change, or installed-provider changes. These are private messages between the bundled extension and its bridge; HOST_DAEMON_PROTOCOL_VERSION is unchanged.

This is separate from #5271 (Windows launching), and complementary to #5255 (built-in background shell tools). This PR observes work owned by third-party extensions; it does not execute/cancel that work, collect its output, or deliver results to the model. A Pi Toolbox adapter is deliberately outside this PR.

How you verified

  • Added contract/projection tests and scripted bridge tests using the real injected extension, event bus, FD transport, schemas, and the published native delta assembler. Coverage includes pending/paused/running and terminal states, post-parent-idle updates, identity and namespace isolation, invalid/oversized/duplicate data, stale sequences/publishers, bounded admission, startup snapshots, absent reload publishers, shutdown, crash, replacement, and failed-candidate preservation.
  • One independent code-review pass found counter eligibility and replacement/reload lifecycle defects. Added regressions and corrected them. Parent inspection also added explicit per-candidate startup UI/tool binding, preserving the previous live session until readiness and cleaning up failed-candidate interactions.
  • Real Pi RPC smoke passed on 0.84.0 and 1.1.0, using an isolated agent directory and a deterministic loopback OpenAI-compatible endpoint, with no external model calls. Actual assembled events persisted into a migrated in-memory BB database produced native active-agent counts 1 → 1 → 0, stable item identity, progress after the parent turn completed, and exactly one model request. The model request contained no telemetry marker.
  • Actual migrated-database reconciliation check: two active sources 2, parent idle 2, observer shutdown 0, reload with one returning source 1, completion 0. The recovered item ID differs from its previously completed observation.
  • pnpm exec turbo run lint typecheck test prepare:bundled --filter=bb-plugin-provider-pi --concurrency=2 --force: all 11 tasks passed, 242 tests passed, one existing Bun-only test skipped. oxfmt --check passed for all nine changed files; git diff --check passed.
  • A separate exploratory extension that awaits a dialog during Pi's session_start exited before producing an interaction request, on both the patched and original provider checkouts. This pre-RPC initialization behavior is not claimed as fixed here; scripted protocol tests verify that an emitted candidate startup request is scoped, forwarded, and cleaned up correctly.

No installed provider or user Pi configuration was changed. No browser/UI visual verification or native Windows/Bun run was performed for this PR; the existing Bun-only test is skipped on this host.

AGENT GENERATED

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant