Skip to content

fix(agents): disable default cron idle timeout for isolated runs - #60210

Closed
skainguyen1412 wants to merge 3 commits into
openclaw:mainfrom
skainguyen1412:fix/cron-idle-timeout-isolated
Closed

skainguyen1412 wants to merge 3 commits into
openclaw:mainfrom
skainguyen1412:fix/cron-idle-timeout-isolated

Conversation

@skainguyen1412

Copy link
Copy Markdown
Contributor

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: isolated cron runs inherited the embedded runner's generic 60-second LLM idle timeout even when the cron job's payload.timeoutSeconds was much higher.
  • Why it matters: scheduled background jobs can legitimately stay quiet for longer than 60 seconds, so they were aborting early and looked like cron was ignoring payload.timeoutSeconds.
  • What changed: cron-triggered embedded runs now disable the default idle watchdog unless agents.defaults.llm.idleTimeoutSeconds is explicitly configured; added regression coverage for the trigger-aware policy.
  • What did NOT change (scope boundary): cron's outer timeout logic did not change, manual/scheduled cron execution plumbing did not change, and explicit agents.defaults.llm.idleTimeoutSeconds still wins when set.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Root Cause / Regression History (if applicable)

  • Root cause: the embedded runner's default LLM idle timeout (60_000ms) was applied to all triggers, including cron, even though scheduled background runs can be intentionally quiet for longer than that.
  • Missing detection / guardrail: there was no test asserting that cron-triggered runs should not inherit the generic default idle timeout.
  • Prior context (git blame, prior PR, issue, or refactor if known): the idle-timeout behavior came from feat: add LLM idle timeout for streaming responses (84b72e66b91); cron already had separate outer timeout coverage and logic.
  • Why this regressed now: once the idle-timeout feature shipped in 2026.4.1, cron-triggered embedded runs started picking up the same default 60-second watchdog as interactive runs.
  • If unknown, what was ruled out: ruled out cron scheduler timeout ignoring payload.timeoutSeconds; the cron outer timeout path still honors job timeouts and already has regression coverage.

Regression Test Plan (if applicable)

For bug fixes or regressions, name the smallest reliable test coverage that should have caught this. Otherwise write N/A.

  • Coverage level that should have caught this:
  • Unit test
  • Seam / integration test
  • End-to-end test
  • Existing coverage already sufficient
  • Target test or file: src/agents/pi-embedded-runner/run/llm-idle-timeout.test.ts
  • Scenario the test should lock in: cron-triggered runs default to no LLM idle timeout unless agents.defaults.llm.idleTimeoutSeconds is explicitly configured; explicit config still applies to cron.
  • Why this is the smallest reliable guardrail: the regression lives in trigger-aware timeout resolution, so a focused unit test on that resolver catches the behavior without needing a live cron/provider setup.
  • Existing test that already covers this (if any): src/cron/service.issue-regressions.test.ts already covers cron honoring payload.timeoutSeconds on the outer timeout path.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

  • Isolated cron runs no longer abort at the default 60-second LLM idle timeout just because the model stays quiet for a while.
  • If users explicitly set agents.defaults.llm.idleTimeoutSeconds, cron runs still use that configured value.
  • No config migration is required.

Diagram (if applicable)

Before:
[cron isolated run] -> [default LLM idle watchdog = 60s] -> [abort around 60s]

After:
[cron isolated run] -> [default idle watchdog disabled for cron] -> [cron outer timeout / explicit llm idle timeout decides outcome]

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node v22.22.1
  • Model/provider: N/A for verification; targeted repo tests only
  • Integration/channel (if any): cron isolated runner
  • Relevant config (redacted): payload.timeoutSeconds > 60, agents.defaults.llm.idleTimeoutSeconds unset

Steps

  1. Create an isolated cron job with a long payload.timeoutSeconds.
  2. Let the embedded run stay quiet long enough to cross the generic LLM idle watchdog window.
  3. Observe the run abort around 60 seconds even though the cron job timeout is higher.

Expected

  • Cron-triggered isolated runs should not inherit the generic 60-second idle timeout by default.

Actual

  • They inherited the generic default idle timeout and could abort around 60 seconds.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios:
    • Ran ./node_modules/.bin/vitest run src/agents/pi-embedded-runner/run/llm-idle-timeout.test.ts
    • Ran ./node_modules/.bin/vitest run src/cron/service.issue-regressions.test.ts -t "applies timeoutSeconds to manual cron.run isolated executions"
    • Ran pnpm build
  • Edge cases checked:
    • explicit idleTimeoutSeconds: 0 still disables the watchdog
    • explicit cron idle timeout still applies when configured
    • non-cron default behavior remains unchanged
  • What you did not verify:
    • no live end-to-end scheduled cron run against a real provider/channel
    • no manual vs scheduled real-world repro on a running gateway instance

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: users who implicitly relied on the default 60-second idle watchdog for cron-triggered runs will now see those runs continue until the cron outer timeout or an explicit idle-timeout config applies.
  • Mitigation: explicit agents.defaults.llm.idleTimeoutSeconds is still honored, and the new regression test locks in the cron-only default behavior change.

