Skip to content

fix(cron): tolerate object-shaped delivery.channel - #46907

Closed
yfge wants to merge 5 commits into
openclaw:mainfrom
yfge:fix/issue-46899
Closed

yfge wants to merge 5 commits into
openclaw:mainfrom
yfge:fix/issue-46899

Conversation

@yfge

@yfge yfge commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

Background

Cron jobs are persisted as JSON and can be edited by multiple clients. In the wild we observed cron job delivery.channel being stored as an object (e.g. { id: "telegram" }) instead of a plain string, which causes resolveCronDeliveryPlan() to fall back to last and mis-route the delivery channel.

This manifested as jobs configured for Telegram attempting to deliver via another channel (e.g. Feishu) using a Telegram chat id as the target.

Fixes #46899.

Changes

  • Make resolveCronDeliveryPlan() tolerant of object-shaped delivery.channel values by accepting { id: string }.
  • Add a regression test covering the object-shaped delivery.channel case.

Verification

  • pnpm vitest src/cron/delivery.test.ts

Impact

  • More robust cron delivery routing when cron jobs are edited/imported by loosely-typed clients.
  • No behavioral change for correctly-typed string delivery.channel values.

yfge added 2 commits March 14, 2026 17:12
When the gateway probe connects but lacks operator.read, downstream RPC calls (eg config.get) fail and status/gateway probe UI renders the gateway as unreachable.

This change distinguishes connect vs RPC success:
- probeGateway now returns ok (connect), rpcOk and scopeLimited
- status/gateway-status surfaces 'reachable · scope-limited' instead of 'unreachable'
- gateway probe --json includes rpcOk + scopeLimited for better diagnostics

Tests: vitest src/commands/{status,gateway-status}*.test.ts
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime commands Command implementations size: M labels Mar 15, 2026
@greptile-apps

greptile-apps Bot commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR delivers a targeted fix for cron delivery mis-routing (delivery.channel stored as { id: "telegram" } instead of a plain string) and bundles a larger refactor of the gateway probe layer — introducing rpcOk/scopeLimited fields to GatewayProbeResult, switching RPC calls to Promise.allSettled, and surfacing auth-warning messages more consistently across the status command.

Key changes:

  • src/cron/delivery.ts: normalizeChannel() now tolerates object-shaped channel values ({ id: string }). Fix is correct and well-tested.
  • src/gateway/probe.ts: Promise.allSettled replaces Promise.all for RPC calls; new rpcOk and scopeLimited fields added. Logic is sound.
  • src/commands/gateway-status/helpers.ts: isScopeLimitedProbeFailure and renderProbeSummaryLine correctly use the new fields with a back-compat branch.
  • src/commands/status.command.ts — two issues found:
    1. The status display hardcodes the label scope-limited for any !rpcOk case, but a general RPC failure (rpcOk=false, scopeLimited=false) would be mislabelled. probe.scopeLimited should be checked for the label.
    2. The new IIFE that generates the auth-warning string checks the same conditions as gatewayProbeAuthWarning (already populated by status.scan.ts), so both values end up in the error join and produce a duplicated warning in the JSON output.

Confidence Score: 3/5

  • Safe to merge for the cron delivery fix; the gateway status display changes have two logic issues that produce mislabelled RPC failures and duplicate warning strings in JSON output.
  • The core cron fix (normalizeChannel) is correct and well-covered by the regression test. The gateway probe refactor is directionally sound but introduces two bugs in status.command.ts: (1) !rpcOk is used to unconditionally show "scope-limited" even for general RPC failures, and (2) the IIFE-generated auth warning duplicates gatewayProbeAuthWarning in the JSON error field. Neither is a data-loss or security issue, but they produce misleading status output.
  • src/commands/status.command.ts — both the display label for RPC failures (lines 292–296) and the auth-warning deduplication in the error array (lines 203–231) need attention.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/commands/status.command.ts
Line: 292-296

Comment:
**"scope-limited" label used for all RPC failures, not just scope-limited ones**

The label `scope-limited` is hardcoded for any case where `!gatewayProbe.rpcOk`, but `rpcOk === false` can also mean a general RPC error (e.g., a timeout or server-side failure), not necessarily a missing-scope error. The new `scopeLimited` field on `GatewayProbeResult` exists specifically to distinguish these two cases. Compare with `renderProbeSummaryLine` in `helpers.ts` which correctly uses `probe.scopeLimited` to pick between "RPC: limited" and "RPC: failed".

```suggestion
        ? (() => {
            const latency = formatDuration(gatewayProbe?.connectLatencyMs);
            if (gatewayProbe && !gatewayProbe.rpcOk) {
              const reason = gatewayProbe.error ? ` (${gatewayProbe.error})` : "";
              const label = gatewayProbe.scopeLimited ? "scope-limited" : "rpc-failed";
              return ok(`reachable ${latency}`) + muted(` · ${label}${reason}`);
            }
            return ok(`reachable ${latency}`);
          })()
```

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

---

This is a comment left during a code review.
Path: src/commands/status.command.ts
Line: 203-231

Comment:
**Duplicate auth warning in the `error` field**

The `error` array contains both `gatewayProbeAuthWarning` (element 2) and the IIFE result (element 3). Both check the same conditions (`mode === "token" && !gatewayProbeAuth?.token` or the password equivalent), which are the same conditions that `status.scan.ts` already uses to populate `gatewayProbeAuthWarning`.

When `gatewayProbe.ok === true` (gateway connected but auth unresolved), `status.scan.ts` does **not** merge `gatewayProbeAuthWarning` into `gatewayProbe.error` (the merge only happens on `ok === false`). This means `gatewayProbeAuthWarning` is non-null AND the IIFE fires with the same string, producing a duplicated value like:

```
"gateway.auth.token SecretRef is unresolved…; gateway.auth.token SecretRef is unresolved…"
```

The IIFE should guard against this by short-circuiting when `gatewayProbeAuthWarning` is already set:

```suggestion
            error:
              [
                gatewayProbe?.error,
                gatewayProbeAuthWarning,
                (() => {
                  if (gatewayProbeAuthWarning) {
                    return null;
                  }
                  const mode = cfg.gateway?.auth?.mode;
                  if (mode === "token" && !gatewayProbeAuth?.token) {
                    return "gateway.auth.token SecretRef is unresolved in this command path; probing without configured auth credentials.";
                  }
                  if (mode === "password" && !gatewayProbeAuth?.password) {
                    return "gateway.auth.password SecretRef is unresolved in this command path; probing without configured auth credentials.";
                  }
                  // Heuristic fallback for best-effort config loads where auth mode
                  // information may be missing from the resolved snapshot.
                  if (
                    !gatewayProbeAuth?.token &&
                    !gatewayProbeAuth?.password &&
                    gatewayProbe?.ok === false &&
                    typeof gatewayProbe?.error === "string" &&
                    /timeout|connect failed/i.test(gatewayProbe.error)
                  ) {
                    return "gateway.auth.token SecretRef is unresolved in this command path; probing without configured auth credentials.";
                  }
                  return null;
                })(),
              ]
                .filter((v) => typeof v === "string" && v.trim())
                .join("; ") || null,
```

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

Last reviewed commit: 8b7d304

Comment thread src/commands/status.command.ts Outdated
Comment on lines +292 to +296
? (() => {
const latency = formatDuration(gatewayProbe?.connectLatencyMs);
if (gatewayProbe && !gatewayProbe.rpcOk) {
const reason = gatewayProbe.error ? ` (${gatewayProbe.error})` : "";
return ok(`reachable ${latency}`) + muted(` · scope-limited${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.

"scope-limited" label used for all RPC failures, not just scope-limited ones

The label scope-limited is hardcoded for any case where !gatewayProbe.rpcOk, but rpcOk === false can also mean a general RPC error (e.g., a timeout or server-side failure), not necessarily a missing-scope error. The new scopeLimited field on GatewayProbeResult exists specifically to distinguish these two cases. Compare with renderProbeSummaryLine in helpers.ts which correctly uses probe.scopeLimited to pick between "RPC: limited" and "RPC: failed".

Suggested change
? (() => {
const latency = formatDuration(gatewayProbe?.connectLatencyMs);
if (gatewayProbe && !gatewayProbe.rpcOk) {
const reason = gatewayProbe.error ? ` (${gatewayProbe.error})` : "";
return ok(`reachable ${latency}`) + muted(` · scope-limited${reason}`);
? (() => {
const latency = formatDuration(gatewayProbe?.connectLatencyMs);
if (gatewayProbe && !gatewayProbe.rpcOk) {
const reason = gatewayProbe.error ? ` (${gatewayProbe.error})` : "";
const label = gatewayProbe.scopeLimited ? "scope-limited" : "rpc-failed";
return ok(`reachable ${latency}`) + muted(` · ${label}${reason}`);
}
return ok(`reachable ${latency}`);
})()
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/status.command.ts
Line: 292-296

Comment:
**"scope-limited" label used for all RPC failures, not just scope-limited ones**

The label `scope-limited` is hardcoded for any case where `!gatewayProbe.rpcOk`, but `rpcOk === false` can also mean a general RPC error (e.g., a timeout or server-side failure), not necessarily a missing-scope error. The new `scopeLimited` field on `GatewayProbeResult` exists specifically to distinguish these two cases. Compare with `renderProbeSummaryLine` in `helpers.ts` which correctly uses `probe.scopeLimited` to pick between "RPC: limited" and "RPC: failed".

```suggestion
        ? (() => {
            const latency = formatDuration(gatewayProbe?.connectLatencyMs);
            if (gatewayProbe && !gatewayProbe.rpcOk) {
              const reason = gatewayProbe.error ? ` (${gatewayProbe.error})` : "";
              const label = gatewayProbe.scopeLimited ? "scope-limited" : "rpc-failed";
              return ok(`reachable ${latency}`) + muted(` · ${label}${reason}`);
            }
            return ok(`reachable ${latency}`);
          })()
```

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

This comment was marked as spam.

Comment on lines +203 to 231
error:
[
gatewayProbe?.error,
gatewayProbeAuthWarning,
(() => {
const mode = cfg.gateway?.auth?.mode;
if (mode === "token" && !gatewayProbeAuth?.token) {
return "gateway.auth.token SecretRef is unresolved in this command path; probing without configured auth credentials.";
}
if (mode === "password" && !gatewayProbeAuth?.password) {
return "gateway.auth.password SecretRef is unresolved in this command path; probing without configured auth credentials.";
}
// Heuristic fallback for best-effort config loads where auth mode
// information may be missing from the resolved snapshot.
if (
!gatewayProbeAuth?.token &&
!gatewayProbeAuth?.password &&
gatewayProbe?.ok === false &&
typeof gatewayProbe?.error === "string" &&
/timeout|connect failed/i.test(gatewayProbe.error)
) {
return "gateway.auth.token SecretRef is unresolved in this command path; probing without configured auth credentials.";
}
return null;
})(),
]
.filter((v) => typeof v === "string" && v.trim())
.join("; ") || null,
authWarning: gatewayProbeAuthWarning ?? null,

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.

Duplicate auth warning in the error field

The error array contains both gatewayProbeAuthWarning (element 2) and the IIFE result (element 3). Both check the same conditions (mode === "token" && !gatewayProbeAuth?.token or the password equivalent), which are the same conditions that status.scan.ts already uses to populate gatewayProbeAuthWarning.

When gatewayProbe.ok === true (gateway connected but auth unresolved), status.scan.ts does not merge gatewayProbeAuthWarning into gatewayProbe.error (the merge only happens on ok === false). This means gatewayProbeAuthWarning is non-null AND the IIFE fires with the same string, producing a duplicated value like:

"gateway.auth.token SecretRef is unresolved…; gateway.auth.token SecretRef is unresolved…"

The IIFE should guard against this by short-circuiting when gatewayProbeAuthWarning is already set:

Suggested change
error:
[
gatewayProbe?.error,
gatewayProbeAuthWarning,
(() => {
const mode = cfg.gateway?.auth?.mode;
if (mode === "token" && !gatewayProbeAuth?.token) {
return "gateway.auth.token SecretRef is unresolved in this command path; probing without configured auth credentials.";
}
if (mode === "password" && !gatewayProbeAuth?.password) {
return "gateway.auth.password SecretRef is unresolved in this command path; probing without configured auth credentials.";
}
// Heuristic fallback for best-effort config loads where auth mode
// information may be missing from the resolved snapshot.
if (
!gatewayProbeAuth?.token &&
!gatewayProbeAuth?.password &&
gatewayProbe?.ok === false &&
typeof gatewayProbe?.error === "string" &&
/timeout|connect failed/i.test(gatewayProbe.error)
) {
return "gateway.auth.token SecretRef is unresolved in this command path; probing without configured auth credentials.";
}
return null;
})(),
]
.filter((v) => typeof v === "string" && v.trim())
.join("; ") || null,
authWarning: gatewayProbeAuthWarning ?? null,
error:
[
gatewayProbe?.error,
gatewayProbeAuthWarning,
(() => {
if (gatewayProbeAuthWarning) {
return null;
}
const mode = cfg.gateway?.auth?.mode;
if (mode === "token" && !gatewayProbeAuth?.token) {
return "gateway.auth.token SecretRef is unresolved in this command path; probing without configured auth credentials.";
}
if (mode === "password" && !gatewayProbeAuth?.password) {
return "gateway.auth.password SecretRef is unresolved in this command path; probing without configured auth credentials.";
}
// Heuristic fallback for best-effort config loads where auth mode
// information may be missing from the resolved snapshot.
if (
!gatewayProbeAuth?.token &&
!gatewayProbeAuth?.password &&
gatewayProbe?.ok === false &&
typeof gatewayProbe?.error === "string" &&
/timeout|connect failed/i.test(gatewayProbe.error)
) {
return "gateway.auth.token SecretRef is unresolved in this command path; probing without configured auth credentials.";
}
return null;
})(),
]
.filter((v) => typeof v === "string" && v.trim())
.join("; ") || null,
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/status.command.ts
Line: 203-231

Comment:
**Duplicate auth warning in the `error` field**

The `error` array contains both `gatewayProbeAuthWarning` (element 2) and the IIFE result (element 3). Both check the same conditions (`mode === "token" && !gatewayProbeAuth?.token` or the password equivalent), which are the same conditions that `status.scan.ts` already uses to populate `gatewayProbeAuthWarning`.

When `gatewayProbe.ok === true` (gateway connected but auth unresolved), `status.scan.ts` does **not** merge `gatewayProbeAuthWarning` into `gatewayProbe.error` (the merge only happens on `ok === false`). This means `gatewayProbeAuthWarning` is non-null AND the IIFE fires with the same string, producing a duplicated value like:

```
"gateway.auth.token SecretRef is unresolved…; gateway.auth.token SecretRef is unresolved…"
```

The IIFE should guard against this by short-circuiting when `gatewayProbeAuthWarning` is already set:

```suggestion
            error:
              [
                gatewayProbe?.error,
                gatewayProbeAuthWarning,
                (() => {
                  if (gatewayProbeAuthWarning) {
                    return null;
                  }
                  const mode = cfg.gateway?.auth?.mode;
                  if (mode === "token" && !gatewayProbeAuth?.token) {
                    return "gateway.auth.token SecretRef is unresolved in this command path; probing without configured auth credentials.";
                  }
                  if (mode === "password" && !gatewayProbeAuth?.password) {
                    return "gateway.auth.password SecretRef is unresolved in this command path; probing without configured auth credentials.";
                  }
                  // Heuristic fallback for best-effort config loads where auth mode
                  // information may be missing from the resolved snapshot.
                  if (
                    !gatewayProbeAuth?.token &&
                    !gatewayProbeAuth?.password &&
                    gatewayProbe?.ok === false &&
                    typeof gatewayProbe?.error === "string" &&
                    /timeout|connect failed/i.test(gatewayProbe.error)
                  ) {
                    return "gateway.auth.token SecretRef is unresolved in this command path; probing without configured auth credentials.";
                  }
                  return null;
                })(),
              ]
                .filter((v) => typeof v === "string" && v.trim())
                .join("; ") || null,
```

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

This comment was marked as spam.

@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: 8b7d3049e3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/commands/status.command.ts Outdated
Comment on lines +294 to +296
if (gatewayProbe && !gatewayProbe.rpcOk) {
const reason = gatewayProbe.error ? ` (${gatewayProbe.error})` : "";
return ok(`reachable ${latency}`) + muted(` · scope-limited${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 Report non-scope RPC failures as failed, not scope-limited

This branch labels every !rpcOk probe as scope-limited, but rpcOk also becomes false for non-scope failures (for example, RPC incompatibility or generic gateway errors). In those scenarios scopeLimited is false, yet the status line still claims a scope limitation, which misdirects debugging and hides real RPC failures. Use scopeLimited to decide the label and keep a distinct RPC failed path for other errors.

Useful? React with 👍 / 👎.

This comment was marked as spam.

Comment on lines +218 to +222
!gatewayProbeAuth?.token &&
!gatewayProbeAuth?.password &&
gatewayProbe?.ok === false &&
typeof gatewayProbe?.error === "string" &&
/timeout|connect failed/i.test(gatewayProbe.error)

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 Avoid unconditional SecretRef warning fallback on timeouts

The fallback emits a SecretRef-unresolved warning whenever auth fields are empty and the probe error matches timeout/connect-failed, even if no token/password auth mode (or SecretRef config) is set. That means a normal unreachable gateway with auth disabled can be reported as a SecretRef problem in JSON gateway.error, which is a misleading regression in diagnostics. Gate this fallback on explicit token/password SecretRef configuration.

Useful? React with 👍 / 👎.

This comment was marked as spam.

Comment thread src/gateway/probe.ts
Comment on lines +105 to +109
const results = await Promise.allSettled([
client.request("health"),
client.request("status"),
client.request("system-presence"),
client.request("config.get", {}),

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 Wrap probe detail RPC setup in try/catch

Replacing Promise.all(...) inside try/catch with bare Promise.allSettled(...) removed handling for synchronous throws while creating the request promises. GatewayClient.request can throw immediately when the socket is no longer open, so a post-handshake close can now cause onHelloOk to reject and the probe to wait until timeout, returning a generic timeout instead of the actual failure cause. Catch around request setup/await and settle the probe immediately on that path.

Useful? React with 👍 / 👎.

This comment was marked as spam.

@yfge

This comment was marked as spam.

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

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/gateway/probe-auth.ts
Comment on lines +67 to +70
const mode = params.cfg.gateway?.auth?.mode;
if (mode === "token") {
const tokenCfg = (params.cfg.gateway?.auth as { token?: unknown } | undefined)?.token;
if (!auth.token && tokenCfg && typeof tokenCfg === "object") {

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 Scope unresolved-auth warnings to the selected probe mode

resolveGatewayProbeAuthSafe now derives warning state from cfg.gateway.auth.mode and cfg.gateway.auth.token even when params.mode is "remote". In remote probes that intentionally authenticate with gateway.remote.password (or other non-token paths), auth.token is expected to be empty, but this branch still emits a gateway.auth.token SecretRef is unresolved warning from local-mode config, producing false diagnostics in status surfaces and obscuring the real connection state.

Useful? React with 👍 / 👎.

This comment was marked as spam.

Comment on lines +90 to +93
if (mode === "token" && !auth.token) {
gatewayProbeAuthWarning =
"gateway.auth.token SecretRef is unresolved in this command path; probing without configured auth credentials.";
} else if (mode === "password" && !auth.password) {

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 Remove local auth-mode fallback from probe warning synthesis

This fallback infers SecretRef unresolved solely from gateway.auth.mode plus missing resolved token/password, which is not tied to the credential source actually used for probing. In remote mode, a valid password-auth probe can therefore be reported as an unresolved local token SecretRef in status --json (gateway.authWarning/gateway.error), creating misleading output for healthy remote configurations.

Useful? React with 👍 / 👎.

This comment was marked as spam.

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

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/gateway/probe.ts
Comment on lines +105 to +109
const results = await Promise.allSettled([
client.request("health"),
client.request("status"),
client.request("system-presence"),
client.request("config.get", {}),

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 Short-circuit detail probe on first RPC rejection

Using Promise.allSettled here means the probe waits for every RPC to settle before reporting failure, so a single stalled request can hide an immediate rejection from another request until the outer probe timer fires. In practice the probe timeout is often 2.5–5s while GatewayClient.request can wait much longer, so a reachable gateway that already returned a concrete RPC error can be misreported as a generic timeout/unreachable result instead of surfacing the real failure cause.

Useful? React with 👍 / 👎.

This comment was marked as spam.

@yfge

This comment was marked as spam.

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

Labels

commands Command implementations gateway Gateway runtime size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cron Job Delivery Channel Mismatch - Telegram Configured but Feishu Used

1 participant