Make task timeout and log cap configurable via env#9
Conversation
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>
WalkthroughTwo files modified: the ChatGPT tool's JSON schema constraint was relaxed by removing an Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
apps/chatgpt/src/index.tspackages/core/src/session.ts
💤 Files with no reviewable changes (1)
- apps/chatgpt/src/index.ts
| 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; |
There was a problem hiding this comment.
🧩 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.tsRepository: 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')));
EOFRepository: 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.tsRepository: 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.
Summary
TIMEOUT_MSandMAX_LOG_ENTRIESinpackages/core/src/session.tsare now configurable viaCLAWCONNECT_TIMEOUT_MSandCLAWCONNECT_MAX_LOG_ENTRIESenv vars.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.jsonundermcpServers.clawconnect.env) without touching source.Test plan
readPositiveIntEnvfalls back on missing/empty/NaN/zero/negative values; accepts positive integers.pnpm run readysucceeds;@clawconnect/coredist contains the new env var references.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
Improvements