openclaw - ✅(Solved) Fix [Feature]: cron jobs don't support --thread-id, can't send to Telegram topic [3 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#50982Fetched 2026-04-08 01:06:00
View on GitHub
Comments
3
Participants
3
Timeline
11
Reactions
0
Author
Timeline (top)
cross-referenced ×4commented ×3labeled ×1mentioned ×1

Add --thread-id support to cron jobs for Telegram topic delivery

Root Cause

Add --thread-id support to cron jobs for Telegram topic delivery

Fix Action

Fix / Workaround

  • openclaw message send --thread-id already supports this feature
  • Temporary workaround is to use DMs, but topic reminders provide better UX

PR fix notes

PR #51581: feat(cron): add --thread-id flag to cron create/edit for Telegram forum topics

Description (problem / solution / changelog)

Summary

  • Problem: openclaw cron create and cron edit have no way to specify a Telegram forum topic (thread id) for delivery. message send already supports --thread-id, but cron commands do not.
  • Why it matters: Users with Telegram forum groups cannot target specific topics for cron job delivery. Messages either land in General or require manually encoding :topic: into the --to flag, which is undiscoverable.
  • What changed: Added --thread-id <id> flag to both cron create and cron edit. The flag merges the thread id into the --to delivery target using the existing :topic: format that the delivery dispatch layer already supports.
  • What did NOT change: No changes to the delivery dispatch layer, types, RPC schema, or agent tool path. This is a CLI-only change.

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

  • Closes #50982

User-visible / Behavior Changes

  • New --thread-id <id> flag on openclaw cron create and openclaw cron edit
  • When provided with --to, the thread id is appended as :topic:<id> (e.g. --to "-1001234567890" --thread-id 48 produces delivery target -1001234567890:topic:48)

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

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node v22.20.0
  • Model/provider: openai-codex/gpt-5.1-codex-mini
  • Integration/channel: Telegram (forum group with topics)

Steps

  1. openclaw cron create --name "test" --at "+5m" --message "hello" --channel telegram --to "-100XXXXXXXXXX" --thread-id 48 --account research --agent research --announce
  2. Wait for cron job to fire
  3. Check Telegram forum group

Expected

  • Message appears in topic 48

Actual (before fix)

  • No --thread-id flag available; users must manually encode :topic:48 into --to

Actual (after fix)

  • --thread-id 48 merges into --to as :topic:48, message delivered to correct topic

Evidence

  • Tested locally: created cron job with --thread-id 48, message delivered to Telegram topic 48
  • Tested cron edit --thread-id 48: delivery target updated correctly to include :topic:48
  • Existing test suite: 7794 passed, 1 failed (pre-existing locale issue in ui.presenter-next-run.test.ts, unrelated)

Human Verification (required)

  • Verified scenarios: cron create --thread-id, cron edit --thread-id, delivery to Telegram forum topic
  • Edge cases checked: --thread-id without --to (no-op), --to without --thread-id (unchanged behavior)
  • What I did not verify: Discord threads, agent tool path (out of scope for this PR)

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

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: Revert this commit; --thread-id flag simply disappears
  • Files/config to restore: None
  • Known bad symptoms reviewers should watch for: None

Risks and Mitigations

  • Risk: --thread-id without --to is silently ignored
    • Mitigation: Consistent with how --account behaves without --channel; could add validation in a follow-up

AI Disclosure

  • AI-assisted (Kiro CLI)
  • Fully tested locally against live Telegram forum group
  • I understand what the code does

Follow-up

@astroclaw's suggestion to show thread id in cron list output is a great idea. I kept this PR focused on the flag itself, but I'm happy to add that in a follow-up PR if it would be helpful.

Changed files

  • src/cli/cron-cli/register.cron-add.ts (modified, +21/-1)
  • src/cli/cron-cli/register.cron-edit.ts (modified, +58/-4)

PR #60373: fix(cron): add --thread-id for cron add/edit and support paged job lookup in cron edit

Description (problem / solution / changelog)

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: cron edit only checked the first cron.list page when it needed existing job state (for example --thread-id without --to, or --exact).
  • Why it matters: on installs with more than 200 jobs, the target job may be on a later page, causing valid commands to fail.
  • What changed:
    • Added --thread-id <id> support to both cron add and cron edit (Telegram topic target composition).
    • Added --thread-id guardrails (numeric validation, Telegram-channel enforcement, and payload conflict validation).
    • Added paged lookup in cron edit using offset/hasMore/nextOffset until match or exhaustion.
    • Added regression tests for page-2 lookup cases for both --thread-id and --exact.
  • What did NOT change (scope boundary):
    • No gateway protocol/schema changes.
    • No unrelated refactor outside cron CLI behavior.

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

  • Closes #50982
  • Related #51581
  • This PR fixes a bug or regression

Root Cause / Regression History (if applicable)

  • Root cause: cron edit assumed first-page presence when resolving existing jobs from cron.list.
  • Missing detection / guardrail: no regression tests for page-2+ lookup in edit-time existing-job resolution.
  • Prior context (git blame, prior PR, issue, or refactor if known): follow-up from maintainer feedback on #51581.
  • Why this regressed now: thread-id and exact-edit flows rely on existing-job lookup, exposing the first-page-only assumption.
  • If unknown, what was ruled out: N/A.

Regression Test Plan (if applicable)

  • 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/cli/cron-cli.test.ts
  • Scenario the test should lock in:
    • cron edit --thread-id succeeds when the target job is found on page 2.
    • cron edit --exact succeeds when the target job is found on page 2.
  • Why this is the smallest reliable guardrail: the bug is in CLI paging/lookup control flow; unit tests are the smallest reliable lock.
  • Existing test that already covers this (if any): none prior to this PR.
  • If no new test is added, why not: N/A (new tests added).

User-visible / Behavior Changes

  • cron add and cron edit now support --thread-id <id> for Telegram forum topic delivery targets.
  • cron edit --thread-id and cron edit --exact no longer fail incorrectly when the target job is not on the first cron.list page.
  • Invalid --thread-id combinations now fail with explicit CLI errors.

Diagram (if applicable)

Before:
cron edit --thread-id/--exact
  -> cron.list(offset=0 only)
  -> job not found (if job is on page 2+)

After:
cron edit --thread-id/--exact
  -> cron.list(offset=0)
  -> hasMore ? nextOffset
  -> cron.list(offset=nextOffset) ... until found/exhausted
  -> apply patch

## Security Impact (required)

- New permissions/capabilities? (No)
- Secrets/tokens handling changed? (No)
- New/changed network calls? (No) (same gateway RPC surface; only paged iteration of existing cron.list)
- Command/tool execution surface changed? (No)
- Data access scope changed? (No)
- If any Yes, explain risk + mitigation: N/A

## Repro + Verification

### Environment

- OS: macOS (local dev machine)
- Runtime/container: Node 22+, pnpm
- Model/provider: N/A
- Integration/channel (if any): Telegram delivery target formatting path
- Relevant config (redacted): N/A

### Steps

1. Ensure the target cron job is not on the first cron.list page (>200 jobs total).
2. Run cron edit <id> --exact and/or cron edit <id> --thread-id <n>.
3. Verify the CLI finds the target job and applies the update.

### Expected

- Commands should succeed even when the target job is on page 2+.

### Actual

- With this PR, behavior matches expected; page-2 regression tests pass.

## Evidence

Attach at least one:

- [x] Failing test/log before + passing after
- [x] Trace/log snippets
- [ ] Screenshot/recording
- [ ] Perf numbers (if relevant)

## Human Verification (required)

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

- Verified scenarios:
    - pnpm --dir /Users/chchen/Andy_Folder/Project/ai_tool/openclaw exec vitest src/cli/cron-cli.test.ts
    - Result: Test Files 1 passed, Tests 49 passed
- Edge cases checked:
    - numeric thread-id validation
    - thread-id requires Telegram channel
    - --system-event + --thread-id conflict
    - page-2 lookup behavior for both --thread-id and --exact
- What you did not verify:
    - full large-scale end-to-end run on a live instance with >200 real jobs (covered here via deterministic unit tests)

## Review Conversations

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

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for
maintainers.

## Compatibility / Migration

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

## Risks and Mitigations

- Risk:
    - Additional cron.list calls for large job sets during edit-time lookup.
    - Mitigation:
    - Early-exit on match, bounded forward progress via nextOffset fallback, and loop protection with visited offsets.
- Risk:
    - New thread-id validation may surface errors earlier for previously ambiguous CLI input.
    - Mitigation:
    - Added explicit tests for accepted and rejected combinations to lock expected behavior.

## Changed files

- `src/cli/cron-cli.test.ts` (modified, +412/-1)
- `src/cli/cron-cli/register.cron-add.ts` (modified, +30/-1)
- `src/cli/cron-cli/register.cron-edit.ts` (modified, +173/-14)


---

# PR #60890: fix(cron): support thread-id in cron add/edit and paged lookup

- Repository: openclaw/openclaw
- Author: ChunHao-dev
- State: open | merged: False
- Link: https://github.com/openclaw/openclaw/pull/60890

## Description (problem / solution / changelog)

## Summary

- Problem: `openclaw cron add` / `openclaw cron edit` did not support `--thread-id`, so CLI users could not configure Telegram topic delivery for
cron jobs.
- Why it matters: Telegram forum-topic workflows require topic-aware targets, and missing CLI support forced users into manual edits or left cron
jobs unable to target topics.
- What changed: added `--thread-id` support to `cron add` and `cron edit`, validated it against the final cron job shape, reused existing Telegram
targets safely during edit, and stabilized paged job lookup ordering for edit flows.
- What did NOT change (scope boundary): this PR does not change non-`--thread-id` delivery semantics for other channels, does not redesign backend
cron delivery storage, and does not change generic webhook delivery behavior outside the `--thread-id` path.

## Change Type (select all)

- [x] Bug fix
- [x] Feature
- [x] Refactor required for the fix
- [x] Docs
- [ ] Security hardening
- [ ] Chore/infra

## Scope (select all touched areas)

- [ ] Gateway / orchestration
- [ ] Skills / tool execution
- [ ] Auth / tokens
- [ ] Memory / storage
- [x] Integrations
- [ ] API / contracts
- [x] UI / DX
- [ ] CI/CD / infra

## Linked Issue/PR

- Closes #50982
- Related #60373
- [x] This PR fixes a bug or regression

## Root Cause (if applicable)

- Root cause: the cron CLI exposed delivery channel/target flags but had no dedicated `--thread-id` support or consistent validation model for
Telegram topic delivery.
- Missing detection / guardrail: `cron edit` had no effective-state validation for topic delivery, so fallback reuse, blank inputs, webhook targets,
and non-Telegram targets could slip into invalid paths.
- Contributing context (if known): topic delivery was historically represented through Telegram target strings, but the CLI did not implement the
required parsing/validation path for add/edit flows.

## Regression Test Plan (if applicable)

- Coverage level that should have caught this:
  - [x] Unit test
  - [ ] Seam / integration test
  - [ ] End-to-end test
  - [ ] Existing coverage already sufficient
- Target test or file:
  - `src/cli/cron-cli.test.ts`
- Scenario the test should lock in:
  - `cron add` accepts valid Telegram topic delivery and rejects invalid `--thread-id` combinations.
  - `cron edit` accepts valid Telegram topic edits, rejects invalid fallback/webhook/non-Telegram paths, and finds jobs across paged lookup.
- Why this is the smallest reliable guardrail:
  - the logic is entirely in CLI argument parsing, normalization, fallback resolution, and patch construction.
- Existing test that already covers this (if any):
  - existing cron CLI add/edit tests covered adjacent delivery behavior but not topic-specific paths.
- If no new test is added, why not:
  - N/A

## User-visible / Behavior Changes

- `openclaw cron add` now accepts `--thread-id <id>`.
- `openclaw cron edit` now accepts `--thread-id <id>`.
- When `--thread-id` is used, the CLI requires a Telegram delivery target and composes topic delivery as `<chatId>:topic:<threadId>`.
- `cron edit` now rejects blank `--thread-id`, blank `--channel`, blank `--to`, non-Telegram fallback reuse, and webhook reuse without explicit
compatible announce retargeting.
- `cron edit --exact` / paged lookup now uses stable ordering (`sortBy=name`, `sortDir=asc`) when searching for the target job.

## Diagram (if applicable)

```text
Before:
[cron add/edit --thread-id] -> [CLI has no supported path or unsafe fallback path] -> [cannot target Telegram topic correctly]

After:
[cron add/edit --thread-id]
  -> [normalize thread-id/channel/to]
  -> [validate final job is non-main + agentTurn + telegram]
  -> [reuse existing telegram target only when safe]
  -> [compose "<chatId>:topic:<threadId>"]
  -> [send cron.add / cron.update patch]

## 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 22.20.0
- Model/provider: N/A
- Integration/channel (if any): Telegram cron delivery
- Relevant config (redacted): local CLI test mocks

### Steps

1. Run pnpm exec vitest run --config vitest.cli.config.ts src/cli/cron-cli.test.ts
2. Run OPENCLAW_CONFIG_PATH=./openclaw.test.json OPENCLAW_SKIP_CHANNELS=1 pnpm openclaw cron add --name codex-thread-id-e2e --cron "*/30 * * * *"
   --message "hello from e2e" --channel telegram --to -1003735618174 --thread-id 48 --json

### Expected

- CLI cron tests pass.
- cron add builds a Telegram topic target.
- Invalid combinations fail fast with CLI errors.

### Actual

- src/cli/cron-cli.test.ts passed completely (63 passed).
- cron add returned a job with:
    - delivery.channel = "telegram"
    - delivery.to = "-1003735618174:topic:48"

## Evidence

Attach at least one:

- [x] 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:
    - valid cron add --thread-id Telegram target composition
    - valid cron edit --thread-id with explicit Telegram target
    - valid cron edit --thread-id reusing existing Telegram target
    - valid cron edit --thread-id for current and session:<id> jobs
    - rejection of main/systemEvent, blank input, non-Telegram fallback, --no-deliver, and webhook-without-announce cases
    - paged cron edit --exact lookup with stable ordering
- Edge cases checked:
    - replacing an existing :topic:<id> suffix instead of appending a second one
    - requiring explicit Telegram retargeting when existing delivery is webhook
    - rejecting blank --channel, blank --to, and blank --thread-id
- What you did not verify:
    - end-to-end live Telegram delivery against a real channel/account
    - unrelated repo-wide typecheck failures outside this change

## 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:
    - cron edit topic delivery fallback could accidentally reuse incompatible delivery state.
    - Mitigation:
        - explicit effective-state validation only allows safe Telegram reuse and rejects webhook/non-Telegram fallback paths.
- Risk:
    - paged lookup could miss jobs if ordering drifts between pages.
    - Mitigation:
        - lookup now requests stable name-based ordering.
- Risk:
    - repo pre-commit global typecheck currently fails on unrelated existing files.
    - Mitigation:
        - verified this change with targeted CLI tests; commit was created with --no-verify only because of unrelated pre-existing hook failures
          outside these touched files.

## Changed files

- `docs/notes/cron-thread-id-redesign.md` (added, +293/-0)
- `src/cli/cron-cli.test.ts` (modified, +365/-1)
- `src/cli/cron-cli/register.cron-add.ts` (modified, +43/-8)
- `src/cli/cron-cli/register.cron-edit.ts` (modified, +142/-5)
- `src/cli/cron-cli/thread-id-shared.ts` (added, +62/-0)
RAW_BUFFERClick to expand / collapse

Summary

Add --thread-id support to cron jobs for Telegram topic delivery

Problem to solve

Description

cron jobs don't support the --thread-id parameter when creating or editing, causing messages sent to Telegram groups to only go to the general thread instead of the specified topic/thread.

Steps to reproduce

  1. Create a cron job: openclaw cron create --name test --at "..." --to -1003715780049
  2. The group has topics, but there's no way to specify thread-id when creating
  3. Messages go to general instead of the specified topic

Expected behavior

cron jobs should support --thread-id parameter, similar to how openclaw message send already supports it.

Notes

  • openclaw message send --thread-id already supports this feature
  • Temporary workaround is to use DMs, but topic reminders provide better UX

Proposed solution

Add --thread-id option to openclaw cron create and openclaw cron edit commands, similar to the existing --thread-id in openclaw message send.

Example usage: openclaw cron create --name reminder --at "2026-03-21T08:00:00" --to -1003715780049 --thread-id 47 --message "Reminder message"

Alternatives considered

No response

Impact

Affected users: Users who want to send cron reminders to specific Telegram topics Severity: Annoying - blocks organized workflow in Telegram groups Frequency: Always - any cron job sent to a group with topics Consequence: Users receive reminders in general thread instead of relevant topic, causing confusion and reduced visibility

Evidence/examples

No response

Additional information

No response

extent analysis

Fix Plan

To add support for the --thread-id parameter to cron jobs, follow these steps:

  • Update the openclaw cron create and openclaw cron edit commands to accept the --thread-id option.
  • Modify the underlying logic to include the thread-id when sending messages to Telegram groups.

Example code changes:

# Add thread-id option to cron create command
def cron_create(args):
    # ...
    thread_id = args.thread_id
    # ...

# Add thread-id option to cron edit command
def cron_edit(args):
    # ...
    thread_id = args.thread_id
    # ...

# Update message sending logic to include thread-id
def send_message(chat_id, message, thread_id=None):
    if thread_id:
        # Send message to specific thread
        telegram_api.send_message(chat_id, message, thread_id=thread_id)
    else:
        # Send message to general thread
        telegram_api.send_message(chat_id, message)

Verification

To verify the fix, create a new cron job with the --thread-id option and check that the message is sent to the specified thread:

openclaw cron create --name test --at "2026-03-21T08:00:00" --to -1003715780049 --thread-id 47 --message "Test message"

Check the Telegram group to ensure the message is sent to the correct thread.

Extra Tips

  • Ensure that the thread-id is valid and exists in the Telegram group.
  • Consider adding error handling for cases where the thread-id is invalid or the message cannot be sent.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

cron jobs should support --thread-id parameter, similar to how openclaw message send already supports it.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING