Skip to content

fix(cron): force main-target system events onto main session#28898

Merged
Takhoffman merged 1 commit intoopenclaw:mainfrom
Sid-Qin:fix/28770-cron-main-systemevent-sessionkey-clean
Feb 28, 2026
Merged

fix(cron): force main-target system events onto main session#28898
Takhoffman merged 1 commit intoopenclaw:mainfrom
Sid-Qin:fix/28770-cron-main-systemevent-sessionkey-clean

Conversation

@Sid-Qin
Copy link
Contributor

@Sid-Qin Sid-Qin commented Feb 27, 2026

Summary

  • Problem: For cron jobs configured with sessionTarget: "main" + payload.kind: "systemEvent", persisted sessionKey could override main-session routing and create/send to unintended Telegram sessions after upgrades.
  • Why it matters: Users don't receive cron output in their expected main chat; events land in wrong session context.
  • What changed: Updated src/cron/service/timer.ts to ignore persisted job.sessionKey when sessionTarget is main, and always resolve through main-session path (sessionKey: undefined in enqueue/wake calls); updated regression expectations in src/cron/service.runs-one-shot-main-job-disables-it.test.ts.
  • What did NOT change: Isolated cron jobs and non-main targeting behavior are unchanged.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • 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

User-visible / Behavior Changes

  • Main-target cron system events now reliably route to agent main session.
  • Legacy/persisted session keys no longer divert main-target jobs into separate chat sessions.

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 26.3 (dev), reporter environment Ubuntu/WSL + Telegram
  • Runtime: Node.js + pnpm test runner
  • Integration/channel: Cron + main session routing

Steps

  1. Create a cron job with sessionTarget: "main", payload.kind: "systemEvent", and a persisted channel-like sessionKey.
  2. Trigger job run (wakeMode: now) and observe routing arguments.

Expected

  • Main-target job resolves to main session, not to persisted channel session key.

Actual

  • Before fix: persisted sessionKey could be forwarded and misroute events.
  • After fix: main-target path ignores persisted sessionKey and uses main-session resolution.

Evidence

  • Updated regression test:
    • src/cron/service.runs-one-shot-main-job-disables-it.test.ts
  • Test run (same patch before cherry-pick):
    • pnpm --dir /Users/sidqin/Desktop/openclaw-contrib exec vitest src/cron/service.runs-one-shot-main-job-disables-it.test.ts
    • Result: 1 file passed, 14 tests passed.

Human Verification (required)

  • Verified scenarios:
    • Main-target wakeMode-now job with explicit agentId uses main-session resolution path.
    • Busy-heartbeat fallback path also keeps main-session resolution behavior.
  • Edge cases checked:
    • Existing system-event execution flow remains intact for wake/run outcomes.
  • What I did not verify:
    • Live Telegram E2E delivery in a real upgraded production instance.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert: Revert this commit.
  • Files/config to restore: src/cron/service/timer.ts, test expectation file.
  • Known bad symptoms: Main-target cron jobs may again route into unintended sessions.

Risks and Mitigations

  • Risk: Deployments relying on non-main sessionKey overrides for main-target jobs may observe changed behavior.
  • Mitigation: sessionTarget: "main" semantics are now strictly enforced and covered by regression test expectations.

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 27, 2026

Greptile Summary

Forces main-target cron system events to always route through the main session by setting the session parameter to undefined during execution. This prevents persisted session identifiers from overriding main-session routing after upgrades. The fix is applied consistently across all main-target execution paths: enqueueSystemEvent, runHeartbeatOnce, and requestHeartbeatNow. Isolated cron jobs and non-main targeting behavior remain unchanged.

Confidence Score: 5/5

  • Safe to merge - targeted bug fix with clear scope and appropriate test coverage
  • Fix is straightforward: introduces constant set to undefined and applies it consistently across execution paths in the main-target block. Test expectations are updated to verify new behavior. Isolated jobs remain unaffected as designed. Change is backward compatible and solves a specific routing issue without adding complexity.
  • No files require special attention

Last reviewed commit: 2e07144

