Skip to content

Make task timeout and log cap configurable via env#9

Open
jaruesink wants to merge 3 commits intomainfrom
fix/env-configurable-timeout
Open

Make task timeout and log cap configurable via env#9
jaruesink wants to merge 3 commits intomainfrom
fix/env-configurable-timeout

Conversation

@jaruesink
Copy link
Copy Markdown
Contributor

@jaruesink jaruesink commented Apr 16, 2026

Summary

  • TIMEOUT_MS and MAX_LOG_ENTRIES in packages/core/src/session.ts are now configurable via CLAWCONNECT_TIMEOUT_MS and CLAWCONNECT_MAX_LOG_ENTRIES env vars.
  • Defaults are unchanged (600_000 ms / 200 entries) — behavior only changes when operators opt in.
  • Invalid or missing values fall back to the defaults.

Why

Long-running investigations (multi-step infra debugging, large codebase audits) routinely hit the hardcoded 10-minute task timeout and get cut off mid-reasoning. When that happens the MCP-side promise rejects but the OpenClaw agent keeps churning, so follow-up messages on the same session can collide with the still-running task and return "Stream finished with no response collected."

Before this change, the only way to tune these was editing the constants and rebuilding @clawconnect/core. With env support, operators can set values in their MCP server config (e.g. ~/.claude.json under mcpServers.clawconnect.env) without touching source.

Test plan

  • Unit-level: readPositiveIntEnv falls back on missing/empty/NaN/zero/negative values; accepts positive integers.
  • Build: pnpm run ready succeeds; @clawconnect/core dist contains the new env var references.
  • Runtime: restart MCP server with CLAWCONNECT_TIMEOUT_MS=1800000; run a task that previously hit the 10-minute cap and confirm it runs to completion.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Configuration

    • Session operations now support environment variable configuration for timeout and log entry limits with sensible defaults.
  • Improvements

    • Relaxed validation constraints for task checking operations to support more flexible parameter combinations.

jaruesink and others added 3 commits April 9, 2026 10:56
Remove top-level anyOf from check_task inputSchema — Claude API does
not support oneOf/allOf/anyOf at the schema root.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Long-running investigations (multi-step infra debugging, large codebase
audits) routinely hit the hardcoded 10-minute TIMEOUT_MS and get cut off
mid-reasoning. Operators had to rebuild the package to tune it.

Add CLAWCONNECT_TIMEOUT_MS and CLAWCONNECT_MAX_LOG_ENTRIES env vars that
override the module-level defaults when set to a positive integer.
Invalid or missing values fall back to the prior defaults (600_000 ms
and 200 entries), so behavior is unchanged unless operators opt in.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

Walkthrough

Two files modified: the ChatGPT tool's JSON schema constraint was relaxed by removing an anyOf requirement, and environment variable configuration was added to the session module for timeout and log entry limits, each with preserved default values.

Changes

