Skip to content

fix: goals stop pursuing after a background command completes - #187069

Merged
roboclaw-bot merged 17 commits into
mainfrom
openclaw/goal-bg-exec-continuation
Oct 29, 2026
Merged

roboclaw-bot merged 17 commits into
mainfrom
openclaw/goal-bg-exec-continuation

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #186928, #183705

What Problem This Solves

Fixes: an active Goal stops pursuing, with no further continuation turns, after a background command completes and its completion takes the next turn.

User Impact

User impact: a Goal keeps moving after a background exec completion is delivered as its own turn, including when the command was started by a configured command owner. A completion that was explicitly silent (deliver: false) keeps its continuation turns silent too, and pause or Stop during that pursuit is still honored. Continuation turns never gain authority the original requester did not have.

Scope limits: this does not address length/token-limit endings (#186928), Goals created mid-turn (#183705 / #183706), Resume after Stop (#185273, landed separately), or non-built-in harnesses. It is not presented as the explanation for every reported Goal stall.

Why This Change Was Made

A background exec completion is admitted as a session-event turn. When that turn ended normally, enqueueGoalContinuation built the Goal nudge from the event run and inherited its abortSignal, internalEventExecution settlement hooks, and one-shot queuedFollowupReplyDisposition. Instrumentation showed two failures: retiring the settled exec occurrence (the system-events.ts cancel path) aborted the queued nudge, and a nudge that survived reused the already-settled one-shot delivery, so its operation ended run_failed and cancelled the next nudge. The Goal stayed active with continuationTurns: 0.

The Goal successor of a session-event turn now owns three things separately, none of them tied to the event occurrence:

  • Cancellation: only its own cancellation signal.
  • Delivery: the session's ordinary routed delivery. An explicitly silent event's restriction is carried as run-owned data (sessionEventOrigin: { deliver: false }). Follow-up delivery and background producers honor it.
  • Authority:
    • The successor stays classified as event-originated. It never mints a trusted current-conversation message-action capability from the event's captured route, and command-owner status is not refreshed from that route.
    • If the event carried its requester's command-owner authority (an owner-started exec), the successor holds only that requester's live owner check under current config, or the live operator source for handoffs. It does not keep the event-occurrence check, which would fail once the event settled.
    • Without such authority, the successor holds none.

Non-event sources are unchanged.

Evidence

Tests that fail on the earlier code and pass on this head (Gateway goal suite; model mocked, real admission, queue and session-event handoff):

  • Background completion: "keeps pursuing after a background exec completion / an explicitly silent completion takes the next turn". On main 9cb5447 both time out at 120s with the Goal still active. On this head, 4 turns run, the Goal completes with continuationTurns: 2, and successors of the silent completion run with sessionEventDelivery: false.
  • Real exec producer with a captured owner target (prepareExecExitNotification → maybeNotifyOnExit, configured owner telegram:456). The previous candidate is 70f8bd4.
Case What it checks Previous candidate 70f8bd4 This head
Owner completion Goal continues; completion turn and both successors run as owner (senderIsOwner: true) stalls (120s timeout; successor admission fails on the settled event) passes
Owner, silent completion Same as above, plus every successor keeps sessionEventDelivery: false stalls passes
Guest (789) completion Goal continues; no turn runs as owner (senderIsOwner: false) passes passes
Owner revoked before the next successor is admitted Next successor is refused at admission (before it reaches the model or any tool); exactly 3 model calls; Goal stays active fails: only 1 owner turn ran passes
Owner revoked after a successor is admitted Inside the admitted owner successor, the run's real admission assertion (the check the runner hands its tools as assertInvocationCurrent) allows an owner-only effect, then refuses the next one once the owner is removed from config. The refusal's cause is CommandOwnerRevokedError; no further successor runs added on this head passes
Stop during the successor of a silent owner completion sessions.abort aborts it; no further turns run; Goal resumes once stalls passes

Limitation of the after-admission case: the guarded "effect" is a test-only action (an array append) behind the production admission assertion, not a production tool's execute. How individual tools apply that assertion is covered by their existing tests. Temporarily making the successor's owner check always pass makes this test fail, but by a drain timeout (the Goal keeps continuing) rather than at the effect assertion.

  • Pause: "does not continue past a pause made during … turn" (normal and silent): passes.
  • Channel authority (goal-continuation.test.ts, "binds channel-turn authority only for successors of …"):
    • Uses the real producer and the real capability mint on a Discord route.
    • On 7d36425, event-derived successors received a current-conversation capability. On this head they receive none.
    • Control: a user-turn successor's capability resolves to that conversation only. It is refused for another session and after revocation.
  • Silent route: followup-delivery.test.ts "keeps a silent source event's successor off every automatic route". On e3d85dd the successor's progress and final reply were routed to the external origin twice. On this head there is no route or dispatcher call.
  • Suite results on this head:
    • server.chat-goal.test.ts 52/52.
    • goal-continuation + followup-delivery + agent-runner-utils 131/131.
    • session-event-handoff + session-event-permissions 51/51.
    • check:baseline-ratchets against main: all 9 pass.
    • Typecheck (tsgo:test:src), format and changed-file lint pass.
  • Test-line allowance: this branch now carries main's test-line ceiling (6,320,000, chore: restore measured test-code headroom #187162). The earlier ceiling change was dropped when main was merged in.

Real Gateway proof: an in-process Gateway using a scripted loopback model, a real exec background process with completion wake, and sessions.abort for Stop. Delivery restrictions were read from the Gateway's live run registry. The harness is task-local and not part of this diff. Limitation: no external channel was loaded in that Gateway, so suppression of an actual outbound send is proven by the follow-up delivery test above, not by a live external send.

Case main 9cb5447 previous head e3d85dd this head
/goal start → exec background → real completion turn → pursuit → Stop stalls after the completion; Goal active, continuationTurns: 0 — 3 continuation turns; Stop aborts the third and no further turns run; Goal active, continuationTurns: 2
Same, with the background command started by a delivery: none scheduled turn in the Goal session (silent completion) stalls after the completion; continuationTurns: 0 pursuit continues, but all 3 successor runs lose the restriction 3 continuation turns, all with sessionEventDelivery: false; Stop aborts and no further turns run

Work sessions

Worked on by

roboclaw-bot and others added 2 commits October 28, 2026 22:48
A background exec completion is admitted as a session-event turn. When that
turn ended normally, its Goal successor inherited the event occurrence's abort
signal, settlement hooks, and one-shot source delivery. Retiring the occurrence
aborted the queued nudge, so pursuit stopped with the Goal still active.

The successor now keeps only its own cancellation and the session's ordinary
routed delivery when its source is a session event.

Co-authored-by: hannesrudolph <[email protected]>
Worked on by:
- @hannesrudolph

Co-authored-by: hannesrudolph <[email protected]>
OpenClaw-Publication: 303a6874-5b39-4f4a-9d76-1d270b4bf891
@clawsweeper

clawsweeper Bot commented Oct 28, 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: S labels Oct 28, 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. 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. 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 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR detaches Goal continuations from completed session events’ cancellation, settlement, and one-shot delivery hooks.

Example: An active Goal receives a background exec completion before its next continuation.

  • Before: Pursuit stops with the Goal active and continuationTurns at 0.
  • After: The regression scenario reaches four turns, completes the Goal, and records continuationTurns as 2.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported repair with useful Gateway regressions; runtime evidence remains limited to an in-process harness.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored PR is outside the ordinary contributor proof gate; its supplied validation exercises real Gateway continuation owners with mocked model execution, rather than a shipped-entry-point runtime demonstration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An active Goal stops making progress after a background command’s completion takes the next turn.
Reason: The maintainer-authored direction restores the documented continuation contract within its explicitly bounded background-event scenario.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR addresses a concrete Goal-continuation lifetime bug still present on main; no actionable introduced defect was identified.

Priority: P2
Reviewed head: e3d85ddf9aa3591b1bf21ad836db0455367611c2

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not exercise an actual background command and real model through a shipped Gateway.
Agent review details

How this fits together

The reply layer converts normally completed turns into queued Goal nudges; the session controller admits them against current Goal, session, cancellation, and operator-authority facts.

flowchart TD
A[Background exec completion] --> B[Session event turn]
B --> C[Goal continuation owner]
C --> D[Followup queue]
D --> E[Session admission]
E --> F[Agent execution]
F --> G[Session reply delivery]
F --> C
Loading

Technical review

Best possible solution:

Keep the event-specific lifetime correction in the existing Goal owner while preserving ordinary queue admission, Stop, and operator-authority checks.

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

Source shows the inherited occurrence signal and one-shot delivery lifetime mismatch, supported by the author’s reported red-base/green-fix Gateway regression; no target code was executed during this review.

Is this the best way to solve the issue?

The patch is a small correction at the existing successor-construction owner, and both added scenarios protect distinct lifecycle outcomes without introducing another continuation mechanism.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Goal successor cancellation and delivery inheritance changes intended behavior with a stated reason (c845d6d: Continue active Goals using existing source delivery, cancellation, authority, and queue owners.)
  • Shared transcript-followup construction keeps the original intent (49f28b6: Consolidate transcript-only followup construction while preserving caller-specific lifecycle contracts.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • RoboClaw: Raw commit c845d6d adds src/auto-reply/reply/goal-continuation.ts:101 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c845d6df82b4; files: src/auto-reply/reply/goal-continuation.ts)

PR surface

Source +13, Tests +53. Total +66 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 22 9 +13
Tests 1 53 0 +53
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 75 9 +66

Labels

Label changes:

  • add P2: An unfinished Goal can silently stop after a background completion, but the evidence establishes a bounded workflow failure rather than a core outage.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: An unfinished Goal can silently stop after a background completion, but the evidence establishes a bounded workflow failure rather than a core outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Demonstrate a real background command completion followed by continued Goal pursuit through an isolated shipped Gateway.

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.

Reviewed October 28, 2026, 7:09 PM ET / 23:09 UTC.

roboclaw-bot and others added 12 commits October 28, 2026 23:30
A Goal successor detached from its session-event source no longer kept that
event's explicit delivery suppression. When a background completion was
silent (deliver: false), the successor's ordinary reply could still route to
the session's external origin, and its own background work could deliver.

The successor now carries the suppression as a run-owned policy that follow-up
delivery and background producers honor, without retaining the event's
occurrence-scoped callbacks or signal.

Co-authored-by: hannesrudolph <[email protected]>
Worked on by:
- @hannesrudolph

Co-authored-by: hannesrudolph <[email protected]>
OpenClaw-Publication: 0b1f0b3a-6800-4268-8029-fcbcf34afcbd
#187090 reshaped the shutdown and spawn-broker test mock factories without
updating the mock-export ratchet, so their grandfathered entries no longer
matched and every pull request merged with main failed the ratchet.

These factories intentionally keep the real modules unloaded: the shutdown
test records which runtime modules preparation loads, and the spawn-broker
test replaces core startup to observe only broker and admission ownership.
Mark them with mock-isolation reasons and prune the stale baseline entries.

Co-authored-by: hannesrudolph <[email protected]>
Worked on by:
- @hannesrudolph

Co-authored-by: hannesrudolph <[email protected]>
OpenClaw-Publication: 4a4e8039-4176-4f03-b353-b15660a428e1
…-continuation

# Conflicts:
#	src/gateway/server-shutdown.runtime.test.ts
#	src/gateway/server.chat-goal-continuation.test-support.ts
#	src/gateway/server.spawn-broker.test.ts
Worked on by:
- @hannesrudolph

Co-authored-by: hannesrudolph <[email protected]>
OpenClaw-Publication: 1c0c6253-8ccd-42eb-bad5-1b39be252b15
A Goal successor detached from its session-event source no longer carried
internalEventExecution, which also classified the run as event-originated.
On a session with an external route, the successor could then mint a trusted
current-conversation message-action capability from the event's captured route,
and refresh command-owner authority from the run's requester origin, unlike its
event source.

The successor now keeps the event origin as run-owned data
(sessionEventOrigin), which carries the explicit delivery suppression and is
consulted by the capability and owner-authority gates without retaining the
event's occurrence callbacks or signal.

Co-authored-by: hannesrudolph <[email protected]>
The Goal regression tests add 149 counted test lines (measured as the
test-lines ratchet's net delta against main). Raise the ceiling by exactly
that allowance, from 6,243,924 to 6,244,073.

Co-authored-by: hannesrudolph <[email protected]>
An exec completion from a configured channel owner is admitted with that
requester's command-owner authority, whose live check also asserts the event
occurrence is current. The Goal successor copied that capability. Once the
event settled, the successor's admission ran the occurrence check and failed
("Session event occurrence is settled"), so owner-started work still stalled.

The event context now also supplies a successor form holding only the
requester's own live owner check (or the live operator source). The Goal
successor moves to that form and drops the occurrence-bound check; without it,
the successor holds no owner authority. Ownership is not refreshed from the
event's delivery route, and revocation still stops the successor before it runs.

Co-authored-by: hannesrudolph <[email protected]>
The owner-successor regression cases bring the Goal fix's counted test lines
to 260 (the test-lines ratchet's net delta against main). Keep the ceiling
raised by exactly that allowance: 6,243,924 to 6,244,184.

Co-authored-by: hannesrudolph <[email protected]>
Worked on by:
- @hannesrudolph

Co-authored-by: hannesrudolph <[email protected]>
OpenClaw-Publication: 429f4f93-c651-46fe-9f26-548706c48246
roboclaw-bot and others added 3 commits October 29, 2026 03:23
…-continuation

# Conflicts:
#	config/test-lines-baseline.txt
Worked on by:
- @hannesrudolph

Co-authored-by: hannesrudolph <[email protected]>
OpenClaw-Publication: f598e8cb-3785-4632-b4af-751ef71af046
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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

1 participant