Skip to content

improve(advisor): steer agents back on course with a much simpler plugin - #174568

Merged
obviyus merged 12 commits into
mainfrom
feat/advisor-runend-followup
Oct 17, 2026
Merged

obviyus merged 12 commits into
mainfrom
feat/advisor-runend-followup

Conversation

@obviyus

@obviyus obviyus commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Advisor almost never interjects when an agent goes off course. Corrections waited until every tool call settled, then passed through a second verifier fork, and the verifier rejected most real corrections, so in practice the agent kept looping, polling or drifting without hearing anything.

User Impact

With Advisor enabled, an agent that repeats a failing step, polls finished work, works around a blocker it could fix, or drifts beyond the request gets one short correction in its active run, before its next step. Advisor stays off by default and its config keys are unchanged.

Why This Change Was Made

Advisor is now one review and one steer, using primitives core already has:

  • Count tool calls in user-triggered runs. When everyToolCalls or everyMinutes is due, fork the session (forkSession) and ask whether the agent is on track.
  • On CORRECTION, steer the active run (steerActiveRun). The advice joins the requester's own run, so its permissions and sender restrictions still apply. If the run already ended, or steering is refused (for example hooks.allowPromptInjection=false), nothing is delivered. The run ending also cancels a review still in flight.
  • The plugin reference now documents the single-pass review.
  • A due review forks only once every running tool call has its real result (Codex native tools: their item completion; outer Code Mode calls: their recorded output; a raw call and a native child that share an ID settle separately). The original dispatch-time recheck is kept: a review queued before another call starts stands down and stays due until that call's result, because a live unfinished-call fork once produced synthetic aborted results and false retry advice., because Codex fills a missing output with a synthetic aborted result in forks.
  • Removed: the verifier stage, the old settlement bookkeeping, Codex item bookkeeping, the next-turn injection fallback and the reply parser's word and token rules. The model decides; code only reads the NO_CHANGE/CORRECTION shape.
  • The default instructions say plainly what "off course" means.

The plugin drops from about 1,600 to about 420 lines including tests (+339/−1617 overall).

Evidence

  • Focused tests: pnpm vitest run extensions/advisor (12 passed; the outer-call, shared-ID receipt and dispatch-recheck cases each fail without their fix) and src/plugins/contracts/boundary-invariants.test.ts (12 passed). ui:i18n:verify and the config-doc baseline check pass.
  • Live, isolated Gateway, openai/gpt-6.1-sol on the Codex harness, Advisor at everyToolCalls: 3. Task: poll a check script whose config has a typo. Rows 18–20: the third identical failure. Row 21: the Advisor steer, stored after the tool result with sourceTool: plugin:advisor. Row 22: the agent switches from re-running to inspecting the config, fixes the key, and reports READY. Gateway log: advisor: steered active run.
  • Built-in OpenClaw runtime (agentRuntime.id: "openclaw"), same setup with the Control UI: reviews fork with a warm cache (17–25k cached input tokens, 75 uncached), and corrections are stored between tool calls while the run keeps going.
  • Steer-only head, built-in runtime, test-only reviewInstructions that force a correction: the steer is stored at row 26 directly after a tool result (sourceTool: plugin:advisor), the run continues at row 28, and the log shows advisor: steered active run. No other turn is started.
  • Codex harness, three 15-second commands in a row with everyToolCalls: 1: each review forked within 1 ms of the command's commandExecution item completing (10:00:51.3, 10:01:08.1) and never while a command was running.
  • Codex Code Mode, one outer call that runs a command, waits 15 seconds, then runs another (everyToolCalls: 1): the child command finished at 10:21:48.3 while the outer call stayed open; the review forked only after the outer call recorded its output at 10:22:06.5.
  • Permission boundary, isolated Gateway: with hooks.allowPromptInjection=false and test-only reviewInstructions that force a correction, every correction logged correction not delivered (blocked by plugins.entries.advisor.hooks.allowPromptInjection=false).
  • Replay of a real 4-hour coding session (62 review points at the default 10-tool-call trigger, real transcript history): Advisor proposed the same course change the user later asked for about 20 minutes earlier in two of four user interventions ("stop debugging unrelated Gateway startup and implement the fix"; "stop expanding the evidence bundle").

Labs description on this branch:

Labs Advisor row

Merge danger: two-way door. A revert restores the previous plugin entirely; nothing migrates and no state is written. Blast radius is limited to users who turned on the Advisor lab: their agents can receive one short steered correction per review while a run is active.