Cohort / File(s) Summary
ChatGPT Tool Schema
apps/chatgpt/src/index.ts
Removed anyOf constraint from check_task tool's inputSchema that previously required either jobId or sessionKey to be present. Runtime handling logic unchanged.
Session Configuration
packages/core/src/session.ts
Added readPositiveIntEnv helper function to read environment variables. Made TIMEOUT_MS and MAX_LOG_ENTRIES configurable via CLAWCONNECT_TIMEOUT_MS and CLAWCONNECT_MAX_LOG_ENTRIES env vars, preserving existing default values (600_000 and 200 respectively).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Make task timeout and log cap configurable via env' directly and clearly describes the main change: making two hardcoded constants (TIMEOUT_MS and MAX_LOG_ENTRIES) configurable through environment variables.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/env-configurable-timeout

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/core/src/session.ts`:
- Around line 7-11: The helper readPositiveIntEnv currently allows decimal
strings like "1.5"; update it to enforce integer-only values by validating with
Number.isInteger(parsed) (or using parseInt and verifying exact match) in
addition to Number.isFinite and > 0, so it returns fallback for non-integer or
non-positive inputs; update callers/tests (e.g., MAX_LOG_ENTRIES and comparisons
to job.logs.length) to rely on this stricter behavior and add unit tests for
readPositiveIntEnv covering decimal, integer, zero, negative, and missing env
cases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a4f4e548-c56e-47f2-a1e4-3e716f4e168a

📥 Commits

Reviewing files that changed from the base of the PR and between b7646db and fb200de.

📒 Files selected for processing (2)
  • apps/chatgpt/src/index.ts
  • packages/core/src/session.ts
💤 Files with no reviewable changes (1)
  • apps/chatgpt/src/index.ts

Comment on lines +7 to +11
function readPositiveIntEnv(name: string, fallback: number): number {
const raw = process.env[name];
if (!raw) return fallback;
const parsed = Number(raw);
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
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 | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Helper implementation =="
rg -n -C2 'function readPositiveIntEnv|Number\.isFinite|Number\.isInteger' packages/core/src/session.ts

echo
echo "== Env parsing tests (look for decimal/float cases) =="
rg -n -C2 'readPositiveIntEnv|CLAWCONNECT_TIMEOUT_MS|CLAWCONNECT_MAX_LOG_ENTRIES|1\.5|0\.5|decimal|float' --iglob '*test*'

Repository: lambda-curry/clawconnect

Length of output: 666


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find test files more broadly
echo "== Searching for test files =="
fd -e test.ts -e spec.ts -e test.js -e spec.js | head -20

# Search for usage of MAX_LOG_ENTRIES and readPositiveIntEnv
echo
echo "== Usage of MAX_LOG_ENTRIES =="
rg -n 'MAX_LOG_ENTRIES' packages/

echo
echo "== Usage of readPositiveIntEnv =="
rg -n 'readPositiveIntEnv' packages/

# Check for any existing integer parsing patterns
echo
echo "== Check for existing integer validation patterns =="
rg -n 'Number.isInteger|parseInt|Math.floor|%' packages/core/src/session.ts

Repository: lambda-curry/clawconnect

Length of output: 753


🏁 Script executed:

#!/bin/bash
# Verify JavaScript number behavior with a quick test
node <<'EOF'
console.log("Number.isFinite behavior:");
console.log("  1.5:", Number.isFinite(1.5), "isInteger:", Number.isInteger(1.5));
console.log("  1:", Number.isFinite(1), "isInteger:", Number.isInteger(1));
console.log("  '1.5' parsed:", Number.isFinite(Number('1.5')), "isInteger:", Number.isInteger(Number('1.5')));
console.log("  '1' parsed:", Number.isFinite(Number('1')), "isInteger:", Number.isInteger(Number('1')));
EOF

Repository: lambda-curry/clawconnect

Length of output: 221


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Look for test-related files and directories
echo "== Testing setup files =="
fd -e 'json|js|ts' -p 'jest|vitest|mocha|test|spec' packages/ 2>/dev/null | head -20

# Check package.json for test config
echo
echo "== Package.json test scripts =="
rg -l 'package\.json' packages/ | xargs -I {} grep -A5 '"test"' {} 2>/dev/null || echo "No test scripts found"

# Look for any JavaScript/TypeScript files that might be tests
echo
echo "== All .test. or .spec. files =="
find packages -name '*test*' -o -name '*spec*' 2>/dev/null | head -20

# Check the line around usage of MAX_LOG_ENTRIES to understand context
echo
echo "== Context of MAX_LOG_ENTRIES usage (line 89 area) =="
sed -n '85,95p' packages/core/src/session.ts

Repository: lambda-curry/clawconnect

Length of output: 671


Enforce integer-only validation in env parsing.

Line 10-11 currently accepts decimal values (e.g., "1.5"), but the function name promises positive integers. This causes a semantic mismatch: MAX_LOG_ENTRIES could be set to a decimal value and compared against job.logs.length (an integer) at line 89, producing unintuitive behavior. Additionally, there are no tests for this helper function to catch such inputs.

🔧 Proposed fix
 function readPositiveIntEnv(name: string, fallback: number): number {
   const raw = process.env[name];
   if (!raw) return fallback;
   const parsed = Number(raw);
-  return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
+  return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/session.ts` around lines 7 - 11, The helper
readPositiveIntEnv currently allows decimal strings like "1.5"; update it to
enforce integer-only values by validating with Number.isInteger(parsed) (or
using parseInt and verifying exact match) in addition to Number.isFinite and >
0, so it returns fallback for non-integer or non-positive inputs; update
callers/tests (e.g., MAX_LOG_ENTRIES and comparisons to job.logs.length) to rely
on this stricter behavior and add unit tests for readPositiveIntEnv covering
decimal, integer, zero, negative, and missing env cases.

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.

1 participant