One unified primitive for all session spawning. Cross-session events. Reactive triggers. Background session management.
Session cbbd5d39 • February 2026 • 4 PRs across the Ecosystem
The Problem
Fragmented Session Spawning
Before this work, spawning sessions was inconsistent, duplicated, and isolated.
📋
~400 Lines Duplicated
CLI and Foreman each had their own spawning logic. Same patterns, different implementations, diverging behavior.
🔇
No Event Communication
Sessions were islands. When Session A completed, Session B had no way to know or react.
⚙️
Manual Asyncio Everywhere
Background tasks required hand-rolled async patterns. No declarative way to define long-running sessions.
The Solution
spawn_bundle()
One function that handles everything: bundle resolution, config inheritance, context passing, background execution, and event emission.
Bundle
→
spawn_bundle()
→
Session
→
Events
5 phases of implementation. 500+ tests. Zero regressions. Fully backward compatible.
Phase 1A
Core spawn_bundle() Primitive
The unified foundation for all session spawning in Amplifier.
# New kernel events in amplifier-coreclassEventType(Enum):
SESSION_COMPLETED = "session_completed"
SESSION_ERROR = "session_error"# The core primitive in amplifier-foundationasync defspawn_bundle(
bundle: str | BundleConfig,
instruction: str,
parent_session: AmplifierSession | None = None,
storage: SessionStorage | None = None,
background: bool = False,
) -> SpawnResult:
"""Spawn a session from a bundle - THE unified entry point."""
SpawnResult
Dataclass with session, task handle, and result access.
SessionStorage
Protocol for custom storage backends.
35 Test Cases
Comprehensive coverage of all spawning scenarios.
Phase 1B
Consumer Migration
Refactored existing consumers to use the new primitive.
Before
CLI: custom spawn_sub_session()
Foreman: custom worker spawning
~400 lines of duplicated logic
Diverging behavior over time
After
CLI: uses spawn_bundle()
Foreman: uses spawn_bundle()
Single source of truth
ForemanSessionStorage impl
122+ tests passing. Zero regressions. Both CLI and Foreman work identically.
Phase 2
Cross-Session Event Communication
Sessions can now talk to each other through a pub/sub event system.
# Session A emits an event when it completesawait session_a.emit_event("analysis_complete", {"findings": results})
# Session B subscribes and reactsasync for event in router.subscribe("analysis_complete"):
awaitprocess_findings(event.payload)
# Or wait for a specific event with timeout
event = await router.wait_for_event("build_finished", timeout=300)
SessionEvent
Typed event dataclass with source, type, and payload.
EventRouter
Central pub/sub broker for cross-session communication.
20 Test Cases
Event emission, subscription, timeouts, and error handling.
Phase 3
Reactive Trigger Infrastructure
Define when sessions should start—not just how.
⏱️
TimerTrigger
Schedule sessions on intervals. Cron-like patterns for periodic tasks.
📡
SessionEventTrigger
React to events from other sessions. Chain workflows together.
🎯
ManualTrigger
Programmatic activation. Trigger from code when conditions are met.