Skip to content
Open
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
1 change: 0 additions & 1 deletion apps/chatgpt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const TOOLS = [
description: 'Polling mode: "poll" returns on new logs (default for ChatGPT widget), "wait" blocks until completion.',
},
},
anyOf: [{ required: ["jobId"] }, { required: ["sessionKey"] }],
},
annotations: {
title: "Check Task Status",
Expand Down
11 changes: 9 additions & 2 deletions packages/core/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import { classifyError } from "./errors.ts";
import { OpenClawGateway } from "./gateway.ts";
import type { CheckMode, ContinuationState, Job, JobSnapshot, TaskInput } from "./types.ts";

const TIMEOUT_MS = 600_000; // 10 minutes
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;
Comment on lines +7 to +11
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.

}

const TIMEOUT_MS = readPositiveIntEnv("CLAWCONNECT_TIMEOUT_MS", 600_000); // 10 minutes default
const POLL_WAIT_MS = 50_000; // max time check waits before returning
const MAX_LOG_ENTRIES = 200;
const MAX_LOG_ENTRIES = readPositiveIntEnv("CLAWCONNECT_MAX_LOG_ENTRIES", 200);

const LEGACY_CHATGPT_SESSION_PREFIX = "agent:chatgpt:";

Expand Down