Claw Web commited on
Commit
3f28951
·
1 Parent(s): e46d888

fix: remove 30-step limit — match original usize::MAX (conversation.rs)

Browse files

Original claw-code conversation.rs line 141:
max_iterations: usize::MAX

This means the agent loop runs until the LLM stops calling tools,
with NO artificial step limit. The 30-step limit was a Claw-Web
deviation that broke long-running tasks.

Also fixed comments about compaction — it IS manual-only in both
original and Claw-Web (via /compact command).

Files changed (1) hide show
  1. server/runtime/agent.ts +8 -6
server/runtime/agent.ts CHANGED
@@ -6,14 +6,14 @@
6
  import { ENV } from "../_core/env";
7
  import { buildSystemPrompt, TOOL_DEFINITIONS } from "./system-prompt";
8
  import { executeTool, getPlanMode, runPreToolHooks, runPostToolHooks, initializeMcpFromConfig, getMcpManager } from "../tools/executor";
9
- // Compact is manual-only via /compact command (matches original claw-code)
10
- // import { shouldCompact, compactSession, dbMessagesToSession, DEFAULT_COMPACTION_CONFIG } from "./compact";
11
  import { UsageTracker, pricingForModel, defaultSonnetTierPricing, estimateCostUsdWithPricing, totalCostUsd, formatUsd, summaryLinesForModel } from "./usage";
12
  import type { TokenUsage } from "./usage";
13
  import type { Response } from "express";
14
  import { execSync } from "child_process";
15
 
16
- // No auto-compaction — in original claw-code, compact is ONLY triggered by /compact command
 
17
 
18
  interface AgentMessage {
19
  role: "system" | "user" | "assistant" | "tool";
@@ -255,7 +255,9 @@ export async function runAgentLoop(
255
  let totalCompletionTokens = 0;
256
  let totalCost = 0;
257
  let iterations = 0;
258
- const MAX_ITERATIONS = cfg.maxIterations || 30;
 
 
259
  const assistantMessages: AgentMessage[] = [];
260
  const toolResultMessages: AgentMessage[] = [];
261
 
@@ -516,7 +518,7 @@ export async function runAgentLoop(
516
  toolResultMessages.push(toolResultMsg);
517
  }
518
 
519
- // No auto-compaction — in original claw-code, compact is ONLY manual via /compact command
520
 
521
  // Continue the loop — LLM will see tool results and decide next action
522
  sendSSE(res, "status", {
@@ -534,7 +536,7 @@ export async function runAgentLoop(
534
  }
535
 
536
  if (iterations >= MAX_ITERATIONS) {
537
- sendSSE(res, "error", { message: `Maximum iterations (${MAX_ITERATIONS}) reached. The agent has been stopped to prevent runaway execution.` });
538
  }
539
 
540
  // Calculate cost using UsageTracker (matches original)
 
6
  import { ENV } from "../_core/env";
7
  import { buildSystemPrompt, TOOL_DEFINITIONS } from "./system-prompt";
8
  import { executeTool, getPlanMode, runPreToolHooks, runPostToolHooks, initializeMcpFromConfig, getMcpManager } from "../tools/executor";
9
+ // Compact is manual-only via /compact command (matches original claw-code conversation.rs)
 
10
  import { UsageTracker, pricingForModel, defaultSonnetTierPricing, estimateCostUsdWithPricing, totalCostUsd, formatUsd, summaryLinesForModel } from "./usage";
11
  import type { TokenUsage } from "./usage";
12
  import type { Response } from "express";
13
  import { execSync } from "child_process";
14
 
15
+ // In original claw-code, max_iterations defaults to usize::MAX (effectively unlimited).
16
+ // Compact is triggered externally by the caller, not inside the loop.
17
 
18
  interface AgentMessage {
19
  role: "system" | "user" | "assistant" | "tool";
 
255
  let totalCompletionTokens = 0;
256
  let totalCost = 0;
257
  let iterations = 0;
258
+ // Original claw-code: max_iterations defaults to usize::MAX (conversation.rs line 141)
259
+ // This means the loop runs until the LLM stops calling tools — no artificial step limit.
260
+ const MAX_ITERATIONS = cfg.maxIterations || Number.MAX_SAFE_INTEGER;
261
  const assistantMessages: AgentMessage[] = [];
262
  const toolResultMessages: AgentMessage[] = [];
263
 
 
518
  toolResultMessages.push(toolResultMsg);
519
  }
520
 
521
+ // Compact is manual-only via /compact command (matches original claw-code conversation.rs)
522
 
523
  // Continue the loop — LLM will see tool results and decide next action
524
  sendSSE(res, "status", {
 
536
  }
537
 
538
  if (iterations >= MAX_ITERATIONS) {
539
+ sendSSE(res, "error", { message: `Maximum iterations (${MAX_ITERATIONS}) reached. Use /compact to reduce context and continue.` });
540
  }
541
 
542
  // Calculate cost using UsageTracker (matches original)