Skip to content

fix: route remaining cli-backed helper runs through CLI paths#72499

Closed
nicko-ai wants to merge 48 commits into
openclaw:mainfrom
nicko-ai:codex/fix-cli-backend-provider-runtime
Closed

fix: route remaining cli-backed helper runs through CLI paths#72499
nicko-ai wants to merge 48 commits into
openclaw:mainfrom
nicko-ai:codex/fix-cli-backend-provider-runtime

Conversation

@nicko-ai

@nicko-ai nicko-ai commented Apr 27, 2026

Copy link
Copy Markdown

Summary

Latest main already has the primary/direct CLI backend dispatch fix from #57326.

This PR keeps the remaining helper paths on the same dispatch path when the selected runtime is CLI-backed:

  • queued followup runs
  • models status --probe
  • LLM slug generation
  • cron runs whose canonical provider resolves to a CLI runtime

Supersedes #57327.

Changes

  • route CLI-backed helper runs through runCliAgent()
  • preserve active runtime config, auth profile, session binding, routing context, and cancellation context
  • keep auth probes isolated, tool-disabled, and on the correct CLI auth provider
  • avoid duplicate cron fallback delivery when the message tool already sent to the intended threaded target
  • cover followups, probes, slug generation, cron runtime selection, and MCP message-tool tracking

Out of scope

The stale persisted agentHarnessId/CLI-runtime-alias pin reported later in #57326 is a separate compatibility hardening path. This PR fixes the helper paths that still bypass CLI dispatch; it does not try to migrate or canonicalize old session harness pins.

Fixes #57326

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime commands Command implementations agents Agent runtime and tooling size: XL labels Apr 27, 2026
@greptile-apps

greptile-apps Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR routes the remaining CLI-backed helper paths — queued followup runs, models status --probe, LLM slug generation, and cron runs whose canonical provider resolves to a CLI runtime — through runCliAgent(), matching the primary dispatch path already fixed in #57326. It also introduces mcpRoutingHash for session reuse invalidation when the messaging context changes, a module-level messaging-tool-tracker to carry MCP-side message tool sends through to delivery suppression, and propagates messageTo/messageThreadId/currentChannelId into the MCP loopback env so the embedded tool context is correct for CLI runs.

Confidence Score: 4/5

Safe to merge with minor caveats; no P0/P1 issues found, all significant behavioral changes are covered by tests.

Only P2 findings: (1) the module-level sendsBySessionKey singleton could produce cross-run interference for concurrent agents sharing a session key; (2) the expansion of isCoreMessageToolSendAction to include reply/sendAttachment/upload-file also affects the non-CLI embedded runner without explicit validation of argument shape; (3) isNewSession is hard-forced to false for the first run of isolated sessions on the aliased-runtime path. None of these are clearly broken today but each is worth a second look.

src/agents/cli-runner/messaging-tool-tracker.ts (singleton state), src/agents/pi-embedded-messaging.ts (broadened action set), src/cron/isolated-agent/run-executor.ts (isNewSession for isolated sessions)

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/cli-runner/messaging-tool-tracker.ts
Line: 9

Comment:
**Module-level singleton risks cross-run interference**

`sendsBySessionKey` is a process-wide Map. `runPreparedCliAgent` drains it at start to purge stale state, but if two CLI agents for the **same `sessionKey`** run concurrently (e.g. a queued followup races with a cron delivery on the same session), the second agent's startup-drain will silently discard sends that the first agent's MCP calls already recorded, and the first agent's end-drain will return an empty result. No guard exists to detect or prevent this overlap.

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/agents/pi-embedded-messaging.ts
Line: 26-28

Comment:
**Expanded action set also affects non-CLI embedded runner**

`isCoreMessageToolSendAction` now includes `"reply"`, `"sendAttachment"`, and `"upload-file"` in addition to the previous `"send"` / `"thread-reply"`. This change propagates into `isMessagingToolSendAction` (used by the embedded Pi runner) and `extractMessagingToolSend` (used in `pi-embedded-subscribe.tools.ts`), not only the new CLI MCP tracker. If any of these new actions uses a different argument shape for the `to` / `target` field, `extractMessagingToolSend` may silently record an incomplete or wrong target. Confirm that argument conventions are uniform across all five action types.

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/cron/isolated-agent/run-executor.ts
Line: 159-160

Comment:
**`isNewSession: false` forced for first-run isolated sessions**

When `params.job.sessionTarget === "isolated"` and `params.cronSession.isNewSession === true` (the very first run of an isolated session), `isNewSession` evaluates to `false`. `resolveSessionAuthProfileOverride` will therefore look for a stored profile binding that does not yet exist, potentially returning `undefined` and leaving the CLI agent to pick a profile itself. This is only relevant for the aliased-runtime path (`cliExecutionProvider !== providerOverride`), but it may silently select a different auth profile than intended on session creation.

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

