Skip to content

Give opencode real timeout headroom in Local Agent Guides CI - #7235

Merged
danielhanchen merged 3 commits into
mainfrom
fix/agent-guides-opencode-timeout
Jul 19, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
fix/agent-guides-opencode-timeout

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

The connection (opencode) cell of Local Agent Guides CI flakes with a timeout, surfaced as guide drift:

[guide drift] agent=opencode: invoke timed out after 600s (headless-TTY hang -- the recipe likely needs a non-interactive/print flag)

It is not actually a hang. In a passing run the same opencode run finishes in about 482s (08:12:31 to 08:20:33), which sits right against the shared AGENT_INVOKE_TIMEOUT of 600s. Roughly one recent run in six drifts past the cap and fails, so this cell has been intermittently red on unrelated PRs.

Why opencode is the slow one

The print-mode agents (claude -p, codex exec) run a single turn against the minimal system prompt the workflow injects. opencode run is different: it runs its own full turn with opencode's large system prompt, and on top of that it makes a separate small_model call to name the session (start.py pins small_model to the same 4B the server hosts). On a CPU-served gemma-4-E4B that is roughly 8 minutes of prefill and generation, so 600s leaves almost no margin and normal per-run variance tips it over.

Fix

Give opencode double the per-invoke timeout in agent-guides-drive.sh, and keep the tight 600s cap for the fast agents so a genuine headless-TTY hang still fails quickly. 1200s stays well under the 40-minute job budget.

case "$AGENT" in
  opencode) TIMEOUT=$(( TIMEOUT * 2 )) ;;
esac

Verification

  • bash -n and shellcheck -S warning clean on agent-guides-drive.sh.
  • The per-agent branch resolves opencode to 1200s and every other agent stays at 600s.

The connection (opencode) cell flakes with a 600s timeout reported as guide drift, but it is not a hang: in a passing run the same opencode run finishes in ~482s (08:12:31 to 08:20:33), right against the shared AGENT_INVOKE_TIMEOUT of 600s, so about one run in six drifts past the cap.

opencode is the slow outlier. The print-mode agents (claude -p, codex exec) run one turn against a minimal injected system prompt, while opencode run runs its own full turn with opencode's large system prompt plus a separate small_model call to name the session (start.py pins small_model to the same 4B the server hosts). On a CPU-served gemma-4-E4B that is about 8 minutes, leaving no margin under 600s.

Double opencode's per-invoke timeout in agent-guides-drive.sh and keep the tight 600s cap for the fast agents, so a genuine headless-TTY hang still fails quickly. 1200s stays well under the 40-minute job budget.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request doubles the timeout limit for the 'opencode' agent in .github/scripts/agent-guides-drive.sh to prevent test flakiness caused by its slower execution. Feedback points out that if the timeout value contains a trailing 's' suffix, the arithmetic multiplication will fail with a syntax error in Bash, and suggests stripping the suffix beforehand.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread .github/scripts/agent-guides-drive.sh Outdated
# headroom (still well under the 40-min job budget); the fast agents keep the
# tight cap that still catches a real headless-TTY hang.
case "$AGENT" in
opencode) TIMEOUT=$(( TIMEOUT * 2 )) ;;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If AGENT_INVOKE_TIMEOUT is configured with a trailing s suffix (e.g., 600s), which is a common format for timeout values, the arithmetic expansion $(( TIMEOUT * 2 )) will fail with a syntax error in Bash. Additionally, if the suffix is preserved, the error message on line 145 (timed out after ${TIMEOUT}s) would print 1200ss.

We can robustly handle this by stripping the trailing s suffix before performing the multiplication.

Suggested change
opencode) TIMEOUT=$(( TIMEOUT * 2 )) ;;
opencode)
TIMEOUT_NUM="${TIMEOUT%s}"
TIMEOUT=$(( TIMEOUT_NUM * 2 ))
;;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Normalized at assignment in 2b5936b: TIMEOUT="${TIMEOUT%s}" strips an optional trailing 's' before the doubling, so both the arithmetic and the "${TIMEOUT}s" message stay valid for a timeout(1)-style value. Placed it at the assignment so it also covers the non-opencode display path, not just the opencode branch.

Strip an optional trailing 's' from AGENT_INVOKE_TIMEOUT so the opencode
arithmetic, and the "${TIMEOUT}s" timeout message, stay valid if a
timeout(1)-style suffix is ever configured.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b5936b614

ℹ️ 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".

Comment thread .github/scripts/agent-guides-drive.sh Outdated
# headroom (still well under the 40-min job budget); the fast agents keep the
# tight cap that still catches a real headless-TTY hang.
case "$AGENT" in
opencode) TIMEOUT=$(( TIMEOUT * 2 )) ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve all GNU timeout duration formats

When a caller sets AGENT_INVOKE_TIMEOUT using a valid non-second GNU timeout duration such as 10m, 1h, or 0.5s, this arithmetic expansion fails before the agent is invoked (10m: value too great for base / invalid arithmetic). GNU timeout --help explicitly accepts floating-point values with optional s, m, h, or d suffixes, all of which worked before this change because the value was passed through unchanged. Normalize these formats to seconds before doubling, or only apply arithmetic when the value is a numeric seconds value.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Reworked in 2fcb24c to only apply the doubling when TIMEOUT is a bare-integer seconds value; any GNU timeout(1) duration suffix (s/m/h/d, including floats like 0.5s) is now passed through unchanged and parsed by timeout(1) directly, so the arithmetic never sees a non-number. Bare seconds (the CI default) still double.

Guard the arithmetic so a GNU timeout(1) duration suffix (s/m/h/d, including
floats like 0.5s) is passed through unchanged instead of breaking the
expansion; timeout(1) parses those directly. Bare seconds still double.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 2fcb24ce20

ℹ️ 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".

@danielhanchen
danielhanchen merged commit 03590f6 into main Jul 19, 2026
15 checks passed
@danielhanchen
danielhanchen deleted the fix/agent-guides-opencode-timeout branch July 19, 2026 13:08
VectorCipher pushed a commit to VectorCipher/unsloth that referenced this pull request Jul 20, 2026
…ai#7235)

* Raise the opencode invoke timeout in Local Agent Guides CI

The connection (opencode) cell flakes with a 600s timeout reported as guide drift, but it is not a hang: in a passing run the same opencode run finishes in ~482s (08:12:31 to 08:20:33), right against the shared AGENT_INVOKE_TIMEOUT of 600s, so about one run in six drifts past the cap.

opencode is the slow outlier. The print-mode agents (claude -p, codex exec) run one turn against a minimal injected system prompt, while opencode run runs its own full turn with opencode's large system prompt plus a separate small_model call to name the session (start.py pins small_model to the same 4B the server hosts). On a CPU-served gemma-4-E4B that is about 8 minutes, leaving no margin under 600s.

Double opencode's per-invoke timeout in agent-guides-drive.sh and keep the tight 600s cap for the fast agents, so a genuine headless-TTY hang still fails quickly. 1200s stays well under the 40-minute job budget.

* Normalize the agent invoke timeout before doubling it for opencode

Strip an optional trailing 's' from AGENT_INVOKE_TIMEOUT so the opencode
arithmetic, and the "${TIMEOUT}s" timeout message, stay valid if a
timeout(1)-style suffix is ever configured.

* Only double the opencode timeout for a bare-integer seconds value

Guard the arithmetic so a GNU timeout(1) duration suffix (s/m/h/d, including
floats like 0.5s) is passed through unchanged instead of breaking the
expansion; timeout(1) parses those directly. Bare seconds still double.

---------

Co-authored-by: danielhanchen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants