Skip to content

fix: surface safe terminal tool fallbacks#90872

Closed
fuller-stack-dev wants to merge 111 commits into
openclaw:mainfrom
fuller-stack-dev:codex/safe-terminal-tool-fallbacks
Closed

fix: surface safe terminal tool fallbacks#90872
fuller-stack-dev wants to merge 111 commits into
openclaw:mainfrom
fuller-stack-dev:codex/safe-terminal-tool-fallbacks

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Jun 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Add opt-in terminal fallback metadata through agent-core, session tool definitions, subscribe handling, and the embedded runner.
  • Surface safe terminal summaries for tool-loop and incomplete-turn exits, while keeping undeclared tool output neutral instead of leaking raw results.
  • Declare structured fallbacks for cron and web_fetch, and keep Docker image builds from carrying stale dist output.
  • Tighten delivery/side-effect evidence for channel replies, source-reply deliveries, context-engine pairing, compaction ownership, heartbeat lifecycle handling, and tool-plugin result preservation.

Contract note

  • terminalSummary and terminalResultFallback are intentionally public tool metadata for safe terminal presentation.
  • Tools opt in explicitly; undeclared raw tool output is not surfaced as a fallback.
  • Generic tool activity, accepted child-session spawns, messaging sends, cron additions, and replay-invalid aborts continue to suppress fallback model replay so side effects are not duplicated.
  • defineToolPlugin preserves intentional helper-created tool results while continuing to JSON-wrap bare text-shaped objects with content and details fields.

Verification

  • node scripts/run-vitest.mjs src/plugin-sdk/tool-plugin.test.ts src/agents/embedded-agent-runner/run.incomplete-turn.test.ts src/agents/embedded-agent-subscribe.handlers.tools.test.ts src/auto-reply/reply/agent-runner.runreplyagent.e2e.test.ts -- --reporter=dot
  • pnpm check:docs
  • pnpm lint --threads=8
  • pnpm plugin-sdk:api:check
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base upstream/main --codex-bin /Users/jason/.codex/openclaw-pr-autopilot/bin/codex-persist-sessions --model codex=gpt-5.5 --thinking codex=high
  • git diff --check

Real behavior proof

Behavior addressed: Channel-facing agents that ended a turn after successful tool work could reply with planning text, repeat promises, or expose unsafe raw fallback text instead of delivering the completed tool result.

Real environment tested: A live Discord-backed OpenClaw stack using the patched image and a connected bot. Identifying stack, bot, channel, image, and run IDs are intentionally omitted from this public PR.

Exact steps or command run after this patch: Sent live prompts that exercised a scheduler/cron path and a web_fetch tool-loop timeout path through the running gateway.

Evidence after fix:

Redacted live channel output, scheduler path:

The requested scheduler state cannot be checked from this runtime because no scheduler, cron, gateway, or exec tool is available in this channel session. I cannot claim a live cron check without that tool.

Redacted live channel output, web_fetch terminal fallback path:

URL: https://example.com
Final URL: https://example.com
Status: 200
Title: Example Domain
Cached: true
Truncated: false

Observed result after fix: The channel received user-visible results for both proof cases. The web_fetch fallback included URL, final URL, status, title, cache state, and truncation state, with no raw unsafe tool dump. The scheduler path returned a direct capability blocker instead of a promise to perform an unavailable check.

What was not tested: Broad cross-channel E2E beyond Discord was not rerun. One unrelated live runtime metadata drift was observed during proof and is omitted here because it is not part of this patch.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord docker Docker and sandbox tooling agents Agent runtime and tooling size: XL triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 6, 2026
@fuller-stack-dev
fuller-stack-dev force-pushed the codex/safe-terminal-tool-fallbacks branch from f360f5f to 768d38d Compare June 6, 2026 06:50
@clawsweeper

clawsweeper Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution. I reviewed the branch, and this PR is not a good landing base for OpenClaw.

Close: the terminal-fallback problem is useful, but this branch is no longer a viable landing base after an explicit maintainer rejection and code inspection showing broad public SDK, core tool-contract, and embedded-runner rewrites.

So I’m closing this PR rather than keeping an unmergeable branch open. A new narrow PR that carries only the useful part is welcome.

Review details

Best possible solution:

Close this branch as the landing candidate and pursue a narrow replacement PR that fixes one terminal-fallback delivery path, with any public Plugin SDK API handled as a separate maintainer-approved contract change.

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

No high-confidence reviewer-run reproduction was established in this read-only pass. The PR's redacted live Discord proof and source inspection make the reported terminal fallback failure plausible, but current-head behavior was not independently reproduced.

Is this the best way to solve the issue?

No. This branch is a plausible exploration, but the best maintainable solution is a much narrower runtime repair plus a separate product/API decision for durable Plugin SDK fallback metadata.

Security review:

