Skip to content

fix(agents): show CLI tool activity in session tail and trajectory exports - #188069

Merged
obviyus merged 4 commits into
openclaw:mainfrom
wyf027:fix/cli-tool-trajectory-140273-20261030
Oct 30, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
wyf027:fix/cli-tool-trajectory-140273-20261030

Conversation

@wyf027

@wyf027 wyf027 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Related: #140273

What Problem This Solves

sessions tail and trajectory exports omit tool calls/results already observed during CLI-backed turns. The native CLI can perform the correct tool work while later inspection shows none of it.

User Impact

Future CLI tool observations remain inspectable after later turns. Known failures remain failures; ambiguous host outcomes remain unknown; capture opt-outs retain their existing behavior. Historical turns and chat.history are not backfilled.

Why This Change Was Made

Forward the existing CLI start/result observations to the existing bounded trajectory recorder before terminal correlation is retired. Reuse existing normalization, replay filtering, first-terminal handling and the host-owned outcome. No permission, auth, SDK, schema, setting or retention rule changes.

Reported by @d3vn0mi in #140273. Builds on the recorder from merged #178007 and the earlier investigation in closed, unmerged #140615. Contributor implementation and commit are retained.

Evidence

Genuine Claude CLI → built Gateway → tail/export before/after proof. Latest-head diagnostic retention and checks.

  • Independently built main and candidate in secretless Node 24.22.1 Linux Docker. Selected genuine official Claude Code 2.1.309 through the normal registered backend, managed synthetic profile and credential FD. No login, private account, paid key or fake CLI.
  • HTTPS CONNECT plus a trusted task CA routes the real CLI to a local Messages fixture with normal TLS verification. The container has no external Docker network. The fixture observed 20 Messages requests carrying an API-key header and actual read results containing the known file marker; it does not synthesize tool results or CLI events.
  • Native ToolSearch loads the real registered read schema before the real OpenClaw read runs. Each capture then completes another no-tool turn before using the shipped tail/export commands.
  • Main twice: actual reads confirmed, but 0 tool calls/results and 0 tail tool rows. Candidate twice: 2 calls/results (ToolSearch plus Read), including exactly one normalized read pair with status:completed, success:true, the marker path and actual marker contents. Tail displays read and read ok.
  • Independent no-tool controls on both refs retain normal session lifecycle events and 0 tool rows. This establishes genuine missing observations rather than disabled capture or failed execution. It resolves the earlier [Bug]: claude-cli-backed turns are tool-use-invisible in the OpenClaw transcript — cliSessionBindings doesn't reliably point at the CLI session that served the turn #140273 fixture-routing blocker without changing settings-sources or permission/auth guards.
  • The identical unknown-outcome forwarding regression fails on main. Four owner/consumer suites passed 130 tests in aggregate; the final capture suite passed all 52 after consolidation. The original six-event ambiguous-call diagnostic assertions remain alongside the new trajectory assertions, and MCP/server-native timeout cases reject fabricated trajectory results. Existing lifecycle, opt-out and consumer tests stay in their existing owners. Targeted formatting, lint, changed-page MDX and whitespace checks pass.
  • Simplification removes the added shared fixture/sibling and the 153-line allocation, extending existing meaningful cases instead. Final PR: production +23, tests +30/-30 (net 0), docs +2/-1. No new test file or allocation remains. Production code is unchanged from the built contributor revision.

This proves the native CLI/tool/Gateway/SQLite consumer path against a deterministic local model endpoint, not live Anthropic authentication or model quality.

Merge Danger

Two-way runtime-code door; reverting does not delete observations already captured under existing retention. No storage migration, public API or execution-policy change. Blast radius is CLI tool trajectory inspection; canonical transcript/history semantics remain unchanged.

@clawsweeper

clawsweeper Bot commented Oct 30, 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.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L labels Oct 30, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Records observed CLI tool calls and results so session tail and trajectory exports retain tool activity.

Example: Claude CLI reads proof.txt containing TASK_188069_ACTUAL_READ_RECEIPT, followed by another turn.

  • Before: Session tail and trajectory export contain no tool rows despite the completed read.
  • After: Tail shows read and read ok, and the export retains the normalized read call, actual contents, and successful outcome.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused, correct repair with shipped-entry-point before/after proof and restored independent diagnostic coverage; ordinary exact-head CI remains pending.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Obviyus's linked output exercises genuine Claude Code through independently built Gateways in secretless Docker against a local Messages fixture, verifies actual read contents, then invokes shipped tail/export after another turn; candidate tool pairs persist while baseline pairs are absent, and the reviewed production code is unchanged.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Operators cannot inspect tool activity from CLI-backed turns through session tail or trajectory exports.
