Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/reference/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ In addition to `settings.json`, the `.proto/` directory can contain:

These variables take effect at runtime and do not require a settings file entry.

| Variable | Default | Description |
| ------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `PROTO_STREAM_STALL_TIMEOUT_MS` | `90000` | Max ms to wait between streaming chunks before the stall watchdog fires (throws a retryable error). Increase if complex agentic responses are hitting the limit. |
| `PROTO_SYSTEM_DEFAULTS_PATH` | — | Override path to the system defaults settings file |
| `PROTO_SYSTEM_SETTINGS_PATH` | — | Override path to the system settings override file |
| Variable | Default | Description |
| ------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `PROTO_STREAM_STALL_TIMEOUT_MS` | `300000` | Max ms to wait between streaming chunks before the stall watchdog fires (throws a retryable error). Increase if complex agentic responses are hitting the limit. |
| `PROTO_SYSTEM_DEFAULTS_PATH` | — | Override path to the system defaults settings file |
| `PROTO_SYSTEM_SETTINGS_PATH` | — | Override path to the system settings override file |

### `modelProviders`

Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/core/turn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ import { withChunkTimeout, StreamStallError } from '../utils/streamStall.js';

/**
* Max ms to wait between individual stream chunks before declaring a stall.
* 90 s gives complex agentic responses (e.g. parallel subagent dispatch)
* enough room for Gemini's mid-stream planning pauses while still catching
* genuine frozen connections well before the 120 s SDK timeout.
* 5 min gives complex agentic responses (e.g. parallel subagent dispatch
* and long mid-stream planning pauses) ample headroom while still catching
* genuine frozen connections.
* Override via PROTO_STREAM_STALL_TIMEOUT_MS env var.
*/
const STREAM_STALL_TIMEOUT_MS = parseInt(
process.env['PROTO_STREAM_STALL_TIMEOUT_MS'] ?? '90000',
process.env['PROTO_STREAM_STALL_TIMEOUT_MS'] ?? '300000',
10,
Comment on lines 45 to 47
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Harden env timeout parsing to avoid invalid watchdog values.

parseInt(process.env[...] ?? '300000', 10) accepts invalid/unsafe inputs (NaN, <= 0), which can cause immediate or undefined stall behavior. Add a bounded fallback after parsing.

Suggested patch
-const STREAM_STALL_TIMEOUT_MS = parseInt(
-  process.env['PROTO_STREAM_STALL_TIMEOUT_MS'] ?? '300000',
-  10,
-);
+const parsedStreamStallTimeoutMs = Number.parseInt(
+  process.env['PROTO_STREAM_STALL_TIMEOUT_MS'] ?? '300000',
+  10,
+);
+const STREAM_STALL_TIMEOUT_MS =
+  Number.isFinite(parsedStreamStallTimeoutMs) && parsedStreamStallTimeoutMs > 0
+    ? parsedStreamStallTimeoutMs
+    : 300_000;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/core/turn.ts` around lines 45 - 47, STREAM_STALL_TIMEOUT_MS
currently uses parseInt on an env var without validation; after parsing the raw
value for STREAM_STALL_TIMEOUT_MS, validate it (reject NaN or values <= 0),
apply a safe default of 300000 if invalid, and clamp the parsed value to a
reasonable min/max range (e.g., min 1000 ms, max something large) before
assigning; locate and update the constant definition for STREAM_STALL_TIMEOUT_MS
in turn.ts so it uses the validated/clamped numeric value instead of the raw
parseInt result.

);

Expand Down
Loading