Security review cleared: No concrete security or supply-chain regression was found; the diff does not add dependencies or workflows, but any replacement must keep terminal fallback output explicitly public and redacted.

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy read: Root AGENTS.md and scoped guides for agents, embedded-runner/run, tools, Plugin SDK, docs, scripts, and extensions were read; Plugin SDK and fallback compatibility rules affected the review. (AGENTS.md:18, f1b8827d20c8)
  • Live PR scale and state: Live PR inspection showed current head e7ad604, 75 changed files, +15999/-1907, mergeable but unstable, and no protected maintainer/security/release-blocker labels. (e7ad60421281)
  • Maintainer decision: steipete commented on 2026-06-14 that this PR is not landing and that the 15k LOC approach cannot be right.
  • Public Plugin SDK expansion: The PR head adds terminalResultFallback to tool plugin definitions and exports toolResult(...), turning the fix into a new public Plugin SDK contract. (src/plugin-sdk/tool-plugin.ts:50, e7ad60421281)
  • Core tool contract expansion: The PR head adds AgentToolTerminalSummary, AgentToolTerminalResultFallback, terminalSummary, and terminalResultFallback to core agent tool types. (packages/agent-core/src/types.ts:439, e7ad60421281)
  • Broad runtime rewrite: The PR head adds a new embedded-runner tool-loop fallback module and wires fallback resolution into run.ts, confirming this is a broad runner rewrite rather than a narrow repair. (src/agents/embedded-agent-runner/run/tool-loop-fallback.ts:1, e7ad60421281)

Likely related people:

  • steipete: Merged adjacent current-main agent/reply fixes and left the explicit June 14 decision that this branch shape should not land. (role: recent merger and branch decision commenter; confidence: high; commits: 81924cfd5e61, ecaebfc51b4a, c67dc59b02b0; files: src/agents/embedded-agent-runner/run.ts, src/agents/embedded-agent-runner/run/incomplete-turn.ts, src/auto-reply/reply/agent-runner.ts)
  • ai-hpc: Authored the merged thinking-only errored-turn retry work that recently touched the embedded runner and incomplete-turn paths this PR rewrites. (role: recent adjacent agent-runner contributor; confidence: medium; commits: ecaebfc51b4a; files: src/agents/embedded-agent-runner/run.ts, src/agents/embedded-agent-runner/run/incomplete-turn.ts)
  • sandieman2: Authored the merged final-reply and routed-thread delivery work adjacent to this PR's source-reply and channel-delivery changes. (role: recent adjacent reply-delivery contributor; confidence: medium; commits: c67dc59b02b0; files: src/auto-reply/reply/agent-runner.ts, src/agents/embedded-agent-subscribe.handlers.tools.ts)
  • joelnishanth: Authored the merged length-limited response handling that touched incomplete-turn and terminal trajectory behavior adjacent to this PR. (role: recent adjacent terminal-run contributor; confidence: medium; commits: 81924cfd5e61; files: src/agents/embedded-agent-runner/run/incomplete-turn.ts, src/agents/embedded-agent-runner/run/attempt-trajectory-status.ts, src/agents/embedded-agent-subscribe.ts)
  • ragesaq: Current-main blame and log show recent direct work on the incomplete-turn and message-tool final-reply paths that form the base this PR rewrites. (role: recent adjacent fallback/delivery contributor; confidence: medium; commits: a15427d605fe; files: src/agents/embedded-agent-runner/run/incomplete-turn.ts, src/auto-reply/reply/agent-runner.ts, src/plugin-sdk/tool-plugin.ts)

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

@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: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jun 6, 2026
@fuller-stack-dev

fuller-stack-dev commented Jun 6, 2026

Copy link
Copy Markdown
Member Author

Visual verification request: verify a Discord-backed run surfaces safe scheduler/web_fetch terminal fallback without raw tool output.

@fuller-stack-dev
fuller-stack-dev force-pushed the codex/safe-terminal-tool-fallbacks branch from 768d38d to fdd98e0 Compare June 6, 2026 07:40
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 6, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 6, 2026
@fuller-stack-dev
fuller-stack-dev force-pushed the codex/safe-terminal-tool-fallbacks branch from fdd98e0 to d541d51 Compare June 6, 2026 08:13
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 6, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 6, 2026
@fuller-stack-dev
fuller-stack-dev force-pushed the codex/safe-terminal-tool-fallbacks branch from d541d51 to 72faa63 Compare June 6, 2026 08:23
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 6, 2026
@fuller-stack-dev
fuller-stack-dev force-pushed the codex/safe-terminal-tool-fallbacks branch from 72faa63 to 8f274c9 Compare June 6, 2026 08:29
@steipete

Copy link
Copy Markdown
Contributor

We are not landing this. This is 15k LOC and can't possibly be the right approach.

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Closing as superseded by #93073.

This PR established the real Discord-facing failure and contains useful investigation/proof history, but the 75-file, +15,999/-1,907 approach adds broad public tool/fallback contracts and is not the implementation we want to land. #93073 carries the motivating evidence forward and replaces this with a narrow typed post-tool empty-final recovery using the existing bounded continuation, with fail-closed replay handling for unclassified tools and no natural-language regex parsing or raw-result fallback.

Please continue implementation review and proof discussion on #93073. Reopen this PR only if concrete evidence shows a distinct required behavior that the narrow replacement cannot cover and that requires the broader public fallback contract.

@steipete

Copy link
Copy Markdown
Contributor

Superseded by #93228.

The replacement keeps this PR's goal, but removes the natural-language classifier and large English-specific regular expressions. It uses explicit harness/protocol terminal states, structured replay-safety evidence, and post-middleware tool summaries instead. The original contribution remains credited through Co-authored-by: Jason (Json) <[email protected]>.

Thank you @fuller-stack-dev for identifying and implementing the original safe-terminal-fallback direction.

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

Labels

agents Agent runtime and tooling channel: discord Channel integration: discord channel: slack Channel integration: slack docker Docker and sandbox tooling docs Improvements or additions to documentation gateway Gateway runtime 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. P1 High-priority user-facing bug, regression, or broken workflow. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: XL 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.

3 participants