Reason: Restores the documented trajectory contract with a narrow producer-side repair, preserving historical transcript semantics and existing capture controls.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR repairs a current CLI trajectory gap through the existing recorder, and the earlier diagnostic-retention finding is resolved.

Priority: P2
Reviewed head: 4ef98d9c7e95e21a2c924396c96482bc95627209

Before merge

None.

Findings

None.

Agent review details

How this fits together

The CLI runner receives parsed native tool observations, correlates Gateway-owned outcomes, and forwards bounded events to the existing SQLite trajectory recorder consumed by session tail and export.

flowchart LR
  A[Native CLI output] --> B[Streaming parser]
  B --> C[CLI event handlers]
  D[Gateway tool outcomes] --> C
  C --> E[Trajectory recorder]
  E --> F[SQLite storage]
  F --> G[Session tail and export]
Loading

Technical review

Best possible solution:

Forward observed CLI tool events through the existing bounded recorder while preserving authoritative outcomes and canonical transcript semantics.

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

Supplied genuine-CLI before/after proof reproduces missing tool observations on pinned main, and current-main source retains the responsible omission; no target code was executed during this review.

Is this the best way to solve the issue?

This is the smallest complete repair for forward-looking trajectory inspection: it connects existing observations to the existing recorder without introducing another history or storage owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +23, Tests 0, Docs +1. Total +24 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 23 0 +23
Tests 1 30 30 0
Docs 1 2 1 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 55 31 +24

Review metrics

Metric Value Why it matters
Production versus test changes Production +23/-0; tests +30/-30 Necessary forwarding reuses existing owners, and regression coverage extends existing cases without adding test scaffolding.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Missing persisted tool observations impair CLI session inspection without stopping execution or delivery.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 (2 earlier review cycles)
  • reviewed 2026-10-30T03:45:05.604Z sha a59b902 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-30T04:50:23.595Z sha 02b8d7f :: needs changes before merge. :: [P3] Restore the ambiguous-call diagnostic assertions

Reviewed October 30, 2026, 1:08 AM ET / 05:08 UTC (Revision 3).

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S and removed size: L labels Oct 30, 2026
@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Genuine Claude CLI → built Gateway → tail/export proof

Head: 02b8d7f804b960ae5cf1abcaf35183f4336481c1; pinned main: 315380c4789590e3aff9be3cfc6fcfcb9e1f6eee. Contributor commit retained. Both refs were independently installed/built in secretless Linux/arm64 Docker, Node 24.22.1. The tested candidate's production code is unchanged from the contributor revision; subsequent changes only consolidate tests and clarify documentation.

Actual native binary: official npm Claude Code 2.1.309, verified by its own claude --version. The Gateway selected the normal registered claude-cli backend, using a managed synthetic anthropic:fixture profile and the existing credential-FD path. No login, private account or paid key was used.

The earlier #140273 settings-route blocker is avoided without changing its guards: a task-local HTTPS CONNECT proxy and trusted test CA serve the Anthropic Messages fixture. Normal TLS verification remains enabled; the certificate was verified for api.anthropic.com. The container was disconnected from all Docker networks before proof (NetworkSettings.Networks = {}), leaving only its loopback fixture reachable. All CONNECT authorities were api.anthropic.com:443; 20 Messages requests were observed, all with an API-key header, and no TLS errors. No permission, auth, settings-sources or SDK code was changed.

Claude initially exposes deferred tools. The fixture requests the real native ToolSearch to load the registered OpenClaw read schema, then requests the real mcp__openclaw__read. It does not invent a tool result or a CLI event. The result received back by the Messages fixture contains the exact file marker TASK_188069_ACTUAL_READ_RECEIPT, proving actual tool execution. The fixture's final reply only says “Receipt verified.”

Each capture ran two real Gateway turns: the first performs the tool work, the later turn explicitly uses no tools. Only then were the shipped consumers invoked:

openclaw --profile p188069base agent --session-key <key> --message '<read the task marker file>' --timeout 90 --json
openclaw --profile p188069base agent --session-key <key> --message 'Reply briefly without using tools.' --timeout 90 --json
openclaw --profile p188069base sessions tail --session-key <key> --tail 200
openclaw --profile p188069base sessions export-trajectory --session-key <key> --workspace <task-workspace> --output <label> --json

Candidate uses its own built binary/profile. Both exact binaries printed their task-owned config and agent-database paths before running.

Ref / case, inspected after the later turn Genuine read result received Exported tool calls /results Read call /result pair Tail tool rows
Main, tool repetition 1 yes 0 /0 0 /0 0
Main, tool repetition 2 yes 0 /0 0 /0 0
Candidate, tool repetition 1 yes 2 /2 1 /1 4
Candidate, tool repetition 2 yes 2 /2 1 /1 4
Main, no-tool control no tool requested 0 /0 0 /0 0
Candidate, no-tool control no tool requested 0 /0 0 /0 0