@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 docs Improvements or additions to documentation app: web-ui App: web-ui extensions: advisor size: XL labels Oct 16, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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:feature 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

Simplifies Advisor to one background review that steers an active run, removing verification and next-turn fallback delivery.

Example: Advisor reviews after three repeated failures caused by a misspelled configuration key.

  • Before: A second verifier could reject the correction, leaving the agent repeating the failed command.
  • After: The supplied live run records Advisor guidance after the third failure, followed by the agent inspecting and fixing the key.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Useful owner-directed simplification with live entry-point evidence, resolved prior findings, and green exact-head CI.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Supplied isolated Gateway output exercises Advisor corrections on both runtimes, native and outer Code Mode completion boundaries, and denied prompt injection; the latest scheduling repair has focused regression coverage supplementing that live proof.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Enabled Advisor often leaves agents repeating failed steps or drifting because proposed corrections are rejected before delivery.
Reason: The existing feature owner explicitly chooses single-pass active steering, supported by live corrections and session replay; defaults and configuration keys remain unchanged.

Merge readiness

✅ Ready for maintainer review

This PR is ready for normal landing review: the previous dispatch-time finding is fixed, current-head CI is green, and no additional actionable defect was found.

Priority: P2
Reviewed head: 5f3d9284a0bf12f7c1feec5b182eec7f0dec2130

Before merge

None.

Findings

None.

Agent review details

How this fits together

Advisor is an optional bundled plugin that consumes user-run lifecycle and tool-completion events, forks the session for a tool-free review, and sends guidance through the existing guarded steering API.

flowchart TD
  A[User run] --> B[Lifecycle and tool events]
  B --> C[Advisor settlement and triggers]
  C --> D[Service scheduled session fork]
  D --> E[Review decision]
  E --> F[Guarded active run steering]
  F --> A
Loading

Technical review

Best possible solution:

Land the single-pass Advisor implementation with its settlement checks, cancellation, existing permission enforcement, and updated documentation.

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

This is an existing feature's behavior redesign; supplied live Gateway evidence demonstrates the intervention scenario, while source and the new regression establish the previous dispatch finding's repair.

Is this the best way to solve the issue?

The simpler implementation uses existing fork, scheduler, event, and guarded steering owners, removes the superseded controller and verifier, and explains its intervention-quality tradeoff.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Verification, parser restrictions, and next-turn delivery changes intended behavior with a stated reason (a77bf04: The original feature used verification and restrictive parsing to reduce false corrections, and queued guidance when active steering was unavailable.)
  • Stale-review cancellation keeps the original intent (330c27e: Aborted or superseded runs must not receive unfinished guidance from a preceding review.)
  • Tool settlement before review forks keeps the original intent (a77bf04: Forking with unfinished calls produced synthetic aborted outputs and false retry advice in live use.)
  • Operator-visible guidance keeps the original intent (aaed6bf: Control UI exposes attributed guidance separately from private model instructions without claiming successful native acceptance.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Previous finding resolved: The scheduled callback now rechecks pending calls before resetting counters or starting a fork; when another call is running, the review stays due until its completion. The added regression exercises the previously reported sequence. (extensions/advisor/index.ts:152, 5f3d9284a0bf)
  • Live behavior and permission rejection: The full PR body supplies isolated Gateway traces for successful steering on Codex and the built-in runtime, native and outer-call settlement, and corrections rejected with hooks.allowPromptInjection=false. The downloaded Labs screenshot matches the changed English description; historical screenshots establish the preceding copy. (extensions/advisor/index.ts:118, 5f3d9284a0bf)
  • Existing authority owner preserved: Advisor continues using the host steering owner, which checks prompt-injection policy and plugin lifecycle authority; guidance remains internal, non-owner input to the existing active runtime. The follow-up-turn path implicated in earlier findings is removed. (src/plugins/registry-api.ts:178, 5f3d9284a0bf)
  • Original intent and accepted simplification: The original feature in feat(labs): add experimental Advisor that steers agents off avoidable work #169564 deliberately added verification to reduce false corrections; fix(advisor): cancel stale guidance after abort or new turn #173459 established stale-review cancellation. This maintainer-authored PR explains removing verification to improve intervention usefulness, explicitly drops fallback delivery, and retains cancellation. (extensions/advisor/index.ts:85, a77bf0478040)
  • Current main still uses the previous design: Fetched main retains the controller, verifier, and queued next-turn fallback, so the central simplification is not already implemented there. (extensions/advisor/index.ts:3, bb55f0c90e5f)
  • Codex normalization contract inspected: The settlement behavior and proof claims depend directly on Codex history normalization. The sibling source inserts synthetic aborted outputs for unfinished function, custom-tool, and local-shell calls, supporting the need to wait for authoritative receipts; its checkout remote identifies only a local cache. (codex-rs/core/src/context_manager/normalize.rs:51, c1382380de69521303b416720a52f42d51af6248)

Likely related people:

  • Ayaan Zaidi: Raw commit a77bf04 adds extensions/advisor/index.ts:48 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a77bf0478040; files: extensions/advisor/index.ts)

