Skip to content

fix(codex): honor timeoutSeconds for dynamic tool calls - #98880

Closed
harjothkhara wants to merge 2 commits into
openclaw:mainfrom
harjothkhara:codex/98864-dynamic-tool-timeout-seconds
Closed

harjothkhara wants to merge 2 commits into
openclaw:mainfrom
harjothkhara:codex/98864-dynamic-tool-timeout-seconds

Conversation

@harjothkhara

@harjothkhara harjothkhara commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #98864

What Problem This Solves

Codex dynamic tool calls such as sessions_send can pass timeoutSeconds without timeoutMs. The app-server watchdog only read timeoutMs, so a call with a seconds-form budget fell back to the default 90-second dynamic-tool guard and long-running bounded helpers were killed early.

Why This Change Was Made

The dynamic-tool timeout readers now fall back to timeoutSeconds when timeoutMs is absent, with two deliberate properties beyond a verbatim mapping:

  • Shared, validated seconds conversion. The conversion goes through finiteSecondsToTimerSafeMilliseconds({ floorSeconds: true }) from openclaw/plugin-sdk/number-runtime — the same helper sessions_send uses for the same field (src/agents/tools/sessions-send-tool.ts) — so the watchdog and the tool agree on what counts as a usable budget. A naive floor-then-multiply reading maps a fractional value like 0.5 to 0, which survives the ?? fallback chain and gets clamped up to a 1 ms watchdog (instant kill of the call). The shared helper rejects it and the reader falls back to the existing default. DynamicToolCallParams.arguments is raw JsonValue in the Codex app-server protocol (codex-rs/app-server-protocol/src/protocol/v2/item.rs, DynamicToolCallParams), so unvalidated values do reach this reader.
  • Grace headroom over the budget. timeoutSeconds is the tool's inner wait budget: sessions_send does gateway pre-work (session resolve, baseline snapshot, startAgentRun) before waiting that long, then returns a structured {status: "timeout", runId, sentBeforeError} result. A watchdog armed with exactly the same value deterministically fires first and replaces that structured result with a generic hard-timeout error, losing the runId. The watchdog is now the seconds budget plus CODEX_DYNAMIC_TOOL_SECONDS_GRACE_MS (30 s) via the shared addTimerTimeoutGraceMs, so the tool's own timer wins the race. timeoutMs keeps exact-override precedence and the existing 600 s hard cap is unchanged.

The side-thread path previously duplicated the whole timeout-reader stack; the byte-identical readSide* leaf readers are deleted and side-question.ts now imports the shared readers from dynamic-tool-execution.ts, so the main-thread and side-thread watchdogs cannot silently diverge (net-negative production LOC).

AI-assisted: yes (initial implementation by Codex; multi-agent review and this revision by Claude). No agent transcript is included because sanitized transcript insertion was not approved in this automated run.

User Impact

Seconds-form dynamic-tool budgets are honored instead of being capped by the default 90-second guard. Unlike a verbatim mapping, a sessions_send whose target run outlasts its budget still returns its structured timeout result (with runId and delivery status) instead of a generic watchdog error, and a malformed fractional budget can no longer produce an instant ~1 ms kill.

Evidence

Proof harness driving the real dynamic-tool-execution.ts code (resolveDynamicToolCallTimeoutMs + handleDynamicToolCallWithTimeout) with the tool bridge mocked as a sessions_send-shaped waiter (pre-work, inner budget wait, structured timeout result). Harness kept out of the repo per contribution guidelines.

On origin/main (6e79ca3) — the reported bug, timeoutSeconds ignored:

Scenario 1: sessions_send {timeoutSeconds: 2}, target run outlasts budget
  resolved watchdog: 90000ms (inner tool budget: 2000ms)
  [FAIL] watchdog is derived from the 2s budget (bounded, not the unrelated 90s default) — 90000ms
  ...
1 FAILED (5 checks)

On the previous head of this branch (4806bd5db5) — why the verbatim mapping was not enough:

Scenario 1: sessions_send {timeoutSeconds: 2}, target run outlasts budget
  resolved watchdog: 2000ms (inner tool budget: 2000ms)
  [PASS] watchdog is derived from the 2s budget (bounded, not the unrelated 90s default) — 2000ms
  [FAIL] watchdog has grace headroom over the 2000ms inner budget — 2000ms
  [FAIL] tool's graceful timeout result (with runId) beats the watchdog — {"contentItems":[{"type":"inputText","text":"OpenClaw dynamic tool call timed out after 2000ms while running tool sessions_send."}],"success

