Skip to content

fix: let plugin helpers keep exec after a subagent reports back - #206174

Open
etzelm wants to merge 3 commits into
openclaw:mainfrom
etzelm:fix/fork-owner-click-exec
Open

etzelm wants to merge 3 commits into
openclaw:mainfrom
etzelm:fix/fork-owner-click-exec

Conversation

@etzelm

@etzelm etzelm commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #206173

What Problem This Solves

Plugin helpers that fork a chat with exec stop working right after a subagent finishes in that chat. Better (obviyus/openclaw-better-prompt) is one of them: the owner clicks Better in a chat where a subagent just reported back, and gets "This chat's tool policy does not allow read, ls and exec, so the helper cannot read your files." The click only works again after the owner sends a throwaway message. Chats that use subagents, such as Goal chats, hit this most.

User Impact

  • The owner can use fork-based helpers right after a subagent finishes, with no extra message.
  • Nothing changes for non-owners. A session writer, or anyone whose turn was not the owner's, is still refused exec. A signed-in caller still needs to be the person who sent the turn, as fix(plugins): run session-scoped plugin forks in the admitted session #204411 set.
  • Known limit: a completion report stored before this change has no marker, so it behaves as today. If the latest row in a chat is such a report, the owner still needs to send one message, once. The next report the Gateway delivers is marked. There is no backfill. Existing transcripts, sessions and settings load unchanged after an upgrade (proof below).
  • No config, schema, protocol or SDK change. The new field is internal transcript metadata.

Why This Change Was Made

A plugin fork checks tool policy as the requester of the turn it reads through, and takes that requester from the latest user-role row. A subagent's completion report is a user-role row, but it records no owner: it delivers the result of work an earlier turn started. So the fork judged the owner's click by the report instead of by the owner's turn.

The fork already skips steering rows for the same reason (a steer joins the running turn). It now also skips completion reports, but only the ones the Gateway delivered itself:

  • When the host's own completion delivery writes a report (subagent_settle, subagent_announce, or an agent-mediated completion), the Gateway records __openclaw.hostCompletion: true on the row. It sets this only on its own write path, for backend callers (the same canUseInternalRuntimeHandoff check that already guards other internal handoff controls).
  • A client can still send completion provenance through agent; upstream accepts that on purpose. Its row carries no marker, so it stays that client's own input. agent params cannot carry the marker (the agent and provenance schemas are closed), and a before_message_write hook can neither add the marker nor keep a forged one.
  • A marked report that names a sender other than the earlier input's sender is not skipped.
  • If no earlier input is in the read window, the report's own facts are used, as before, so a read-only fork never starts failing.

Decisions

Choice Evidence How to reverse
Skip completion reports when finding the turn's requester Same model as steering rows. One requester for the whole fork, so read/ls policy and the run's requester stay consistent. Drop the completion branch in readSessionForkTurn.
Skip only reports the host marked The agent method accepts completion provenance from any operator.write client, and a client without a signed-in identity records no sender. Without the marker, such a row would borrow the owner's earlier turn. Drop the hostCompletion check in the reader.
Mark on the write path, not reserve provenance in preflight Rejecting completion provenance from public callers would change maintained behavior: agent.events-and-subagents asserts a public caller may send subagent_announce provenance and is recorded as non-owner. The marker leaves that behavior alone. Reserve the provenance in agent-request-preflight.ts instead.
Do not admit exec on the signed-in caller's own authority #204411 tests on purpose that a signed-in admin is refused exec on another owner's turn through a sessionAccess method. #205483 removed a second owner producer so one turn gives one owner answer. Not built.
No backfill of old rows A stored row cannot prove after the fact that the host wrote it. Old rows keep today's behavior, which is safe and costs at most one message. Not built.

Evidence

Real-model proof, before and after. A throwaway Gateway on a Mac with its own HOME and OPENCLAW_STATE_DIR, Better 0.1.1 installed from its published package, and a real model: anthropic/claude-haiku-4-5 on the claude-cli runtime with a Claude Code setup token, the routing a Claude subscription install uses. Tool profile coding. The owner asks the agent to call sessions_spawn; the model does, the child runs on the same model and finishes, and the Gateway delivers its completion report into the chat. Then the owner clicks Better with no new message, asking the helper to run sh probe.sh, which writes a marker file when exec runs. Rows are read from the stored transcript.

Base 36395007cf0b:

user row: senderIsOwner=1 hostCompletion=- provenance=external_user/- text=Call the sessions_spawn tool exactly onc
user row: senderIsOwner=0 hostCompletion=- provenance=inter_session/subagent_settle text=[Subagent Context] Every subagent in thi
== owner clicks Better, no new message
TAKE {"ok":true,"result":{"error":"This chat's tool policy does not allow read, ls and exec, so the helper cannot read your files."}}
== exec marker: absent (exec did not run)

Head (this PR):