The extra candidate pair is the genuine native ToolSearch, not duplicate read recording. Every case retains four session-start/end events, confirming that main's missing tools are not disabled capture or failed execution.

Candidate tail, on both repetitions:

tool.call    ... tool_search {"query":"select:mcp__openclaw__read","max_results":5}
tool.result  ... tool_search ok
tool.call    ... read {"path":"<task-workspace>/proof.txt"}
tool.result  ... read ok

The redacted export retains the actual read identity and outcome:

{"type":"tool.call","data":{"toolCallId":"toolu_188069_tool-1","name":"read","args":{"path":"$WORKSPACE_DIR/proof.txt"}}}
{"type":"tool.result","data":{"toolCallId":"toolu_188069_tool-1","name":"read","status":"completed","success":true,"result":[{"type":"text","text":"TASK_188069_ACTUAL_READ_RECEIPT\n"}]}}

Zero-growth regression and checks

Removed the added fixture extraction, duplicate trajectory fixture cases and the introduced 153-line allocation. The existing correlation scenario now checks recorded unknown outcomes (no fabricated success) and a later settled completion; existing MCP/server-native timeout cases additionally assert no unobserved tool.result. Canonical prepared-context defaults replace duplicated fixture state, and the typed spawn assertion no longer needs a cast. Existing lifecycle, capture-opt-out, parser and consumer coverage remains in its existing owners.

  • Main's identical unknown-outcome regression fails: no recorded tool results, versus the expected three correlated outcomes.
  • Four owner/consumer suites passed 130 tests in aggregate; the final modified capture suite passed all 52 after the last consolidation.
  • Targeted formatting, oxlint, changed-page MDX and whitespace checks passed.
  • Final PR delta: production +23; tests +29/-29 (net 0); docs +2/-1. No added test file or test-line allocation remains.

Scope: this qualifies the real native CLI, tool, Gateway and SQLite consumer path against a deterministic local model fixture. It is not a live Anthropic-service/authentication test. Historical CLI turns and chat.history are not backfilled. An initial CONNECT pilot reached the real CLI but did not load its deferred read schema; it is retained as setup diagnostics and is not counted as a tool reproduction above.

@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Diagnostic contract retained on the repaired head

Head: 4ef98d9c7e95e21a2c924396c96482bc95627209.

Addressed the P3 test-retention finding: the ambiguous identical-call scenario again captures trusted diagnostic events and asserts exactly six, including both tool.execution.error events with tool_outcome_unknown, all three starts, and the later completed call. Those original diagnostic expectations now remain alongside the new trajectory-outcome assertions. MCP/server-native timeout cases still reject any unobserved trajectory tool.result.

The fixture cleanup inlines redundant single-identity emission wrappers and uses a standard recorder spy; the order and contents of the emitted CLI records and host outcomes are unchanged. This retains both independent output contracts without increasing test lines. The final capture suite passes 52/52, with targeted formatter/lint and whitespace checks passing. The other unchanged owner/consumer suites retain their earlier passing results (130 tests across the four suites in aggregate).

Production code is unchanged from both the built contributor revision and the independently proved previous head. Therefore the genuine Claude Code 2.1.309 / built Gateway / tail-and-export proof applies to this SHA unchanged: two actual-read reproductions per ref after later turns, candidate-only persisted tool pairs, and no-tool controls on both refs. No permission, auth or SDK changes were made.

Final surface: production +23; tests +30/-30 (net 0); docs +2/-1. No added test file or test-line allocation remains.

@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 30, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@obviyus
obviyus merged commit cd7a3fb into openclaw:main Oct 30, 2026
139 of 140 checks passed
@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Landed in cd7a3fb. Thanks @wyf027. Session tail and export now show tool calls from CLI-backed runs.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…ports (openclaw#188069)

fix(agents): record CLI backend tool calls in the session trajectory

Fixes openclaw#140273.

For CLI-backed agent runs (for example Claude Code), OpenClaw already observed each tool call and result, but it never passed them to the session trajectory recorder. Session tail and export therefore showed no tool activity even when the CLI read files. Those existing observations now go to the bounded trajectory recorder, so tool calls and results show up like they do for other runtimes.

Evidence: real Claude Code 2.1.309 driven through a built Gateway, routed to a local fixture over HTTPS CONNECT with a trusted test CA, with no login or paid key. After real file reads, session tail and export on main showed 0 tool calls or results (twice). With this change they showed both tool call and result pairs, ToolSearch and Read, with the actual file contents (twice). Runs without tool use recorded no tool rows on both refs. Details: openclaw#188069 (comment) and openclaw#188069 (comment).

Thanks @wyf027.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants