Skip to content

fix(advisor): cancel stale guidance after abort or new turn - #173459

Merged
obviyus merged 2 commits into
mainfrom
fix/advisor-review-cancellation
Oct 15, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/advisor-review-cancellation

Conversation

@obviyus

@obviyus obviyus commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes Advisor guidance arriving after an aborted run, or remaining queued from a stale review after a new user turn starts.

User Impact

Aborting work also cancels its in-flight Advisor review and verification. Starting a new user turn drops unfinished advice based on the preceding turn instead of delivering it later. A duplicate steering outcome never creates fallback guidance. Normal run-end fallback remains supported.

Why This Change Was Made

The lifecycle subscription treated aborted terminal events like ordinary completion, ignoring their aborted flag. The controller also retained in-flight reviews when a new user run replaced the previous one. These transitions now cancel the stale review at the owning controller, preventing both active delivery and fallback queueing.

Duplicate keys are terminal no-ops rather than unavailable steering, so the fallback path now leaves them alone.

Evidence

  • Reproduced on 5678421c757: aborted end and error events left the review signal active; regression assertions failed with expected false to be true.
  • Reproduced active delivery followed by another pending review spanning a new user turn; its cancellation assertion failed on the baseline.
  • A duplicate-result regression also demonstrated an unwanted fallback queue entry before its repair.
  • All 51 Advisor tests passed, including cancellation, duplicate handling, normal run-end fallback, tool settlement, verification, and interval accounting. Combined owner checks covered 127 distinct tests; changed-file oxfmt/oxlint, scoped tsgo, Madge (0 cycles), and diff checks passed.
  • Final raw-evidence campaign combined this head 1fac8ffa671, core head 5677912be70 (fix: deduplicate steering without replaying rejected guidance #173458), and display fix 07c940c6959 (fix(gateway): keep private model prompt projections out of display output #173460); tested integration 04a5747760d1e9655b73fac511ddb81fad7a3c97.
  • Executable invariants: before 80 PASS / 5 FAIL; after 86 PASS / 0 FAIL / 0 UNPROVED. Shared case/invariant pairs improved 59 PASS / 5 FAIL → 64 PASS / 0 FAIL; totals include different commissioning/channel coverage and the new successor-run case.
  • The accepted abort left zero queued notes. The overlapping user turn retained one active correction and zero queued copies. Built-in minutes review completed verification and delivered once. Provider requests, SQLite rows, and events independently establish these outcomes.
  • A/B behavior stayed unchanged: Advisor-on 4 tool calls / 2 repeated actions, solved; off 8 / 7, unresolved. Actual Codex tool/minutes and late-snapshot Telegram persistence/display/recipient checks passed. No active-session compaction occurred; that RPC remained refused.
  • The fork slice from the tested core revision is now isolated in fix: preserve session forks during parent request preparation #173489; fix: deduplicate steering without replaying rejected guidance #173458 retains steering deduplication and the later native rejected-guidance producer repair.

@clawsweeper

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

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR cancels stale Advisor reviews after aborts or replacement user turns and suppresses fallback guidance for duplicate steering outcomes.

Example: Advisor is reviewing run-1 when the user aborts it.

  • Before: The review can finish and deliver or queue advice about the aborted work.
  • After: The controller cancels the review and scheduled work without queueing its advice.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused, worthwhile repair with no actionable finding; independently inspectable behavioral evidence remains at the plugin harness boundary.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored PR is outside the ordinary contributor-proof gate; inspectable coverage reaches the real plugin controller and scheduler with mocked endpoints, while integrated Gateway outcomes are reported in prose and the downloaded screenshots show only the original settings UI.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Advisor can deliver guidance derived from work the user aborted or superseded.
Reason: The collaborator who authored the feature supplies a focused lifecycle repair that preserves normal fallback behavior.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: the feature owner repairs current Advisor lifecycle defects that remain on main, and no concrete introduced bug was found.

Priority: P2
Reviewed head: 1fac8ffa6712a750e19ceca75cd3eaa755bd5323

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The body reports Gateway abort and replacement-turn results, but inspectable raw lifecycle and delivery traces are not linked.
Agent review details

How this fits together

Advisor consumes admitted user-run lifecycle and tool events, reviews and verifies session context through service-owned forks, and sends approved guidance through existing session workflow APIs.

flowchart TD
  A[User run events] --> B[Advisor subscription]
  B --> C[Session controller]
  C --> D[Review and verification forks]
  D --> E[Active run steering]
  E --> F[Next turn fallback]
  B --> G[Abort or replacement turn]
  G --> C
Loading

Technical review

Best possible solution:

Keep cancellation in the Advisor controller while preserving ordinary completion fallback and the existing session workflow delivery owner.

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

Current-main source exposes both cancellation omissions, and the body reports failing baseline assertions for those paths; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch fixes the owning lifecycle transitions, reuses existing abort propagation, and treats duplicate steering as terminal without adding configuration or competing state.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Advisor review lifetime changes intended behavior with a stated reason (a77bf04: Service-owned reviews survive ordinary run completion so approved guidance can become next-turn context.)
  • Fallback after unavailable steering keeps the original intent (a77bf04: Fallback preserves approved advice when active steering is unavailable; an already accepted duplicate requires no additional delivery.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit a77bf04 adds extensions/advisor/src/controller.ts:195 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/src/controller.ts)

PR surface

Source +18, Tests +55, Docs +2. Total +75 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 18 0 +18
Tests 1 55 0 +55
Docs 1 6 4 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 79 4 +75

Review metrics

Metric Value Why it matters
Production versus test growth Production +18 lines; tests +55 lines Small additions reuse existing cancellation and delivery owners, with focused regression coverage for the changed behavior.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Stale guidance can affect subsequent agent work, but Advisor is experimental and disabled by default.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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-10-15T20:57:08.187Z sha 1fac8ff :: needs maintainer review before merge. :: none

Reviewed October 15, 2026, 5:09 PM ET / 21:09 UTC (Revision 2).

@obviyus

obviyus commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

obviyus added a commit that referenced this pull request Oct 15, 2026
## What Problem This Solves

Fixes repeated plugin steering reaching the model twice, and rejected native guidance being retained as if it had been delivered.

## User Impact

Plugins can retry steering without injecting the same guidance twice, including after a successor run starts. A native steer rejected before dispatch leaves no guidance in subsequent model context and can be retried after plugin reload. No configuration, schema, or stored-row shape change is required.

## Why This Change Was Made

Transcript idempotency alone did not protect the active-run input queue. The existing run registration now joins pending/accepted admissions after authority validation, and the plugin host checks the durable session/key owner before dispatch. Stored steering receipts replay the original run ID, matching `src/gateway/server-methods/inflight.ts:38-51`; older rows without a receipt return terminal `duplicate`. Rejected queue reservations are released.

Codex previously appended internal guidance before the final physical-send authority check. It now retains preceding tool-result mirroring and inbound user persistence, but appends internal plugin guidance only after native acceptance or accepted-unconfirmed delivery. Accepted history can still be recorded if the plugin is subsequently disposed; session/storage identity guards remain. This prevents rejected guidance from poisoning both replay and same-key retry without adding stored fields.

The independent fork snapshot repair moved to #173489. Advisor cancellation and duplicate-fallback handling are in #173459.

## Evidence

- Baseline `5678421c757`: sequential/concurrent duplicate-key regressions persisted one row but admitted two model-input messages.
- Successor-run regression: before the durable check, the same key was accepted by a later run rather than deduplicated.
- Native regression: before the producer fix, pre-wire disposal left a hidden transcript row, included it in `SessionManager` model context, and caused a reloaded plugin's retry to return `duplicate`. Afterward, rejected guidance is absent from both transcript and context; retry reaches native `turn/steer` once. Accepted-then-disposed guidance still persists once.
- Focused steering, native admission/authority/settlement, recorder, and recorder-persistence tests passed. Changed-file oxfmt/oxlint, scoped tsgo, Madge (0 cycles), and diff checks passed.
- The pre-review-fix combined raw-evidence campaign tested integration `04a5747760d1e9655b73fac511ddb81fad7a3c97`: **80 PASS / 5 FAIL → 86 PASS / 0 FAIL / 0 UNPROVED**. Shared case/invariant pairs: **59 PASS / 5 FAIL → 64 PASS / 0 FAIL**. Totals include added successor/channel coverage rather than an identical inventory.
- That campaign proves same-run and successor-run idempotency, abort/overlap handling, display isolation, and built-in/native minutes verification. The later rejected-guidance producer fix is separately covered by the focused native regression above, not claimed as part of that campaign.
- Focused native follow-up tested `0903019c1131cfa29a81b4e192c3353fb65a3def` (integration `998ff42a15f` plus the display fix): **36 PASS / 0 FAIL / 0 UNPROVED**. Live Codex tool-call, minutes, abort, overlap, and same-key within/across runs passed; every accepted steer row preceded its first provider request. A controlled native-transport probe separately proved pre-wire rejection leaves no row or wire request, then same-key retry delivers exactly once. The controlled rejection probe is not claimed as live-daemon fault injection.

Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus
obviyus merged commit 330c27e into main Oct 15, 2026
116 checks passed
@obviyus
obviyus deleted the fix/advisor-review-cancellation branch October 15, 2026 22:05
@obviyus

obviyus commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 330c27e. Advisor cancels an in-flight review when its run is aborted and when a new user turn replaces the run, and treats a duplicate steer as terminal, so no stale or duplicate correction is delivered. Proof: abort/overlap/duplicate regressions failing before; raw-evidence campaign 86/0; exact-head CI green.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
…aw#173458)

## What Problem This Solves

Fixes repeated plugin steering reaching the model twice, and rejected native guidance being retained as if it had been delivered.

## User Impact

Plugins can retry steering without injecting the same guidance twice, including after a successor run starts. A native steer rejected before dispatch leaves no guidance in subsequent model context and can be retried after plugin reload. No configuration, schema, or stored-row shape change is required.

## Why This Change Was Made

Transcript idempotency alone did not protect the active-run input queue. The existing run registration now joins pending/accepted admissions after authority validation, and the plugin host checks the durable session/key owner before dispatch. Stored steering receipts replay the original run ID, matching `src/gateway/server-methods/inflight.ts:38-51`; older rows without a receipt return terminal `duplicate`. Rejected queue reservations are released.

Codex previously appended internal guidance before the final physical-send authority check. It now retains preceding tool-result mirroring and inbound user persistence, but appends internal plugin guidance only after native acceptance or accepted-unconfirmed delivery. Accepted history can still be recorded if the plugin is subsequently disposed; session/storage identity guards remain. This prevents rejected guidance from poisoning both replay and same-key retry without adding stored fields.

The independent fork snapshot repair moved to openclaw#173489. Advisor cancellation and duplicate-fallback handling are in openclaw#173459.

## Evidence

- Baseline `4bf119f2359`: sequential/concurrent duplicate-key regressions persisted one row but admitted two model-input messages.
- Successor-run regression: before the durable check, the same key was accepted by a later run rather than deduplicated.
- Native regression: before the producer fix, pre-wire disposal left a hidden transcript row, included it in `SessionManager` model context, and caused a reloaded plugin's retry to return `duplicate`. Afterward, rejected guidance is absent from both transcript and context; retry reaches native `turn/steer` once. Accepted-then-disposed guidance still persists once.
- Focused steering, native admission/authority/settlement, recorder, and recorder-persistence tests passed. Changed-file oxfmt/oxlint, scoped tsgo, Madge (0 cycles), and diff checks passed.
- The pre-review-fix combined raw-evidence campaign tested integration `04a5747760d1e9655b73fac511ddb81fad7a3c97`: **80 PASS / 5 FAIL → 86 PASS / 0 FAIL / 0 UNPROVED**. Shared case/invariant pairs: **59 PASS / 5 FAIL → 64 PASS / 0 FAIL**. Totals include added successor/channel coverage rather than an identical inventory.
- That campaign proves same-run and successor-run idempotency, abort/overlap handling, display isolation, and built-in/native minutes verification. The later rejected-guidance producer fix is separately covered by the focused native regression above, not claimed as part of that campaign.
- Focused native follow-up tested `0903019c1131cfa29a81b4e192c3353fb65a3def` (integration `998ff42a15f` plus the display fix): **36 PASS / 0 FAIL / 0 UNPROVED**. Live Codex tool-call, minutes, abort, overlap, and same-key within/across runs passed; every accepted steer row preceded its first provider request. A controlled native-transport probe separately proved pre-wire rejection leaves no row or wire request, then same-key retry delivers exactly once. The controlled rejection probe is not claimed as live-daemon fault injection.

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

## What Problem This Solves

Fixes Advisor guidance arriving after an aborted run, or remaining queued from a stale review after a new user turn starts.

## User Impact

Aborting work also cancels its in-flight Advisor review and verification. Starting a new user turn drops unfinished advice based on the preceding turn instead of delivering it later. A duplicate steering outcome never creates fallback guidance. Normal run-end fallback remains supported.

## Why This Change Was Made

The lifecycle subscription treated aborted terminal events like ordinary completion, ignoring their `aborted` flag. The controller also retained in-flight reviews when a new user run replaced the previous one. These transitions now cancel the stale review at the owning controller, preventing both active delivery and fallback queueing.

Duplicate keys are terminal no-ops rather than unavailable steering, so the fallback path now leaves them alone.

## Evidence

- Reproduced on `4bf119f2359`: aborted `end` and `error` events left the review signal active; regression assertions failed with `expected false to be true`.
- Reproduced active delivery followed by another pending review spanning a new user turn; its cancellation assertion failed on the baseline.
- A duplicate-result regression also demonstrated an unwanted fallback queue entry before its repair.
- All 51 Advisor tests passed, including cancellation, duplicate handling, normal run-end fallback, tool settlement, verification, and interval accounting. Combined owner checks covered 127 distinct tests; changed-file oxfmt/oxlint, scoped tsgo, Madge (0 cycles), and diff checks passed.
- Final raw-evidence campaign combined this head `1fac8ffa671`, core head `5677912be70` (openclaw#173458), and display fix `07c940c6959` (openclaw#173460); tested integration `04a5747760d1e9655b73fac511ddb81fad7a3c97`.
- Executable invariants: **before 80 PASS / 5 FAIL; after 86 PASS / 0 FAIL / 0 UNPROVED**. Shared case/invariant pairs improved **59 PASS / 5 FAIL → 64 PASS / 0 FAIL**; totals include different commissioning/channel coverage and the new successor-run case.
- The accepted abort left zero queued notes. The overlapping user turn retained one active correction and zero queued copies. Built-in minutes review completed verification and delivered once. Provider requests, SQLite rows, and events independently establish these outcomes.
- A/B behavior stayed unchanged: Advisor-on 4 tool calls / 2 repeated actions, solved; off 8 / 7, unresolved. Actual Codex tool/minutes and late-snapshot Telegram persistence/display/recipient checks passed. No active-session compaction occurred; that RPC remained refused.
- The fork slice from the tested core revision is now isolated in openclaw#173489; openclaw#173458 retains steering deduplication and the later native rejected-guidance producer repair.

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

extensions: advisor P2 Normal backlog priority with limited blast radius. 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.

1 participant