Skip to content

fix: standardize timeout/gtimeout handling - #2162

Merged
cv merged 9 commits into
mainfrom
fix/macos-timeout-fallback-in-e2e
Apr 23, 2026
Merged

cv merged 9 commits into
mainfrom
fix/macos-timeout-fallback-in-e2e

Conversation

@hunglp6d

@hunglp6d hunglp6d commented Apr 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Standardize the timeout/gtimeout detection preamble across all 10 e2e test scripts. Fixes a hard crash on macOS without GNU coreutils (exec: timeout: not found) by detecting both binaries up-front, failing fast with actionable remediation when neither is available, and consolidating ad-hoc per-file patterns into a single shared shape.

Related Issue

Closes #2160

Changes

  • Move timeout/gtimeout detection above the self-wrap block so TIMEOUT_CMD is set on every invocation — including the re-execed run after exec timeout … "$0" "$@". Previously the variable was scoped inside the wrap block; on the re-execed run it was unset, causing set -u crashes (test-sandbox-operations.sh, test-inference-routing.sh) or silent loss of per-call timeouts (test-network-policy.sh, test-deployment-services.sh).
  • Fail-fast with exit 127 and actionable guidance when neither timeout nor gtimeout is available, instead of crashing with exec: not found or silently dropping the timeout protection:

Type of Change

  • Code change (feature, bug fix, or refactor)

Verification

  • npx prek run --all-files passes
  • npm test passes
  • Tests added or updated for new or changed behavior
  • No secrets, API keys, or credentials committed

Signed-off-by: Hung Le [email protected]

Summary by CodeRabbit

  • Tests
    • Centralized e2e timeout detection and consistent re-exec wrapping using the system timeout utility.
    • Added a helper to run commands under timeout and updated test call sites.
    • Bypass now requires an explicit opt-in to skip timeouts, preventing recursive wrapping.
    • Prints clear guidance and aborts when timeouts are enabled but no timeout utility is available.

hunglp6d and others added 2 commits April 21, 2026 16:26
#2149)

## Summary

Fix 4 nightly failures in `test/e2e/test-network-policy.sh` caused by PR
#2070 changing `nemoclaw policy-add` to require a preset name in
non-interactive mode.

## Related Issue

Fixes #2148

## Changes

- **Replace expect-based preset application with direct CLI calls:**
`apply_preset` now calls `nemoclaw <sandbox> policy-add <preset> --yes`
directly instead of capturing the interactive list, grepping for a
number, and automating prompts with `expect`. This works with the new
non-interactive mode from #2070.

- **Add interactive mode coverage (TC-NET-03):** New
`apply_preset_interactive` function unsets `NEMOCLAW_NON_INTERACTIVE`
and uses `expect` to exercise the interactive prompt path. TC-NET-03
tries interactive first, falls back to non-interactive. Both CLI code
paths are now tested.

- **Fix TC-NET-03 reachability assertion:** After applying the telegram
preset, `api.telegram.org` returns HTTP 403 (unauthenticated — no bot
token). This is correct: the proxy lets the request through, Telegram
rejects the bare request. Changed assertion to accept any HTTP status
(2xx-4xx) as "reachable" — only `ERROR_` responses (proxy blocks) count
as failure.

- **Remove expect as hard dependency:** `expect` is installed with a
warning if missing (only needed for TC-NET-03 interactive test).
Non-interactive tests work without it.

## Type of Change

- Code change (feature, bug fix, or refactor)

## Verification

- `npx prek run --all-files` passes
- Tests added or updated for new or changed behavior
- No secrets, API keys, or credentials committed
- Verified on CI: 10/10 PASS on ubuntu-latest

## AI Disclosure

- AI-assisted — tool: Cursor

---

Signed-off-by: Truong Nguyen <[email protected]>