Reviews (1): Last reviewed commit: "fix: share message send action tracking" | Re-trigger Greptile

Comment thread src/agents/cli-runner/messaging-tool-tracker.ts Outdated
Comment thread src/agents/pi-embedded-messaging.ts
Comment thread src/cron/isolated-agent/run-executor.ts
@clawsweeper

clawsweeper Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Workflow note: Future ClawSweeper reviews update this same comment in place.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

Summary
The PR routes CLI-backed helper paths through CLI dispatch for followups, model auth probes, LLM slug generation, and canonical-provider cron runs.

Reproducibility: yes. at source level: current main still routes model auth probes and LLM slug generation through runEmbeddedPiAgent after provider/model selection, while followups have since been fixed. I did not run a live CLI-backed helper path in this read-only review.

PR rating
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦐 gold shrimp
Summary: Useful source-level work exists, but missing real behavior proof and broad conflicting cron/MCP changes keep it below merge-ready quality.

Rank-up moves:

  • Add redacted live output, logs, or a terminal screenshot showing a CLI-backed probe, slug, or cron helper after the patch.
  • Rebase against current main and remove or reconcile the already-merged followup fix.
  • Preserve and prove restricted cron tool policy before asking for merge.
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Real behavior proof
Needs real behavior proof before merge: Missing; the contributor should add redacted terminal output, logs, a recording, screenshot, or linked artifact showing an after-fix CLI-backed helper run, then update the PR body for re-review.

Risk before merge

  • The branch conflicts with current main and overlaps the already-merged queued-followup fix, so a rebase may materially change the patch.
  • The cron/MCP changes can alter which tools scheduled runs may access; green unit tests alone do not settle that security boundary.
  • The external PR lacks after-fix real behavior proof from a CLI-backed helper run.
  • The linked canonical issue is still open and includes additional remaining runtime paths beyond this PR's cleanly-reviewed scope.

Maintainer options:

  1. Rebase and split cron policy (recommended)
    Keep the probe and slug dispatch fixes separate from the cron/MCP policy work so maintainers can review the security boundary independently.
  2. Replace with a narrower PR
    A replacement PR can credit this branch while landing only the remaining helper dispatch fixes that do not overlap the merged followup change.
  3. Pause broad cron changes
    Maintainers can defer or close the cron portion unless it proves restricted toolsAllow, message-tool targeting, and CLI auth-profile behavior after rebase.

Next step before merge
Human review is needed because the branch is conflicting, lacks contributor real-behavior proof, and changes a security-sensitive cron/MCP policy boundary.

Security
Needs attention: The diff touches cron CLI dispatch and MCP loopback tool exposure, so the scheduled-run tool-policy boundary needs attention before merge.

Review findings

  • [P2] Preserve cron tool policy on CLI runs — src/cron/isolated-agent/run-executor.ts:203-205
Review details

Best possible solution:

Land a rebased or replacement change that keeps the merged followup fix, routes probe and slug helpers through CLI dispatch, and handles cron only if the fail-closed tool-policy contract is preserved with focused proof.

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

Yes, at source level: current main still routes model auth probes and LLM slug generation through runEmbeddedPiAgent after provider/model selection, while followups have since been fixed. I did not run a live CLI-backed helper path in this read-only review.

Is this the best way to solve the issue?

No, not as-is. Reusing CLI dispatch is the right direction for the remaining helpers, but this branch is conflicting, partly superseded, missing real behavior proof, and needs cron/MCP policy safety resolved before merge.

Label changes:

  • add P1: The PR targets a real CLI-backed helper dispatch regression that can break agent and channel workflows for CLI-runtime users.
  • add merge-risk: 🚨 compatibility: The branch conflicts with current main and overlaps a merged followup fix, so upgrade behavior depends on a careful rebase.
  • add merge-risk: 🚨 auth-provider: The changes affect CLI auth-profile and provider-runtime selection for probes, slug generation, followups, and cron runs.
  • add merge-risk: 🚨 security-boundary: The cron/MCP portion can change scheduled-run tool availability and must preserve restrictive tool policy.
  • add rating: 🧂 unranked krab: Current PR rating is 🧂 unranked krab because proof is 🧂 unranked krab, patch quality is 🦐 gold shrimp, and Useful source-level work exists, but missing real behavior proof and broad conflicting cron/MCP changes keep it below merge-ready quality.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Missing; the contributor should add redacted terminal output, logs, a recording, screenshot, or linked artifact showing an after-fix CLI-backed helper run, then update the PR body for re-review.

