Skip to content

fix(cron): auto-fill agentId from session when not explicitly provided - #40571

Closed
ChanningYul wants to merge 1 commit into
openclaw:mainfrom
ChanningYul:fix/cron-auto-fill-agentid
Closed

ChanningYul wants to merge 1 commit into
openclaw:mainfrom
ChanningYul:fix/cron-auto-fill-agentid

Conversation

@ChanningYul

Copy link
Copy Markdown

Summary

  • Fix: When a sub-agent creates a cron job without specifying --agent, the system now correctly auto-fills the agentId from the current session.
  • Previously, the condition !("agentId" in job) would fail when agentId: undefined was passed (e.g., from CLI), because the key existed but the value was undefined.
  • The fix changes the condition to check for a valid string value, while preserving the special case of agentId: null (user explicitly wants no agent).

Background

This fix addresses a design issue reported by the community:

Sub-agents should have their agentId automatically set when creating scheduled tasks (cron jobs), rather than leaving it empty or requiring explicit specification.

Test plan

  • Added 2 new test cases for auto-fill scenarios
  • All 35 tests pass
  • Existing tests for agentId: null preservation still pass

🤖 Generated with Claude Code

When a sub-agent creates a cron job without specifying an agentId,
the system now correctly auto-fills the agentId from the current session.

Previously, the condition `!("agentId" in job)` would fail when
`agentId: undefined` was passed (e.g., from CLI), because the key
existed but the value was undefined.

The fix changes the condition to check for a valid string value,
while preserving the special case of `agentId: null` (user explicitly
wants no agent).

Fixes: Sub-agents creating cron jobs would have empty agentId fields
instead of their own agent ID.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Mar 9, 2026
@greptile-apps

greptile-apps Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR correctly fixes a subtle auto-fill bug in the cron tool's agentId logic. When the CLI passes agentId: undefined explicitly, the old guard (!("agentId" in job)) would fail because the key exists in the object even though the value is meaningless. The fix changes the condition to check the actual value, correctly distinguishing between three cases:

  • agentId: null → user explicitly opts out (preserved)
  • agentId: "non-empty-string" → user specifies an agent (preserved)
  • agentId: undefined, "", or absent → auto-fill from the current session

Key changes:

  • cron-tool.ts (lines 356-372): Replaces the key-existence check with a three-way value check using .trim() for whitespace handling
  • cron-tool.test.ts: Adds two new test cases covering the missing-key and agentId: undefined paths, with proper mock setup for test isolation

The logic is sound, backward-compatible, and all 35 tests pass.

Confidence Score: 5/5

  • This is a safe, targeted fix that correctly handles the documented auto-fill behavior with no regressions or breaking changes.
  • The implementation is minimal and correct. The fix directly addresses the root cause (checking actual value instead of key existence) and maintains backward compatibility for all three cases. All existing tests pass, and new tests validate the main scenarios. The code is production-ready.
  • No files require special attention

Last reviewed commit: 7a61030

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Apr 25, 2026
@vincentkoc

Copy link
Copy Markdown
Member

ProjectClownfish could not safely update this branch, so it opened a narrow replacement PR instead.

Replacement PR: #72326
Source PR: #40571
Contributor credit is preserved in the replacement PR body and changelog plan.

@vincentkoc

Copy link
Copy Markdown
Member

ProjectClownfish could not safely update this branch, so it opened a narrow replacement PR instead.

Replacement PR: #72326
Source PR: #40571
Contributor credit is preserved in the replacement PR body and changelog plan.

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 stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants