Skip to content

fix: make Honcho SDK timeout configurable (closes #25)#28

Open
offendingcommit wants to merge 1 commit into
plastic-labs:mainfrom
offendingcommit:fix/25-configurable-sdk-timeout
Open

fix: make Honcho SDK timeout configurable (closes #25)#28
offendingcommit wants to merge 1 commit into
plastic-labs:mainfrom
offendingcommit:fix/25-configurable-sdk-timeout

Conversation

@offendingcommit
Copy link
Copy Markdown

@offendingcommit offendingcommit commented Apr 17, 2026

Closes #25.

What this does

Replaces the hardcoded timeout: 8000 in getHonchoClientOptions() with a configurable value.

Precedence: HONCHO_TIMEOUT env var → config.sdkTimeout (on-disk) → DEFAULT_SDK_TIMEOUT_MS (30000).

Why

As documented in #25, 8s aborts dialectic chat at high/max reasoning levels even with healthy backends, because multi-iteration tool loops on local models (LM Studio/Ollama) or rich observation sets regularly take 10-30s. 30s matches the issue's primary suggestion and leaves headroom without matching the SDK's 60s default (which felt too generous as a new default). Users who want 60s can set HONCHO_TIMEOUT=60000 or add "sdkTimeout": 60000 to their config.

Changes

  • HonchoFileConfig (on-disk shape): added sdkTimeout?: number so the value survives saveConfig().
  • HonchoCLAUDEConfig (resolved runtime shape): added sdkTimeout?: number with doc comment citing Hardcoded 8s SDK timeout breaks dialectic queries at high/max reasoning levels #25.
  • New parseTimeoutEnv() helper: reads HONCHO_TIMEOUT, coerces to a positive finite integer, returns undefined on invalid input so the next precedence level wins.
  • resolveConfig(): env var first, then raw.sdkTimeout from the file.
  • loadConfigFromEnv(): env var only.
  • getHonchoClientOptions(): config.sdkTimeout ?? DEFAULT_SDK_TIMEOUT_MS.
  • Exported DEFAULT_SDK_TIMEOUT_MS = 30000 replaces the magic number.

Test plan

  • bunx tsc --noEmit clean
  • Verified with no env + no config field → 30000
  • Verified with HONCHO_TIMEOUT=45000 → 45000 (parsed as positive int)
  • Verified with invalid HONCHO_TIMEOUT=abc → falls through to file/default
  • File-config sdkTimeout: 20000 with no env var → 20000

Not included

Summary by CodeRabbit

New Features

  • Added configurable SDK timeout via the HONCHO_TIMEOUT environment variable
  • Updated default SDK timeout to 30 seconds (previously 8 seconds)
  • Added optional sdkTimeout configuration setting for granular timeout control

The SDK client was constructed with `timeout: 8000`, which aborts
dialectic chat calls at high/max reasoning levels where server-side
processing can take 10-30+ seconds (multi-iteration tool loops,
local model backends, rich observation sets).

Changes:
- Add `sdkTimeout?: number` to both HonchoFileConfig (on-disk) and
  HonchoCLAUDEConfig (resolved runtime shape) with a doc comment
  pointing to plastic-labs#25.
- New `parseTimeoutEnv()` helper reads `HONCHO_TIMEOUT` env var and
  coerces it to a positive integer.
- `resolveConfig` prefers env var, then file config.
- `loadConfigFromEnv` reads env var into the resolved config.
- `getHonchoClientOptions` uses `config.sdkTimeout ?? 30000`; exported
  `DEFAULT_SDK_TIMEOUT_MS` replaces the magic number.

Precedence: HONCHO_TIMEOUT env > config.sdkTimeout file field > 30000.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

Walkthrough

The changes make the SDK client timeout configurable by adding an optional sdkTimeout field to the config interfaces, introducing environment variable parsing for HONCHO_TIMEOUT, exporting a DEFAULT_SDK_TIMEOUT_MS constant (30 seconds), and updating the client initialization logic to use the configurable value instead of a hardcoded 8-second timeout.

Changes

Cohort / File(s) Summary
SDK Timeout Configuration
plugins/honcho/src/config.ts
Added optional sdkTimeout?: number field to HonchoFileConfig and HonchoCLAUDEConfig interfaces; introduced parseTimeoutEnv() function to parse HONCHO_TIMEOUT environment variable; updated resolveConfig() and loadConfigFromEnv() to resolve timeout from env var or config file; exported DEFAULT_SDK_TIMEOUT_MS = 30000 constant; modified getHonchoClientOptions() to use config.sdkTimeout ?? DEFAULT_SDK_TIMEOUT_MS instead of hardcoded timeout: 8000.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 The timeout once stood firm at eight,
But dialectic queries couldn't wait,
Now thirty seconds let wisdom flow,
Through reasoning depths both high and low!
Configuration unlocked, the SDK now free,
A timeout that fits, for all to see.

🚥 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: making the Honcho SDK timeout configurable, and references the related issue #25.
Linked Issues check ✅ Passed The PR successfully addresses issue #25 by implementing configurable SDK timeout with environment variable, file config, and default fallback precedence as suggested.
Out of Scope Changes check ✅ Passed All changes are directly related to making the SDK timeout configurable; no unrelated modifications detected in config parsing or client options.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
plugins/honcho/src/config.ts (2)

240-246: Minor: comment says "positive integer" but code accepts any positive finite number; also no validation for raw.sdkTimeout from the config file.

  • Number("30.5")30.5 passes Number.isFinite(n) && n > 0, so the function accepts non-integer values despite the doc comment. Either tighten the check (Number.isInteger(n)) or relax the comment.
  • raw.sdkTimeout read from ~/.honcho/config.json on Lines 351/721 is used as-is with no validation, so a malformed file value (e.g., 0, -1, a string) can reach the SDK as the HTTP timeout. Consider running file values through the same sanitizer as the env var.
  • Silently discarding an invalid HONCHO_TIMEOUT makes misconfiguration hard to notice; a one-time console.warn on invalid input would save debugging time.
🔧 Suggested refactor
-/** Parse HONCHO_TIMEOUT env var into a positive integer, or undefined. */
-function parseTimeoutEnv(): number | undefined {
-  const raw = process.env.HONCHO_TIMEOUT;
-  if (!raw) return undefined;
-  const n = Number(raw);
-  return Number.isFinite(n) && n > 0 ? n : undefined;
-}
+/** Coerce a value to a positive finite number of milliseconds, or undefined. */
+function sanitizeTimeout(value: unknown): number | undefined {
+  if (value === undefined || value === null || value === "") return undefined;
+  const n = typeof value === "number" ? value : Number(value);
+  return Number.isFinite(n) && n > 0 ? n : undefined;
+}
+
+/** Parse HONCHO_TIMEOUT env var, warning on invalid input. */
+function parseTimeoutEnv(): number | undefined {
+  const raw = process.env.HONCHO_TIMEOUT;
+  if (!raw) return undefined;
+  const parsed = sanitizeTimeout(raw);
+  if (parsed === undefined) {
+    console.warn(`[honcho] Ignoring invalid HONCHO_TIMEOUT="${raw}"; expected positive number of ms.`);
+  }
+  return parsed;
+}

And at Line 351:

-    sdkTimeout: parseTimeoutEnv() ?? raw.sdkTimeout,
+    sdkTimeout: parseTimeoutEnv() ?? sanitizeTimeout(raw.sdkTimeout),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@plugins/honcho/src/config.ts` around lines 240 - 246, The docstring for
parseTimeoutEnv() is inaccurate and file config values aren't validated: tighten
parseTimeoutEnv() to accept only positive integers (use Number.isInteger check)
or update the comment to allow non-integer positives; ensure the config loader
that reads raw.sdkTimeout runs the same sanitizer as parseTimeoutEnv() (apply
the same validation logic to raw.sdkTimeout before passing to the SDK), and emit
a one-time console.warn when HONCHO_TIMEOUT (env) or raw.sdkTimeout (config
file) is present but invalid so misconfigurations are visible.

712-724: LGTM — default raised to 30s and client option is now configurable.

Clean replacement of the hardcoded 8000 with config.sdkTimeout ?? DEFAULT_SDK_TIMEOUT_MS, and exporting the constant makes it easy for tests/other callers to reference. This directly addresses #25 for the common dialectic chat timeout case.

One forward-looking thought (out of scope for this PR, per your test plan): the issue also mentions per-tool timeouts so short data tools aren't forced to wait 30s. A follow-up could thread a per-call override through getHonchoClientOptions() or expose a second constant (e.g. DEFAULT_CHAT_TIMEOUT_MS) for the long-running path.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@plugins/honcho/src/config.ts` around lines 712 - 724, Change
getHonchoClientOptions to accept an optional per-call timeout or add a separate
constant for long-running chat timeouts: either add an optional parameter (e.g.,
timeoutMs?: number) to getHonchoClientOptions and use timeout: timeoutMs ??
config.sdkTimeout ?? DEFAULT_SDK_TIMEOUT_MS, or export a new
DEFAULT_CHAT_TIMEOUT_MS and use that where chat-specific clients are created;
update callers of getHonchoClientOptions (or the chat client creation site) to
pass the chat-specific timeout when needed and keep DEFAULT_SDK_TIMEOUT_MS as
the general default.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@plugins/honcho/src/config.ts`:
- Around line 240-246: The docstring for parseTimeoutEnv() is inaccurate and
file config values aren't validated: tighten parseTimeoutEnv() to accept only
positive integers (use Number.isInteger check) or update the comment to allow
non-integer positives; ensure the config loader that reads raw.sdkTimeout runs
the same sanitizer as parseTimeoutEnv() (apply the same validation logic to
raw.sdkTimeout before passing to the SDK), and emit a one-time console.warn when
HONCHO_TIMEOUT (env) or raw.sdkTimeout (config file) is present but invalid so
misconfigurations are visible.
- Around line 712-724: Change getHonchoClientOptions to accept an optional
per-call timeout or add a separate constant for long-running chat timeouts:
either add an optional parameter (e.g., timeoutMs?: number) to
getHonchoClientOptions and use timeout: timeoutMs ?? config.sdkTimeout ??
DEFAULT_SDK_TIMEOUT_MS, or export a new DEFAULT_CHAT_TIMEOUT_MS and use that
where chat-specific clients are created; update callers of
getHonchoClientOptions (or the chat client creation site) to pass the
chat-specific timeout when needed and keep DEFAULT_SDK_TIMEOUT_MS as the general
default.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 98ecb57d-895b-4b17-ad04-264d79094dc6

📥 Commits

Reviewing files that changed from the base of the PR and between 0813ebd and 9c4f46b.

📒 Files selected for processing (1)
  • plugins/honcho/src/config.ts

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.

Hardcoded 8s SDK timeout breaks dialectic queries at high/max reasoning levels

1 participant