Repository navigation
feat: expose final worker prompts to admission hooks - #182142
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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e82ad254a5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const response = await connection.rpc.request("turn-admission", { | ||
| ...event, | ||
| runEpoch: descriptor.admission.ownerEpoch, | ||
| }); |
There was a problem hiding this comment.
Allow admission to outlast the default RPC timeout
When the before_agent_run hook chain takes more than 30 seconds, this request times out and fails the worker turn even if every hook approves within its supported deadline. WorkerConnection defaults requests to 30,000 ms, while runModifyingHook in src/plugins/hooks.ts executes handlers sequentially with a default 15,000 ms timeout per handler. For example, three approving handlers taking 11 seconds each previously succeeded through Gateway-side admission but now cause the socket to be interrupted and the worker to exit before inference. Give admission a deadline that accommodates the complete hook chain and persistence work rather than implicitly using the ordinary RPC timeout.
Useful? React with 👍 / 👎.
|
Codex review: needs real behavior proof before merge. What this changesThis PR lets updated workers submit their final system prompt and history to the Gateway’s admission hook before input persistence and inference. Example: A plugin injects MARKER into the system prompt and requires before_agent_run to verify it.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 7 items remain Keep this PR open: the maintainer-approved feature addresses a documented worker-hook limitation, but the admission transport and persistence refactor introduce actionable regressions. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe worker completes host-specific prompt assembly, sends an admission RPC to the Gateway’s existing turn owner, and waits for its policy decision and committed transcript leaf before inference. flowchart LR
A[Gateway prepares turn] --> B[Worker completes prompt]
B --> C[Admission RPC]
C --> D[Gateway plugin gate]
D --> E[Approved input persistence]
E --> F[Worker inference]
D --> G[Redacted rejection]
Technical reviewBest possible solution: Retain worker-side final prompt assembly and the existing Gateway policy owner, while supporting long admission waits, preserving heartbeat service, completing wrapper imports, and retaining original persistence errors. Do we have a high-confidence way to reproduce the issue? Current main source confirms the documented missing-systemPrompt behavior; the PR reports a red/green marker-policy regression, and CI independently exposes the wrapper and persistence-error regressions. Is this the best way to solve the issue? The negotiated handoff is an appropriate small extension of the existing owners because only the worker has the completed prompt, and the added schema, callback, and transcript-leaf handoff each serve that boundary. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9cf739b6c0da. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: in-process harness. SecurityNeeds attention: The new admission approval handoff needs final-effect proof for authority revoked during an awaited hook. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +320, Tests +335, Docs +7. Total +662 across 23 files. Added test files: 1. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 23, 2026, 11:22 PM ET / October 24, 2026, 03:22 UTC. |
before_agent_run hooks run sequentially with Gateway-enforced per-hook deadlines (15 s each), so several plugins can exceed the 30 s default worker RPC timeout and fail a turn every hook would approve. Give the admission request a 10-minute budget; the Gateway always answers, and connection teardown still ends the request.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2328bbf5fd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const operation = service.admitTurn; | ||
| return execute( | ||
| WORKER_TURN_ADMISSION_PROTOCOL_FEATURE, | ||
| validateWorkerTurnAdmissionParams, | ||
| operation && ((request) => operation.call(service, params.identity, request)), |
There was a problem hiding this comment.
Keep turn admission from blocking the heartbeat queue
When approving hooks take more than roughly 45 seconds in total—for example, four sequential handlers taking 12 seconds each—the worker still loses its connection despite the new 10-minute admission timeout. In worker-connection.ts, only computer and Gateway-tool invocations dispatch outside the FIFO message queue, so this awaited admission operation prevents subsequent heartbeats from being processed. The Gateway advertises a 15-second heartbeat interval, and WorkerConnection.sendHeartbeat() retains the default 30-second request timeout; its timeout interrupts the socket and fails the pending admission. Dispatch admission independently of the heartbeat queue while retaining the input-approval guards. The remaining failure is caused by the queued heartbeat timeout, rather than the admission-request timeout identified previously.
Useful? React with 👍 / 👎.
|
Landing note for head |
Cloud-worker turns bypassed the Gateway's before_agent_run plugin hooks, so plugins could not see or adjust the final system prompt and input of turns executed on a worker. Workers now request Gateway turn admission before running: the Gateway prepares the hook input itself (never trusting worker-supplied event content), runs the hooks with their normal per-hook deadlines, and binds the approval to the exact turn claim. Persistence, proxied inference, Gateway tools and live events all require that approval; cancelled runs still settle their terminal receipt without approved worker content. The worker allows up to 10 minutes for admission because sequential hooks with 15 s deadlines can exceed the default 30 s RPC timeout. Workers without the admission protocol feature keep the prior path.
Fixes #170118
What Problem This Solves
Plugins cannot inspect the final system prompt in
before_agent_runfor worker-placed sessions. The worker supplies the host-local prompt, but the Gateway must own the other hook fields and enforce admission itself: trusting worker-provided input or worker call order allows rejection-before-persistence to be bypassed.User Impact
Updated workers report their final system prompt while the Gateway supplies the authoritative prepared triggering prompt, history, and identity. Approval is bound to the exact turn claim and required before input persistence, transcript commits, proxied inference, Gateway tools, and content-bearing live events. Rejection persists only the redacted block message; cleanup receipts omit unapproved worker content. Older workers retain the original Gateway gate without
systemPrompt.Cancellation can still stop inference and drain queued events after execution authority closes. The exact claim retains its recorded input approval; existing event publication and ACK checks continue to enforce cancellation. Errors after a committed user append preserve the original authority failure as their cause.
Why This Change Was Made
The worker remains the sole owner of final prompt assembly. The negotiated
worker-turn-admission-v1transport preserves existing prompt bytes and the base protocol version. Worker-provided prompt/history fields are ignored by the gate. The existing turn owner records approval for its captured Gateway input; pending-result finalization and cancellation settlement retain that decision after execution closes. The worker admission RPC uses a 10-minute timeout so interactive plugin decisions can outlast the default RPC timeout.The Gateway cannot verify host-local prompt bytes. A compromised worker can misreport
systemPrompt, so the hook documentation explicitly says that field is not a trust boundary.The CI repair fixes the missing wrapper schema inventory, separates inference-start admission from cancellation, restores the throwing persistence authority assertion, and makes low-level test clients complete the real admission RPC. No test assertions or timeouts were weakened. Simplification removes redundant lookup state while retaining the claim and execution checks. This follow-up adds/removes 33/22 production lines and 25/11 test lines; the full PR adds/removes 572/153 production, 645/53 test, and 20/6 documentation lines versus its merge base. No state store is added.
Evidence
The following files were run in full with Node 24.22.1,
OPENCLAW_VITEST_RUNTIME=node, andpnpm test <file> --maxWorkers=1. These address the PR-caused failures from run 40059706099 at 2328bbf.test/scripts/eager-import-closure.test.tssrc/worker/worker.chat-abort.test.tssrc/gateway/worker-environments/worker-turn-execution.test.tssrc/worker/worker.fault-injection.test.tssrc/gateway/worker-environments/live-chat.test.tsorigin/mainat e3d3962 in 177.79 s, before testing the repaired PR fixture.worker.turn.admit, inference start, and inference cancel. This located the failure after successful admission, rather than in fixture placement identity. The full repaired suite preserves every cancellation, publication, and ACK assertion.worker-turn-admission.test.ts,worker-turn-rpc.live-ack.test.ts,worker-turn-rpc.inference-publication.test.ts, andworker-turn-rpc.inference-reconnect.test.ts: 20 passed in 267.22 s. They cover exact gate/model system-prompt equality, both persistence owners, blocked input redaction, old-worker allow/block fallback, forged prompt/history, skipped-admission effect boundaries, and inference/ACK ownership.node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json <changed TypeScript files>: type-aware lint passed in 31.14 s.pnpm run tsgo:core: passed in 3.83 s.node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.gateway-other.json --incremental: Gateway and worker test types passed in 29.94 s, including artifact-lock wait.pnpm exec oxfmt --check <changed TypeScript files>,pnpm check:line-cap-ratchet(2.23 s), andgit diff --check: passed. The initial size-limit failures were resolved by deleting redundant intermediate lookup code; no guard, coverage, or limit was removed.The admission regression uses real Gateway placement, admission, transcript storage, and worker prompt assembly with a synthetic model boundary. No live model was called. PR CI remains the broad proof. The inherited retention-inventory failure and iOS network failures are outside this repair.