Scenario 2: {timeoutSeconds: 0.5} from unvalidated model JSON
  resolved watchdog: 1ms
  [FAIL] falls back to the 90s default instead of a ~1ms watchdog — 1ms
  [FAIL] a 300ms tool call survives instead of being killed instantly — {"contentItems":[{"type":"inputText","text":"OpenClaw dynamic tool call timed out after 1ms while running tool sessions_

4 FAILED (5 checks)

On this branch — fixed:

Scenario 1: sessions_send {timeoutSeconds: 2}, target run outlasts budget
  resolved watchdog: 32000ms (inner tool budget: 2000ms)
  [PASS] watchdog is derived from the 2s budget (bounded, not the unrelated 90s default) — 32000ms
  [PASS] watchdog has grace headroom over the 2000ms inner budget — 32000ms
  [PASS] tool's graceful timeout result (with runId) beats the watchdog — {"contentItems":[{"type":"inputText","text":"{\"status\":\"timeout\",\"runId\":\"run-123\"}"}],"success":true}

Scenario 2: {timeoutSeconds: 0.5} from unvalidated model JSON
  resolved watchdog: 90000ms
  [PASS] falls back to the 90s default instead of a ~1ms watchdog — 90000ms
  [PASS] a 300ms tool call survives instead of being killed instantly — {"contentItems":[{"type":"inputText","text":"ok"}],"success":true}

ALL PASS (5 checks)
  • node scripts/run-vitest.mjs extensions/codex/src/app-server/dynamic-tool-execution.test.ts extensions/codex/src/app-server/side-question.test.ts — 2 files, 55 tests passed, including a new fractional-seconds regression case
  • git diff --check clean; oxfmt --check clean; oxlint clean on the four changed files
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main — clean ("patch is correct", no actionable findings); an earlier autoreview run on the previous head independently flagged the zero-grace race fixed here

What was not tested: live end-to-end gateway + real Codex model traffic. Behavior above the pre-existing 600 s watchdog cap is unchanged (a larger budget is still capped; that cap predates this PR and applies equally to timeoutMs).

@clawsweeper

clawsweeper Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 1, 2026, 11:40 PM ET / 03:40 UTC.

Summary
The PR updates Codex app-server dynamic-tool timeout readers and focused tests so timeoutSeconds is used as a seconds-form fallback when timeoutMs is absent.

PR surface: Source +9, Tests +57. Total +66 across 4 files.

Reproducibility: yes. at source level: current main reads only timeoutMs in both Codex dynamic-tool timeout readers, while sessions_send accepts timeoutSeconds. I did not run a live dynamic-tool timeout turn in this read-only review.

Review metrics: 1 noteworthy metric.

  • Timeout readers changed: 2 resolver paths. The primary Codex app-server path and side-thread dynamic-tool path both need the same timeout argument invariant before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #98864
Summary: This PR is a candidate fix for the linked source-reproducible timeoutSeconds bug; a sibling PR overlaps the primary reader but misses the side-thread path.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted real behavior proof showing a Codex dynamic tool call with only timeoutSeconds uses the requested watchdog budget after the fix.
  • After adding proof, update the PR body to trigger a fresh ClawSweeper review, or ask a maintainer to comment @clawsweeper re-review if it does not rerun.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body lists targeted tests and diff-check evidence, but no after-fix real Codex dynamic-tool call, terminal output, logs, recording, or linked artifact; proof should redact private details before posting. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Real behavior proof is currently test-only; the external PR body does not show a real Codex dynamic-tool call or redacted runtime output exercising timeoutSeconds after the fix.
  • [P1] There is an open overlapping PR for the same linked issue, so maintainers should either land the side-thread-aware branch or consolidate the side-thread coverage into the chosen branch before closing the issue.

Maintainer options:

  1. Decide the mitigation before merge
    Land one consolidated side-thread-aware fix after real behavior proof, preserving timeoutMs precedence and closing the linked issue only after merge.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] This external draft PR needs contributor-supplied real behavior proof and maintainer consolidation with the overlapping sibling PR; there is no narrow code repair for automation to apply now.

Security
Cleared: The diff only changes Codex timeout parsing logic and focused tests; no concrete security or supply-chain concern was found.

Review details

Best possible solution:

Land one consolidated side-thread-aware fix after real behavior proof, preserving timeoutMs precedence and closing the linked issue only after merge.

Do we have a high-confidence way to reproduce the issue?

Yes at source level: current main reads only timeoutMs in both Codex dynamic-tool timeout readers, while sessions_send accepts timeoutSeconds. I did not run a live dynamic-tool timeout turn in this read-only review.

Is this the best way to solve the issue?

Yes: the PR fixes the existing timeout readers at the owning Codex app-server boundary and is more complete than the sibling primary-reader-only PR. The best merge path still needs real behavior proof and branch consolidation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6a96bbc7ad77.

Label changes

Label changes:

  • add status: 🛠️ actively grinding: The PR author has acted after the latest ClawSweeper review and work remains. Needs real behavior proof before merge: The PR body lists targeted tests and diff-check evidence, but no after-fix real Codex dynamic-tool call, terminal output, logs, recording, or linked artifact; proof should redact private details before posting. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • remove status: 📣 needs proof: Current PR status label is status: 🛠️ actively grinding.

Label justifications:

  • P2: This is a bounded Codex dynamic-tool timeout bug with limited but real impact on long-running session helper calls.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 🛠️ actively grinding: The PR author has acted after the latest ClawSweeper review and work remains. Needs real behavior proof before merge: The PR body lists targeted tests and diff-check evidence, but no after-fix real Codex dynamic-tool call, terminal output, logs, recording, or linked artifact; proof should redact private details before posting. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +9, Tests +57. Total +66 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 11 2 +9
Tests 2 57 0 +57
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 68 2 +66

What I checked:

Likely related people:

  • steipete: Recent current-main history touches both the dynamic-tool execution file and side-question app-server behavior, including commits for terminal outcome ordering and side-fork approvals. (role: recent Codex app-server contributor; confidence: high; commits: a09f6b1b2787, 27104c1afb13, a4c2e7f5cf1b; files: extensions/codex/src/app-server/dynamic-tool-execution.ts, extensions/codex/src/app-server/side-question.ts)
  • harjothkhara: Prior merged work touched sessions_send timeout-sensitive behavior, so the linked tool surface is in their recent history beyond this PR. (role: recent sessions_send contributor; confidence: medium; commits: c49714f7b6d2; files: src/agents/tools/sessions-send-tool.ts)
  • vincentkoc: Recent current-main history touches Codex app-server side behavior and sessions_send routing work adjacent to this timeout path. (role: adjacent Codex and sessions contributor; confidence: medium; commits: 5c3469549159, 3659ff8bbf71; files: extensions/codex/src/app-server/side-question.ts, src/agents/tools/sessions-send-tool.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 2, 2026
@harjothkhara
harjothkhara force-pushed the codex/98864-dynamic-tool-timeout-seconds branch from 4806bd5 to 6993612 Compare July 2, 2026 04:27
@harjothkhara
harjothkhara marked this pull request as ready for review July 2, 2026 04:32
@harjothkhara

Copy link
Copy Markdown
Contributor Author

The PR was force-pushed and the description rewritten since the last ClawSweeper review, so the status: 📣 needs proof label is from the earlier revision.

The Evidence section now has real captured before/after output from a harness that drives the real timeout-resolution + watchdog code with the tool bridge mocked as a sessions_send-shaped waiter: it fails on origin/main (seconds ignored, 90s default), fails on the previous head (the exact-budget watchdog kills the call at 2000ms and a fractional timeoutSeconds produces a ~1ms kill), and passes on the current head. The "Real behavior proof" check is green on 699361282d.

Could this get a re-review so the proof label reflects the current revision? Happy to adjust if anything's still missing.

@steipete

steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Thanks @harjothkhara for working on this. The canonical repair has landed via #100722 as 68487e4c1e3410a27b50b9cc0b67b2f5af6f82ad.

It covers the same timeoutSeconds gap and also consolidates the main and side-question paths on one timeout owner, preserves exact timeoutMs precedence, adds bounded setup/completion headroom, rejects fractional seconds, and proves structured sessions_send timeout completion. Closing this duplicate in favor of the landed implementation.

@steipete steipete closed this Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dynamic tool hard timeout should honor timeoutSeconds when timeoutMs is absent

2 participants