Repository navigation
Description
Native hook relay drops mid-agent-turn after long model-thinking gaps
Filed against: OpenClaw 2026.5.28 (commit e932160)
Reporter date: 2026-05-27
Retest / submission update: 2026-06-01
Severity: Medium — recoverable per-turn but disrupts long agent runs; affects all Codex (GPT-5) sessions that include >~90s thinking gaps mid-turn.
Environment
- OpenClaw
2026.5.28(commite932160), installed via npm at/opt/homebrew/lib/node_modules/openclaw/; CLI and Gateway both verified on2026.5.28after gateway restart on 2026-06-01 - macOS 26.5 arm64, node 25.5.0
- Codex (GPT-5) agent running via
ai.openclaw.gatewayLaunchAgent - Gateway was freshly
bootout+bootstrap-restarted at 2026-05-27 15:22 PT before the captured reproducer (rules out stale-process drift across the boundary)
Symptom
The Codex exec_command tool returns the literal string:
Command blocked by PreToolUse hook: Native hook relay unavailable.
mid-way through an agent turn that had previously executed successful tool calls on the same gateway PID. The same shell-style call (sed -n, rg, pwd) succeeds before the gap and fails after, with no intervening user action.
Reproducer
Rollout file:
/Users/synthiacipher/.openclaw/agents/main/agent/codex-home/sessions/2026/05/27/rollout-2026-05-27T16-31-43-019e6bc7-9987-74d0-97a9-0a7459da7a9f.jsonl
Timeline (UTC, single agent turn, gateway PID 41808 throughout):
| Time (UTC) | Δ | Tool calls | Result |
|---|---|---|---|
| 23:32:08–23:32:17 | — | 8 reads (sed -n, rg) |
All exited with code 0 ✓ |
| 23:33:57 | +100s (model thinking) | 4 reads (sed -n) |
All Native hook relay unavailable ✗ |
| 23:35:46 | +107s | 1 read (pwd) |
Native hook relay unavailable ✗ |
The 100-second model-thinking gap is the inflection point — every tool call after the gap fails until the agent yields, and the failure persists across additional thinking gaps inside the same turn.
Contradiction with documented constants
Per the shipped bundle at /opt/homebrew/lib/node_modules/openclaw/dist/:
CODEX_NATIVE_HOOK_RELAY_MIN_TTL_MS = 30 * 6e4→ 30 minutes minimum TTLCODEX_NATIVE_HOOK_RELAY_RENEW_INTERVAL_MS = 6e4→ 60s renewal intervalMAX_NATIVE_HOOK_RELAY_INVOCATIONS = 200→ 200-call cap per bridge
A 100-second model-thinking gap should not exhaust any of these on its own. Hypothesis: the renewal pings are driven by the Codex app-server tool-call cadence and stop while the model is in long thinking, with no server-side keepalive timer. By the time the next tool call arrives, the bridge has either been GC'd or its state is stale, and the app-server surfaces the resulting "unavailable" verbatim to the model.
Other observations
openclaw hooks checkreportsReady: 5 / Not ready: 0both before and after the failure window, so that diagnostic doesn't detect this case — it tests registry, not in-flight bridges.- The bridge directory
~/.openclaw/tmp/openclaw-native-hook-relays-501/is empty at idle, which appears to be normal lazy-init behavior; not the cause. - 12 distinct rollouts on 2026-05-27 alone contain this error or the agent's narrativized form of it ("the hook relay seems to have failed…"). This is not a one-off.
- Gateway log (
~/Library/Logs/openclaw/gateway.log) has no[hook]/[relay]/[bridge]entries around the failure window. The failure path is either logged only at DEBUG, or it lives in the Codex sidecar stream rather than the gateway's main log. Either way, the user-visible surface is the literal verbatim error inside the model's tool-call output, with no breadcrumb anywhere in the standard logs.
Reproduction status on 2026.5.28
Retested on 2026-06-01 after upgrading the CLI to OpenClaw 2026.5.28 (commit e932160). The running Gateway initially remained on 2026.5.27, which caused immediate agent-turn failures with:
GatewayClientRequestError: Error: Unable to resolve bundled plugin public surface speech-core/runtime-api.js
Restarting the Gateway aligned CLI and Gateway on 2026.5.28; the synthetic relay test was then run again.
Test protocol:
- Prompt A (baseline, no injected keepalive):
Think very carefully for at least 90 seconds about the tradeoffs between event-driven and timer-driven keepalive mechanisms in client/server bridges. Then run pwd. - Prompt B (keepalive injected):
First run pwd. Then think very carefully for at least 90 seconds about the tradeoffs between event-driven and timer-driven keepalive mechanisms in client/server bridges. Then run pwd again. - Each prompt was run 3 times with a unique fresh session key,
--thinking high, and--timeout 420.
Results:
| Prompt | Runs | Result | Durations |
|---|---|---|---|
| A baseline | 3 | 3/3 final pwd succeeded; no Native hook relay unavailable string |
91s, 47s, 65s |
| B keepalive | 3 | 3/3 final pwd succeeded; no Native hook relay unavailable string |
56s, 91s, 77s |
Interpretation: the synthetic prompt did not reproduce the mid-turn relay failure on 2026.5.28. It also did not demonstrate that the no-op keepalive helps, because baseline did not fail. Only two of the six runs reached the requested ~90s duration, so this is best treated as inconclusive rather than proof of a fix.
Full raw experiment log:
~/.openclaw/logs/relay-keepalive-experiment-2026-06-01.md
Additional post-upgrade observation: each valid run included an earlier failed/timed-out internal attempt with:
Package subpath './plugin-sdk/codex-native-task-runtime' is not defined by "exports" in /Users/synthiacipher/.openclaw/npm/node_modules/@openclaw/codex/node_modules/openclaw/package.json imported from /Users/synthiacipher/.openclaw/npm/node_modules/@openclaw/codex/dist/run-attempt-BqRPAaHk.js
OpenClaw retried and produced a successful final answer, so this appears separate from the native-hook-relay failure but may indicate a package export mismatch in the bundled Codex runtime.
Related
- Native hook relay remains unavailable after gateway restart and hooks report 5/5 ready #73723 is related but distinct. It appears to cover the same user-visible error string after a restart or stale process boundary; this report is about the same string surfacing mid-turn after a long model-thinking gap, after successful tool calls on the same gateway process.
Suggested fix area
The likely fix area is a server-side keepalive timer independent of tool-call cadence. The relay should be renewed every CODEX_NATIVE_HOOK_RELAY_RENEW_INTERVAL_MS / NATIVE_HOOK_RELAY_RENEW_INTERVAL_MS by wall clock while the turn is active, regardless of whether the model is currently issuing tool calls. That would prevent long model-thinking gaps from starving relay renewal and would keep the app-server from surfacing a low-level bridge availability error as a tool result.
Suggested fixes (for upstream to consider)
- Server-side keepalive timer. Renew the relay bridge independently of app-server tool-call cadence, so model-thinking gaps don't starve the renewal loop.
- Granular INFO logging on relay failure. When the relay returns "unavailable," log which specific condition tripped —
bridge expiredvsbridge not foundvsunreadable resultvsrenewal-window missed— at INFO so users can self-diagnose without greppingdist/. - App-server side: re-spawn the bridge before surfacing failure. On
Native hook relay unavailable, have the Codex app-server transparently re-spawn the bridge and retry once, since the model has no useful recovery action and currently confabulates an explanation instead. - (Optional) Surface relay state in
openclaw hooks check. Extend the diagnostic to inspect in-flight bridge state and TTL, not just registry readiness, so the check matches what users assume it covers.
How I'd reproduce
- Start a fresh gateway:
launchctl bootout gui/$(id -u) ~/Library/LaunchAgents/ai.openclaw.gateway.plist && launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/ai.openclaw.gateway.plist - Open a Codex session and issue a prompt that forces the model into a long chain-of-thought between tool calls — e.g. "Read the following 8 files quickly, then think for two minutes about how they interact, then read 4 more."
- Observe: the first burst (pre-thinking) succeeds; the second burst (post-thinking) returns
Native hook relay unavailablefor every call until the turn ends. - Cross-check
openclaw hooks checkimmediately after — it will report all hooks Ready, confirming the diagnostic gap. - Grep
~/.openclaw/agents/main/agent/codex-home/sessions/**/rollout-*.jsonlfor"Native hook relay unavailable"to count occurrences across the day.
Rollout-file evidence is from the 2026.5.26 install at commit 10ad3aa; the reproduction status section above records retest results after upgrading to 2026.5.28 (e932160).
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Jun 1, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 21, 2026, 5:00 AM ET / 09:00 UTC.
Summary
Keep open: current main and v2026.6.9 still have progress-driven Codex relay renewal, synchronous PreToolUse command relays, and fail-closed unavailable behavior, while the related open PR only covers overlapping idle PreToolUse fan-out and does not prove this long-thinking mid-turn failure fixed.
Reproducibility: Partially: source inspection confirms the current progress-driven renewal, synchronous PreToolUse relay, and fail-closed unavailable path, and the issue has multiple field reports. I did not establish a fresh live current-main long-thinking reproduction in this read-only review.
Ways to help us reproduce this
Next step
Manual review is needed because the likely repair crosses relay lifecycle, subprocess fan-out, and native tool approval security semantics, and existing labels already block a new autonomous fix PR.
Security
Needs attention: The issue is security-sensitive because repair choices can change Codex PreToolUse fail-closed behavior before native tools execute.
Review details
Best possible solution:
Choose one maintainer-approved Codex relay lifecycle and fallback design that keeps required PreToolUse and PermissionRequest enforcement, renews or refreshes relays independently of sparse tool-call progress, and validates the long-thinking, subagent, restart, and fan-out paths separately.
Do we have a high-confidence way to reproduce the issue?
Partially: source inspection confirms the current progress-driven renewal, synchronous PreToolUse relay, and fail-closed unavailable path, and the issue has multiple field reports. I did not establish a fresh live current-main long-thinking reproduction in this read-only review.
Is this the best way to solve the issue?
Unclear as a complete fix: a wall-clock keepalive is plausible for the original gap, but later evidence also implicates stale fallback, subprocess fan-out, and PreToolUse security semantics. The best solution needs maintainer agreement on that combined boundary.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model internal, reasoning high; reviewed against 3b332fd0a485.
Label changes
Label changes:
clawsweeper:fix-shape-clear: Current issue advisory state no longer selects this label.Label justifications:
P2: The issue reports a real Codex relay stability bug that disrupts long agent turns, but it is not a freshly reproduced current-main emergency.impact:session-state: The failure strands an active agent turn or subagent with blocked tools and can force parent-session recovery or a new session.impact:security: The remaining fix choices touch Codex PreToolUse, which is part of the native tool-execution approval boundary.Evidence reviewed
Security concerns:
src/agents/harness/native-hook-relay.ts:788Current unavailable PreToolUse handling blocks unless the generated command explicitly records a no-policy noop path; retry, refresh, or omit behavior needs maintainer security acceptance so policy-active tool calls do not fail open.
Confidence: 0.86
What I checked:
renewNativeHookRelayForTurnProgressrefreshes the relay, and the observed call site is the turn-watchonAttemptProgresscallback rather than an independent wall-clock keepalive. (extensions/codex/src/app-server/run-attempt.ts:1559, 3b332fd0a485)async: false, so selected PreToolUse events run through the native relay command path. (extensions/codex/src/app-server/native-hook-relay.ts:272, 3b332fd0a485)tools.loopDetectionis treated as enabled when a session key exists, keeping native PreToolUse relay work active without a custom before-tool hook. (src/agents/harness/native-hook-relay.ts:585, 3b332fd0a485)Native hook relay unavailablemessage. (src/agents/harness/native-hook-relay.ts:788, 3b332fd0a485)extensions/codex/src/app-server/run-attempt.ts:1467, c645ec4555c0)../codex/codex-rs/hooks/src/engine/command_runner.rs:24, aaf737fa59c4)Likely related people:
src/agents/harness/native-hook-relay.ts,extensions/codex/src/app-server/native-hook-relay.ts,extensions/codex/src/app-server/run-attempt.ts)extensions/codex/src/app-server/native-hook-relay.ts,extensions/codex/src/app-server/run-attempt.ts,extensions/codex/src/app-server/session-binding.ts)src/cli/native-hook-relay-cli.ts,src/agents/harness/native-hook-relay.ts,extensions/codex/src/app-server/native-hook-relay.ts)src/agents/harness/native-hook-relay.ts,extensions/codex/src/app-server/native-hook-relay.ts)src/agents/harness/native-hook-relay.ts,extensions/codex/src/app-server/native-hook-relay.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.mgonto commentedon Jun 2, 2026
Additional recurrence from a separate OpenClaw/Codex environment on 2026-06-02.
This happened multiple times in real work, not just synthetic prompts:
Native hook relay unavailableduring a recurring month-end report setup. Work was recoverable only after the relay recovered.xhighCodex sub-agent for CRM cleanup failed before editing anything because the native tool relay broke withNative hook relay unavailable; the parent session had to resume the task manually.xhighCodex sub-agent completed most CRM work, but its finalopenclaw wiki lintrerun was blocked byNative hook relay unavailable; parent session had to rerun verification and discovered additional cleanup needed.Observed impact:
The existing suggested fix still seems right: app-server should transparently re-spawn/retry the native hook relay once before surfacing
Native hook relay unavailableto the model, and logs/diagnostics should distinguish expired bridge vs missing bridge vs renewal starvation.No private logs attached; this comment is from user-facing task memory and omits workspace/customer details.
Stoff81 commentedon Jun 4, 2026
I am seeing this constantly with GPT5.5 /new is the only resolution running v2026.5.26
alexph-dev commentedon Jun 18, 2026
Additional live recurrence from a production OpenClaw/Codex host on 2026-06-18.
Root-cause hypothesis, not just symptom: default-enabled Codex native
PreToolUserelay work can create many concurrent short-livedopenclaw hooks relayNode subprocesses. Each subprocess loads enough OpenClaw CLI/native-relay runtime that a burst of tool calls can exhaust an 8 GB host before the 4-5s hook timeout drains the process set. In this environment the trigger wastools.loopDetectionbeing unset, because OpenClaw treats that as enabled and therefore keepspre_tool_userelay work active even without a user-defined before-tool hook.Version note: this environment already contains PR #87272's merge commit (
42e9504114f3b7cb7eae2efba99d79be8626a08a). Deployed tree wasv2026.6.8-24-g31c89e4d7c, package version2026.6.8, with@openai/codex0.139.0. So this is not explained by #87272 simply being absent.Evidence from the OOM boot:
2026-06-18 11:26:46 UTCwithFree swap = 0kB.21openclaw-hooksprocesses.openclaw-hooksmemory in that dump: about5.5 GiBRSS plus1.46 GiBswap, about6.96 GiBcombined.openclaw-hooksrow was about326 MiBRSS plus204 MiBswap.oom_score_adjwas1000, but Chrome aggregate in the same dump was much smaller, about368 MiBcombined across 12chromerows.Live process/source mapping before mitigation:
/usr/bin/node /home/clawd/openclaw/openclaw.mjs hooks relay --provider codex --relay-id ... --generation ... --event pre_tool_use --timeout 4000extensions/codex/harness.tshardcodesnativeHookRelay: { enabled: true }for Codex attempts and side questions.extensions/codex/src/app-server/native-hook-relay.tsmapspre_tool_useto CodexPreToolUseand installs a synchronous command hook withasync: false.src/agents/harness/native-hook-relay.tsbuilds theopenclaw hooks relay --provider codex ... --event pre_tool_usecommand.src/agents/harness/native-hook-relay.tskeepspre_tool_useactive whentools.loopDetection.enabled !== false.Mitigation test:
{ "tools": { "loopDetection": { "enabled": false } } }After restarting only OpenClaw Gateway with that config:
openclaw-hooksprocess rows dropped to0.0.Ruled out by evidence:
openclaw-hooksaggregate memory.git-autocommit: the hot process class was Codex nativepre_tool_userelay, not internal hook handlers.Suggested maintainer investigation:
relayId,generation,event, session, and turn.tools.loopDetectionunset and a Codex turn that emits many tool calls quickly, especially after a long-thinking turn or under high system load.openclaw hooks relay --event pre_tool_useprocess RSS/swap and startup imports. The CLI path goes throughhooks-cli.ts -> runNativeHookRelayCli -> native-hook-relay.tsand can fall back tocallGateway.PreToolUse, or avoiding a full Node/OpenClaw CLI subprocess whenpre_tool_useonly needs the loop detector.tools.loopDetection.enabled=falseas a temporary mitigation for resource-constrained hosts until this is fixed.No secrets or private logs included; numbers above are sanitized kernel/systemd counters and source-path references.
isopenclaw commentedon Jun 28, 2026
I can add a sanitized recurrence on OpenClaw
2026.6.10that looks adjacent to this issue and may share the same native-hook relay lifecycle/generation failure mode. I am intentionally omitting local paths, session identifiers, chat/channel identifiers, task content, and full logs.Environment:
2026.6.10Observed behavior:
pwddatepwd/dateself-check passedNative hook relay unavailablenativeHook.invoke ... native hook relay not found.Why this may be relevant here:
Local code inspection of the installed
2026.6.10package points at a compatible mechanism:nativeHook.invokepath requires generation validation--generationnativeHookRelayGenerationNative hook relay unavailableThis may be a generation/thread-binding/cached-hook-command variant rather than only a TTL renewal gap. A useful regression test shape might be:
Native hook relay unavailable; it should either refresh/retry against the current relay or safely re-inject hook config.Operational workaround for now:
Stoff81 commentedon Jul 3, 2026
This affects me really badly, I have to reset a session after each prompt
openclaw-barnacle commentedon Jul 18, 2026
This issue has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.
openclaw-barnacle commentedon Jul 25, 2026
Closing due to inactivity.
If this is still an issue, please retry on the latest OpenClaw release and share updated details.
If you are absolutely sure it still happens on the latest release, open a new issue with fresh steps to reproduce.