feat(runtime): expose process lifecycle hooks to embedding hosts - #514
feat(runtime): expose process lifecycle hooks to embedding hosts#514MertBasar0 wants to merge 3 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 3:48 AM ET / 07:48 UTC. ClawSweeper reviewWhat this changesAdds optional public lifecycle hooks that let embedding hosts observe and admit ACP agent process launches, failures, and exits with session or probe scope metadata. Merge readinessKeep open for a maintainer product/API decision. The implementation and real embedding-host evidence are strong, but the new public admission hooks deliberately permit an embedding host to hold agent startup indefinitely, so that availability contract needs explicit acceptance. Priority: P2 Review scores
Verification
How this fits togetherThe runtime API creates ACP clients for embedded sessions and health probes, which spawn adapter processes and then establish ACP connections. This change exposes that spawn boundary to an embedding host before session initialization and when the child later exits. flowchart LR
A[Embedding host] --> B[Runtime options]
B --> C[ACP client process launch]
C --> D{Lifecycle admission hook}
D --> E[ACP session initialization]
C --> F[Spawn failure or process exit]
F --> G[Host lifecycle observer]
Decision needed
Why: The implementation intentionally makes hook completion part of the process-start boundary, so choosing a timeout or recovery policy changes the public availability contract rather than repairing a coding defect. Before merge
Agent review detailsSecurityNone. Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Adopt the public hook only if maintainers explicitly accept host-owned timeout and recovery policy; otherwise define a bounded admission/cancellation contract before releasing it. Do we have a high-confidence way to reproduce the issue? Not applicable as a feature request; the supplied real embedding-host terminal trace nevertheless exercises the changed public runtime boundary and its failure cases. Is this the best way to solve the issue? Unclear pending product direction: the implementation handles the tested process races, but maintainers must choose whether unbounded host-owned admission is the desired stable API policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ef6b81e71756. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (10 earlier review cycles; latest 8 shown)
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@steipete This is ready for a maintainer product/API decision. The current head includes real embedding-host proof, all repository checks pass, and ClawSweeper reports no actionable findings. Could you confirm whether ACPX should adopt the opt-in awaited onBeforeSpawn / onSpawned admission hooks as a public runtime contract, with timeout and recovery policy owned by embedding hosts? If so, the PR is ready as-is. If you prefer bounded timeout/cancellation or nonblocking semantics, I’m happy to adjust. |
Related: #499
Context: openclaw/openclaw#128006
What Problem This Solves
Embedding hosts can launch ACP agents through
AcpClientorAcpRuntime, but they currently have no supported way to durably record process ownership around the exact spawn boundary. Hosts that need crash recovery or process-lease reconciliation must either wrap ACPX internals or accept a gap between preparing a launch and learning the child PID.Why This Change Was Made
This adds an optional lifecycle contract with immutable, correlated events for pre-spawn admission, successful spawn, spawn failure, and process exit. Runtime-created clients also receive stable session/probe scopes.
The two admission hooks are deliberately awaited: rejecting before spawn prevents launch, while rejecting after spawn terminates the child before returning the error. Failure and exit observers remain best-effort and cannot mask the underlying process outcome. Exit notification is ordered after spawned admission settles, avoiding a stale-lease race when a child exits quickly.
This is an embedding seam only. It does not add persistence, process-tree cleanup, or host-specific lease policy to ACPX, and therefore does not claim to close #499.
User Impact
Embedding developers can now implement durable host-owned launch tracking without wrapping ACPX spawn internals. Existing clients are unaffected because every lifecycle hook is optional.
Evidence
pnpm run checkpasses in a clean Linux checkout: formatting, TypeScript checks, type-aware lint, package and replay-viewer builds, 942 repository tests, and 130 coverage tests.onSpawnFailednonblocking while preserving synchronous invocation, correlation data, and logging for synchronous throws and asynchronous rejections.@agentclientprotocol/codex-acp1.6.2 adapter passes; redacted runtime proof is included below.openclaw/acpxmainat commit time.Real embedding-host proof
Environment: WSL2 Linux x64, Node v24.15.0, PR head
08a8601, published@agentclientprotocol/codex-acp1.6.2, existing Codex ChatGPT login. No credential values were logged. The temporary external host imported the built publicdist/runtime.jsAPI and usedcreateAcpRuntime,createRuntimeStore, andcreateAgentRegistry; it was not added to the PR.The first scenario initialized a real ACP session through
codex-acp, then closed it. The second used a real Node child that exited with code 17 while a slow but successfulonSpawnedadmission hook was pending. The third used a real OS spawn failure whileonSpawnFaileddeliberately returned a Promise that never settles.The successful adapter PID and the admission-test PID were both confirmed exited after the run. No model prompt or inference was needed; this proof exercises the embedding boundary, real adapter process lifecycle, ACP session initialization, correlation, the repaired startup-exit path, and the repaired spawn-failure semantics.
AI assistance
The implementation was AI-assisted. I reviewed the resulting lifecycle contract, failure semantics, tests, generated diff, and real embedding-host trace, and validated it with the checks listed above.