Skip to content

Read whole numbers from computer env, and keep the port in range - #501

Merged
davidmckayv merged 2 commits into
CopilotKit:mainfrom
Ayush7614:fix/computer-env-integer-validation
Sep 12, 2026
Merged

Read whole numbers from computer env, and keep the port in range#501
davidmckayv merged 2 commits into
CopilotKit:mainfrom
Ayush7614:fix/computer-env-integer-validation

Conversation

@Ayush7614

Copy link
Copy Markdown
Contributor

What this changes

Fixes #497. The computer's env reader accepted anything Number called finite and positive:

  • PORT=80.5, NAVIGATION_TIMEOUT_MS=0.5, ACTION_TIMEOUT_MS=0.1, COMPUTER_MAX_BROWSERS=2.5, COMPUTER_BROWSER_IDLE_MS=0.5 were all returned verbatim. A fractional port misbound at boot, a fractional timeout fired before any action could finish (surfacing as 502s reading as a broken computer), and a fractional cap reached eviction math. PORT=99999 parsed fine and then misbound — a deployment failure instead of the documented fallback.
  • numberFromEnv now takes whole numbers on sight (trim + /^\\d+\$/ + parseInt, the same rule as the supervisor's listenPort), with optional min\)/maxfor settings with a range.PORTrides{ min: 1, max: 65535 }; timeouts and counts stay unbounded above, like before. Zero semantics unchanged: COMPUTER_BROWSER_IDLE_MS=0` still keeps browsers resident, and the empty-string-means-unset rule the function exists for is untouched.

Where it runs

The computer process holding one Bot browser, at env read. Same fallback on every computer.

  • New state that outlives a request? None. Per-process env parsing.
  • What happens on the second replica? Same fallback on every computer: pure function of the environment. No cross-computer coordination.
  • Anything serialised? No.
  • Anything fanned out to a browser? Timeouts reach Playwright only after parsing, on the computer that owns that browser — and now only as whole numbers.
  • New listener, port, or schedule? No. The port this process serves on is unchanged when the variable is well-formed.

Postgres is already there and is the default answer to all of the above: nothing here needs it.

Boundary and audit

  • Every acting call still goes through the gateway: resolve, decide, audit, then act. The computer holds no policy engine; this checks well-formedness only, same as the existing navigate/timeout/scroll checks.
  • New refusals and new failures each write a row. N/A on this process: fallbacks are startup config answered with the documented default, matching the existing behaviour.
  • Nothing new is trusted from the client that the server can resolve itself. Stricter: fewer shapes reach Bun.serve/Playwright/eviction math.

Changelog

  • A line in CHANGELOG.md under Unreleased: computer env validation entry.

Proof

  • bun test agent-computer/tests/number-from-env.test.ts: 28 pass (11 pre-existing + 17 new: 6 fractional/sci/hex fallbacks, large-int passthrough, zero-off fraction, 4 in-range ports, 6 out-of-range/non-whole fallbacks).
  • bun test in agent-computer: 306 pass, 15 skip, 0 fail across 21 files.
  • bun run typecheck in agent-computer (after bun install --frozen-lockfile, as CI does): clean.
  • bunx biome format + bunx biome lint --error-on-warnings on touched files: clean.

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

Deep-reviewed clean (validation, no secret leak, fail-closed, agrees with existing layers). CI green.

@davidmckayv
davidmckayv merged commit 1f3db0d into CopilotKit:main Sep 12, 2026
15 checks passed
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.

numberFromEnv accepts fractions and out-of-range ports instead of taking the fallback

2 participants