PR surface

Source -348, Tests -697, Docs -96, Generated 0. Total -1141 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 215 563 -348
Tests 1 189 886 -697
Docs 3 51 147 -96
Config 0 0 0 0
Generated 1 2 2 0
Other 0 0 0 0
Total 10 457 1598 -1141

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: 🦐 gold shrimp: 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: Improves an optional, default-off experimental plugin with limited user exposure.
  • 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 (8 earlier review cycles)
  • reviewed 2026-10-16T19:24:31.263Z sha 963b180 :: needs real behavior proof before merge. :: [P1] Honor prompt-injection rejection before scheduling a follow-up | [P2] Recheck cancellation after the awaited steer | [P2] Track terminal review independently of the interval counter
  • reviewed 2026-10-17T01:10:13.277Z sha c671c4f :: needs real behavior proof before merge. :: [P1] Preserve the originating sender’s tool restrictions in follow-ups
  • reviewed 2026-10-17T03:15:10.752Z sha 49b3ca9 :: needs changes before merge. :: [P3] Update the plugin reference for single-pass reviews
  • reviewed 2026-10-17T04:13:54.468Z sha 67e6430f1cf99b8e0d3ac7b9846a24ec1c040452 :: needs changes before merge. :: [P2] Preserve truthful tool results in native Codex review forks
  • reviewed 2026-10-17T04:45:05.497Z sha 846ef1596bdd9042b80b7c911a716971f6cad2aa :: needs changes before merge. :: [P2] Track raw outer calls until their output is recorded
  • reviewed 2026-10-17T05:07:07.428Z sha f8cbe0042d4180f21e056f2f3b50b7ef850d060e :: needs changes before merge. :: none
  • reviewed 2026-10-17T05:15:56.274Z sha 5bc1b78 :: needs changes before merge. :: [P2] [P2] Settle native and raw receipts independently
  • reviewed 2026-10-17T05:36:48.167Z sha 65161dc :: needs changes before merge. :: [P2] Recheck pending calls before dispatching the review

Reviewed October 17, 2026, 1:54 AM ET / 05:54 UTC (Revision 9).

@obviyus
obviyus marked this pull request as ready for review October 16, 2026 23:22
@obviyus
obviyus force-pushed the feat/advisor-runend-followup branch from e63ffdb to c671c4f Compare October 17, 2026 00:42
@obviyus

obviyus commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator 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:feature Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 17, 2026
@obviyus obviyus changed the title improve(advisor): interject when the agent goes off course, with a much simpler plugin improve(advisor): steer agents back on course with a much simpler plugin Oct 17, 2026
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 17, 2026
@obviyus
obviyus force-pushed the feat/advisor-runend-followup branch from 1642e8a to 49b3ca9 Compare October 17, 2026 02:29
@obviyus

obviyus commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator 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 the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 17, 2026
@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 17, 2026
@obviyus

obviyus commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator 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:feature 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: 🦐 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. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 17, 2026
@obviyus
obviyus merged commit 22dd373 into main Oct 17, 2026
120 of 121 checks passed
@obviyus
obviyus deleted the feat/advisor-runend-followup branch October 17, 2026 05:57
@obviyus

obviyus commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 22dd373. Advisor is now one review that steers the active run when the agent goes off course: no verifier, no follow-up turns, no hidden next-turn notes, so advice always stays inside the requester's own run and permissions. Reviews fork only after running tool calls (including Codex native and Code Mode calls) report real results. Proof: live mid-run steers on the Codex and built-in runtimes, the prompt-injection refusal trace, Codex Code Mode timing traces, and the focused suite (12 tests, each new case failing without its fix).

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…gin (openclaw#174568)

## What Problem This Solves

Advisor almost never interjects when an agent goes off course. Corrections waited until every tool call settled, then passed through a second verifier fork, and the verifier rejected most real corrections, so in practice the agent kept looping, polling or drifting without hearing anything.

## User Impact

With Advisor enabled, an agent that repeats a failing step, polls finished work, works around a blocker it could fix, or drifts beyond the request gets one short correction in its active run, before its next step. Advisor stays off by default and its config keys are unchanged.

## Why This Change Was Made

Advisor is now one review and one steer, using primitives core already has:

- Count tool calls in user-triggered runs. When `everyToolCalls` or `everyMinutes` is due, fork the session (`forkSession`) and ask whether the agent is on track.
- On `CORRECTION`, steer the active run (`steerActiveRun`). The advice joins the requester's own run, so its permissions and sender restrictions still apply. If the run already ended, or steering is refused (for example `hooks.allowPromptInjection=false`), nothing is delivered. The run ending also cancels a review still in flight.
- The plugin reference now documents the single-pass review.
- A due review forks only once every running tool call has its real result (Codex native tools: their item completion; outer Code Mode calls: their recorded output; a raw call and a native child that share an ID settle separately). The original dispatch-time recheck is kept: a review queued before another call starts stands down and stays due until that call's result, because a live unfinished-call fork once produced synthetic aborted results and false retry advice., because Codex fills a missing output with a synthetic `aborted` result in forks.
- Removed: the verifier stage, the old settlement bookkeeping, Codex item bookkeeping, the next-turn injection fallback and the reply parser's word and token rules. The model decides; code only reads the `NO_CHANGE`/`CORRECTION` shape.
- The default instructions say plainly what "off course" means.

The plugin drops from about 1,600 to about 420 lines including tests (+339/−1617 overall).

## Evidence

- Focused tests: `pnpm vitest run extensions/advisor` (12 passed; the outer-call, shared-ID receipt and dispatch-recheck cases each fail without their fix) and `src/plugins/contracts/boundary-invariants.test.ts` (12 passed). `ui:i18n:verify` and the config-doc baseline check pass.
- Live, isolated Gateway, `openai/gpt-6.1-sol` on the Codex harness, Advisor at `everyToolCalls: 3`. Task: poll a check script whose config has a typo. Rows 18–20: the third identical failure. Row 21: the Advisor steer, stored after the tool result with `sourceTool: plugin:advisor`. Row 22: the agent switches from re-running to inspecting the config, fixes the key, and reports READY. Gateway log: `advisor: steered active run`.
- Built-in OpenClaw runtime (`agentRuntime.id: "openclaw"`), same setup with the Control UI: reviews fork with a warm cache (17–25k cached input tokens, 75 uncached), and corrections are stored between tool calls while the run keeps going.
- Steer-only head, built-in runtime, test-only `reviewInstructions` that force a correction: the steer is stored at row 26 directly after a tool result (`sourceTool: plugin:advisor`), the run continues at row 28, and the log shows `advisor: steered active run`. No other turn is started.
- Codex harness, three 15-second commands in a row with `everyToolCalls: 1`: each review forked within 1 ms of the command's `commandExecution` item completing (10:00:51.3, 10:01:08.1) and never while a command was running.
- Codex Code Mode, one outer call that runs a command, waits 15 seconds, then runs another (`everyToolCalls: 1`): the child command finished at 10:21:48.3 while the outer call stayed open; the review forked only after the outer call recorded its output at 10:22:06.5.
- Permission boundary, isolated Gateway: with `hooks.allowPromptInjection=false` and test-only `reviewInstructions` that force a correction, every correction logged `correction not delivered (blocked by plugins.entries.advisor.hooks.allowPromptInjection=false)`.
- Replay of a real 4-hour coding session (62 review points at the default 10-tool-call trigger, real transcript history): Advisor proposed the same course change the user later asked for about 20 minutes earlier in two of four user interventions ("stop debugging unrelated Gateway startup and implement the fix"; "stop expanding the evidence bundle").

Labs description on this branch:

![Labs Advisor row](https://github.com/user-attachments/assets/ad593f1c-7ff6-43cb-88c9-1ba4600dc0e2)

**Merge danger:** two-way door. A revert restores the previous plugin entirely; nothing migrates and no state is written. Blast radius is limited to users who turned on the Advisor lab: their agents can receive one short steered correction per review while a run is active.

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

app: web-ui App: web-ui docs Improvements or additions to documentation extensions: advisor 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: XL 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.

1 participant