Made with [Cursor](https://cursor.com)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Tests**
* Tests now tolerate missing interactive tooling and log a warning
instead of aborting.
* Added non-interactive and interactive preset-application flows with
automatic fallback when interactive tooling is unavailable.
* Simplified one preset workflow to a direct dry-run path that checks
for "would be opened" output.
* Improved result classification to better distinguish success,
proxy-blocked, and unexpected responses.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Truong Nguyen <[email protected]>
Co-authored-by: Carlos Villela <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Detects an available timeout/gtimeout into TIMEOUT_CMD across e2e scripts, re-executes under that wrapper unless NEMOCLAW_E2E_NO_TIMEOUT is exactly "1", adds a run_with_timeout() helper for conditional command wrapping, and emits a clear error + exit 127 when timeouts are required but no binary exists.

Changes

Cohort / File(s) Summary
E2E Timeout Standardization
test/e2e/test-deployment-services.sh, test/e2e/test-double-onboard.sh, test/e2e/test-inference-routing.sh, test/e2e/test-network-policy.sh, test/e2e/test-onboard-resume.sh, test/e2e/test-sandbox-operations.sh, test/e2e/test-sandbox-survival.sh, test/e2e/test-shields-config.sh, test/e2e/test-skip-permissions-policy.sh, test/e2e/test-token-rotation.sh
All scripts now probe for timeout or gtimeout and set TIMEOUT_CMD; only bypass re-exec when NEMOCLAW_E2E_NO_TIMEOUT=="1"; when enforcing, execs via "$TIMEOUT_CMD" -s TERM <seconds> after exporting the bypass; if enforcement is required but no timeout binary exists, print installation/bypass guidance and exit 127; add run_with_timeout <seconds> <command> [args...] and replace inline ${TIMEOUT_CMD:+...} prefixes with this helper to avoid malformed empty-prefix invocations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇
I hopped through scripts in dusk and dew,
Found missing timeouts, then stitched them new.
I wrap the runs so tests won't roam,
macOS and Linux both feel at home.
Nibbles of success — a carrot comb.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: standardizing timeout/gtimeout handling across all e2e test scripts, which is the primary objective.
Linked Issues check ✅ Passed The PR fully addresses the objectives from issue #2160: standardizes timeout/gtimeout detection across 10 e2e scripts, ensures the TIMEOUT_CMD variable is set before re-exec, adds fail-fast behavior with exit code 127 and remediation guidance, and removes inconsistent ad-hoc patterns.
Out of Scope Changes check ✅ Passed All changes are focused on refactoring timeout handling in e2e scripts with consistent detection, re-exec ordering, and error handling—directly aligned with the linked issue objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/macos-timeout-fallback-in-e2e

Comment @coderabbitai help to get the list of available commands and usage tips.

@hunglp6d
hunglp6d marked this pull request as ready for review April 21, 2026 11:06

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/e2e/test-inference-routing.sh`:
- Around line 40-49: Introduce a small wrapper function (e.g., timeout_run) that
checks NEMOCLAW_E2E_NO_TIMEOUT and whether TIMEOUT_CMD is non-empty and then
either prefixes the invocation with "$TIMEOUT_CMD" -s TERM "$TIMEOUT_SECONDS" or
runs the command directly; replace all direct expansions of $TIMEOUT_CMD in the
script with calls to this wrapper so every timed invocation uses the safe,
quoted execution path and the wrapper forwards arguments and preserves exit
status (search for usages of TIMEOUT_CMD in the file to update every call).

In `@test/e2e/test-sandbox-operations.sh`:
- Around line 30-38: The bypass leaves TIMEOUT_CMD empty so callsites using the
pattern "$TIMEOUT_CMD <seconds> ..." end up running "<seconds> ..." and fail;
fix by ensuring TIMEOUT_CMD is always a callable (either the real timeout binary
or a small shell function) — e.g., define a NOOP_TIMEOUT_CMD function (name
referenced as NOOP_TIMEOUT_CMD) that accepts the seconds arg, shifts it off and
then execs the remaining command, and set TIMEOUT_CMD to that function whenever
NEMOCLAW_E2E_NO_TIMEOUT=1 or no timeout binary is found; update the wrapper
logic around TIMEOUT_CMD/TIMEOUT_SECONDS (symbols TIMEOUT_CMD,
NEMOCLAW_E2E_NO_TIMEOUT, TIMEOUT_SECONDS) so downstream "$TIMEOUT_CMD <seconds>
..." invocations continue to work safely.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3ae8cb79-2b75-4260-a329-46e818728533

📥 Commits

Reviewing files that changed from the base of the PR and between 5c4c48a and f310627.

📒 Files selected for processing (10)
  • test/e2e/test-deployment-services.sh
  • test/e2e/test-double-onboard.sh
  • test/e2e/test-inference-routing.sh
  • test/e2e/test-network-policy.sh
  • test/e2e/test-onboard-resume.sh
  • test/e2e/test-sandbox-operations.sh
  • test/e2e/test-sandbox-survival.sh
  • test/e2e/test-shields-config.sh
  • test/e2e/test-skip-permissions-policy.sh
  • test/e2e/test-token-rotation.sh

Comment thread test/e2e/test-inference-routing.sh Resolved
Comment thread test/e2e/test-sandbox-operations.sh Resolved
@wscurran wscurran added platform: macos Affects macOS, including Apple Silicon NemoClaw CLI labels Apr 21, 2026
@wscurran

Copy link
Copy Markdown
Contributor

✨ Thanks for submitting this PR that proposes a fix for an issue with NemoClaw scripts crashing on macOS — the changes and test plan will help us review this further.


Related open issues:


Possibly related open issues:

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
test/e2e/test-network-policy.sh (1)

53-56: Consider making run_with_timeout honor the explicit no-timeout bypass flag.

Right now, if NEMOCLAW_E2E_NO_TIMEOUT=1 is set and a timeout binary exists, per-call timeouts still apply. If the intent is “disable all timeouts,” gate on the flag inside the helper too.

♻️ Proposed tweak
 run_with_timeout() {
   local seconds="$1"
   shift
-  if [ -n "$TIMEOUT_CMD" ]; then
+  if [ "${NEMOCLAW_E2E_NO_TIMEOUT:-0}" = "1" ] || [ -z "$TIMEOUT_CMD" ]; then
+    "$@"
+  else
     "$TIMEOUT_CMD" "$seconds" "$@"
-  else
-    "$@"
   fi
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/e2e/test-network-policy.sh` around lines 53 - 56, The helper
run_with_timeout currently calls "$TIMEOUT_CMD" if set, ignoring the global
NEMOCLAW_E2E_NO_TIMEOUT flag; update run_with_timeout to first check if
NEMOCLAW_E2E_NO_TIMEOUT is set/non-empty and, when true, run the command
directly with "$@" (bypassing any timeout binary) otherwise preserve the
existing behavior of using TIMEOUT_CMD when available; refer to the variables
and helper name run_with_timeout, TIMEOUT_CMD and NEMOCLAW_E2E_NO_TIMEOUT to
locate the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/e2e/test-token-rotation.sh`:
- Around line 38-48: The script reduces the default TIMEOUT_SECONDS to 900
causing flaky runs; update the TIMEOUT_SECONDS assignment so it uses the
standardized 1800-second default (respecting NEMOCLAW_E2E_TIMEOUT_SECONDS if
set) instead of 900. Edit the TIMEOUT_SECONDS line in test-token-rotation.sh to
set the default to 1800 and keep the existing logic that honors
NEMOCLAW_E2E_TIMEOUT_SECONDS and NEMOCLAW_E2E_NO_TIMEOUT unchanged.
- Around line 50-61: The run_with_timeout helper incorrectly honors the
NEMOCLAW_E2E_NO_TIMEOUT bypass because it checks TIMEOUT_CMD first; change
run_with_timeout to first check whether NEMOCLAW_E2E_NO_TIMEOUT is set/true and,
if so, run the command directly, otherwise detect TIMEOUT_CMD and use it;
alternatively introduce an internal flag (e.g., USE_TIMEOUT or
WRAPPED_BY_TIMEOUT) that is set only when you actually wrap the call so
subsequent invocations respect the user bypass — update the run_with_timeout
function and any places that set/inspect TIMEOUT_CMD to use the new order/flag
(referencing run_with_timeout, TIMEOUT_CMD, and NEMOCLAW_E2E_NO_TIMEOUT).

---

Nitpick comments:
In `@test/e2e/test-network-policy.sh`:
- Around line 53-56: The helper run_with_timeout currently calls "$TIMEOUT_CMD"
if set, ignoring the global NEMOCLAW_E2E_NO_TIMEOUT flag; update
run_with_timeout to first check if NEMOCLAW_E2E_NO_TIMEOUT is set/non-empty and,
when true, run the command directly with "$@" (bypassing any timeout binary)
otherwise preserve the existing behavior of using TIMEOUT_CMD when available;
refer to the variables and helper name run_with_timeout, TIMEOUT_CMD and
NEMOCLAW_E2E_NO_TIMEOUT to locate the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0760ceaf-1627-4237-b93c-d96378c7b806

📥 Commits

Reviewing files that changed from the base of the PR and between f7b5501 and 2a79e23.

📒 Files selected for processing (2)
  • test/e2e/test-network-policy.sh
  • test/e2e/test-token-rotation.sh

Comment thread test/e2e/test-token-rotation.sh Resolved
Comment thread test/e2e/test-token-rotation.sh Resolved
@cv
cv merged commit d9aced4 into main Apr 23, 2026
19 checks passed
jyaunches pushed a commit that referenced this pull request Apr 23, 2026
…sh (#2368)

# Summary

Centralize the duplicated timeout/gtimeout detection, self-wrap, and
run_with_timeout() code from 10 E2E test scripts into a single shared
helper (test/e2e/e2e-timeout.sh). PR #2162 introduced ~31 identical
lines in every script;
this extracts them into one place and replaces each copy with a 4-line
source stanza, removing ~210 lines of boilerplate with no behavioral
changes.

# Related Issue

 Follow-up to #2162.

# Changes

 - New file test/e2e/e2e-timeout.sh — shared helper containing:
     - timeout / gtimeout binary detection
- Self-wrap logic (exec $TIMEOUT_CMD -s TERM … "$0" "$@") gated on
NEMOCLAW_E2E_TIMEOUT_WRAPPED
- Fail-fast with exit 127 and remediation guidance when neither binary
is found
     - run_with_timeout() per-command helper
- Updated 10 E2E scripts to source the helper instead of inlining the
block:
     - test-deployment-services.sh (default 3600s)
     - test-double-onboard.sh (900s)
     - test-inference-routing.sh (1200s)
     - test-network-policy.sh (3600s)
     - test-onboard-resume.sh (600s)
     - test-sandbox-operations.sh (1800s)
     - test-sandbox-survival.sh (900s)
     - test-shields-config.sh (900s)
     - test-skip-permissions-policy.sh (900s)
     - test-token-rotation.sh (2400s)
- Each script sets export NEMOCLAW_E2E_DEFAULT_TIMEOUT=<seconds> before
sourcing, preserving per-script defaults
- All environment knobs unchanged: NEMOCLAW_E2E_NO_TIMEOUT,
NEMOCLAW_E2E_TIMEOUT_SECONDS, NEMOCLAW_E2E_TIMEOUT_WRAPPED
- Used SCRIPT_DIR_TIMEOUT to avoid collisions with existing SCRIPT_DIR
variables

# Type of Change

 - Code change (feature, bug fix, or refactor)

# Verification

 - npx prek run --all-files passes
 - npm test passes
 - Tests added or updated for new or changed behavior
 - No secrets, API keys, or credentials committed

# AI Disclosure

 - AI-assisted — tool: Claude Code


────────────────────────────────────────────────────────────────────────────────

 Signed-off-by: Brandon Pelfrey <[email protected]>

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Refactor**
* Extracted timeout management logic from multiple end-to-end test
scripts into a centralized shared utility module. This consolidates
platform-specific timeout command detection, configuration handling, and
helper utility functions to eliminate code duplication and ensure
consistent, reliable timeout behavior across all test suites and
environments.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@hunglp6d
hunglp6d deleted the fix/macos-timeout-fallback-in-e2e branch May 2, 2026 08:48
@wscurran wscurran added area: cli Command line interface, flags, terminal UX, or output bug-fix PR fixes a bug or regression and removed priority: medium labels Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli Command line interface, flags, terminal UX, or output bug-fix PR fixes a bug or regression platform: macos Affects macOS, including Apple Silicon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[macOS] scripts crash on macOS without coreutils; standardize timeout handling across the suite

4 participants