Skip to content

fix(gateway): silent exec-completion prompts show as user messages in imported Claude CLI history - #174780

Merged
obviyus merged 7 commits into
openclaw:mainfrom
maliv2:fix/claude-cli-silent-exec-prompt-display
Oct 26, 2026
Merged

obviyus merged 7 commits into
openclaw:mainfrom
maliv2:fix/claude-cli-silent-exec-prompt-display

Conversation

@maliv2

@maliv2 maliv2 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: #151962

What Problem This Solves

Imported Claude history can show silent background-command completion instructions as human messages. The original reader-only matcher did not cover durable catalog copies made by sessions import claude.

Why This Change Was Made

Recognize the producer's complete opening/closing frame once in the existing shared internal-wake classifier. Both generic transcript projection and the native Claude reader consume it; the duplicate reader-only matcher is removed. Require durable Claude catalog origin or explicit native-reader context, because canonical human rows can inherit importedFrom metadata during deduplication. Human quotes and canonical human rows remain visible. No generated prompt text, stored schema, or import policy changes.

Evidence

Inspected before/after screenshots and built-entry observations.

Synthetic native Claude JSONL imported through shipped sessions import claude into real isolated built Gateways; actual chat.history and compiled Control UI in Chromium, main twice and candidate twice. Main is 503bc1bd44992f5dc5426fe2f2fea263524fe0db, after #174815. Candidate behavior-bearing code is preserved at final head e2996b6f882619ed4b70547cf3906302015120f7 (last commit adds only an explanatory comment).

Main 2/2: five user rows — real control, silent completion, scratch completion,
retired response-tool completion, quoted control.
Candidate 2/2: two user rows — real control and quoted control.
All three internal completion envelopes absent from human projection.
Assistant response and imported-reference notice retained on both.

Focused shared classifier suite 28/28 and native importer suite 41/41 pass. Formatter and lint pass, zero lint warnings/errors. Canonical human duplicates, quoted text, incomplete frames, timestamp prefixes, scratch suffixes, and heartbeat-only classification boundaries are covered.

Not fixed here

This fixes silent background-command completion envelopes, not every phantom-message subtype in #151962. It does not change native producers, recover missing history, or claim that all imported internal-message shapes are classified. The broader issue should remain open. GitHub closingIssuesReferences was empty before push; this body intentionally says Related, not Fixes/Closes.

Simplification and Risk

The reader-only recognition path is replaced by the shared classifier; existing projection remains the sole display owner. The original contributor commits are preserved. Production +20/-3 and tests +47 against the integrated main baseline. Additional shared attribution checks and regressions are necessary to cover durable imports without hiding canonical human messages.

Two-way door: reverting restores the previous display classification without migrating data. Blast radius is imported Claude transcript visibility and shared wake classification; ordinary authored messages must remain visible.

…CLI history

The Claude CLI importer recognized the delivered exec-completion prompt as an internal turn but not the deliverToUser=false form, so Claude's native user row for it was shown as a human message. Match the whole silent frame (fixed opening and closing sentences), with and without the heartbeat response tool.
@clawsweeper

clawsweeper Bot commented Oct 16, 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 gateway Gateway runtime size: XS labels Oct 16, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 16, 2026
…eartbeat scratch

The heartbeat runner can append a scratch section after the prompt, so match the closing sentence anywhere in the body instead of at its end.
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR hides saved silent exec-completion prompts in imported Claude history through the shared internal-wake classifier.

Example: Import a Claude session containing a silent completion ending “Do not mention, summarize, or reuse command output.”

  • Before: The completion instructions appear as a human message.
  • After: The internal instructions disappear while genuine human messages, quoted instructions, and assistant replies remain visible.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong shipped-entry proof and a focused patch with no findings; the overall tier reflects intentionally partial coverage of the linked umbrella report.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): The shared classifier and native reader were exercised through shipped sessions import claude, built isolated Gateways, chat.history, and compiled Control UI in Chromium; inspected before/after screenshots show all three internal envelopes removed while human and quoted controls and assistant output remain.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Imported Claude history attributes silent background-command instructions to the human user.