Copy link

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

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: 2e07144904

ℹ️ 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".

}
// main-target cron jobs should always resolve via the agent's main session.
// Avoid forwarding persisted channel session keys from legacy records.
const targetMainSessionKey = undefined;

Choose a reason for hiding this comment

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

P1 Badge Pass explicit main session key to heartbeat wake calls

Setting targetMainSessionKey to undefined does not actually force heartbeat execution onto the main session; it only removes the forced session override. In runHeartbeatOnce, forcedSessionKey is optional, and when absent the runner can pick heartbeat.session instead of main (src/infra/heartbeat-runner.ts:275-307), while the cron event was enqueued to main in the gateway path (src/gateway/server-cron.ts). For users with heartbeat.session configured to a non-main session, main-target cron events can be queued in main but the wake/run reads a different session, so the cron message is effectively missed.

Useful? React with 👍 / 👎.

@Takhoffman Takhoffman merged commit fe9a7c4 into openclaw:main Feb 28, 2026
27 of 29 checks passed
vincentkoc pushed a commit to Sid-Qin/openclaw that referenced this pull request Feb 28, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
vincentkoc pushed a commit to rylena/rylen-openclaw that referenced this pull request Feb 28, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
mrosmarin added a commit to mrosmarin/openclaw that referenced this pull request Feb 28, 2026
* main: (31 commits)
  fix(browser): resolve correct targetId in navigate response after renderer swap (openclaw#25326)
  fix: sed escaping and UID mismatch in Podman Quadlet setup (openclaw#26414)
  fix(cron): pass heartbeat target=last for main-session cron jobs (openclaw#28508) (openclaw#28583)
  fix(cron): disable messaging tool when delivery.mode is none (openclaw#21808) (openclaw#21896)
  fix: clear delivery routing state when creating isolated cron sessions (openclaw#27778)
  fix(cron): avoid marking queued announce paths as delivered (openclaw#29716)
  fix(cron): enable completion direct send for text-only announce delivery (openclaw#29151)
  fix(cron): force main-target system events onto main session (openclaw#28898)
  fix(cron): condition requireExplicitMessageTarget on resolved delivery (openclaw#28017)
  feat(cron): add --account flag for multi-account delivery routing (openclaw#26284)
  fix: schedule nextWakeAtMs for isolated sessionTarget cron jobs (openclaw#19541)
  fix: sandbox browser docker no-sandbox rollout (openclaw#29879) (thanks @Lukavyi)
  GitHub: add regression bug issue template and routing (openclaw#29864) thanks @Takhoffman
  feat(feishu): add chat info/member tool (openclaw#14674)
  feat(feishu): add markdown tables, positional insert, color_text, and table ops (openclaw#29411)
  feat(feishu): add parent/root inbound context for quote support (openclaw#18529)
  fix: land android onboarding and voice reliability updates (openclaw#29796)
  fix(android-voice): rotate playback token per assistant reply
  fix(android-voice): retry talk config after transient failures
  fix(android-voice): cancel in-flight speech when speaker muted
  ...
newtontech pushed a commit to newtontech/openclaw-fork that referenced this pull request Feb 28, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
nsd97 pushed a commit to nsd97/openclaw that referenced this pull request Feb 28, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Mar 1, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Mar 1, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
ansh pushed a commit to vibecode/openclaw that referenced this pull request Mar 2, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
safzanpirani pushed a commit to safzanpirani/clawdbot that referenced this pull request Mar 2, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
robertchang-ga pushed a commit to robertchang-ga/openclaw that referenced this pull request Mar 2, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
execute008 pushed a commit to execute008/openclaw that referenced this pull request Mar 2, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
dorgonman pushed a commit to kanohorizonia/openclaw that referenced this pull request Mar 3, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
sachinkundu pushed a commit to sachinkundu/openclaw that referenced this pull request Mar 6, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
Mateljan1 pushed a commit to Mateljan1/openclaw that referenced this pull request Mar 7, 2026
…w#28898)

Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades.

Closes openclaw#28770
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

2 participants