Skip to content

fix(agents): proportional idle timeout for cron runs - #61239

Closed
Linux2010 wants to merge 1 commit into
openclaw:mainfrom
Linux2010:fix/61118-cron-idle-timeout-proportional
Closed

Linux2010 wants to merge 1 commit into
openclaw:mainfrom
Linux2010:fix/61118-cron-idle-timeout-proportional

Conversation

@Linux2010

Copy link
Copy Markdown
Contributor

Summary

Fixes #61118

Alternative to #60210 with a more flexible approach.

Problem

Isolated cron runs inherited the embedded runner's default 60s LLM idle timeout, causing jobs with timeoutSeconds > 60 to abort early when the model didn't produce tokens for >60s.

Solution

Instead of completely disabling idle timeout for cron (as #60210 does), this PR makes it proportional to the overall job timeout:

idle_timeout = min(overall_timeout * 0.5, 60s)

Examples

timeoutSeconds idle timeout
300s (5 min) 60s (capped)
120s (2 min) 60s (capped)
100s 50s
60s 30s
not set 0 (disabled)

Benefits over #60210

  1. Still detects stuck models - If a model is genuinely hung, we'll detect it within min(timeout/2, 60s)
  2. More flexible - Jobs with very short timeouts get shorter idle checks
  3. Configurable - Explicit idleTimeoutSeconds config still wins

Changes

  • llm-idle-timeout.ts: Add trigger and timeoutMs parameters to resolveLlmIdleTimeoutMs
  • attempt.ts: Pass trigger and timeoutMs to the function
  • llm-idle-timeout.test.ts: Add 12 new test cases for cron scenarios
  • CHANGELOG.md: Document the fix

Testing

All 20 tests pass:

✓ agents | src/agents/pi-embedded-runner/run/llm-idle-timeout.test.ts (20 tests) 156ms

Comparison with #60210

Aspect #60210 This PR
Cron idle timeout Always 0 (disabled) Proportional to timeoutSeconds
Detects stuck models No Yes (within timeout/2)
Config complexity Simpler Slightly more complex
Flexibility Low High

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Apr 5, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: edd9da46ea

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +43 to +44
if (params.trigger === "cron" && params.timeoutMs) {
return Math.min(Math.floor(params.timeoutMs * 0.5), DEFAULT_LLM_IDLE_TIMEOUT_MS);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Handle no-timeout cron jobs before proportional idle math

resolveLlmIdleTimeoutMs applies the proportional cron branch whenever timeoutMs is truthy, but isolated cron runs always pass a numeric timeout and resolveAgentTimeoutMs encodes timeoutSeconds: 0 (no overall timeout) as 2_147_000_000 (src/agents/timeout.ts). That means no-timeout cron jobs still get a 60s idle timeout and can abort early, while the fallback branch that returns 0 for cron is effectively unreachable in production (src/cron/isolated-agent/run.ts). Please gate the proportional branch on an actual bounded cron timeout (or plumb raw timeoutSeconds) so explicit no-timeout cron jobs do not inherit the idle timeout.

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes early-abort on cron runs whose timeoutSeconds exceeds the hard-coded 60 s LLM idle timeout. Instead of disabling idle checks entirely, it makes the idle timeout proportional to the configured job timeout — min(overall_timeout × 0.5, 60 s) — and disables idle checking when no overall timeout is set. The change is implemented by extending resolveLlmIdleTimeoutMs in llm-idle-timeout.ts to accept trigger and timeoutMs parameters, and threading those values through from the existing params object at the single call site in attempt.ts. Explicit idleTimeoutSeconds user config continues to take priority over both the proportional and the default paths.

  • The logic is correct: proportional capping, explicit-config-wins, and the disable-via-zero paths all behave as described and are verified by tests.
  • 20 tests cover the key scenarios well, including edge cases (negative values, Infinity, max safe timeout, explicit config override for cron, timeoutMs-is-ignored for non-cron triggers).
  • Minor: \"memory\" and \"overflow\" are valid EmbeddedRunTrigger values but are not exercised in the non-cron describe block; they share the same code branch, so this is a coverage gap, not a bug.
  • CHANGELOG entry is correctly appended at the end of the ### Fixes section in the active ## 2026.4.2 version block, consistent with repo guidelines.

Confidence Score: 5/5

Safe to merge — narrowly scoped change with correct logic and solid test coverage.

The change touches only llm-idle-timeout.ts and its single call site in attempt.ts. The proportional formula is correct, explicit user config always wins, and the 20-test suite validates all meaningful paths including edge cases. No boundary violations, no security concerns, no build surface impact.

No files require special attention; the minor test-coverage gap in llm-idle-timeout.test.ts (missing "memory" and "overflow" in the non-cron describe block) is a suggestion, not a blocker.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run/llm-idle-timeout.test.ts
Line: 96-106

Comment:
**Missing `"memory"` and `"overflow"` trigger coverage**

The non-cron triggers describe block tests `"user"`, `"heartbeat"`, and `"manual"` but omits `"memory"` and `"overflow"`, which are also valid `EmbeddedRunTrigger` values (see `params.ts:26`). Since the function falls through to `DEFAULT_LLM_IDLE_TIMEOUT_MS` for any non-`"cron"` trigger, this is a coverage gap rather than a bug — but adding them makes the suite exhaustive and guards against future divergence if the two omitted triggers ever need different handling.

```suggestion
    it("returns default for non-cron triggers", () => {
      expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "user" })).toBe(
        DEFAULT_LLM_IDLE_TIMEOUT_MS,
      );
      expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "heartbeat" })).toBe(
        DEFAULT_LLM_IDLE_TIMEOUT_MS,
      );
      expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "manual" })).toBe(
        DEFAULT_LLM_IDLE_TIMEOUT_MS,
      );
      expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "memory" })).toBe(
        DEFAULT_LLM_IDLE_TIMEOUT_MS,
      );
      expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "overflow" })).toBe(
        DEFAULT_LLM_IDLE_TIMEOUT_MS,
      );
    });
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(agents): proportional idle timeout f..." | Re-trigger Greptile

Comment on lines +96 to +106
it("returns default for non-cron triggers", () => {
expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "user" })).toBe(
DEFAULT_LLM_IDLE_TIMEOUT_MS,
);
expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "heartbeat" })).toBe(
DEFAULT_LLM_IDLE_TIMEOUT_MS,
);
expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "manual" })).toBe(
DEFAULT_LLM_IDLE_TIMEOUT_MS,
);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Missing "memory" and "overflow" trigger coverage

The non-cron triggers describe block tests "user", "heartbeat", and "manual" but omits "memory" and "overflow", which are also valid EmbeddedRunTrigger values (see params.ts:26). Since the function falls through to DEFAULT_LLM_IDLE_TIMEOUT_MS for any non-"cron" trigger, this is a coverage gap rather than a bug — but adding them makes the suite exhaustive and guards against future divergence if the two omitted triggers ever need different handling.

Suggested change
it("returns default for non-cron triggers", () => {
expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "user" })).toBe(
DEFAULT_LLM_IDLE_TIMEOUT_MS,
);
expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "heartbeat" })).toBe(
DEFAULT_LLM_IDLE_TIMEOUT_MS,
);
expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "manual" })).toBe(
DEFAULT_LLM_IDLE_TIMEOUT_MS,
);
});
it("returns default for non-cron triggers", () => {
expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "user" })).toBe(
DEFAULT_LLM_IDLE_TIMEOUT_MS,
);
expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "heartbeat" })).toBe(
DEFAULT_LLM_IDLE_TIMEOUT_MS,
);
expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "manual" })).toBe(
DEFAULT_LLM_IDLE_TIMEOUT_MS,
);
expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "memory" })).toBe(
DEFAULT_LLM_IDLE_TIMEOUT_MS,
);
expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "overflow" })).toBe(
DEFAULT_LLM_IDLE_TIMEOUT_MS,
);
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run/llm-idle-timeout.test.ts
Line: 96-106

Comment:
**Missing `"memory"` and `"overflow"` trigger coverage**

The non-cron triggers describe block tests `"user"`, `"heartbeat"`, and `"manual"` but omits `"memory"` and `"overflow"`, which are also valid `EmbeddedRunTrigger` values (see `params.ts:26`). Since the function falls through to `DEFAULT_LLM_IDLE_TIMEOUT_MS` for any non-`"cron"` trigger, this is a coverage gap rather than a bug — but adding them makes the suite exhaustive and guards against future divergence if the two omitted triggers ever need different handling.

```suggestion
    it("returns default for non-cron triggers", () => {
      expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "user" })).toBe(
        DEFAULT_LLM_IDLE_TIMEOUT_MS,
      );
      expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "heartbeat" })).toBe(
        DEFAULT_LLM_IDLE_TIMEOUT_MS,
      );
      expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "manual" })).toBe(
        DEFAULT_LLM_IDLE_TIMEOUT_MS,
      );
      expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "memory" })).toBe(
        DEFAULT_LLM_IDLE_TIMEOUT_MS,
      );
      expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "overflow" })).toBe(
        DEFAULT_LLM_IDLE_TIMEOUT_MS,
      );
    });
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

amittell pushed a commit to amittell/openclaw that referenced this pull request Apr 5, 2026
Cherry-pick of openclaw#61239 (Linux2010). Cron jobs with timeoutSeconds > 60s
no longer abort early at the default 60s LLM idle timeout.
idle_timeout = min(overall_timeout * 0.5, 60s).
CHANGELOG conflict resolved by keeping HEAD.
Cron-triggered runs now use proportional idle timeout (50% of overall
timeout, capped at 60s) instead of the hardcoded 60s default. This allows
long-running cron jobs with custom timeoutSeconds to run without early
abortion, while still detecting genuinely stuck models.

Changes:
- resolveLlmIdleTimeoutMs: add trigger and timeoutMs parameters
- Cron with timeoutMs: idle = min(timeoutMs * 0.5, 60s)
- Cron without timeoutMs: disable idle check (return 0)
- Non-cron triggers: unchanged behavior
- Add 12 new test cases covering cron scenarios

Fixes openclaw#61118
@Linux2010
Linux2010 force-pushed the fix/61118-cron-idle-timeout-proportional branch from edd9da4 to 9c3e3ee Compare April 6, 2026 08:45

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c3e3ee04f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +43 to +44
if (params.trigger === "cron" && params.timeoutMs) {
return Math.min(Math.floor(params.timeoutMs * 0.5), DEFAULT_LLM_IDLE_TIMEOUT_MS);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Distinguish unbounded cron runs before proportional idle math

In the isolated cron path, timeoutMs is always numeric (from prepareCronRunContext via resolveAgentTimeoutMs), and timeoutSeconds: 0 is represented as 2_147_000_000 for “no timeout.” With the current truthy check, those unbounded cron runs still take the proportional branch and resolve to a 60s idle timeout, so they can still abort early on long silent model phases. That also makes the later cron fallback branch returning 0 effectively unreachable in production.

Useful? React with 👍 / 👎.

@steipete

steipete commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Thanks @Linux2010. I landed the cron timeout fix on main in d9dc75774b.

I went with disabling the default idle watchdog for cron runs when no timeout is explicitly configured, and inheriting agents.defaults.timeoutSeconds when it is configured. That avoids the proportional cap still cutting off long quiet cron jobs around 60s.

Closing this PR as superseded by the landed commit.

@steipete steipete closed this Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isolated cron agentTurn jobs time out around 60-75s after upgrading to 2026.4.2

2 participants