Skip to content

Read the computer's port and timeouts through the fallback the browser limits use - #114

Open
kevin9327 wants to merge 1 commit into
CopilotKit:mainfrom
kevin9327:fix/computer-env-number-fallback
Open

Read the computer's port and timeouts through the fallback the browser limits use#114
kevin9327 wants to merge 1 commit into
CopilotKit:mainfrom
kevin9327:fix/computer-env-number-fallback

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

What this changes

agent-computer reads PORT, NAVIGATION_TIMEOUT_MS and ACTION_TIMEOUT_MS with
Number.parseInt(process.env.X ?? "default", 10). That is the exact shape #96 removed for the
browser limits: an unset variable declared in a compose file arrives as an empty string, so ??
sees "" rather than undefined, never fires, and Number.parseInt("") is NaN.

ACTION_TIMEOUT_MS is a documented variable (.env.example:173), so a deployment that sets it the
way the compose file already sets COMPUTER_MAX_BROWSERS/COMPUTER_BROWSER_IDLE_MS (${VAR:-})
hands Playwright a NaN timeout instead of the 10s the default promises — a computer that looks
broken rather than misconfigured, which is precisely the failure #96 wrote up.

The fix reuses #96's own helper: numberFromEnv (empty, absent, non-numeric and non-positive all
take the fallback) is exported from profiles.ts and the three values are read through it, so the
whole package treats a bad or empty timeout the same way it already treats a bad or empty browser
cap.

Where it runs

  • New state that outlives a request? None. Three module constants read once at startup.
  • What happens on the second replica? Identical to the first — this is per-process config,
    not shared state. The change is that an empty or malformed value now yields the default on
    every replica instead of NaN.
  • Anything serialised / fanned out / new listener? No. No schema, socket, port or schedule
    changes; the port number is parsed more safely but the listener is the same one.

Boundary and audit

  • No acting call, policy decision or audit path is touched. This is startup configuration for the
    computer process's own timeouts and port.

Proof

agent-computer is not reached by the root typecheck (that gap is filed as #112), so verified in
the package directly:

  • bunx tsc --noEmit — clean.
  • bun test tests/number-from-env.test.ts — 5/5. New test covers a positive value (trimmed), unset,
    the empty string a compose file passes for an unset variable, a non-numeric value, and
    zero/negative — each of the last four taking the fallback.

Self-contained: numberFromEnv already existed and is unchanged in behaviour; this only exports it
and moves three neighbours onto it.

…r limits use

CopilotKit#96 found that an unset variable declared in a compose file arrives as an empty string, so
`Number.parseInt(process.env.X ?? "default")` never falls back: `??` sees "" rather than undefined,
and the parse is NaN. It moved the browser limits onto `numberFromEnv`, which treats empty, absent,
non-numeric and non-positive alike as "not set".

The three values alongside them in `agent-computer/src/index.ts` kept the raw parse: `PORT`,
`NAVIGATION_TIMEOUT_MS` and `ACTION_TIMEOUT_MS`. `ACTION_TIMEOUT_MS` is a documented variable
(`.env.example:173`), so a deployment that sets it the way the compose file already sets the browser
limits gets a NaN timeout, Playwright waiting on NaN instead of the 10s the default promises, a
computer that looks broken rather than misconfigured.

Export `numberFromEnv` and read the three through it. Adds a test for the helper, including the
empty-string case that is the whole point.

This is in agent-computer, which the root typecheck does not reach (that gap is CopilotKit#112). Verified in the
package: `bunx tsc --noEmit` clean, and `bun test tests/number-from-env.test.ts` is 5/5.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@davidmckayv

Copy link
Copy Markdown
Contributor

The fix is right and low-risk — a declared-but-empty compose var arrives as "", Number.parseInt("") is NaN, and routing PORT and the two timeouts through the existing numberFromEnv matches what #96 did for the browser limits. It merges clean against main. But it ships CI red, and that's the blocker.

agent-computer/tests/number-from-env.test.ts:2 imports numberFromEnv from ../src/profiles, and agent-computer/src/profiles.ts:38 hard-imports playwright at module load. The test runner can't resolve playwright there, so the test file throws on import — Cannot find package 'playwright' — which drops the file's tests and fails both the tests job and verify.

The move: put numberFromEnv in its own tiny playwright-free module (e.g. agent-computer/src/env.ts), re-export it from profiles.ts so nothing else changes, and import it in the test from there. Then CI goes green and this is a merge.

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