Repository navigation
fix: harden remote Codex hook callbacks against planted links, replays and slow hook starts - #200835
Conversation
- Remove whatever occupies the stable credential name before the app-server writes the relay credential: fs/writeFile follows links and has no exclusive create, so a link planted between turns redirected the credential. - Accept each remote pre_tool_use and post_tool_use callback once per tool use id and event, require the id, and log every remote callback outcome. - Count the hook CLI deadline from process start: Codex starts its hook timeout before spawning the hook, so slow startup could let Codex kill the hook and run the tool call instead of receiving the relay's refusal.
|
🦞👀 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. What this changesThis PR removes planted credential links before delivery, rejects duplicate remote tool callbacks, records callback outcomes, and includes process startup in hook deadlines. Example: The remote relay receives PreToolUse callback call-1 twice.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR contains useful remote-hook hardening absent from current main; both earlier findings are resolved, and no new concrete code defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherCodex hook subprocesses read a projected credential and send HTTPS callbacks to the Gateway, whose existing relay owner checks registration and policy before returning a native hook response. flowchart LR
A[Codex adapter] --> B[Remote credential file]
B --> C[Native hook CLI]
C --> D[Gateway HTTPS callback]
D --> E[Registration and replay checks]
E --> F[Existing hook policy]
F --> C
Technical reviewBest possible solution: Retain the focused repairs in the existing credential projection, relay registration, and CLI deadline owners. Do we have a high-confidence way to reproduce the issue? Source inspection establishes link-following credential delivery, duplicate callback acceptance, and startup-excluding deadlines on the base; the author reports matching red/green tests, which were not executed during this read-only review. Is this the best way to solve the issue? The patch is a small repair using existing owners: unlink before projection, retain event-and-tool-use replay keys for the registration lifetime, and subtract process age from the existing deadline. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 75a31ed2854c. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +51, Tests +215, Docs +15. Total +281 across 13 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label 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 HistoryReview history (2 earlier review cycles)
Reviewed November 18, 2026, 1:19 AM ET / 06:19 UTC (Revision 3). |
- The child-retention test treated any fs/remove as early disposal. Delivery now removes the stable credential name before it writes, so count only the removals after the last write: none while the yielded parent waits, one after the retained child finishes. - Drop the process-start override from the relay CLI entry points. The deadline always counts from the performance.now() origin, and the test helper moves that origin to the call (or a simulated process age) instead.
|
@clawsweeper re-review Both findings are addressed in 2b47650:
The relay suites (10 files, 147 tests) pass with these changes. |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review The head is now 9456117. Since the reviewed head (2b47650) the branch only merged main four times; the change against main is unchanged (13 files, +382/-101, same patch ID). |
|
🦞👀 Re-review progress:
|
…s and slow hook starts (openclaw#200835) * fix(codex): harden the remote native hook relay - Remove whatever occupies the stable credential name before the app-server writes the relay credential: fs/writeFile follows links and has no exclusive create, so a link planted between turns redirected the credential. - Accept each remote pre_tool_use and post_tool_use callback once per tool use id and event, require the id, and log every remote callback outcome. - Count the hook CLI deadline from process start: Codex starts its hook timeout before spawning the hook, so slow startup could let Codex kill the hook and run the tool call instead of receiving the relay's refusal. * test(codex): follow the credential delivery change in the relay tests - The child-retention test treated any fs/remove as early disposal. Delivery now removes the stable credential name before it writes, so count only the removals after the last write: none while the yielded parent waits, one after the retained child finishes. - Drop the process-start override from the relay CLI entry points. The deadline always counts from the performance.now() origin, and the test helper moves that origin to the call (or a simulated process age) instead.
…s and slow hook starts (#200835) * fix(codex): harden the remote native hook relay - Remove whatever occupies the stable credential name before the app-server writes the relay credential: fs/writeFile follows links and has no exclusive create, so a link planted between turns redirected the credential. - Accept each remote pre_tool_use and post_tool_use callback once per tool use id and event, require the id, and log every remote callback outcome. - Count the hook CLI deadline from process start: Codex starts its hook timeout before spawning the hook, so slow startup could let Codex kill the hook and run the tool call instead of receiving the relay's refusal. * test(codex): follow the credential delivery change in the relay tests - The child-retention test treated any fs/remove as early disposal. Delivery now removes the stable credential name before it writes, so count only the removals after the last write: none while the yielded parent waits, one after the retained child finishes. - Drop the process-start override from the relay CLI entry points. The deadline always counts from the performance.now() origin, and the test helper moves that origin to the call (or a simulated process age) instead. (cherry picked from commit 7de7053) Co-authored-by: RomneyDa <[email protected]>
…s and slow hook starts (openclaw#200835) * fix(codex): harden the remote native hook relay - Remove whatever occupies the stable credential name before the app-server writes the relay credential: fs/writeFile follows links and has no exclusive create, so a link planted between turns redirected the credential. - Accept each remote pre_tool_use and post_tool_use callback once per tool use id and event, require the id, and log every remote callback outcome. - Count the hook CLI deadline from process start: Codex starts its hook timeout before spawning the hook, so slow startup could let Codex kill the hook and run the tool call instead of receiving the relay's refusal. * test(codex): follow the credential delivery change in the relay tests - The child-retention test treated any fs/remove as early disposal. Delivery now removes the stable credential name before it writes, so count only the removals after the last write: none while the yielded parent waits, one after the retained child finishes. - Drop the process-start override from the relay CLI entry points. The deadline always counts from the performance.now() origin, and the test helper moves that origin to the call (or a simulated process age) instead. (cherry picked from commit 7de7053) Release adaptation: approved 2026.11.7 models replay; see models-hook-safe-v2/REPORT.md. Co-authored-by: RomneyDa <[email protected]>
…s and slow hook starts (#200835) Baseline adaptation: Adapt callback custody, credential publication and process-start deadlines to the shipped remote Codex bridge and CLI, retaining owner checks and shipped fail-closed policy. (cherry picked from commit 7de7053) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 046bfba2ba80b221c5305278d398c75e6f4a04b1)
What Problem This Solves
When OpenClaw runs Codex in a dedicated app-server, Codex's native hooks call back to the Gateway over HTTPS with a per-turn relay credential. Three gaps weakened that path:
fs/writeFilefollows links, so a link planted at that name between turns made the next turn's credential (URL and token) land in a file of the planter's choosing.pre_tool_use,post_tool_useandbefore_agent_finalizecallbacks that the Gateway accepted, could replay identical bodies, and left no log line.User Impact
Operators of dedicated Codex app-servers get a credential delivery that cannot be redirected by a link left in the credential directory, remote tool hook callbacks that are accepted once per tool use, a Gateway log record for every remote callback (refusals as warnings), and a hook that refuses the call when the Gateway does not answer in time even if the hook process was slow to start. Local (loopback) relays are unchanged apart from the deadline.
A hook process that cannot start and reach OpenClaw's code before the Codex timeout still lets the call run; the docs now say so.
Why This Change Was Made
fs/removeremoves a link, never its target) and then writes. A process running as the same user while the turn starts can still race the two requests, but such a process can read the credential directly anyway; the docs already say the directory is not a boundary against same-user code.tool_use_idonpre_tool_useandpost_tool_useand accepts each event once per tool use id for the life of the relay registration; a repeat gets 409, which the hook CLI turns into its normal unavailable answer (deny forPreToolUse, no-op forPostToolUse).permission_requestandbefore_agent_finalizecan legitimately recur and have no per-call id, so they keep the existing checks. Every remote callback writes one log record with relay id, event, tool use id and status: accepted ones to the file log only, refusals as warnings.performance.now()origin). The deadline was already a little under the Codex hooktimeoutit is installed with, and a timed-outPreToolUsealready returned a deny.Evidence
Each new test was run against
mainsources (red) and against this branch (green) on a Linux test VM with Node 24,--maxWorkers=1:extensions/codex/src/app-server/native-hook-relay-remote.test.ts, "replaces a link planted at the stable name instead of writing through it": a fake app-server that writes through links like Codex does. Onmainthe credential lands in the linked workspace file; with the fix the workspace file is untouched and the credential is a regular file.src/agents/harness/native-hook-relay.remote-http.test.ts, "accepts each remote tool callback once and logs every outcome": onmaina replayedpre_tool_usegets 200 and nothing is logged; with the fix the repeat gets 409 and each callback, including the unknown-relay 403, writes one record.src/cli/native-hook-relay-cli.test.ts, "counts the deadline from process start and refuses before Codex's hook timeout": onmainthe transport is still open 5 ms after the deadline measured from process start; with the fix it is aborted then and the hook answers deny.With the fix, the relay suites that consume the changed code also pass (
pnpm testover 18 files: the core relay, bridge, remote HTTP callback, remote client, hook CLI and CLI process tests, and the Codex extension's relay, remote credential and remote-hook thread lifecycle tests).pnpm check:changedtypecheck and guards, the formatter on touched files and the docs format check pass on the same VM; the SQLite worker ratchet (--staged, no T1 call growth) and type-aware oxlint on the touched files (0 warnings, 0 errors) pass too. A fullpnpm lintof the branch fails on existingmax-lineserrors in files this PR does not touch.Two existing cold-process tests now pass a longer
--timeout, because the relay deadline includes their TypeScript process start.extensions/codex/src/app-server/run-attempt.native-hook-relay-retention.test.tstreated anyfs/removeas early disposal of the credential; it now counts only removals after the last write (none while the yielded parent waits, one after the retained child finishes). Its remote case fails with the old assertion and passes with the new one. The relay CLI keeps no test-only parameter: its test helper moves theperformance.now()origin to the call, or to a simulated process age.Not verified: a live run against a real Codex app-server; the fix was reproduced against a fake app-server with Codex 0.164's filesystem semantics (writes follow links, removal does not).