Repository navigation
feat(agentsapi): select plugin-owned self-hosted executors - #161609
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 6:12 PM ET / 22:12 UTC (Revision 24). ClawSweeper reviewWhat this changesAdds an optional plugin controller for connecting, reusing, and retiring self-hosted Agents API executors, with persisted ownership and retryable session cleanup. Merge readiness✅ Ready for maintainer review This PR remains useful: current main lacks plugin-selected executor controllers. No actionable correctness or security findings remain, and the new evidence resolves the previous authority, cleanup-retry, and saved-session compatibility blockers. Priority: P2 Review scores
Verification
How this fits togetherThe Agents API harness connects OpenClaw conversations to native agent sessions. Selected controller plugins manage executor infrastructure, while the harness preserves conversation identity and coordinates cleanup. flowchart TD
A[Conversation input] --> B[Agents API harness]
B <--> C[Saved session binding]
B --> D[Native connection request]
D --> E[Selected controller plugin]
E --> F[Self-hosted executor]
B --> G[Native settlement and cleanup]
G --> C
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +880, Tests +1702, Docs +290, Generated 0, Other +3. Total +2875 across 43 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep native identity and settlement in the existing harness, with infrastructure management delegated through the documented opt-in controller contract. Do we have a high-confidence way to reproduce the issue? Not applicable as a feature request; the supplied real Gateway failure traces establish the cleanup defects and their repaired retention/retry behavior. Is this the best way to solve the issue? Yes. The narrow controller contract preserves existing external management, uses the existing registry and binding owners, and avoids a universal infrastructure launcher. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e557d807ffba. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (23 earlier review cycles; latest 8 shown)
|
d84ed11 to
0fa140a
Compare
0fa140a to
f974cc4
Compare
Security-sensitive guard clearedCurrent revision: This PR no longer changes files in the maintainer security-review tier. Separate CODEOWNERS requirements still apply to security policy and enforcement files. |
2535257 to
ad826c4
Compare
6a4a5b9 to
e08f34a
Compare
ad826c4 to
ff798a1
Compare
e08f34a to
fe759c3
Compare
414b227 to
afec6e6
Compare
ClawSweeper requested: "Require acknowledged settlement or a durable execution fence before removing ownership, and preserve the binding on failure; only retirement of already-settled executor resources should be best effort." Propagate native settlement failures, reacquire agent-scoped API-key authentication after restart, and invalidate failed cleanup handles so repaired authentication takes effect on retry. Keep executor retirement best effort only after native settlement. Cover reset, deletion, restart, authentication, and revoked cleanup authority.
ClawSweeper requested: "Require acknowledged settlement or a durable execution fence before removing ownership, and preserve the binding on failure; only retirement of already-settled executor resources should be best effort." Propagate required cleanup through the host reset boundary and run it before automatic session replacement. Join sibling hooks before releasing mutation admission while preserving ordinary optional-hook behavior.
Cleanup repair and runtime proofCurrent head: f71b67ab416a10241e46cb0cb569083852450c2c. The approved settlement repair now preserves native ownership when status reads, cancellation or authentication fail. The host also propagates required cleanup failure before changing the local session, including the real The maintainer-selected design retains the narrow opt-in controller contract and persisted controller ownership, with infrastructure/process management in the selected plugin and externally managed sessions preserved. Live runtime evidenceTested on 2026-10-04, America/Los_Angeles. All images ran natively as linux/arm64, with a local Docker Gateway and real Agents API sessions. Controller-managed executors ran as independent processes on one persistent remote host and shared workspace.
The published head differs from the final runtime source only in test fixtures, formatting, and SDK export accounting. The tested runtime is identified above rather than claiming a different commit was built. Actual Gateway failure and recoveryA private test-only transport wrapper rejected one exact native-session GET or cancellation POST with Commands below represent the actual private proof driver. python3 <proof-root>/gateway-call.py sessions.reset \
'{"key":"<session-B>","expectedSessionId":"<local-session-B>"}' \
--head 284b35305685b7b47cb2fd6fbd519133ea518b8d \
--record final-read-fault-reset.json
python3 <proof-root>/gateway-call.py sessions.delete \
'{"key":"<session-C1>","expectedSessionId":"<local-session-C1>"}' \
--head 284b35305685b7b47cb2fd6fbd519133ea518b8d \
--record final-cancel-fault-delete.jsonOriginal baseline: the injected session-read failure still produced Final runtime, GET failure: the RPC returned the following actual error text (the trailing truncation was returned by the Gateway): {
"ok": false,
"method": "sessions.reset",
"error": {
"name": "GatewayClientRequestError",
"message": "AgentHarnessSessionCleanupError: Connection error. | fetch failed | PR161609 proof injected connection reset | ECONNRESET <- Error: Connection error. <- TypeError: fetch failed <- Error: PR161609 proof injected connection reset: code=ECONNR...",
"code": "UNAVAILABLE"
}
}The local session ID, lifecycle revision and updated timestamp were unchanged. The same persisted native binding and executor PID 520887 remained. After removing the fault, one explicit reset retry succeeded: the real API reported idle at 14:47:21 PDT, then the controller reported that executor absent at 14:47:22 PDT. Sibling executors and shared files remained. Final runtime, active cancellation failure: actual Gateway input started a bounded foreground After removing that fault, one explicit deletion retry produced the following extracted receipt fields in order. Time fields are rendered in Pacific time, and identifiers are consistently replaced with {"time":"2026-10-04 14:51:41 PDT","session":"native-C1","operation":"session-read","httpStatus":200,"nativeStatus":"in_progress"}
{"time":"2026-10-04 14:52:05 PDT","session":"native-C1","operation":"cancel","httpStatus":202}
{"time":"2026-10-04 14:52:05 PDT","session":"native-C1","operation":"session-read","httpStatus":200,"nativeStatus":"in_progress"}
{"time":"2026-10-04 14:52:11 PDT","session":"native-C1","operation":"session-read","httpStatus":200,"nativeStatus":"idle"}
{"time":"2026-10-04 14:52:18 PDT","session":"native-C1","operation":"controller.stop","state":"ABSENT"}
{"time":"2026-10-04 14:52:22 PDT","operation":"sessions.delete","ok":true,"deleted":true}The backend session remained queryable and idle afterward. This proves cancellation settlement before local retirement, not deletion of the native API session or revocation of independently held API credentials. Shared workspace, concurrency and process recoveryTwo separate top-level Slack requests created two native sessions and executor PIDs 518697 and 520887. The first wrote one newline-terminated marker to The Gateway image replacement preserved PID 520887, its native session ID, and the shared file. A subsequent Slack follow-up returned both original lines without another ensure. Three new top-level Slack requests were admitted within 3.3 seconds. They overlapped, used three separate native sessions and PIDs 539624, 539770, and 539814, and each completed with its own single appended marker plus the same shared file contents. Replies completed at 14:29:35, 14:29:37, and 14:29:43 PDT. A scoped idle-executor stop removed PID 539814. One follow-up through the same Slack session caused a second ensure and replacement PID 541394, retained the same native session ID, and appended Slack-visible rollover on final runtimeA real Exact-main saved-session upgradePASS: created real hosted and externally managed self-hosted sessions on the PR's exact main base, then replaced only the Gateway image with the final runtime. Both configurations omitted the executor controller. The same saved state/configuration was reused, without reset, native-session replacement or binding edits. Before/after records for both modes remained byte-for-byte equal as JSON values: the same local session ID, native session ID and configuration fingerprint; neither record acquired controller/executor fields. The independently managed external executor retained PID 574374 and its existing file. Extracted terminal receipts: {"hosted":{"localIdentityEqual":true,"nativeIdentityEqual":true,"fingerprintEqual":true},"external":{"localIdentityEqual":true,"nativeIdentityEqual":true,"fingerprintEqual":true,"executorPidEqual":true,"fileEqual":true}}
{"mode":"openai_hosted","phase":"main baseline","status":"ok","successfulToolNames":["bash"],"reply":"31 * 37 = 1147; proof-161609-current-main-hosted"}
{"mode":"openai_hosted","phase":"candidate continuation","status":"ok","successfulToolNames":["bash","memory_search"],"reply":"proof-161609-current-main-hosted; 41 * 43 = 1763","runtimeMs":20943}
{"mode":"self_hosted, externally managed","phase":"main baseline","status":"ok","successfulToolNames":["bash"],"file":"proof-161609-current-main-external\n"}
{"mode":"self_hosted, externally managed","phase":"candidate continuation","status":"ok","successfulToolNames":["bash"],"file":"proof-161609-current-main-external\n","calculation":1763,"runtimeMs":15951}Replies above normalize Markdown while preserving returned values. The exact PR-base main source and final candidate source are identified in the image table. This is saved-session image upgrade proof, not a claim that a published updater binary or every older release was exercised. Packaged executor-controller authority proofPASS, tested source a8d1b87d6319bca89efd649e0f02c696c4a282fe in native An isolated plugin registered through the real packaged loader and public The controller resolver, operation context, captured registration, registration owner, public plugin API and API builder are unchanged between this tested source and the final candidate. The later repair changes required session cleanup at the harness and host reset boundaries, covered separately by the live Gateway evidence. Actual command, with the original host fixture path replaced by the explicitly marked placeholder docker --context colima run --rm --network none --read-only \
--user 501:20 --tmpfs /tmp:rw,size=256m \
--mount type=bind,source=<proof-directory>,target=/proof,readonly \
--entrypoint node \
sha256:6e24a2b85d6ccc7215d0acc24cb5419a5ded542ac878eaca32baa55e4414ab1a \
/proof/proof.mjs healthySeparate invocations used The fixture's actual registered callback and side effect were: globalThis[Symbol.for('authority-proof.controller')] = {
workspaceDirectory: state,
async ensure(_binding, context) {
retained = context;
started.resolve();
await gate.promise;
context.assertCurrent();
const child = spawnSync(process.execPath, [
'-e',
'require("node:fs").writeFileSync(process.argv[1],"authorized child write")',
target,
], { encoding: 'utf8' });
assert.equal(child.status, 0, child.stderr);
},
async retire() {},
};The plugin entry registered that implementation with Actual stdout, healthy case: {
"status": "PASS",
"mode": "healthy",
"commit": "a8d1b87d6319bca89efd649e0f02c696c4a282fe",
"architecture": "arm64",
"ok": true,
"fileCreated": true,
"signalAborted": false,
"filesystem": [
"authorized.txt"
],
"scope": "Real packaged loader, registry lifecycle and child-process filesystem I/O. No backend or Gateway claim."
}Actual stdout, registry retired while the callback awaited its gate: {
"status": "PASS",
"mode": "registry-retirement",
"commit": "a8d1b87d6319bca89efd649e0f02c696c4a282fe",
"architecture": "arm64",
"ok": false,
"error": "Agent executor controller plugin \"authority-proof\" is no longer available",
"fileCreated": false,
"signalAborted": true,
"filesystem": [],
"scope": "Real packaged loader, registry lifecycle and child-process filesystem I/O. No backend or Gateway claim."
}Actual stdout, plugin owner revoked while the callback awaited its gate: {
"status": "PASS",
"mode": "owner-revocation",
"commit": "a8d1b87d6319bca89efd649e0f02c696c4a282fe",
"architecture": "arm64",
"ok": false,
"error": "Agent executor controller plugin \"authority-proof\" is no longer available",
"fileCreated": false,
"signalAborted": false,
"filesystem": [],
"scope": "Real packaged loader, registry lifecycle and child-process filesystem I/O. No backend or Gateway claim."
}The initial proof fixture incorrectly required record-only revocation to abort the signal. Source inspection showed that The healthy invocation also checked retained authority after completion: assert.throws(() => {
retained.assertCurrent();
fs.writeFileSync(`${state}/late.txt`, 'late write');
}, /operation has completed/);
assert.equal(fs.existsSync(`${state}/late.txt`), false);This passed before the healthy stdout was emitted. It proves the retained callback cannot use the completed operation's authority to reach that file write. It does not prove automatic prevention of arbitrary plugin code that ignores the contract, termination of an already-started child, backend rejection of an old session, or Gateway/Slack end-to-end behavior. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Why
Self-hosted Agents API sessions need an executor on infrastructure chosen by the operator. The Gateway owns the conversation, while a selected plugin supplies the workspace and connects an executor when the API requests it. Healthy turns should not require another connection check or SSH round trip.
What Problem This Solves
Operators need a supported plugin contract for connecting and retiring self-hosted executors without replaying conversation input during connection recovery.
User Impact
Each native session gets its own executor lifecycle, reused across turns. Executors may share one persistent VM, remote host, container, or workspace, or use separately isolated environments. Sharing is an optional deployment choice. Operators can also continue managing executors externally.
The public setup guide explains prerequisites, controller-plugin registration, configuration, session ownership, recovery, reset, and verification. The contract does not include a universal SSH launcher. Operators supply or install a controller appropriate to their infrastructure.
Maintainer design decision: retain the narrow, opt-in controller SDK contract and persisted controller ownership. Keep infrastructure and process management in the selected plugin, preserve externally managed executors, and require native settlement before session ownership is removed.
Why This Change Was Made
api.registerAgentExecutorController({ workspaceDirectory, ensure, retire }), selected byplugins.entries.agentsapi.config.executorController.environment_connectionactions while input is pending, including actions already present before subscription and after stream recovery.This branch is based directly on
main; it does not include the separate cron PR.Upgrade Behavior
Changing an existing session's controller requires reset. Retire earlier factory-owned sessions with the previous version before upgrading; their saved bindings have no plugin owner and are not silently reassigned. Compatible hosted and externally managed sessions remain supported.
Evidence
Validation of the main-based candidate:
/newregressions fail on the previous code for swallowed errors and session mutation before failure, respectively. The repaired registry passed 15 tests in 68.00 seconds wall, with the new case taking 27 ms. Session initialization passed eight tests in 54.05 seconds wall, with the new case taking 2.527 seconds. The 22 existing lifecycle-hook tests also passed. Wall times include compiled worker preparation.pnpm test extensions/agentsapi/agentsapi-harness.persistence.test.ts --maxWorkers=1cost: 111.69 seconds wall, including runner/worker preparation; Vitest reported 106.94 seconds under concurrent validation load. CI per-file time is not separately reported./new, and saved hosted/external sessions upgraded from the PR's exact main base.plugins/hooks.md:134 :: /plugins/hooks/reference#sessions-and-compaction :: fragment not found (terminal: /plugins/hooks/reference#sessions-and-compaction). Neither page is changed here.Measured cleanup-test costs (CI reports individual case durations, not isolated file wall time):
The new registry, initialization, Gateway reset and Gateway deletion cases took 0.004, 0.889, 3.361 and 2.252 seconds in CI, respectively.