@greptile-apps

greptile-apps Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug where cron-triggered isolated runs inadvertently inherited the embedded runner's default 60-second LLM idle watchdog, causing background scheduled jobs to abort early even when payload.timeoutSeconds was set much higher.

Key changes:

  • resolveLlmIdleTimeoutMs signature updated from a bare cfg argument to a params: { cfg?, trigger? } object, keeping the call-site change in attempt.ts minimal.
  • A new guard added as the last fallback: if trigger === \"cron\" and no explicit idleTimeoutSeconds is configured, the function returns 0 (disabled). Explicit user config still wins for every trigger, including cron.
  • Two new test cases added to llm-idle-timeout.test.ts locking in both the disabled-by-default cron path and the explicit-config-still-applies path.
  • No behavior change for any non-cron trigger; non-cron paths continue to fall back to DEFAULT_LLM_IDLE_TIMEOUT_MS.

The fix is narrow, correct, and well-tested. One minor coverage gap exists: the new cron test only exercises the cfg: undefined path; the case where cfg is present but idleTimeoutSeconds is absent (also routed by the trigger === \"cron\" guard) is not explicitly tested.

Confidence Score: 5/5

Safe to merge — the change is minimal, correctly scoped, and well-tested with no risk to non-cron trigger paths.

The function signature change is backwards-compatible (single call site updated), the cron guard is placed after all explicit-config checks so explicit user config always wins, existing non-cron behavior is unchanged, and the two new test cases directly lock in the regression scenario described in the bug report.

No files require special attention. The only minor gap is a missing companion test for the cfg-present-but-no-idleTimeoutSeconds + trigger: cron path in llm-idle-timeout.test.ts.

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: 24-26

Comment:
**Missing cron test with cfg present but unset idleTimeoutSeconds**

The new cron test only checks the `cfg: undefined` path. The case where `cfg` is provided (e.g. agents section exists) but `idleTimeoutSeconds` is not set is a distinct code path that is also exercised by the `trigger === "cron"` guard. It would strengthen the regression lock-in to add a companion case:

```suggestion
  it("disables the default idle timeout for cron triggers when not explicitly configured", () => {
    expect(resolveLlmIdleTimeoutMs({ cfg: undefined, trigger: "cron" })).toBe(0);
    const cfgNoTimeout = { agents: { defaults: { llm: {} } } } as OpenClawConfig;
    expect(resolveLlmIdleTimeoutMs({ cfg: cfgNoTimeout, trigger: "cron" })).toBe(0);
  });
```

This makes the guard resilient to future refactors that might split the `undefined`-cfg and present-but-empty-llm paths.

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

Reviews (1): Last reviewed commit: "agents: disable default cron idle timeou..." | Re-trigger Greptile

@martingarramon

Copy link
Copy Markdown
Contributor

Clean fix, tight scope. The trigger-aware default in resolveLlmIdleTimeoutMs is the right call — cron runs staying quiet for >60s is expected behavior, and the explicit config override still wins.

One thing I liked: checking raw === 0 before the trigger guard so that an explicit disable stays consistent across all paths.

Tests cover the two key scenarios (cron default disabled, explicit config still applies). LGTM.

@steipete steipete 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.

Root cause and fix direction both check out.

I verified the relevant call path locally: isolated cron runs invoke runEmbeddedPiAgent with trigger: "cron", and the current shared idle-timeout resolver still defaults to 60s whenever agents.defaults.llm.idleTimeoutSeconds is unset. Moving the cron-specific default policy into resolveLlmIdleTimeoutMs is the right layer, and the regression coverage added here matches that boundary.

This is the stronger fix for the ~60s cron idle-timeout cluster.

@skainguyen1412

Copy link
Copy Markdown
Contributor Author

Root cause and fix direction both check out.

I verified the relevant call path locally: isolated cron runs invoke runEmbeddedPiAgent with trigger: "cron", and the current shared idle-timeout resolver still defaults to 60s whenever agents.defaults.llm.idleTimeoutSeconds is unset. Moving the cron-specific default policy into resolveLlmIdleTimeoutMs is the right layer, and the regression coverage added here matches that boundary.

This is the stronger fix for the ~60s cron idle-timeout cluster.

Thanks for the review, Peter. Let me know if you’d like any changes.

@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: 293a4416c3

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@skainguyen1412

Copy link
Copy Markdown
Contributor Author

Hi @steipete, I think the PR is ready to merge. The CI/CD failures are not related to this PR.

@steipete

steipete commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Thanks @skainguyen1412. This was the right cron-specific behavior.

I landed the maintainer patch on main in d9dc75774b. It disables the unconfigured LLM idle watchdog for cron-triggered runs, while still honoring explicit agents.defaults.llm.idleTimeoutSeconds and inheriting agents.defaults.timeoutSeconds when configured.

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: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scheduled cron jobs ignore payload.timeoutSeconds — hard timeout at ~60s since 2026.4.1+

3 participants