Reason: This is a bounded repair of established history-display behavior, supported by collaborator-supplied production proof; the Related link correctly leaves the broader report open.

Merge readiness

✅ Ready for maintainer review

This PR fixes a concrete history-display bug that remains on current main; no actionable patch defects were found, and exact-head CI is still pending.

Priority: P2
Reviewed head: e2996b6f882619ed4b70547cf3906302015120f7

Before merge

None.

Findings

None.

Agent review details

How this fits together

Claude native history and durable catalog imports feed Gateway transcript projection, which returns human-facing messages through chat.history to Control UI.

flowchart TD
  A[Claude native history] --> B[Native history reader]
  A --> C[Durable catalog import]
  B --> D[Shared wake classifier]
  C --> D
  D --> E[History display projection]
  E --> F[Chat history RPC]
  F --> G[Control UI]
Loading

Technical review

Best possible solution:

Land the shared, attribution-scoped classifier repair while retaining the broader phantom-message issue for its remaining subtypes.

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

The supplied built-Gateway comparison reproduces the display failure on the integrated main baseline, and inspected screenshots agree with current-main source; no target code was executed during this review.

Is this the best way to solve the issue?

The patch uses the existing shared classifier for both import paths, preserves canonical human attribution, and adds no competing owner or persisted format.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Native Claude internal-frame recognition keeps the original intent (667b2e5: Recognize producer-owned runtime frames at import while retaining original text for canonical matching and preserving human rows.)
  • Shared silent transcript filtering keeps the original intent (2ab3a4e: Remove silent operational spans while preserving completed visible output and genuine user turns.)
  • Heartbeat-only truncated-token classification keeps the original intent (22799f8: Limit truncated silence recognition to heartbeat context rather than ordinary or other internal wakes.)
  • Shared periodic-task recognition keeps the original intent (503bc1b: Make generic history projection and the Claude reader recognize saved periodic-task heartbeat frames consistently.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Marvinthebored: Raw commit 667b2e5 adds src/gateway/cli-session-history.claude.ts:363 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 667b2e519112; files: src/gateway/cli-session-history.claude.ts)
  • mali: Raw commit 503bc1b adds src/auto-reply/heartbeat-filter.ts:33 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 503bc1bd4499; files: src/auto-reply/heartbeat-filter.ts)

PR surface

Source +17, Tests +47. Total +64 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 20 3 +17
Tests 2 47 0 +47
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 67 3 +64

Labels

Label changes:

  • add proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

Label justifications:

  • P2: Internal completion instructions appear as human messages in imported history, with a limited and well-defined display impact.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; 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.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

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 (3 earlier review cycles)
  • reviewed 2026-10-16T22:57:23.787Z sha 211a432 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-17T10:42:20.728Z sha 211a432 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-21T23:25:15.910Z sha 211a432 :: needs maintainer review before merge. :: none

Reviewed October 26, 2026, 12:20 PM ET / 16:20 UTC (Revision 4).

@maliv2

maliv2 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 17, 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 17, 2026
@maliv2

maliv2 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 21, 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Oct 21, 2026
@obviyus

obviyus commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Root-cause completion after integrating #174815: the initial reader-only patch did not fix durable sessions import claude copies. Recognition now lives once in the shared internal-wake classifier consumed by generic projection and the native reader; the reader-only matcher is removed. Attribution guard preserves canonical human rows even when native deduplication adds importedFrom metadata. Built-Gateway proof, main 503bc1b twice versus repaired candidate twice: synthetic Claude JSONL → shipped sessions import claude → real chat.history → compiled Control UI in Chromium. Main projects five user rows (real control, silent completion, scratch-bearing completion, retired response-tool completion, quoted control); candidate projects only the two genuine controls. All three internal envelopes are absent from human projection, with assistant response/import notice preserved. Screenshots inspected below. Focused shared-filter tests 28/28 and native importer tests 41/41 pass; lint zero warnings/errors. Final head e2996b6 differs from the proven behavior-bearing commit only by an explanatory comment. Related #151962, not a claim to fix every phantom-message subtype.

Before: three internal silent completion envelopes appear as user bubbles

After: shared classifier removes internal envelopes while preserving human and quoted controls

@obviyus

obviyus commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
@obviyus
obviyus merged commit cd3bcc0 into openclaw:main Oct 26, 2026
132 of 133 checks passed
@obviyus

obviyus commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Landed in cd3bcc0. Thanks @maliv2. Imported Claude history no longer shows silent completion envelopes as user messages.

github-actions Bot pushed a commit to KrillDD6869/openclaw that referenced this pull request Oct 26, 2026
… imported Claude CLI history (#174780)

fix(claude-cli): stop silent background-command completion envelopes showing as user messages

Imported Claude history showed OpenClaw's internal silent background-command completion envelopes as human user messages. They are now recognized by the shared internal-wake classifier, the same owner that handles heartbeat instructions, so durable imports and the native history reader both leave them out. Real user text, quoted envelope text, assistant replies and the import notice are unchanged.

Evidence: synthetic native Claude sessions imported with the shipped `sessions import claude` into built Gateways. On main chat.history and the Control UI in Chromium showed all three silent-completion variants as user messages (twice); with this change they are gone (twice), while the real and quoted controls remain. Screenshots: openclaw/openclaw#174780 (comment). The rest of #151962 is not addressed here.

Thanks @maliv2.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to SharonZ92901/openclaw that referenced this pull request Oct 26, 2026
… imported Claude CLI history (#174780)

fix(claude-cli): stop silent background-command completion envelopes showing as user messages

Imported Claude history showed OpenClaw's internal silent background-command completion envelopes as human user messages. They are now recognized by the shared internal-wake classifier, the same owner that handles heartbeat instructions, so durable imports and the native history reader both leave them out. Real user text, quoted envelope text, assistant replies and the import notice are unchanged.

Evidence: synthetic native Claude sessions imported with the shipped `sessions import claude` into built Gateways. On main chat.history and the Control UI in Chromium showed all three silent-completion variants as user messages (twice); with this change they are gone (twice), while the real and quoted controls remain. Screenshots: openclaw/openclaw#174780 (comment). The rest of #151962 is not addressed here.

Thanks @maliv2.

Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Thanks @maliv2 for the silent completion repair. Merged with shared-classifier coverage for both native history and durable imports, preserving human/quoted controls. Broader #151962 remains separate.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
… imported Claude CLI history (openclaw#174780)

fix(claude-cli): stop silent background-command completion envelopes showing as user messages

Imported Claude history showed OpenClaw's internal silent background-command completion envelopes as human user messages. They are now recognized by the shared internal-wake classifier, the same owner that handles heartbeat instructions, so durable imports and the native history reader both leave them out. Real user text, quoted envelope text, assistant replies and the import notice are unchanged.

Evidence: synthetic native Claude sessions imported with the shipped `sessions import claude` into built Gateways. On main chat.history and the Control UI in Chromium showed all three silent-completion variants as user messages (twice); with this change they are gone (twice), while the real and quoted controls remain. Screenshots: openclaw#174780 (comment). The rest of openclaw#151962 is not addressed here.

Thanks @maliv2.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Oct 27, 2026
…t history (#184216)

Related: #174780

## What Problem This Solves

Fixes: background exec completion notices show as user messages in Control UI history for Claude CLI sessions.

## User Impact

In Claude CLI sessions, the internal `[OpenClaw exec completion]` wake no longer appears as if the user typed it. The model still receives the wake and reports the result. A person who pastes wake text and adds a question still sees that message. Other backends are unchanged.

## Why This Change Was Made

Claude Code records every stream-json input as an ordinary user row, so the history importer had to recognize wakes by their exact text. That broke when #182188 changed the wake frame. Another text matcher would break again the next time any wake text changes.

Claude Code has a native marker for this case. Input sent with `isSynthetic: true` is saved as a meta row (`isMeta: true`, `turnOrigin: "host_synthetic"`), and the model still receives it. The importer already omits meta rows. The fix:

- Core sets a new optional `promptOrigin: "host"` on the CLI backend execute context for exec completion wakes.
- The bundled Claude runtime sends that prompt as synthetic input.
- Steering messages that a person injects into the same turn stay ordinary user input.

With this change, provenance comes from Claude itself instead of from text matching. The text matchers for shipped frames (the older prose wake and the silent wake from #174780) stay in place for existing transcripts. The current wake prompt, built in #182188, never reached a stable release, so it needs no matcher; stable releases used the bare `[OpenClaw exec completion]` string only as OpenClaw's own placeholder row, which existing filters already hide.

Plugin SDK: additive only. `CliBackendExecuteContext` gains the optional `promptOrigin?: "host"` (documented in `docs/plugins/cli-backend-plugins.md`). `plugin-sdk:api:diff` against the merge base reports only this declaration.

Credit: @Marvinthebored found and reported the regression, and wrote the first fix on this branch.

## Evidence

**Live Gateway, real Claude CLI (Claude Code 2.1.310).** I ran two isolated Gateways (own state, port and workspace), one from `main` (`d0916212f`) and one from this branch. Each used a `claude-cli` Sonnet model and was driven through `chat.send`.

Steps:

1. The model starts `sleep 8; echo wake-e2e-done` as a background OpenClaw exec. The completion wakes the session.
2. A person sends pasted wake text with `Why did you send this?` appended.

`chat.history` rows:

```text
main
user       Use your OpenClaw exec tool (not native Bash) to run: sleep 8; echo wake-e2e-done…
assistant  Started in background (session mild-reef); ending the turn now…
user       [OpenClaw exec completion]↵Exec completed (mild-ree, code 0) :: wake-e2e-done↵↵Treat this…   <- internal wake shown as user
assistant  The background command finished: `wake-e2e-done`.
user       [OpenClaw exec completion]↵Exec completed (pasted, code 0) :: done↵↵Why did you send this?
assistant  I ran `sleep 8; echo wake-e2e-done` in the background per your earlier instruction…

this PR
user       Use your OpenClaw exec tool (not native Bash) to run: sleep 8; echo wake-e2e-done…
assistant  Started the background command (session nimble-gulf). I'll be notified when it exits.
assistant  Background command finished successfully: `wake-e2e-done` (exit 0).
user       [OpenClaw exec completion]↵Exec completed (pasted, code 0) :: done↵↵Why did you send this?
assistant  I sent that because you'd asked me to run `sleep 8; echo wake-e2e-done` as a background ex…
```

Native Claude rows for the wake turn:

- On `main`: an ordinary user row (`turnOrigin: "sdk"`).
- With this PR: `isMeta: true`, `turnOrigin: "host_synthetic"`. Claude prefixes the content with `[MESSAGE FROM NON-USER SOURCE - NOT USER INPUT]`, and the model still acts on it.

**Claude Code behavior checks**, with direct `claude -p --input-format stream-json` probes:

- Synthetic input reaches the model and survives `--resume`. The model repeated a word given only in a synthetic message on the next resumed turn.
- The `UserPromptSubmit` hook still fires for synthetic input, so private resume context and steering admission are unchanged.

**Tests**

- `cli-runtime.test.ts`: a host prompt is sent with `isSynthetic`, and an ordinary prompt is not.
- `execute-plugin.test.ts`: only exec completion wakes get `promptOrigin: "host"`. Heartbeat, external user and missing provenance do not.
- Focused suites pass: `extensions/anthropic/cli-runtime.test.ts`, `src/agents/cli-runner/execute-plugin.test.ts`, `src/gateway/cli-session-history.test.ts` and `src/gateway/cli-session-history.claude-input.test.ts`.
- `oxlint` and `oxfmt` are clean on the touched files.

**Gaps**

- Paired-node Claude execution uses the host-managed process path and does not send stream-json input. Wakes there still rely on existing behavior.
- Heartbeat and restart-recovery prompts still use the existing text recognition. Moving them to `promptOrigin` needs separate proof that Claude's non-user framing does not change how the model treats heartbeat task instructions.

**Merge danger:** two-way door. Reverting restores the previous native rows. Already-written meta rows stay hidden, which is correct for internal wakes. Blast radius: Claude CLI sessions with background exec completion wakes. Third-party CLI backend plugins can ignore the new optional field.

Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Oct 27, 2026
…matchers (#185746)

Related: #184216, #174780, #166080

## What Problem This Solves

Claude CLI history hid OpenClaw-generated turns (exec completion wakes, heartbeats, restart recovery) by matching their exact prompt text. Each time a prompt's wording changed, the matcher missed it, and the internal turn showed in history as if the user had typed it. The current restart-recovery wording is already unmatched.

## Why This Change Was Made

#184216 used Claude Code's native marker for exec wakes. Input sent with `isSynthetic: true` is stored as a meta row (`isMeta: true`, `turnOrigin: "host_synthetic"`). The model still receives it, and the history importer already drops meta rows.

This PR applies the same marker to every OpenClaw-generated turn and deletes the text matchers:

- The CLI runner sets `promptOrigin: "host"` exactly when the run's input provenance is `internal_system`. Provenance is the one signal for "OpenClaw wrote this turn".
- Isolated cron recorded its `internal_system` provenance on the transcript row only and never passed it to the CLI run, so cron prompts reached Claude as ordinary user input. The cron executor now passes that provenance to `runCliAgent`. Hook-mapped jobs carry external content and get no provenance, so they stay ordinary input. Other runtimes are unchanged: Codex's scheduled-MCP authority and the requester tool policy read run provenance, and this change does not touch them.
- The importer keeps only Claude's own frames (`/compact`, a resume note with no prompt), the task-notification and interrupt markers, and the inbound-context stripping that matches decorated human rows to canonical rows.
- Removed:
  - the exec-wake, heartbeat and restart-recovery text matchers in `cli-session-history.claude.ts`
  - the silent exec-wake branch in `heartbeat-filter.ts`
  - their fixtures and tests

Net: +15 / −182.

## User Impact

- New Claude CLI history never shows OpenClaw-generated turns as user messages, whatever the prompt wording.
- Older Claude CLI transcripts, written before #184216, can show those internal frames as user messages again. This is a display change.
- One model-facing reader is affected. When a Claude CLI run falls back to another provider, `readClaudeCliFallbackSeed` builds a recent-turns prelude from native history. That reader skips meta rows, so cron and recovery prompts are now left out of the prelude, as exec wakes already are since #184216. The assistant replies stay in it.
- Other backends are unchanged.

## Evidence

Isolated Gateway on this branch, real Claude CLI (Claude Code 2.1.310), `claude-cli` Sonnet. I checked the native Claude rows and `chat.history`:

| Turn | Native row | Model followed the turn | Shown as user |
| --- | --- | --- | --- |
| Isolated cron job: "create `cron-isolated.txt` containing `<nonce>`" | `isMeta: true`, `host_synthetic` | yes, the file was written with the exact nonce | no |
| Main-session cron job, same task | `isMeta: true`, `host_synthetic` | yes, the file was written | no (history shows only the assistant's "Done.") |
| Background exec completion wake | meta (as in #184216) | yes, it reported `wake-e2e-done` | no |
| Person pastes wake text plus a question | ordinary row | yes | yes (`external_user`) |

Before the cron provenance hand-off, the isolated cron row was `turnOrigin: "sdk"`, an ordinary user row, because the run had no provenance.

These cron runs also answer the open question from #184216: Claude labels synthetic input "NOT USER INPUT", but the model still carried out the job's instructions.

Tests:

- `execute-plugin.test.ts`: `internal_system` provenance (exec, cron) gives `promptOrigin: "host"`; inter-session, external-user and absent provenance do not.
- `run.cli-ownership.test.ts`: the cron executor passes `{kind: "internal_system", sourceTool: "cron"}` to `runCliAgent`. It fails without the executor change.
- Focused suites pass: `execute-plugin`, `run.cli-ownership`, `run.message-tool-policy`, `run.payload-fallbacks`, `heartbeat-filter`, `cli-session-history.claude-input`, `cli-session-history.paging`, `cli-session-history`, `extensions/anthropic/cli-runtime`.
- `tsgo:core` and `tsgo:core:test` pass. `oxlint` and `oxfmt` are clean.

Gaps:

- Restart recovery uses the same `internal_system` provenance as the exec wake. I could not trigger an automatic recovery turn on a non-main CLI session in the isolated Gateway, so it is covered by the provenance rule and unit test, not by a live run.
- Paired-node Claude execution does not use stream-json input and is unchanged.

Credit: @Marvinthebored reported the exec-wake and restart-recovery history regressions that led here.

**Merge danger:** two-way door. A revert restores the matchers. Meta rows already written stay hidden, which is correct for internal turns. Blast radius: Claude CLI history display, and the fallback recent-turns prelude described above. Pre-#184216 internal frames reappear in old transcripts. Third-party CLI backends can ignore `promptOrigin`.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…t history (openclaw#184216)

Related: openclaw#174780

## What Problem This Solves

Fixes: background exec completion notices show as user messages in Control UI history for Claude CLI sessions.

## User Impact

In Claude CLI sessions, the internal `[OpenClaw exec completion]` wake no longer appears as if the user typed it. The model still receives the wake and reports the result. A person who pastes wake text and adds a question still sees that message. Other backends are unchanged.

## Why This Change Was Made

Claude Code records every stream-json input as an ordinary user row, so the history importer had to recognize wakes by their exact text. That broke when openclaw#182188 changed the wake frame. Another text matcher would break again the next time any wake text changes.

Claude Code has a native marker for this case. Input sent with `isSynthetic: true` is saved as a meta row (`isMeta: true`, `turnOrigin: "host_synthetic"`), and the model still receives it. The importer already omits meta rows. The fix:

- Core sets a new optional `promptOrigin: "host"` on the CLI backend execute context for exec completion wakes.
- The bundled Claude runtime sends that prompt as synthetic input.
- Steering messages that a person injects into the same turn stay ordinary user input.

With this change, provenance comes from Claude itself instead of from text matching. The text matchers for shipped frames (the older prose wake and the silent wake from openclaw#174780) stay in place for existing transcripts. The current wake prompt, built in openclaw#182188, never reached a stable release, so it needs no matcher; stable releases used the bare `[OpenClaw exec completion]` string only as OpenClaw's own placeholder row, which existing filters already hide.

Plugin SDK: additive only. `CliBackendExecuteContext` gains the optional `promptOrigin?: "host"` (documented in `docs/plugins/cli-backend-plugins.md`). `plugin-sdk:api:diff` against the merge base reports only this declaration.

Credit: @Marvinthebored found and reported the regression, and wrote the first fix on this branch.

## Evidence

**Live Gateway, real Claude CLI (Claude Code 2.1.310).** I ran two isolated Gateways (own state, port and workspace), one from `main` (`3240d0117`) and one from this branch. Each used a `claude-cli` Sonnet model and was driven through `chat.send`.

Steps:

1. The model starts `sleep 8; echo wake-e2e-done` as a background OpenClaw exec. The completion wakes the session.
2. A person sends pasted wake text with `Why did you send this?` appended.

`chat.history` rows:

```text
main
user       Use your OpenClaw exec tool (not native Bash) to run: sleep 8; echo wake-e2e-done…
assistant  Started in background (session mild-reef); ending the turn now…
user       [OpenClaw exec completion]↵Exec completed (mild-ree, code 0) :: wake-e2e-done↵↵Treat this…   <- internal wake shown as user
assistant  The background command finished: `wake-e2e-done`.
user       [OpenClaw exec completion]↵Exec completed (pasted, code 0) :: done↵↵Why did you send this?
assistant  I ran `sleep 8; echo wake-e2e-done` in the background per your earlier instruction…

this PR
user       Use your OpenClaw exec tool (not native Bash) to run: sleep 8; echo wake-e2e-done…
assistant  Started the background command (session nimble-gulf). I'll be notified when it exits.
assistant  Background command finished successfully: `wake-e2e-done` (exit 0).
user       [OpenClaw exec completion]↵Exec completed (pasted, code 0) :: done↵↵Why did you send this?
assistant  I sent that because you'd asked me to run `sleep 8; echo wake-e2e-done` as a background ex…
```

Native Claude rows for the wake turn:

- On `main`: an ordinary user row (`turnOrigin: "sdk"`).
- With this PR: `isMeta: true`, `turnOrigin: "host_synthetic"`. Claude prefixes the content with `[MESSAGE FROM NON-USER SOURCE - NOT USER INPUT]`, and the model still acts on it.

**Claude Code behavior checks**, with direct `claude -p --input-format stream-json` probes:

- Synthetic input reaches the model and survives `--resume`. The model repeated a word given only in a synthetic message on the next resumed turn.
- The `UserPromptSubmit` hook still fires for synthetic input, so private resume context and steering admission are unchanged.

**Tests**

- `cli-runtime.test.ts`: a host prompt is sent with `isSynthetic`, and an ordinary prompt is not.
- `execute-plugin.test.ts`: only exec completion wakes get `promptOrigin: "host"`. Heartbeat, external user and missing provenance do not.
- Focused suites pass: `extensions/anthropic/cli-runtime.test.ts`, `src/agents/cli-runner/execute-plugin.test.ts`, `src/gateway/cli-session-history.test.ts` and `src/gateway/cli-session-history.claude-input.test.ts`.
- `oxlint` and `oxfmt` are clean on the touched files.

**Gaps**

- Paired-node Claude execution uses the host-managed process path and does not send stream-json input. Wakes there still rely on existing behavior.
- Heartbeat and restart-recovery prompts still use the existing text recognition. Moving them to `promptOrigin` needs separate proof that Claude's non-user framing does not change how the model treats heartbeat task instructions.

**Merge danger:** two-way door. Reverting restores the previous native rows. Already-written meta rows stay hidden, which is correct for internal wakes. Blast radius: Claude CLI sessions with background exec completion wakes. Third-party CLI backend plugins can ignore the new optional field.

Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…matchers (openclaw#185746)

Related: openclaw#184216, openclaw#174780, openclaw#166080

## What Problem This Solves

Claude CLI history hid OpenClaw-generated turns (exec completion wakes, heartbeats, restart recovery) by matching their exact prompt text. Each time a prompt's wording changed, the matcher missed it, and the internal turn showed in history as if the user had typed it. The current restart-recovery wording is already unmatched.

## Why This Change Was Made

openclaw#184216 used Claude Code's native marker for exec wakes. Input sent with `isSynthetic: true` is stored as a meta row (`isMeta: true`, `turnOrigin: "host_synthetic"`). The model still receives it, and the history importer already drops meta rows.

This PR applies the same marker to every OpenClaw-generated turn and deletes the text matchers:

- The CLI runner sets `promptOrigin: "host"` exactly when the run's input provenance is `internal_system`. Provenance is the one signal for "OpenClaw wrote this turn".
- Isolated cron recorded its `internal_system` provenance on the transcript row only and never passed it to the CLI run, so cron prompts reached Claude as ordinary user input. The cron executor now passes that provenance to `runCliAgent`. Hook-mapped jobs carry external content and get no provenance, so they stay ordinary input. Other runtimes are unchanged: Codex's scheduled-MCP authority and the requester tool policy read run provenance, and this change does not touch them.
- The importer keeps only Claude's own frames (`/compact`, a resume note with no prompt), the task-notification and interrupt markers, and the inbound-context stripping that matches decorated human rows to canonical rows.
- Removed:
  - the exec-wake, heartbeat and restart-recovery text matchers in `cli-session-history.claude.ts`
  - the silent exec-wake branch in `heartbeat-filter.ts`
  - their fixtures and tests

Net: +15 / −182.

## User Impact

- New Claude CLI history never shows OpenClaw-generated turns as user messages, whatever the prompt wording.
- Older Claude CLI transcripts, written before openclaw#184216, can show those internal frames as user messages again. This is a display change.
- One model-facing reader is affected. When a Claude CLI run falls back to another provider, `readClaudeCliFallbackSeed` builds a recent-turns prelude from native history. That reader skips meta rows, so cron and recovery prompts are now left out of the prelude, as exec wakes already are since openclaw#184216. The assistant replies stay in it.
- Other backends are unchanged.

## Evidence

Isolated Gateway on this branch, real Claude CLI (Claude Code 2.1.310), `claude-cli` Sonnet. I checked the native Claude rows and `chat.history`:

| Turn | Native row | Model followed the turn | Shown as user |
| --- | --- | --- | --- |
| Isolated cron job: "create `cron-isolated.txt` containing `<nonce>`" | `isMeta: true`, `host_synthetic` | yes, the file was written with the exact nonce | no |
| Main-session cron job, same task | `isMeta: true`, `host_synthetic` | yes, the file was written | no (history shows only the assistant's "Done.") |
| Background exec completion wake | meta (as in openclaw#184216) | yes, it reported `wake-e2e-done` | no |
| Person pastes wake text plus a question | ordinary row | yes | yes (`external_user`) |

Before the cron provenance hand-off, the isolated cron row was `turnOrigin: "sdk"`, an ordinary user row, because the run had no provenance.

These cron runs also answer the open question from openclaw#184216: Claude labels synthetic input "NOT USER INPUT", but the model still carried out the job's instructions.

Tests:

- `execute-plugin.test.ts`: `internal_system` provenance (exec, cron) gives `promptOrigin: "host"`; inter-session, external-user and absent provenance do not.
- `run.cli-ownership.test.ts`: the cron executor passes `{kind: "internal_system", sourceTool: "cron"}` to `runCliAgent`. It fails without the executor change.
- Focused suites pass: `execute-plugin`, `run.cli-ownership`, `run.message-tool-policy`, `run.payload-fallbacks`, `heartbeat-filter`, `cli-session-history.claude-input`, `cli-session-history.paging`, `cli-session-history`, `extensions/anthropic/cli-runtime`.
- `tsgo:core` and `tsgo:core:test` pass. `oxlint` and `oxfmt` are clean.

Gaps:

- Restart recovery uses the same `internal_system` provenance as the exec wake. I could not trigger an automatic recovery turn on a non-main CLI session in the isolated Gateway, so it is covered by the provenance rule and unit test, not by a live run.
- Paired-node Claude execution does not use stream-json input and is unchanged.

Credit: @Marvinthebored reported the exec-wake and restart-recovery history regressions that led here.

**Merge danger:** two-way door. A revert restores the matchers. Meta rows already written stay hidden, which is correct for internal turns. Blast radius: Claude CLI history display, and the fallback recent-turns prelude described above. Pre-openclaw#184216 internal frames reappear in old transcripts. Third-party CLI backends can ignore `promptOrigin`.

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

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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