Skip to content

fix(gateway): deliver targeted exec-event wakes when heartbeat.every is disabled#79869

Open
xinhuagu wants to merge 2 commits into
openclaw:mainfrom
xinhuagu:fix/62505-exec-event-zero-interval
Open

fix(gateway): deliver targeted exec-event wakes when heartbeat.every is disabled#79869
xinhuagu wants to merge 2 commits into
openclaw:mainfrom
xinhuagu:fix/62505-exec-event-zero-interval

Conversation

@xinhuagu

@xinhuagu xinhuagu commented May 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • allow targeted exec-event heartbeat wakes to run even when heartbeat.every resolves disabled (0m)
  • keep ordinary disabled heartbeats disabled by limiting the bypass to targeted exec-event wakes
  • add regression coverage for both scheduler dispatch and runHeartbeatOnce

Problem

Issue #62505 reports that coding-agent/background work can appear to never complete. One narrow cause is that background exec completion already enqueues an exec-event wake, but heartbeat dispatch drops it when heartbeat.every is disabled. That blocks the one-shot completion wake even though it is not a periodic heartbeat run.

Changes

  • in src/infra/heartbeat-runner.ts
    • allow runHeartbeatOnce(...) to proceed for exec-event wakes when the interval is otherwise disabled
    • allow targeted/session-scoped exec-event wakes through the runner even when no interval-backed agent state exists
  • add focused regression tests in:
    • src/infra/heartbeat-runner.scheduler.test.ts
    • src/infra/heartbeat-runner.returns-default-unset.test.ts

Testing

  • pnpm exec oxlint src/infra/heartbeat-runner.ts src/infra/heartbeat-runner.scheduler.test.ts src/infra/heartbeat-runner.returns-default-unset.test.ts
  • attempted focused Vitest, but the repo-local test harness is currently failing in this environment before these tests execute:
    • test/non-isolated-runner.ts throws Class extends value undefined is not a constructor or null

Closes #62505

@openclaw-barnacle openclaw-barnacle Bot added size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 9, 2026
@clawsweeper

clawsweeper Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open: current main still has the source-level disabled-heartbeat exec completion gap, but this PR is not merge-ready because it overrides an explicit delivery opt-out, can strand deferred zero-interval exec wakes, lacks real behavior proof, and is currently conflicting with main.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #62505
Summary: This PR is the open fix candidate for the canonical disabled-heartbeat background exec completion issue; related PRs address adjacent origin delivery or exec visibility but do not replace this exact wake dispatch problem.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

Do we have a high-confidence way to reproduce the issue?

Yes at source level: current main skips heartbeat execution when heartbeat.every resolves to 0m, while background exec completion still enqueues an exec-event wake. I did not run a live gateway scenario in this read-only review.

Is this the best way to solve the issue?

No. The runner boundary is plausible, but this implementation should preserve outbound delivery authorization separately from exec completion visibility and give fallback cooldown deferrals retry ownership.

Security review:

Security review needs attention: The diff can expose sensitive background command output by overriding an explicit heartbeat delivery opt-out.

  • [medium] Target none can be bypassed for command output — src/infra/heartbeat-runner.ts:1315
    The PR turns explicit heartbeat delivery suppression into target: "last" for origin-carrying zero-interval exec events, which can send background command output to a channel that current main suppresses.
    Confidence: 0.9

AGENTS.md: found and applied where relevant.

What I checked:

  • stale F-rated PR: PR was opened 2026-05-09T15:44:05Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is missing and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • steipete: Recent commits on heartbeat scheduler deferrals, heartbeat timeouts, exec runtime documentation, and adjacent heartbeat-runner behavior make this a strong routing candidate. (role: recent heartbeat scheduler contributor; confidence: high; commits: bbc4bee7a22b, 31169ff3b436, 045145c70082; files: src/infra/heartbeat-runner.ts, src/agents/bash-tools.exec-runtime.ts, docs/gateway/background-process.md)
  • anagnorisis2peripeteia: Merged origin-aware cron wake routing established the current origin delivery behavior while preserving explicit target: none as an opt-out. (role: adjacent origin-delivery contributor; confidence: medium; commits: f1f00cbf1d58; files: src/infra/outbound/targets.ts, src/cron/service/wake.ts, src/gateway/server-cron.ts)
  • zhangguiping-xydt: Recent heartbeat admission and busy-retry work is directly adjacent to the zero-interval fallback retry ownership question. (role: recent heartbeat admission/retry contributor; confidence: medium; commits: 2196ea29304a; files: src/infra/heartbeat-runner.ts)
  • agocs: Recent heartbeat delivery cleanup changed pending-final and send-success bookkeeping in the same runner path reviewed here. (role: recent heartbeat delivery-state contributor; confidence: medium; commits: 305fa9c4ddbe; files: src/infra/heartbeat-runner.ts)

Codex review notes: model internal, reasoning high; reviewed against 2c7e989686ba.

@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: 078830765f

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

