Skip to content

fix(exec): let owner-started background commands schedule follow-ups when they finish - #201146

Closed
Marvinthebored wants to merge 3 commits into
openclaw:mainfrom
Marvinthebored:fix/exec-wake-automations-authority
Closed

Marvinthebored wants to merge 3 commits into
openclaw:mainfrom
Marvinthebored:fix/exec-wake-automations-authority

Conversation

@Marvinthebored

@Marvinthebored Marvinthebored commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Related: #177510

What Problem This Solves

A background command started by an owner can finish, wake the same chat, and then be refused when it tries to create a follow-up automation. Another human message was needed to restore the owner's authority.

User Impact

Owner-started commands can schedule follow-ups from their completion turns without another message. Non-owner commands, other chats, and unrelated system events do not acquire owner authority.

Why This Change Was Made

  • Continue the starting turn's owner decision under its captured operator source and tool restrictions; command output remains untrusted.
  • Bind that continuation to the same chat key, preserving the continuation contract from refactor(sessions): address chats by ChatRef, fence writers by lease, and stop refusing on captured ids #200191. Transcript rotation during compaction does not change ownership.
  • Remove the added transcript-ID reset fence: transcript IDs identify physical storage, not chats. Existing chat-key admission and lease mechanisms govern occurrence lifetime. Goal successors keep only live requester/operator authority, independent of the settled completion event, preserving fix: goals stop pursuing after a background command completes #187069. Ownership revocation is still checked before execution and tool effects.
  • Preserve existing scheduler, hook, and durable-restart behavior. This addresses the owner-only gate, not general toolsBySender matching in the related issue.

Evidence

  • Stock source with the regression test: 1 failed, 3 passed. Patched requester/same-chat tests: 5 passed.
  • Real process-to-completion suite: 29 passed, including owner/non-owner turns, original guest scope and revocation, cron continuations, and reset routing.
  • Isolated Control UI: an owner starts sleep 5; six seconds later its completion resumes the chat and creates the requested one-shot automation without another human message. openclaw automations list --json on that Gateway then showed the stored at job targeting the same session.
  • Post-merge scoped validation on 153765819b95ca483923b7249b75b67690476c9b: requester 5/5, Goal continuation 63/63, process-to-wake 29/29 (97/97 total). The rotation regression also asserts owner authority survives compaction.
  • node --import ./scripts/tsx.mjs scripts/check-session-identity-ratchet.mts --base origin/main --no-merge-base: passed (1613 files, 6408 grandfathered pins). git diff --check: passed. No repository-wide typecheck was run.

AI-assisted (OpenClaw agents). Redacted session log and stored-job check: https://gist.github.com/Marvinthebored/a99536a0a0bfe4e7285cff5e310a7ed7

@clawsweeper

clawsweeper Bot commented Nov 18, 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 agents Agent runtime and tooling size: S labels Nov 18, 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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 Nov 18, 2026
@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves the starting owner's authority when a background command resumes the same chat.

Example: An owner requests sleep 5; echo EXEC_WAKE_PROOF_READY, followed by creation of a one-shot automation after completion.

  • Before: The completion wakes the chat but cannot create the automation until the owner sends another message.
  • After: The completion creates the automation in the same chat without another human message.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, behavior-proven repair with both prior blockers resolved; the overall scope remains partial relative to the linked sender-policy issue, and exact-head CI is still running.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): The inspected linked log exercises an isolated Gateway through Control UI: an owner starts a real background command, its completion resumes without another human message, and the automation is independently observed in stored-job output; later scoped results cover the revised settlement and rotation behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: An owner's background-command completion cannot schedule the requested follow-up until another human message restores owner status.
Reason: This restores an established continuation contract with a small patch; it intentionally addresses only the owner-only gate within the broader related sender-policy issue.

Merge readiness

✅ Ready for maintainer review

Keep open: this focused repair remains necessary on current main, and both earlier blocking findings are resolved.

Priority: P2
Reviewed head: 153765819b95ca483923b7249b75b67690476c9b

Before merge

None.

Findings

None.

Agent review details

How this fits together

Tool assembly supplies the turn's owner decision to exec; notification capture retains its original authority, and session-event admission uses it for the completion and eligible Goal successors.

flowchart LR
  A[Owner request] --> B[Tool assembly]
  B --> C[Background exec]
  C --> D[Captured event target]
  D --> E[Completion admission]
  E --> F[Owner checked automation]
  E --> G[Goal successor]
Loading

Technical review

Best possible solution:

Retain this narrow repair through the existing event-target and command-owner owners while preserving chat-key routing and occurrence-independent Goal authority.

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