user row: senderIsOwner=1 hostCompletion=- provenance=external_user/- text=Call the sessions_spawn tool exactly onc
user row: senderIsOwner=0 hostCompletion=1 provenance=inter_session/subagent_announce text=Continue the OpenClaw runtime event.
== owner clicks Better, no new message
TAKE {"ok":true,"result":{"improved":"Run probe.sh to confirm the release status, then investigate what the fork divergence and pending fix actually are (inspect git history, the fork point, and what changed), ..."}}
== exec marker: PROBE_EXEC_RAN 21:53:13

Both report kinds (subagent_settle from a yield wake, subagent_announce from a direct completion) are completion reports, and the real in-process delivery wrote the marker on head. The setup token was passed on stdin only; a scan of each run directory found it in 0 files.

Upgrade from the latest stable release (2026.11.10, npm). One state directory, first run on the published 2026.11.10 build, then on this PR's build:

== phase=stable gateway=OpenClaw 2026.11.10 (6ea542f)
user row: senderIsOwner=1 hostCompletion=- provenance=external_user/- text=Call the sessions_spawn tool exactly onc
user row: senderIsOwner=- hostCompletion=- provenance=inter_session/subagent_announce text=Continue the OpenClaw runtime event.
TAKE {"ok":true,"result":{"error":"plugin \"better-prompt\" may not add core tool \"read\" to subagent runs."}}