Label justifications:

  • P1: The PR targets a real CLI-backed helper dispatch regression that can break agent and channel workflows for CLI-runtime users.
  • merge-risk: 🚨 security-boundary: The cron/MCP portion can change scheduled-run tool availability and must preserve restrictive tool policy.
  • merge-risk: 🚨 auth-provider: The changes affect CLI auth-profile and provider-runtime selection for probes, slug generation, followups, and cron runs.
  • merge-risk: 🚨 compatibility: The branch conflicts with current main and overlaps a merged followup fix, so upgrade behavior depends on a careful rebase.
  • rating: 🧂 unranked krab: Current PR rating is 🧂 unranked krab because proof is 🧂 unranked krab, patch quality is 🦐 gold shrimp, and Useful source-level work exists, but missing real behavior proof and broad conflicting cron/MCP changes keep it below merge-ready quality.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Missing; the contributor should add redacted terminal output, logs, a recording, screenshot, or linked artifact showing an after-fix CLI-backed helper run, then update the PR body for re-review.

Full review comments:

  • [P2] Preserve cron tool policy on CLI runs — src/cron/isolated-agent/run-executor.ts:203-205
    This CLI cron branch now maps canonical providers such as anthropic to a CLI runtime, but the cliParams path still does not carry the embedded branch's full toolsAllow, requireExplicitMessageTarget, disableMessageTool, and forceMessageTool policy. Restricted cron jobs can therefore move from embedded fail-closed enforcement to a broader CLI loopback surface.
    Confidence: 0.86

Overall correctness: patch is incorrect
Overall confidence: 0.86

Security concerns:

  • [medium] Cron CLI path must preserve restricted tool policy — src/cron/isolated-agent/run-executor.ts:203
    The PR routes canonical-provider cron runs through CLI dispatch and modifies MCP loopback tool grants; this must preserve the current fail-closed toolsAllow and message-tool policy contract for scheduled runs.
    Confidence: 0.86

Acceptance criteria:

  • After rebase, run focused tests for src/commands/models/list.probe.ts, src/hooks/llm-slug-generator.ts, and cron message-tool policy with the repo's Vitest wrapper.
  • Provide real CLI-backed helper proof with redacted terminal/log output.
  • Run changed checks in Testbox/Crabbox if the rebase touches gateway, MCP, or cron policy broadly.

What I checked:

Likely related people:

  • hclsys: Merged the current-main queued-followup CLI dispatch fix that now overlaps this PR's followup portion. (role: followup CLI dispatch contributor; confidence: high; commits: f2d8f38315d2; files: src/auto-reply/reply/followup-runner.ts, src/auto-reply/reply/followup-runner.test.ts)
  • steipete: Recent history shows repeated work in model probe, slug, cron, and CLI runtime surfaces touched by this PR. (role: recent area contributor; confidence: high; commits: 6a87d6e81426, c8a953af9371, 89d7a24a3523; files: src/commands/models/list.probe.ts, src/hooks/llm-slug-generator.ts, src/cron/isolated-agent/run-executor.ts)
  • vincentkoc: Recent runtime seam and slug-generator work is adjacent to the resolveCliRuntimeExecutionProvider pattern needed by the remaining helper paths. (role: runtime and slug adjacent contributor; confidence: medium; commits: dfed74b2546d, 21d850dd6656, a08fbfb1aea9; files: src/hooks/llm-slug-generator.ts, src/cron/isolated-agent/run-executor.ts, src/agents/model-runtime-aliases.ts)
  • shakkernerd: Recent model status auth-probe commits touch the probe path this PR changes from embedded execution to CLI execution. (role: model status probe contributor; confidence: medium; commits: d3c6a8f0fb6d, 4109446c2f54; files: src/commands/models/list.probe.ts)
  • Ayaan Zaidi: Recent blame and cron message-tool policy commits are adjacent to the cron executor and delivery policy surface this PR modifies. (role: adjacent cron/message-tool contributor; confidence: medium; commits: 357e3ecc65e3, 13a0d7a9e035, 49ae60d6cae1; files: src/cron/isolated-agent/run-executor.ts, src/cron/isolated-agent/run.message-tool-policy.test.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 1a7669bc63a0.

@nicko-ai
nicko-ai force-pushed the codex/fix-cli-backend-provider-runtime branch from b5bbb55 to f6df367 Compare April 28, 2026 21:14
@nicko-ai
nicko-ai force-pushed the codex/fix-cli-backend-provider-runtime branch from f6df367 to 9fe2043 Compare April 30, 2026 17:19
@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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels May 20, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 20, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

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

Labels

agents Agent runtime and tooling commands Command implementations gateway Gateway runtime merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. 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. 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: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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.

CLI-backed helper paths still bypass CLI dispatch on latest main

1 participant