Current-main source omits both propagation of the operator owner's continuation decision and exec selection in the owner-context branch; contributor evidence includes a failing base regression and a successful isolated Gateway flow.

Is this the best way to solve the issue?

The patch restores the missing input to existing authority owners with no new manager, persistence, or public configuration; its revised form also preserves the established compaction and Goal-successor contracts.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit b1a2aa2 adds src/auto-reply/reply/session-event-context.ts:250 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b1a2aa2c3f32; files: src/auto-reply/reply/session-event-context.ts)
  • Shakker: Raw commit 147df8d adds src/agents/bash-tools.exec-notify.ts:331 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 147df8d9edf5; files: src/agents/bash-tools.exec-notify.ts)

PR surface

Source +14, Tests +120. Total +134 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 17 3 +14
Tests 2 124 4 +120
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 141 7 +134

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.

Review metrics

Metric Value Why it matters
Production versus test changes Production +17/-3; tests +124/-4 Production growth wires one owner decision through existing layers; tests cover owner versus non-owner, chat/source boundaries, and transcript rotation.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A background completion loses owner-only follow-up capability, requiring another owner message to finish an otherwise authorized task.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; 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-18T11:05:37.581Z sha 137b634 :: needs changes before merge. :: [P1] [P1] Keep successor authority independent of the settled event lease | [P1] [P1] Preserve owner authority across compaction successors

Reviewed November 18, 2026, 8:00 PM ET / November 19, 2026, 01:00 UTC (Revision 2).

@Marvinthebored

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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 rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 19, 2026
@obviyus

obviyus commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Thank you, @Marvinthebored, for the clear report, the regression tests and the isolated Control UI proof. They made this easy to check.

Current main already does what this PR asks for, through the turn grant and not a separate owner flag on exec:

Evidence on main 4934b24699c0:

  • Your scenario, end to end: an isolated Gateway (from source), a real openai/gpt-5.5 turn on a stored account, and an admin (operator.admin) chat. The agent ran sleep 15 in the background and yielded. The exec completion woke the same chat, and that wake turn called automations add with no new human message. The one-shot job was stored, came due 70 s later and ran status: ok with summary AUTOMATION_FIRED_BASE.
  • src/agents/bash-tools.exec-notify.owner-continuation.test.ts: 4/4 pass. It covers an owner wake (senderIsOwner: true), a guest wake (false), a tainted owner, and a cross-session start (false).
  • bash-tools.exec-background-followup.test.ts and bash-tools.exec-notify.requester.test.ts: 32/32 pass.
  • Your added test cases depend on APIs that main has since removed, so they cannot run unchanged. ExecToolDefaults.senderIsOwner and captureCommandOwnerAssertion are gone: refactor(plugins): plugin tools take the turn's owner bit; delete the requester-owner continuation (OA2 PR 6j) #205483 removed the requester-owner continuation path. The owner-continuation test above covers the same behavior.

I am closing this PR as fixed on main. #177510 stays open. As your PR body says, its toolsBySender wildcard case is a separate gate, and I have not verified it on main.