== phase=upgrade (this PR's build, same state directory)
[state/upgrade] Migrated .../state/openclaw.sqlite in place from schema 40.
[state/upgrade] Migrated .../agents/main/agent/openclaw-agent.sqlite in place from schema 42.
== sessions.list after upgrade:
    agent:main:dashboard:<id> label=Goal chat model=claude-haiku-4-5
    agent:main:subagent:<id> label=- model=claude-haiku-4-5
== settings after upgrade: model=anthropic/claude-haiku-4-5 toolProfile=coding better=true
== owner clicks Better on the old chat, no new message
TAKE {"ok":true,"result":{"improved":"Deeper release notes from upgrade test evidence. ..."}}
== a new subagent finishes on this PR's build
user row: senderIsOwner=0 hostCompletion=1 provenance=inter_session/subagent_announce text=Continue the OpenClaw runtime event.
== owner clicks Better, no new message
TAKE {"ok":true,"result":{"improved":"Write release notes for OpenClaw Gateway 2026.11.10 upgrade, ..."}}
== exec marker: PROBE_EXEC_RAN 22:04:16

The transcript, sessions and settings load after the migration. The published 2026.11.10 build refuses Better's core tools entirely (it predates core tools in plugin forks), so the stable side has no "before" for this bug. Its completion report was stored as a steer into the owner's running turn (steerTargetRunId on the row), which the fork already skipped before this change, so that old row behaves as before.

Old unmarked report as its own turn (the known limit). The base build's state from the first run, upgraded to this PR's build:

user row: senderIsOwner=1 hostCompletion=- provenance=external_user/- text=Call the sessions_spawn tool exactly onc
user row: senderIsOwner=0 hostCompletion=- provenance=inter_session/subagent_settle text=[Subagent Context] Every subagent in thi
== owner clicks Better on the old chat, no new message
TAKE {"ok":true,"result":{"error":"This chat's tool policy does not allow read, ls and exec, so the helper cannot read your files."}}
== a new subagent finishes on this PR's build
user row: senderIsOwner=0 hostCompletion=1 provenance=inter_session/subagent_announce text=Continue the OpenClaw runtime event.
== owner clicks Better, no new message
TAKE {"ok":true,"result":{"improved":"Run `sh probe.sh` to verify the release is ready, then write comprehensive release notes ..."}}

The old unmarked report is refused exactly as before; the next report the Gateway delivers is marked, and the fork is admitted with read, ls and exec. Here the model rewrote the request instead of running probe.sh, so no marker file; the admission itself is the change (base and the old row return the refusal above before any model call).

Regression tests.

  • gateway-plugin-forked-turn-session-tools.e2e.test.ts (real Gateway, scripted model): a report written through agent by a local backend Gateway client (the host's delivery path) is skipped, and the owner's fork runs exec. An ordinary client's agent call with hostCompletion in its params, or inside inputProvenance, is rejected as invalid params. The same client's report without the marker stays its own input, and exec is refused before any model call. A host report after a non-owner channel turn is still refused. A signed-in caller's own report through a sessionAccess method is refused.

  • session-manager-model-context-limits.test.ts: the reader skips a marked report, keeps an unmarked report (subagent or media) as its own input, keeps a marked report that names another sender, and falls back to a lone report's own facts.

  • user-turn-transcript.persistence.test.ts: the marker survives a write hook that clears metadata, a hook cannot add it to an unmarked report, and it is never written on an input that is not a completion report.

  • gateway-plugin-forked-turn.e2e.test.ts: a chat whose only input is a completion report still forks.

  • Red (the source fix reverted with git apply -R, new tests kept): the host-report e2e case, the reader unit test and the write-hook test fail.

  • Mutations, each removing one guard:

    • the reader ignores the marker: the forged-report cases fail in both e2e tests (the fork settles with exec), and the reader unit test fails;
    • the Gateway never writes the marker: the host-report e2e case fails (refused);
    • the write path keeps a hook's marker: the write-hook test fails.
  • Green on head: e2e 10 of 10, unit and consumer tests all pass.

  • Consumers of the changed reader and user-turn writer: session-fork-run.test.ts, prompt-cache-keep-warm.test.ts, input-provenance.test.ts, user-turn-transcript.test.ts, agent-run-user-turn.test.ts and the agent handler tests pass.

Not covered. The Control UI button itself was not clicked in a browser; the click goes through the same plugins.sessionAction method the button calls. The e2e host path is a local backend Gateway client, not the in-process announce dispatch; the real-model runs cover the in-process path with a real child. An earlier run of the same flow with a loopback mock model gave the same before and after.

🦞 Made with OpenClaw

A plugin fork reads its requester from the latest user-role row. When a
subagent had just finished, that row was the completion report, which
records no owner, so an owner's fork with exec (Better) was refused
until the owner sent another message.

The Gateway now marks a completion report it delivered itself
(__openclaw.hostCompletion), set only for backend callers on the host's
own write path. Agent params cannot carry it, and a write hook can
neither add nor keep it. The fork skips only marked reports, the same
way it skips steering rows, and takes the requester of the input before
them. A marked report that names a different sender is not skipped.
Reports sent through the agent method by a client stay that client's
input. Rows from before this change have no marker and behave as before.
@clawsweeper

clawsweeper Bot commented Nov 26, 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 docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling plugin: file-transfer size: M labels Nov 26, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. labels Nov 26, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 26, 2026
@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

The PR marks host-delivered completion reports so plugin forks retain the preceding input's requester.

Example: An owner starts a subagent, waits for its completion report, then invokes Better 0.1.1 without sending another message.

  • Before: The helper returns tool_policy and cannot run sh probe.sh.
  • After: The helper is admitted and the recorded exec probe writes PROBE_EXEC_RAN.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, worthwhile repair with real-model and upgrade evidence, resolved prior feedback, and no blocking findings; exact-head CI remains pending.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Terminal evidence exercises the changed writer and reader through an isolated Gateway, real subagent completion, Better's shipped session-action RPC and actual exec; the latest-stable upgrade retains settings and transcripts, including the documented unmarked-row behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Owners cannot use exec-based plugin helpers immediately after a subagent reports back unless they send another message.
Reason: This restores the intended helper flow through shared core ownership while preserving client-originated inputs and existing access restrictions.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current requester-selection bug without weakening the existing exec checks; the earlier fixture finding is resolved, and no blocking defects remain.

Reviewed head: 5e2abf38ba93090c91fb43200b0a8b1ebb488180

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway records user-turn metadata; the session-fork reader selects requester facts that the existing fork admission owner uses to check tools and authenticated callers.

flowchart TD
  A[Host completion delivery] --> B[Gateway user turn writer]
  B --> C[Transcript metadata]
  D[Plugin helper request] --> E[Session fork reader]
  C --> E
  E --> F[Existing tool and caller checks]
  F --> G[Hidden fork execution]
Loading

Technical review

Best possible solution:

Keep requester selection in the existing fork reader, preserve host-only completion marking, and retain the current admission checks and historical-row behavior.

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

Current-main source establishes the refusal path, and the contributor's terminal evidence demonstrates it before the fix; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The repair uses the existing transcript writer and fork reader, distinguishes host delivery from caller-supplied provenance, and preserves the established owner and caller restrictions.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +45, Tests +221, Docs +4. Total +270 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 48 3 +45
Tests 5 222 1 +221
Docs 1 5 1 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 275 5 +270

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #206173
Summary: This PR directly repairs the requester-selection failure described by the linked issue.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • merge-risk: 🚨 compatibility: The existing plugin fork API selects requester facts differently for newly marked completion reports; the supplied upgrade evidence covers the additive persisted metadata and unchanged handling of historical rows.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • 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 (1 earlier review cycle)
  • reviewed 2026-11-26T21:22:50.231Z sha d2d5a60 :: needs real behavior proof before merge. :: [P3] Use awaited async transcript writes in the new fixtures

Reviewed November 26, 2026, 5:30 PM ET / 22:30 UTC (Revision 2).

@etzelm

etzelm commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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 rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Nov 26, 2026
@etzelm
etzelm requested a review from obviyus November 27, 2026 15:56

This branch has not been deployed

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. plugin: file-transfer proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

[Bug]: Plugin helpers lose exec right after a subagent reports back

1 participant