Comment thread src/infra/heartbeat-runner.ts Outdated
Comment on lines +2203 to +2206
return await runOnce({
cfg: state.cfg,
agentId: targetAgentId,
heartbeat: resolveRequestedHeartbeat(resolveHeartbeatConfig(state.cfg, targetAgentId)),

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 Preserve exec-event cooldown when every is 0m

When a targeted exec-event wake arrives for an agent whose heartbeat.every is 0m, state.agents has no HeartbeatAgentState, so this new fallback calls runOnce directly and skips the evaluateWakeDeferral/recordRunBookkeeping path used by normal targeted exec wakes. That reopens the runaway case documented in heartbeat-cooldown.ts and the scheduler regression test: repeated background process exits for the same session can invoke a fresh heartbeat/model run every time instead of respecting the min-spacing/flood guard, specifically for users who disable interval heartbeats but still want exec-event delivery.

Useful? React with 👍 / 👎.

@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: e7576ebf33

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

Comment on lines +2243 to +2245
const deferral = evaluateWakeDeferral(fallbackAgent, now, reason, intent);
if (deferral.defer) {
return { status: "skipped", reason: deferral.reason };

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 Requeue deferred zero-interval exec events

When heartbeat.every is 0m, this new fallback state is not in state.agents, so a second targeted exec-event that arrives within the 30s cooldown returns skipped/not-due here but is never retried: heartbeat-wake.ts:229-240 only requeues retryable busy reasons, and scheduleNext() still returns early when state.agents.size === 0. In the common case of two background execs finishing close together, the later system event stays queued indefinitely unless some unrelated wake happens after the cooldown.

Useful? React with 👍 / 👎.

anagnorisis2peripeteia added a commit to anagnorisis2peripeteia/openclaw that referenced this pull request May 19, 2026
The cron `wake` MCP tool currently forwards only `{mode, text}` to the
gateway. Every wake then enqueues a system event with no sessionKey /
agentId, so the cron service falls back to the heartbeat / main
default. Wakes scheduled from a non-main session (Telegram thread,
Discord channel, multi-agent setup) silently route to the wrong
conversation lane — and on CLI runtimes the woken session burns
tokens generating output that no caller can route back.

Origin capture (closes the upstream half of openclaw#46886 and openclaw#64556):

  - `src/agents/tools/cron-tool.ts` — the `wake` case now resolves
    `opts.agentSessionKey` through `resolveInternalSessionKey` and
    `resolveSessionAgentId`, matching the existing `add` action at
    L569-583. Explicit `sessionKey` / `agentId` params on the tool
    call take precedence over the inferred values so cross-session
    wakes remain expressible.
  - `src/gateway/protocol/schema/agent.ts` — `WakeParamsSchema` now
    declares optional `sessionKey` and `agentId` (NonEmptyString)
    so the gateway-level validator types them explicitly. The
    schema's `additionalProperties: true` continues to accept
    forward-compat metadata unchanged.
  - `src/gateway/server-methods/cron.ts` — the wake handler reads
    both fields, trims them, and forwards to `context.cron.wake`.
  - `src/cron/service.ts` + `src/cron/service/ops.ts` +
    `src/cron/service/timer.ts` — `wake()` accepts optional
    `sessionKey`/`agentId` and threads them into
    `enqueueSystemEvent` and `requestHeartbeatNow`. Missing /
    whitespace-only fields fall through to the dep's default so
    pre-existing call sites with no origin keep behaving the same
    way (backwards compatible).

Tests:

  - `src/cron/service/wake-origin.test.ts` (new, 6 tests) —
    direct seams on `wake()`: origin forwarded on `mode: "now"`,
    queued on `mode: "next-heartbeat"`, default fallback when
    origin omitted, whitespace-only origin treated as omitted,
    empty text still rejected.
  - `src/gateway/protocol/index.test.ts` — extends
    `validateWakeParams` coverage with the new optional fields
    accepted + empty-string rejected.

Out of scope (deliberate split):

  - Channel/thread/topic capture on the job's `delivery` block —
    follow-up PR once this contract lands. The minimum-viable fix
    here is session routing, which unblocks the CLI runtime's
    `--resume <session>` path and the embedded session-resolution
    path without a schema rewrite of the delivery contract.
  - The 5 stalled wake-related PRs (openclaw#70268, openclaw#57199, openclaw#82767,
    openclaw#79869, openclaw#63096) each fix downstream specifics. This PR fixes
    the upstream origin-capture they all silently assume.
anagnorisis2peripeteia added a commit to anagnorisis2peripeteia/openclaw that referenced this pull request May 19, 2026
The cron `wake` MCP tool currently forwards only `{mode, text}` to the
gateway. Every wake then enqueues a system event with no sessionKey /
agentId, so the cron service falls back to the heartbeat / main
default. Wakes scheduled from a non-main session (Telegram thread,
Discord channel, multi-agent setup) silently route to the wrong
conversation lane — and on CLI runtimes the woken session burns
tokens generating output that no caller can route back.

Origin capture (closes the upstream half of openclaw#46886 and openclaw#64556):

  - `src/agents/tools/cron-tool.ts` — the `wake` case now resolves
    `opts.agentSessionKey` through `resolveInternalSessionKey` and
    `resolveSessionAgentId`, matching the existing `add` action at
    L569-583. Explicit `sessionKey` / `agentId` params on the tool
    call take precedence over the inferred values so cross-session
    wakes remain expressible.
  - `src/gateway/protocol/schema/agent.ts` — `WakeParamsSchema` now
    declares optional `sessionKey` and `agentId` (NonEmptyString)
    so the gateway-level validator types them explicitly. The
    schema's `additionalProperties: true` continues to accept
    forward-compat metadata unchanged.
  - `src/gateway/server-methods/cron.ts` — the wake handler reads
    both fields, trims them, and forwards to `context.cron.wake`.
  - `src/cron/service.ts` + `src/cron/service/ops.ts` +
    `src/cron/service/timer.ts` — `wake()` accepts optional
    `sessionKey`/`agentId` and threads them into
    `enqueueSystemEvent` and `requestHeartbeatNow`. Missing /
    whitespace-only fields fall through to the dep's default so
    pre-existing call sites with no origin keep behaving the same
    way (backwards compatible).

Tests:

  - `src/cron/service/wake-origin.test.ts` (new, 6 tests) —
    direct seams on `wake()`: origin forwarded on `mode: "now"`,
    queued on `mode: "next-heartbeat"`, default fallback when
    origin omitted, whitespace-only origin treated as omitted,
    empty text still rejected.
  - `src/gateway/protocol/index.test.ts` — extends
    `validateWakeParams` coverage with the new optional fields
    accepted + empty-string rejected.

Out of scope (deliberate split):

  - Channel/thread/topic capture on the job's `delivery` block —
    follow-up PR once this contract lands. The minimum-viable fix
    here is session routing, which unblocks the CLI runtime's
    `--resume <session>` path and the embedded session-resolution
    path without a schema rewrite of the delivery contract.
  - The 5 stalled wake-related PRs (openclaw#70268, openclaw#57199, openclaw#82767,
    openclaw#79869, openclaw#63096) each fix downstream specifics. This PR fixes
    the upstream origin-capture they all silently assume.
anagnorisis2peripeteia added a commit to anagnorisis2peripeteia/openclaw that referenced this pull request May 19, 2026
The cron `wake` MCP tool currently forwards only `{mode, text}` to the
gateway. Every wake then enqueues a system event with no sessionKey /
agentId, so the cron service falls back to the heartbeat / main
default. Wakes scheduled from a non-main session (Telegram thread,
Discord channel, multi-agent setup) silently route to the wrong
conversation lane — and on CLI runtimes the woken session burns
tokens generating output that no caller can route back.

Origin capture (closes the upstream half of openclaw#46886 and openclaw#64556):

  - `src/agents/tools/cron-tool.ts` — the `wake` case now resolves
    `opts.agentSessionKey` through `resolveInternalSessionKey` and
    `resolveSessionAgentId`, matching the existing `add` action at
    L569-583. Explicit `sessionKey` / `agentId` params on the tool
    call take precedence over the inferred values so cross-session
    wakes remain expressible.
  - `src/gateway/protocol/schema/agent.ts` — `WakeParamsSchema` now
    declares optional `sessionKey` and `agentId` (NonEmptyString)
    so the gateway-level validator types them explicitly. The
    schema's `additionalProperties: true` continues to accept
    forward-compat metadata unchanged.
  - `src/gateway/server-methods/cron.ts` — the wake handler reads
    both fields, trims them, and forwards to `context.cron.wake`.
  - `src/cron/service.ts` + `src/cron/service/ops.ts` +
    `src/cron/service/timer.ts` — `wake()` accepts optional
    `sessionKey`/`agentId` and threads them into
    `enqueueSystemEvent` and `requestHeartbeatNow`. Missing /
    whitespace-only fields fall through to the dep's default so
    pre-existing call sites with no origin keep behaving the same
    way (backwards compatible).

Tests:

  - `src/cron/service/wake-origin.test.ts` (new, 6 tests) —
    direct seams on `wake()`: origin forwarded on `mode: "now"`,
    queued on `mode: "next-heartbeat"`, default fallback when
    origin omitted, whitespace-only origin treated as omitted,
    empty text still rejected.
  - `src/gateway/protocol/index.test.ts` — extends
    `validateWakeParams` coverage with the new optional fields
    accepted + empty-string rejected.

Out of scope (deliberate split):

  - Channel/thread/topic capture on the job's `delivery` block —
    follow-up PR once this contract lands. The minimum-viable fix
    here is session routing, which unblocks the CLI runtime's
    `--resume <session>` path and the embedded session-resolution
    path without a schema rewrite of the delivery contract.
  - The 5 stalled wake-related PRs (openclaw#70268, openclaw#57199, openclaw#82767,
    openclaw#79869, openclaw#63096) each fix downstream specifics. This PR fixes
    the upstream origin-capture they all silently assume.
@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 May 29, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels May 29, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jun 1, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 1, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 14, 2026
@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 stale Marked as stale due to inactivity triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed stale Marked as stale due to inactivity labels Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Coding Agent never completes anything (worked in 2026.4.2 and earlier)

1 participant