Skip to content

fix(browser): guard module-level int() against non-numeric env var - #35789

Closed
annguyenNous wants to merge 1 commit into
NousResearch:mainfrom
annguyenNous:fix/browser-tool-env-int-crash
Closed

fix(browser): guard module-level int() against non-numeric env var#35789
annguyenNous wants to merge 1 commit into
NousResearch:mainfrom
annguyenNous:fix/browser-tool-env-int-crash

Conversation

@annguyenNous

Copy link
Copy Markdown
Contributor

Fix: Guard module-level int() against non-numeric env var

File: tools/browser_tool.py, line 1181

Bug: BROWSER_SESSION_INACTIVITY_TIMEOUT is cast via int() at module level without any error handling. If a user sets BROWSER_INACTIVITY_TIMEOUT to a non-numeric string (e.g. "abc" or an empty string), the entire browser_tool module fails to import with an unhandled ValueError, breaking all browser functionality.

Fix: Wrap the module-level int() call in try/except (ValueError, TypeError) with a fallback to the default value of 300 seconds. This matches the defensive pattern used elsewhere in the codebase (e.g. _env_float() helper in chat_completion_helpers.py).

Impact: High — any misconfigured env var currently causes a complete browser tool outage with no recovery path.

BROWSER_SESSION_INACTIVITY_TIMEOUT was cast via int() at module level
without a try/except. Setting BROWSER_INACTIVITY_TIMEOUT to a
non-numeric string (e.g. "abc") caused an unhandled ValueError on
import, breaking all browser tool functionality.

Wrap in try/except (ValueError, TypeError) with fallback to the
default of 300 seconds.
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have tool/browser Browser automation (CDP, Playwright) labels May 31, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Same class of fix as #35790 (env var cast guards). This PR covers browser_tool.py while #35790 covers chat_completion_helpers.py and platform adapter files. Related to #14756 (merged, web_server float guard).

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

Code Review Summary

Verdict: Approved

🔍 What this does

Wraps the module-level int(os.environ.get(...)) call in a try/except (ValueError, TypeError) so a non-numeric BROWSER_INACTIVITY_TIMEOUT env var doesn't crash the entire browser_tool module at import time.

✅ Looks Good

  • Correctness: Falls back to the documented default (300s) on any parsing failure — matches the existing _env_float() defensive pattern in chat_completion_helpers.py.
  • Edge cases: Handles both ValueError (non-numeric string like "abc") and TypeError (e.g. None from os.environ.get with no default — though the default is provided here, the except TypeError is a good belt-and-suspenders guard).
  • Impact: Prevents a silent full-outage of browser tooling due to misconfiguration.

💡 Suggestion (non-blocking)

Consider extracting this pattern into a reusable helper like _env_int(name, default) to match _env_float() and apply consistently across the codebase. Not needed in this PR — can be a follow-up refactor.


Reviewed by Hermes Agent (cron)

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for identifying this import-time failure mode. This is an automated hermes-sweeper review; the requested guarantee is already present on current main.

  • Commit 2912d943705058cc55f7f5fc102c99dbb1efcc27 (fix: guard int(os.getenv()) casts against malformed env vars (#40598)) replaced this exact browser timeout cast with env_int(...); it also credits @annguyenNous as co-author.
  • Current tools/browser_tool.py:1421 resolves BROWSER_INACTIVITY_TIMEOUT via env_int, and utils.py:410-418 returns the provided default for empty, non-numeric, or otherwise invalid integer input.
  • The later timeout-resolution refactor at tools/browser_tool.py:1420-1433 preserves that safe environment fallback while making config.yaml authoritative.

Closing as implemented on main.

@teknium1 teknium1 closed this Jul 13, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low — cosmetic, nice to have sweeper:implemented-on-main Sweeper: behavior already present on current main tool/browser Browser automation (CDP, Playwright) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants