Skip to content

fix(cron): keep the resolved topic route on CLI-backed cron runs - #138406

Open
ylcn91 wants to merge 3 commits into
openclaw:mainfrom
ylcn91:fix/cron-cli-delivery-context
Open

ylcn91 wants to merge 3 commits into
openclaw:mainfrom
ylcn91:fix/cron-cli-delivery-context

Conversation

@ylcn91

@ylcn91 ylcn91 commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A Telegram forum-topic cron whose run selects a CLI runtime (Codex app-server,
openai/gpt-5.6-sol) loses its topic route. Background exec completions from
that run are relayed later by the heartbeat turn into the owner's DM instead of
the originating topic, leaking topic-local operational output into an unrelated
conversation and contaminating agent:main:main.

src/cron/isolated-agent/run-executor.ts resolved the channel-native
current-channel id only inside its embedded branch. The CLI branch called
runCliAgent with messageChannel and agentAccountId but no
recipient/thread, so src/agents/cli-runner/mcp-grant-context.ts:140,181
minted a loopback grant with no currentChannelId/currentThreadTs,
src/gateway/tool-resolution.ts:500-501 forwarded the gap into the exec
defaults, and src/agents/bash-tools.exec-run.ts:161-166 built
notifyDeliveryContext with an empty target. The downstream heartbeat can only
prefer a route the queued event already carries; it cannot restore fields that
were absent before the completion was queued.

Fixes #138316. Follow-up to #138269, which was closed after reviewing the
embedded path only.

Why This Change Was Made

The violated invariant is that both runtime branches of the cron executor hand
the runner the same resolved delivery route. Rather than duplicating the
resolution, resolveCurrentChannelTarget now runs once above the
if (cliExecution) branch and both runners consume it. The CLI runner takes it
as currentChannelId plus currentThreadTs; RunCliAgentParams
(src/agents/cli-runner/types.ts:237,240) has no messageTo/messageThreadId,
so those are its vocabulary for the same fact. This matches the sibling CLI
caller src/auto-reply/reply/agent-runner-cli-candidate.ts:404,416, which
already passes both.

All six runCliAgent call sites were checked.
src/agents/embedded-agent-runner/cli-backend-dispatch.ts deliberately drops
delivery context for its one-shot bridge (documented in place) and is
unreachable from cron, which never sets cliBackendDispatch.

Codex gate: this change is OpenClaw-side plumbing only. Nothing under
extensions/codex/ or the Codex harness contract is touched; the Codex
app-server is one of the CLI providers routed through isCliProvider, and the
repair is provider-generic.

Production delta +16/-6, of which 6 lines are comments: net +4 code lines. No
new config, no schema change, no fallback path.

User Impact

Telegram forum-topic, and any threaded-channel, automations running on a CLI
runtime keep their background exec completions and message-tool sends in the
originating topic. Embedded-runtime behavior is unchanged; the resolution simply
moved above the branch.

Evidence

  • Regression test src/cron/isolated-agent/run.message-tool-policy.test.ts
    ("forwards the resolved topic route into the CLI run") is the CLI twin of the
    existing embedded cases. Pre-fix, with production reverted:
    CLI run params.currentChannelId: expected undefined to deeply equal 'room#42'
    (1 failed | 59 skipped). Post-fix: 60/60 pass.
  • node scripts/run-vitest.mjs src/cron/isolated-agent: 55 files, 849/849 pass.
  • node scripts/run-vitest.mjs src/agents/cli-runner/mcp-grant-context.test.ts src/agents/cli-runner/prepare.test.ts: 153/153 pass.
  • node scripts/check-changed.mjs -- src/cron/isolated-agent/run-executor.ts src/cron/isolated-agent/run.message-tool-policy.test.ts: exit 0 (format, core + core-test typecheck, lint, dead-export scan, import cycles, plugin boundaries, all guards).
  • Autoreview (Claude engine, P1 threshold, branch against origin/main): patch is correct, no findings.
  • Live Telegram forum-topic proof was not run yet: the Test Server harness leases credentials through the OpenClaw Convex QA broker (qa/convex-credential-broker), and this checkout's authenticated Convex account is not a member of that project (convex env ... get answers You don't have access to the selected project); no OPENCLAW_QA_CONVEX_SITE_URL / OPENCLAW_QA_CONVEX_SECRET_CI pair is available either, so telegram-test-doctor.mjs cannot lease. Everything else is ready at ffc2ed1 (pnpm build exit 0, dist/entry.js, harness prerequisites) and the scenario needs no harness edits: --backend claude-cli selects the CLI runtime this PR changes (resolveCliRuntimeExecutionProvider, extensions/anthropic/openclaw.plugin.json cliBackend), a command action creates a forum topic and an isolated announce cron with openclaw cron add --thread-id <topic>, runs it with --wait, and a 120 s tail with tools.exec.notifyOnExit: true plus a 1-minute heartbeat catches the delayed exec completion; the recorder already reports topicId per row, so the decisive fact is a SUT message containing the marker whose topicId equals the created topic (pre-fix it lands without one). A maintainer with broker access can run it as is; I will attach the timeline as soon as the lease is possible.
  • Follow-up noted, not fixed here: cli-backend-dispatch.ts drops the same
    context by design for opt-in cliBackendDispatch: "subscription-auth" runs.

ClawSweeper review of ffc2ed1, item by item:

  • Avoid plugin resolution for unthreaded CLI cron runs (P2) and the first rank-up move: applied in 0e6c68f, at the owner rather than the call site. resolveCurrentChannelTarget (src/cron/isolated-agent/channel-output-policy.ts) loaded the channel-plugin runtime for every targeted run, but only a thread needs channel-specific conversion: the single implementer of threading.resolveCurrentChannelId (Telegram, extensions/telegram/src/channel.ts:1188) returns to unchanged when threadId == null. An unthreaded route now returns its target before the runtime loader runs, so a CLI-backed run with no thread has the direct path it had before the route was resolved above the runtime split, and embedded runs lose a no-op plugin load; threaded routes still resolve through the plugin. Regression keeps an unthreaded target without consulting the channel plugin (owner test) asserts getChannelPlugin is never called for threadId: null or omitted; on ffc2ed1 it fails with expected "vi.fn()" to not be called at all, but actually been called 2 times.
  • Production LOC: 0e6c68f is +3/-1 production (one condition plus its comment) and +11 test lines.
  • Commands on 0e6c68f (Node 24.18.0, Linux): pnpm test src/cron/isolated-agent/channel-output-policy.test.ts src/cron/isolated-agent/run.message-tool-policy.test.ts (64 tests); node scripts/check-changed.mjs -- src/cron/isolated-agent/channel-output-policy.ts src/cron/isolated-agent/channel-output-policy.test.ts (clean); autoreview (Claude engine, P1 threshold, --mode commit): patch is correct (0.75), no findings.
  • The Telegram Test Server proof remains blocked on broker access, as described above; the prepared scenario is unchanged by this commit.

Boundary proof through the real delayed-completion path (abb948e)

The earlier proof stopped at the executor-to-CLI parameters. abb948e adds
src/cron/isolated-agent/run.cli-topic-delivery.e2e.test.ts (standalone e2e
lane, test/vitest/vitest.e2e.config.ts), which drives the route the review
asked for with production code end to end: the isolated cron executor
(executeCronRun, the changed owner), the real loopback grant
(buildCliMcpGrantContext), real gateway tool resolution
(resolveGatewayScopedTools, surface: "loopback", mediated exec), a real
background exec child process with notifyOnExit, the real system-event
queue, and a real heartbeat turn (runHeartbeatOnce) that selects the route
and delivers through the channel outbound adapter. Only two edges are
replaced: the CLI subprocess (runCliAgent, its received parameters are the
fact under test) and the Telegram network send (deps.telegram, a recording
spy at the mock-Gateway boundary). The sandbox is the existing
withTempTelegramHeartbeatSandbox fixture (isolated OPENCLAW_STATE_DIR,
temp SQLite session store, no port bound, no Gateway touched). Telegram's
resolveCurrentChannelId target grammar (<chat>:topic:<id>,
extensions/telegram/src/channel.ts:1188) is supplied on the plugin facade;
Telegram is the only implementer of that hook in the repo.

Pre-fix (production run-executor.ts and channel-output-policy.ts reverted to
the merge base a049778, everything else at abb948e), exit 1:

FAIL  src/cron/isolated-agent/run.cli-topic-delivery.e2e.test.ts > keeps a CLI-backed topic cron's delayed exec completion in the originating topic
AssertionError: expected '-100999999999' to be '-1003774691294:topic:47'
Expected: "-1003774691294:topic:47"
Received: "-100999999999"

The heartbeat really ran and really delivered the delayed exec completion, to
the session's last target (the owner DM) instead of the forum topic. The queued
system event carried to: undefined in that run, which is the #138316
mechanism.

Post-fix (abb948e as is), exit 0:

✓ keeps a CLI-backed topic cron's delayed exec completion in the originating topic 4395ms
Test Files 1 passed (1) | Tests 1 passed (1)

The queued completion carries deliveryContext { channel: "telegram", to: "-1003774691294:topic:47", accountId: "ops", threadId: "47" } and the
outbound send is called once with "-1003774691294:topic:47".

Also on abb948e: node scripts/run-vitest.mjs over
run.message-tool-policy.test.ts, channel-output-policy.test.ts and the new
file, 65/65 pass; the new file co-resident with the other three
src/cron/isolated-agent/*.e2e.test.ts files in the isolate: false e2e lane,
4 files / 18 tests pass; oxfmt --check and oxlint clean;
scripts/run-tsgo-core-test-shards.mjs exit 0.

What this still does not observe: a message in a real Telegram forum topic. The
Test Server lease is still blocked on broker access as described above, so the
unobserved segment is now the adapter-to-Telegram network hop only. The
prepared live scenario is unchanged and a maintainer with broker access can run
it as is.

Rebase onto main (e8684576989)

Main still omits the topic route on the CLI branch: resolveCurrentChannelTarget runs only for the embedded runner and runCliAgent receives no currentChannelId / currentThreadTs. Conflicts were re-expressed on main's current code:

  • run-executor.ts: main introduced buildCommonRunParams() and moved the CLI call inside withLocalSessionPlacementTurnSettlement / deferredLifecycle. resolveCurrentChannelTarget now runs once before if (cliExecution); the CLI call adds currentChannelId and currentThreadTs: normalizeOptionalStringifiedId(threadId); the embedded call keeps the same value. currentThreadTs is not put in the common params, so embedded behavior is unchanged.
  • run.message-tool-policy.test.ts: main rewrote this file and removed createMessageToolExecutor / expectRecordFields. "forwards the resolved topic route into the CLI run" is rewritten in the file's current idiom (mockCliAnnounce, runCronIsolatedAgentTurn, expectFields(mockCall(runCliAgentMock)[0], …)) on the existing topicchat (room#42) fixture.
  • channel-output-policy.ts commit replayed cleanly; Telegram is still the only threading.resolveCurrentChannelId implementer (extensions/telegram/src/channel.ts:1020).
  • run.cli-topic-delivery.e2e.test.ts adapted to moved APIs: createSourceDeliveryPlan → resolveCronSourceDeliveryPlan (./source-delivery-plan.js); executeCronRun now requires runId, deliveryAttemptFence, and onPromptAdmission; resolveGatewayScopedTools is awaited.

The test numbers above are from the previous base; CI on this head is the gate for the re-run. The ClawSweeper medium item (delayed delivery retaining stale route authority after reset/reassignment) and the Telegram Test Server proof remain open as described above.

@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@ylcn91
ylcn91 marked this pull request as ready for review September 4, 2026 16:39
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR passes the resolved destination and thread to CLI-backed cron runs and skips channel-plugin resolution for unthreaded targets.

Example: An isolated CLI cron targets Telegram chat -1003774691294, topic 47, and starts a background command.

  • Before: The CLI tool context lacks the recipient and topic needed by its delayed completion.
  • After: The CLI receives currentChannelId -1003774691294:topic:47 and currentThreadTs 47.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The useful producer repair remains incomplete for merge: the patch changes a public resolver contract, its added completion regression fails on the reviewed head, and supplied evidence does not satisfy final-effect proof.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Delayed CLI cron output loses its originating topic and can enter another conversation.
Reason: The producer omission is concrete and worth repairing; route propagation alone does not deliver the discussed exact-run history and lifecycle isolation, so that broader work should remain separately linked.

Merge readiness

⛔ Blocked before merge - 6 items remain

Keep this PR open: current main still omits the CLI topic route, and the work has assigned ownership; the patch needs a plugin compatibility repair and a corrected completion regression.

Priority: P1
Reviewed head: 965eae9dd7a5393f5d840842a73aa39f892f76ff

Before merge

  • Add real behavior proof - Authority-chain proof required: The supplied historical transcript exercises real grant, exec, queue, and heartbeat code with a background process, but substitutes the CLI runner and Telegram send; its current-head test now fails. Show the real CLI handoff through the current session-event owner to topic 47, rejection of the nearest unrelated recipient, and invalidation after source reset or reassignment before I/O. Redact credentials, IPs, phone numbers, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • [P1] Preserve plugin resolution for unthreaded targets (P1) - The public resolveCurrentChannelId hook accepts an optional threadId, and current main delegates unthreaded addressed routes to it. A plugin that normalizes room to normalized:room now receives no call and its cron tool context contains raw room, including on the previously working embedded path. The matching regression in fix(cron): preserve CLI-backed cron topic route #147283 demonstrates this supported contract. Restore channel-owned resolution for addressed routes instead of generalizing Telegram's identity behavior to every plugin. The earlier reviewed SHA is unavailable locally, so this is not marked as a verified late finding.
  • [P2] Exercise the current completion owner in the regression (P2) - Exact-head CI fails here with expected ran, received skipped: https://github.com/openclaw/openclaw/actions/runs/38038748377/job/114174806999. The rebased production path now submits background exec completions through enqueueSessionEventForHost, which claims the occurrence for ordinary session execution; this test still manually invokes the former heartbeat consumer. Rebuild the scenario around the current session-event owner and its final delivery, retaining the base-fails/head-passes check rather than weakening the assertion.
  • [P2] Await completion ownership instead of polling the queue (P2) - The new test waits on queue length using a real 15-second polling timeout. Root AGENTS.md and the writing-tests cost policy explicitly prohibit new real-time polling; queue presence also does not establish that the completion's delivery owner has settled. Await an owned completion or delivery signal from the fixture while preserving the real background-process boundary.
  • Resolve security concern: Captured routing needs originating-source authority - Existing session-event guards check captured session identity and currentness; the cron event-routing policy can map the run to main, so those checks alone do not demonstrate invalidation when the originating cron source is reset or reassigned.
  • Resolve merge risk - Establish that delayed CLI completions retain current authority for their originating topic after source reset or reassignment; capturing the routed main-session identity alone does not establish that source contract.

Findings

  • [P1] [P1] Preserve plugin resolution for unthreaded targets — src/cron/isolated-agent/channel-output-policy.ts:41
  • [P2] [P2] Exercise the current completion owner in the regression — src/cron/isolated-agent/run.cli-topic-delivery.e2e.test.ts:204-217
  • [P2] [P2] Await completion ownership instead of polling the queue — src/cron/isolated-agent/run.cli-topic-delivery.e2e.test.ts:196-198
  • [medium] Captured routing needs originating-source authority — src/cron/isolated-agent/run-executor.ts:531

Tests

  • Low-value test src/cron/isolated-agent/run.message-tool-policy.test.ts: The added CLI parameter-shape case repeats the route omission exercised by the completion integration test; once that stronger boundary is repaired, retain one primary regression rather than both.
  • Missing end-to-end proof: Supply a redacted real CLI-to-Telegram topic completion with unrelated-recipient and source-invalidation negative cases; the historical base/head harness transcript predates the rebase and the current-head integration test fails.
Agent review details

How this fits together

The cron executor supplies resolved delivery context to agent runners; CLI grants carry it into tools, whose background completions enter session-event execution and outbound delivery.

flowchart TD
A[Cron delivery target] --> B[Cron executor]
B --> C[CLI runner]
C --> D[Loopback tool grant]
D --> E[Background exec completion]
E --> F[Session event owner]
F --> G[Channel outbound delivery]
Loading

Technical review

Best possible solution:

Preserve channel-owned target normalization and carry the CLI route through the current completion owner with source-authority checks before delivery.

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

Current-main source confirms the CLI recipient/thread omission and its downstream exec-notification inputs; the linked report supplies official-release observations, but no current-main runtime reproduction was executed.

Is this the best way to solve the issue?

Resolving the route once at the cron producer is appropriate, but skipping the public unthreaded resolver changes an unrelated contract and the completion test must follow today's session-event owner.

Full review comments:

  • [P1] [P1] Preserve plugin resolution for unthreaded targets — src/cron/isolated-agent/channel-output-policy.ts:41
    The public resolveCurrentChannelId hook accepts an optional threadId, and current main delegates unthreaded addressed routes to it. A plugin that normalizes room to normalized:room now receives no call and its cron tool context contains raw room, including on the previously working embedded path. The matching regression in fix(cron): preserve CLI-backed cron topic route #147283 demonstrates this supported contract. Restore channel-owned resolution for addressed routes instead of generalizing Telegram's identity behavior to every plugin. The earlier reviewed SHA is unavailable locally, so this is not marked as a verified late finding.
    Confidence: 0.94
  • [P2] [P2] Exercise the current completion owner in the regression — src/cron/isolated-agent/run.cli-topic-delivery.e2e.test.ts:204-217
    Exact-head CI fails here with expected ran, received skipped: https://github.com/openclaw/openclaw/actions/runs/38038748377/job/114174806999. The rebased production path now submits background exec completions through enqueueSessionEventForHost, which claims the occurrence for ordinary session execution; this test still manually invokes the former heartbeat consumer. Rebuild the scenario around the current session-event owner and its final delivery, retaining the base-fails/head-passes check rather than weakening the assertion.
    Confidence: 0.98
  • [P2] [P2] Await completion ownership instead of polling the queue — src/cron/isolated-agent/run.cli-topic-delivery.e2e.test.ts:196-198
    The new test waits on queue length using a real 15-second polling timeout. Root AGENTS.md and the writing-tests cost policy explicitly prohibit new real-time polling; queue presence also does not establish that the completion's delivery owner has settled. Await an owned completion or delivery signal from the fixture while preserving the real background-process boundary.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d54483901779.

Merge-risk options

Maintainer options:

  1. Establish source authority at final delivery (recommended)
    Have the assigned owner verify the existing completion owner against the allowed topic, an unrelated recipient, and source reset or reassignment before transport I/O; repair the existing owner if it cannot enforce that contract.
  2. Hold for the continuation repair
    Keep this PR open while its assigned owner coordinates the route repair with the separately tracked source-authority work.

Provenance checked

  • Cron runner route handoff keeps the original intent (7d9a9d8: Preserve isolated message targets in embedded runs; the subsequent channel-plugin extraction centralized channel-native resolution.)
  • Unthreaded channel resolver changes intended behavior with a stated reason (40719bc: Delegate current-channel formatting to channel plugins for addressed routes. The PR explains its shortcut using Telegram's implementation, but that does not narrow the public optional-thread contract.)

Testing

Proof path: in-process harness.

Security

Needs attention: The route repair addresses a reported disclosure, but exact originating-source authority remains unverified at delayed delivery.

Evidence

Security concerns:

  • [medium] Captured routing needs originating-source authority — src/cron/isolated-agent/run-executor.ts:531
    Existing session-event guards check captured session identity and currentness; the cron event-routing policy can map the run to main, so those checks alone do not demonstrate invalidation when the originating cron source is reset or reassigned.
    Confidence: 0.84

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 40719bc adds src/cron/isolated-agent/channel-output-policy.ts:34 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 40719bcb7462; files: src/cron/isolated-agent/channel-output-policy.ts)
  • Ayaan Zaidi: Raw commit dd8de93 adds src/cron/isolated-agent/run-executor.ts:196 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: dd8de93b0eb8; files: src/cron/isolated-agent/run-executor.ts)
  • Donnie Fiander: Raw commit 4321816 adds src/cron/isolated-agent/run-executor.ts:660 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4321816e2a76; files: src/cron/isolated-agent/run-executor.ts)

PR surface

Source +10, Tests +264. Total +274 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 16 6 +10
Tests 3 264 0 +264
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 280 6 +274

Review metrics

Metric Value Why it matters
Production versus test LOC Production +16/-6; tests +264/-0 The small route handoff is focused, but most growth is a completion integration test that currently fails on the reviewed head.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #138316
Summary: The canonical report identifies the CLI cron producer omission; two open PRs address it, while exact delayed-source authority has separate tracking.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The owned release report describes delayed cron output reaching an unrelated conversation.
  • merge-risk: 🚨 compatibility: The shortcut changes the public plugin resolver's behavior for unthreaded targets.
  • merge-risk: 🚨 message-delivery: The changed route controls where CLI tool sends and delayed completions are delivered.
  • merge-risk: 🚨 security-boundary: Topic-local output crosses a conversation boundary if captured routing survives invalidated source authority.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. Telegram's Test Server can observe whether the delayed CLI cron output reaches the originating forum topic and avoids unrelated conversations.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (6 earlier review cycles)
  • reviewed 2026-09-04T16:55:48.605Z sha ffc2ed1db111ed6b9703be2e55c42c7e3c5a2d25 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-04T19:54:35.105Z sha ffc2ed1db111ed6b9703be2e55c42c7e3c5a2d25 :: needs real behavior proof before merge. :: [P2] Avoid plugin resolution for unthreaded CLI cron runs
  • reviewed 2026-09-04T20:58:06.244Z sha 0e6c68f35dcf0805fc8d5019fafdec2eefe9038b :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-06T10:04:10.326Z sha abb948e7a66e7bc485a066eeb86a3e7a44896575 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-06T13:21:12.747Z sha 0c559086362eb8ac0604e4a78382a1010e6686d9 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-25T22:02:03.767Z sha 0c559086362eb8ac0604e4a78382a1010e6686d9 :: needs real behavior proof before merge. :: none

Reviewed October 10, 2026, 4:50 AM ET / 08:50 UTC (Revision 7).

@ylcn91

ylcn91 commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Telegram Test Server proof status and a request for a maintainer.

The harness is ready at ffc2ed1 (pnpm build exit 0, dist/entry.js, uv for the user driver, ports free) and the forum-topic CLI-runtime cron scenario is prepared with no harness edits (shape in the PR body). What blocks the run is credential access, not code: the skill leases Test Server credentials through the OpenClaw Convex QA broker (qa/convex-credential-broker, deployment reminiscent-ibex-847), and my authenticated Convex account is not a member of that project:

convex env --deployment reminiscent-ibex-847 get OPENCLAW_QA_CONVEX_SECRET_CI
✖ You don't have access to the selected project.

Request, whichever is easier for the team:

  1. Add my Convex account to the broker project (I can share the login e-mail privately), and I will run the scenario and attach the redacted timeline the same day; or
  2. Run the prepared scenario from a broker-enabled checkout (--backend claude-cli, command action creating a forum topic plus openclaw cron add --thread-id <topic>, 120 s tail with tools.exec.notifyOnExit: true and a 1-minute heartbeat; decisive row is the SUT message carrying the marker with topicId equal to the created topic).

Until then the PR's proof stays boundary-level (executor-to-runner seam plus the traced grant, tool-resolution, and exec-notify chain).

@ylcn91

ylcn91 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Applied the P2 in 0e6c68f at the owner: resolveCurrentChannelTarget now returns an unthreaded target before loading the channel-plugin runtime (the only resolveCurrentChannelId implementer returns to unchanged without a thread), so unthreaded CLI cron runs keep their direct path and threaded routes still resolve through the plugin. Owner regression added; it fails on ffc2ed1. Details in the PR body under "ClawSweeper review of ffc2ed1". Telegram proof still waits on broker access.

@obviyus obviyus self-assigned this Sep 6, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 6, 2026
@ylcn91

ylcn91 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (427abe8) as 0c55908 so CI runs with the preflight output-size fix from #140018. No conflicts; the three commits are unchanged. channel-output-policy and run.message-tool-policy suites pass locally (65 tests). The Telegram Test Server proof is still the open item.

@ylcn91
ylcn91 force-pushed the fix/cron-cli-delivery-context branch from abb948e to 0c55908 Compare September 6, 2026 13:15
@obviyus

obviyus commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Maintainer-approved scope for the connected continuation repair:

Live native-runtime proof shows that immediate sends and both delayed command replies reach the originating Telegram topic, while both delayed replies also enter main-session history. The CLI handoff change alone cannot remove those history copies.

For future isolated cron shell work, the original run will own its delayed replies through final delivery. The repair will extend the existing exact-run continuation owner, retaining its runtime, tool policy, lifecycle revision and cancellation checks until pending shell completions and deliveries settle. Existing history will remain unchanged. No schema-version bump, new store, or unrelated event-producer policy change is approved.

Verification must cover native and CLI topic delivery, multiple completions without duplicates, absence from main history and unrelated conversations, cancellation, overlapping runs, restart recovery, and existing delivery overrides. The contributor's route repair and credit will be preserved. This records the accepted design; implementation and verification are still in progress.

@ylcn91

ylcn91 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@obviyus thanks for recording the design. Who is implementing the continuation-owner extension, and does it land on this PR or on top of it? If you want it here, I can start today. Otherwise I will keep this PR scoped to the CLI route repair and rebase it once you confirm.

@obviyus

obviyus commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

I’m implementing the continuation-owner extension on this PR and will preserve your existing commits and credit. The native topic flow is verified; the CLI and lifecycle checks are in progress. Please leave the branch as it is while I finish the repair and verification. Thanks @ylcn91.

@KirDE

KirDE commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

I reproduced a higher-impact variant of this bug: a delayed CLI-backed exec completion lost its Telegram route, entered the agent main session, and was actually sent to an unrelated Telegram group. I documented the sanitized incident in #138316. I opened #147283, preserving all three commits and original authorship from this PR, and added a defense-in-depth fail-closed boundary: route-less or conflicting exec completion batches are consumed before model dispatch, so no model/session fallback can guess a recipient. If maintainers prefer to keep this PR, the standalone hardening commit is KirDE/openclaw@36a19bce40.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed P2 Normal backlog priority with limited blast radius. labels Sep 26, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Sep 26, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Oct 2, 2026
The isolated cron executor resolved the channel-native current-channel id
only inside its embedded branch, so a CLI-backed run (Codex app-server and
every other CLI provider) reached `runCliAgent` with `messageChannel` and
`agentAccountId` but no recipient/thread. `buildCliMcpGrantContext` then
minted a loopback grant without `currentChannelId`/`currentThreadTs`, and
`createExecTool` built `notifyDeliveryContext` with an empty target — so a
background exec completion carried no route and the later heartbeat relay
fell back to the owner DM.

Resolve the route once above the runtime branch and hand it to both
runners; the CLI runner takes it as `currentChannelId` plus
`currentThreadTs`, its vocabulary for the embedded `messageTo`/
`messageThreadId` pair.

User impact: Telegram forum-topic (and any threaded-channel) automations on
a CLI runtime keep background exec completions and message-tool sends in
their originating topic instead of leaking topic-local operational output
into the owner's DM.

Fixes openclaw#138316
…gets

`resolveCurrentChannelTarget` loaded the channel-plugin runtime for every
targeted cron run, but only a thread needs channel-specific conversion (the
one implementer returns the target unchanged without one). An unthreaded
route now returns its target directly, so CLI-backed runs regain the direct
path they had before the route was resolved above the runtime split.
The existing regression test stops at the executor-to-CLI parameters, so no
proof covered the four production owners the route crosses afterwards. This
drives the real loopback grant, gateway tool resolution, exec notify queue,
and heartbeat delivery with a real background process and asserts the delayed
completion is delivered to the originating forum topic.

On the merge-base the same test fails at the delivery boundary:
`expected '<owner-dm>' to be '<chat>:topic:47'`.
@ylcn91
ylcn91 force-pushed the fix/cron-cli-delivery-context branch from 0c55908 to 965eae9 Compare October 10, 2026 08:41
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Oct 10, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Oct 11, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Oct 11, 2026

This branch has not been deployed

No deployments
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. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Codex CLI cron drops Telegram topic route from background exec completions

3 participants