V3 design spike: prototype capability lifecycle sequencing
This pull request was posted by Codex Desktop using gpt-5.6-sol on behalf of David.
[!IMPORTANT]
Non-merging design spike. This PR is for architecture review only. It does not close #7339 and is not proposed for standalone merge. The code probes one possible dispatch seam while the durable-runtime contract in #5477 and the ecosystem migration plan are still being designed.
This is stacked on #7345, which isolates run preparation and lifecycle ownership. Review the capability-specific commit independently; #7345 can land without this spike.
Question this spike answers
Can capability containers and typed Hooks registrations share one framework-owned sequencing engine without changing ordering, recovery, filtering, deferred settlement, or stream ownership?
The probe adds a private, typed LifecycleStack and routes both adapters through it:
CombinedCapabilityretains availability and capability-owned-tool activation.Hooksretains registration order, timeout handling, and tool-name filters.- The stack owns forward/reverse transforms, notifications, middleware nesting, recovery, stream cleanup, and partial deferred-result settlement.
- An explicit inactive-entry sentinel prevents skipped capabilities from mutating propagated tracebacks.
What we learned
The common sequencing behavior can be centralized without changing observable behavior, but this patch is not yet the simplification described by #7339. CombinedCapability and Hooks still mirror the lifecycle operations and adapt each one separately; the probe adds net production code instead of deleting the public hierarchy.
Two design dependencies need agreement before the mergeable v3 implementation:
- #5477 must settle which finite operations the framework owns and which execution, registration, gating, and policy responsibilities belong to durable runtimes.
- Published integrations use
AbstractCapability,CombinedCapability,WrapperCapability,Hooks,for_agent(),for_run(), ordering, and root-capability introspection. Removing those surfaces needs an explicit migration contract, not an internal-only rename.
Proposed roadmap
- Land or otherwise agree on the run-preparation boundary demonstrated by #7345.
- Settle the framework/durable-runtime boundary in #5477.
- Design typed contribution and lifecycle-registration primitives around that boundary.
- Validate the migration against first-party and published integrations, including stable IDs, tool ownership, dynamic state reuse, model provenance, and durable registration.
- Implement the mergeable #7339 change on
v3-main, deleting the mirrored dispatch and obsolete public composition mechanics rather than retaining this scaffold.
Preserved contracts
- Capability composition remains forward for
before_*, reverse forafter_*and capability recovery, and first-entry-outermost for middleware. Hooksregistrations retain registration order for transforms and recovery.- Agent binding remains distinct from exactly-once per-run preparation.
- Stream layers close deterministically on completion, failure, cancellation, and early exit.
- Deferred handlers receive only unresolved calls and accumulate partial results.
- No public API is added or removed by the spike.
Verification
- Focused capability, hook, stream teardown, event-stream, and lifecycle-engine tests pass with the required 100% coverage bar.
- Temporal, Prefect, and DBOS capability/toolset integration spot checks pass.
- Formatting, lint, targeted type checking, and commit hooks pass.
- Independent review approved the patch for its explicitly non-merging spike purpose.
Related to #7339.
Related to #5477.
Checklist
- Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
- No breaking changes in accordance with the version policy.
- PR title is fit for the release changelog.