@obviyus obviyus closed this Nov 26, 2026
obviyus added a commit that referenced this pull request Nov 26, 2026
…ion results (#205873)

Lands #195879 by @dallinromney (reported by @Marvinthebored in #195802), rebased on current `main`, with one change: the alert text now comes from the refusal cause table.

## Problem

An automation with no recorded inference account is refused before inference with `Automation has no recorded inference account …`. A team member described it as "sub-agent death by loss of credentials, and a mis-reported error message":

- In a session-target run, the refusal is in `lastError`, but the run has no diagnostics. When optional delivery suppresses the reply, the cause falls back to `Session event execution failed`.
- The direct failure alert classified the run as `unknown` and said `Cause: unknown`.
- Startup diagnostics did not warn about unbound Codex-runtime jobs that would use a stored account.

## Fix

- The reply owner's failure cause goes to the session-event result separately from the optional chat text. A recognized account refusal is identified by error identity, not by its message text. It gets a permanent classification and a closed `inference-account-unrecorded` failure detail.
- The direct alert text comes from `src/gateway/operator-refusal.ts` (new cause `automation-account-unrecorded`, with a required next step). It names the repair and does not name the stored account. Automation history keeps the full refusal.
- Recurring jobs stay enabled; normal backoff and alert policy apply. Nothing is auto-disabled, no binding is written and no schema changes.
- Startup inspection covers unbound Codex-runtime jobs on stored accounts. It warns only and does not rebind them.

Production changes add more lines than they remove: the cause was dropped because no code carried it, so this PR adds that path. It adds no new state, retry or flag.

## User impact

The history, diagnostics and chat alert all name the real cause (a missing recorded account) and the one command that repairs it, instead of `Session event execution failed` or `Cause: unknown`.

## Evidence

- Isolated Gateway (from source), real `openai/gpt-5.5`, on base `main` `4934b24699c0`. Two automations were created while the provider used a configured key. The provider then moved to a stored account (`models auth paste-api-key`, config key removed, Gateway restarted), and both jobs came due on their timer. On base, both runs are refused with `Automation has no recorded inference account …`. The isolated run has diagnostics. The `session:` run has **no diagnostics**.
- On this head, the same run is listed under the head E2E below.
- Tests: 23 files, every changed test plus the direct importers of the changed modules, all pass (`ocx test`, 6 shards).
- Same user report, other part: a woken owner chat can create a follow-up automation on `main` (the agent's own background exec wakes it, and the automation it creates runs `ok` on a stored account). That part is fixed on `main`, so #201146 was closed with that evidence.

Closes #195879.

Co-authored-by: Dallin Romney <[email protected]>
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 Nov 27, 2026
…ion results (openclaw#205873)

Lands openclaw#195879 by @dallinromney (reported by @Marvinthebored in openclaw#195802), rebased on current `main`, with one change: the alert text now comes from the refusal cause table.

## Problem

An automation with no recorded inference account is refused before inference with `Automation has no recorded inference account …`. A team member described it as "sub-agent death by loss of credentials, and a mis-reported error message":

- In a session-target run, the refusal is in `lastError`, but the run has no diagnostics. When optional delivery suppresses the reply, the cause falls back to `Session event execution failed`.
- The direct failure alert classified the run as `unknown` and said `Cause: unknown`.
- Startup diagnostics did not warn about unbound Codex-runtime jobs that would use a stored account.

## Fix

- The reply owner's failure cause goes to the session-event result separately from the optional chat text. A recognized account refusal is identified by error identity, not by its message text. It gets a permanent classification and a closed `inference-account-unrecorded` failure detail.
- The direct alert text comes from `src/gateway/operator-refusal.ts` (new cause `automation-account-unrecorded`, with a required next step). It names the repair and does not name the stored account. Automation history keeps the full refusal.
- Recurring jobs stay enabled; normal backoff and alert policy apply. Nothing is auto-disabled, no binding is written and no schema changes.
- Startup inspection covers unbound Codex-runtime jobs on stored accounts. It warns only and does not rebind them.

Production changes add more lines than they remove: the cause was dropped because no code carried it, so this PR adds that path. It adds no new state, retry or flag.

## User impact

The history, diagnostics and chat alert all name the real cause (a missing recorded account) and the one command that repairs it, instead of `Session event execution failed` or `Cause: unknown`.

## Evidence

- Isolated Gateway (from source), real `openai/gpt-5.5`, on base `main` `93c4244a2255`. Two automations were created while the provider used a configured key. The provider then moved to a stored account (`models auth paste-api-key`, config key removed, Gateway restarted), and both jobs came due on their timer. On base, both runs are refused with `Automation has no recorded inference account …`. The isolated run has diagnostics. The `session:` run has **no diagnostics**.
- On this head, the same run is listed under the head E2E below.
- Tests: 23 files, every changed test plus the direct importers of the changed modules, all pass (`ocx test`, 6 shards).
- Same user report, other part: a woken owner chat can create a follow-up automation on `main` (the agent's own background exec wakes it, and the automation it creates runs `ok` on a stored account). That part is fixed on `main`, so openclaw#201146 was closed with that evidence.

Closes openclaw#195879.

Co-authored-by: Dallin Romney <[email protected]>
Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…ion results (#205873)

Lands #195879 by @dallinromney (reported by @Marvinthebored in #195802), rebased on current `main`, with one change: the alert text now comes from the refusal cause table.

An automation with no recorded inference account is refused before inference with `Automation has no recorded inference account …`. A team member described it as "sub-agent death by loss of credentials, and a mis-reported error message":

- In a session-target run, the refusal is in `lastError`, but the run has no diagnostics. When optional delivery suppresses the reply, the cause falls back to `Session event execution failed`.
- The direct failure alert classified the run as `unknown` and said `Cause: unknown`.
- Startup diagnostics did not warn about unbound Codex-runtime jobs that would use a stored account.

- The reply owner's failure cause goes to the session-event result separately from the optional chat text. A recognized account refusal is identified by error identity, not by its message text. It gets a permanent classification and a closed `inference-account-unrecorded` failure detail.
- The direct alert text comes from `src/gateway/operator-refusal.ts` (new cause `automation-account-unrecorded`, with a required next step). It names the repair and does not name the stored account. Automation history keeps the full refusal.
- Recurring jobs stay enabled; normal backoff and alert policy apply. Nothing is auto-disabled, no binding is written and no schema changes.
- Startup inspection covers unbound Codex-runtime jobs on stored accounts. It warns only and does not rebind them.

Production changes add more lines than they remove: the cause was dropped because no code carried it, so this PR adds that path. It adds no new state, retry or flag.

The history, diagnostics and chat alert all name the real cause (a missing recorded account) and the one command that repairs it, instead of `Session event execution failed` or `Cause: unknown`.

- Isolated Gateway (from source), real `openai/gpt-5.5`, on base `main` `4934b24699c0`. Two automations were created while the provider used a configured key. The provider then moved to a stored account (`models auth paste-api-key`, config key removed, Gateway restarted), and both jobs came due on their timer. On base, both runs are refused with `Automation has no recorded inference account …`. The isolated run has diagnostics. The `session:` run has **no diagnostics**.
- On this head, the same run is listed under the head E2E below.
- Tests: 23 files, every changed test plus the direct importers of the changed modules, all pass (`ocx test`, 6 shards).
- Same user report, other part: a woken owner chat can create a follow-up automation on `main` (the agent's own background exec wakes it, and the automation it creates runs `ok` on a stored account). That part is fixed on `main`, so #201146 was closed with that evidence.

Closes #195879.

Co-authored-by: Dallin Romney <[email protected]>
Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 480555a)

Release adaptation: preserve stable cron preparation owner, abort/restart precedence, auto-disable policy and CLI guidance; use the stable cron alert renderer for sanitized repair copy. No required follow-up in the pinned audit.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…ion results (#205873)

Lands #195879 by @dallinromney (reported by @Marvinthebored in #195802), rebased on current `main`, with one change: the alert text now comes from the refusal cause table.

## Problem

An automation with no recorded inference account is refused before inference with `Automation has no recorded inference account …`. A team member described it as "sub-agent death by loss of credentials, and a mis-reported error message":

- In a session-target run, the refusal is in `lastError`, but the run has no diagnostics. When optional delivery suppresses the reply, the cause falls back to `Session event execution failed`.
- The direct failure alert classified the run as `unknown` and said `Cause: unknown`.
- Startup diagnostics did not warn about unbound Codex-runtime jobs that would use a stored account.

## Fix

- The reply owner's failure cause goes to the session-event result separately from the optional chat text. A recognized account refusal is identified by error identity, not by its message text. It gets a permanent classification and a closed `inference-account-unrecorded` failure detail.
- The direct alert text comes from `src/gateway/operator-refusal.ts` (new cause `automation-account-unrecorded`, with a required next step). It names the repair and does not name the stored account. Automation history keeps the full refusal.
- Recurring jobs stay enabled; normal backoff and alert policy apply. Nothing is auto-disabled, no binding is written and no schema changes.
- Startup inspection covers unbound Codex-runtime jobs on stored accounts. It warns only and does not rebind them.

Production changes add more lines than they remove: the cause was dropped because no code carried it, so this PR adds that path. It adds no new state, retry or flag.

## User impact

The history, diagnostics and chat alert all name the real cause (a missing recorded account) and the one command that repairs it, instead of `Session event execution failed` or `Cause: unknown`.

## Evidence

- Isolated Gateway (from source), real `openai/gpt-5.5`, on base `main` `4934b24699c0`. Two automations were created while the provider used a configured key. The provider then moved to a stored account (`models auth paste-api-key`, config key removed, Gateway restarted), and both jobs came due on their timer. On base, both runs are refused with `Automation has no recorded inference account …`. The isolated run has diagnostics. The `session:` run has **no diagnostics**.
- On this head, the same run is listed under the head E2E below.
- Tests: 23 files, every changed test plus the direct importers of the changed modules, all pass (`ocx test`, 6 shards).
- Same user report, other part: a woken owner chat can create a follow-up automation on `main` (the agent's own background exec wakes it, and the automation it creates runs `ok` on a stored account). That part is fixed on `main`, so #201146 was closed with that evidence.

Closes #195879.

Co-authored-by: Dallin Romney <[email protected]>
Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 480555a)

Release adaptation: Keep release CLI argument quoting and classify the existing refusal at outcome ownership; retain only the account-safe notification copy from the newer Gateway refusal table, not its broad authority refactor.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. 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.

3 participants