Skip to content

fix: deliver background command results in incognito chats and when storing them fails - #204532

Merged
obviyus merged 1 commit into
mainfrom
fix/owed-exec-notify-tests
Nov 24, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/owed-exec-notify-tests

Conversation

@obviyus

@obviyus obviyus commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

  1. Incognito chats never get a background command's completion turn. On a scratch Gateway with a real model, an incognito chat runs a background command, replies, and then nothing happens when the command finishes. The completion runs in the async context of the turn that started the command. For an incognito chat, that context holds the turn's session-actor binding and work signal, and both end with the turn.

    So this predates fix: let finished background commands reach the agent before an active goal advances #204265. fix: let finished background commands reach the agent before an active goal advances #204265 only moved the failure point.

  2. A failed owe() drops the result. Since fix: let finished background commands reach the agent before an active goal advances #204265, notifyOnExit stores the result (owe()) before it wakes the chat, and its catch only logs a failed owe(). Any store failure (busy database, store fence) silently drops a produced result.

  3. Five exec-notification test files went red on scheduled main (run 45348156095); fix(ci): align exec completion fixtures with process identity #204507 fixed four. fix: let finished background commands reach the agent before an active goal advances #204265's PR CI did not select them. It changed src/sessions/owed.ts, and these tests live in src/agents/, past the two-import walk. This is the cross-directory miss the fix(ci): bound agent owner PR selection to same-directory importers and a declared behavior set #204346 closing loop covers.

Solution

  • notifyOnExit stores and wakes outside the producing turn's session-actor binding and work scope (runWithoutSessionActorStorage, runOutsideAsyncWorkScope). Both are existing helpers for independent work. The completion acquires its own session actor, so incognito chats store the owed row and get their completion turn.
  • If owe() still fails, the completion wakes its chat once through the same live wake, without a stored row. That one result loses restart recovery, and the Gateway logs why. It is never only logged.
  • fix(ci): align exec completion fixtures with process identity #204507 already moved four of the five red files to the owed-row contract (owed-id context keys). The fifth, bash-process-durable.test.ts, still counted restart notices by the old slug key exec:<slug>; its helper now resolves the adopted process instance (processSessionInstanceId).
  • New bash-tools.exec-notify.store-failure.test.ts: owe() rejects, and the completion still wakes its chat once.
  • fix(ci): bound agent owner PR selection to same-directory importers and a declared behavior set #204346 closing loop: src/sessions/owed.ts is now an owner in scripts/lib/ci-changed-node-test-plan.mts. A change to it selects a declared set: the 5 test files and the new store-failure test. A planner test checks that selection.

Impact

  • Fixes a pre-existing loss: incognito exec results were also lost before fix: let finished background commands reach the agent before an active goal advances #204265 (baseline b8c95a3 repro). On the measured production deployment: 0 events in the retained ~3.8-day window.

  • Incognito chats get background command completion turns.

  • A produced exec result is never only logged when its row cannot be stored.

  • Ordinary chats: no change (Goal ordering and restart exactly-once re-proven below).

  • Production: 1 file, +27 −7.

Evidence

  • Incognito, real Gateway (scratch state and ports, real model; the chat runs a background command, replies STARTED, then must answer the completion):
  • Ordinary chats, real Gateway, this PR: Exec completed precedes the Goal's Advance turn and is appended once; a result pending across a Gateway restart is appended exactly once after it (4/4 checks).
  • Store failure: bash-tools.exec-notify.store-failure.test.ts fails on main (the wake is called 0 times) and passes here.
  • Tests (rebased on main): the 5 files plus exec background follow-up, requester, queue-full, yield sweep and planner integration: all pass, except that locally on macOS bash-process-durable.test.ts stops at the Darwin ACL guard in @openclaw/fs-safe before its assertion (CI on Linux runs it). server.chat-goal.test.ts 72/72. pnpm tsgo:core passes.
  • Planner: ci-changed-node-test-plan.integration.test.ts checks that a change to src/sessions/owed.ts selects the 6 declared tests.

@clawsweeper

clawsweeper Bot commented Nov 24, 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 scripts Repository scripts agents Agent runtime and tooling size: M labels Nov 24, 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. P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Nov 24, 2026
@clawsweeper

clawsweeper Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR detaches background completion delivery from the finished turn’s context, attempts a live wake after storage failure, and updates affected tests and CI routing.

Example: An incognito chat starts sleep 2; printf 'build complete' as a background command and finishes its turn.

  • Before: The completion inherits the finished turn’s storage admission, fails, and never reaches the agent.
  • After: The completion acquires independent storage admission and wakes the agent with the command result.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The source repair is focused and appears correct, but inspectable evidence of the changed user-visible delivery behavior remains incomplete.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A conversation can receive no follow-up after its background command finishes.
Reason: Restoring produced results has clear user value, the repair is focused, and the collaborator-authored PR supplies direction without adding configuration or public contracts.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this PR addresses a source-verifiable completion-delivery bug with a focused repair, and I found no discrete introduced defect.

Priority: P1
Reviewed head: 434ca10242938c5a0796680fd680efaf4654828c

Before merge

  • Complete next step - Resolve GitHub’s reported merge conflict while preserving the owed-result delivery path.

Findings

None.

Tests

  • Missing end-to-end proof: Provide a redacted Gateway transcript or logs showing incognito completion after the originating turn ends and actual chat delivery after an injected owe failure; the reported base-failing/head-passing mock test does not establish delivery.
Agent review details

How this fits together

The exec completion owner converts finished process output into an owed session input and submits it through session-event admission for an agent turn and chat reply.

flowchart TD
A[Background command exits] --> B[Exec completion owner]
B --> C[Session actor and owed storage]
C --> D[Completion wake batching]
B -->|Storage failure| D
D --> E[Session event admission]
E --> F[Agent completion turn]
F --> G[Chat reply]
Loading

Technical review

Best possible solution:

Keep the focused forward repair in the existing completion owner while preserving stored-result ordering, restart recovery, and captured delivery authority.

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

Current-main source establishes that an owe rejection skips delivery, and the inherited incognito binding explains the reported admission failure; no target code was executed during this review.

Is this the best way to solve the issue?

The patch uses existing lifetime-detachment helpers and the existing wake owner, updates consumers of the established owed-ID contract, and adds focused CI selection without introducing another delivery mechanism.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Stored completion delivery changes intended behavior with a stated reason (463d774: Store finished results before waking so Goals wait for them and restart recovery can deliver them once.)
  • Session-event admission keeps the original intent (753a7a5: Run background notifications through ordinary session execution with captured destination, permissions, cancellation, and delivery policy.)
  • Declared CI behavior selection keeps the original intent (5754fac: Cover important tests beyond the bounded import walk without selecting the entire runtime suite.)
  • Completion identity assertions keeps the original intent (463d774: Use process-instance owed IDs rather than reusable display slugs for completion wakes.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 463d774 adds src/agents/bash-tools.exec-notify.ts:360 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 463d7748595d; files: src/agents/bash-tools.exec-notify.ts)
  • Vincent Koc: Raw commit 0d78b4b adds scripts/lib/ci-changed-node-test-plan.mts:422 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 0d78b4be104c; files: scripts/lib/ci-changed-node-test-plan.mts)

PR surface

Source +18, Tests +119, Docs +3, Other +17. Total +157 across 10 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 26 8 +18
Tests 7 134 15 +119
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 1 22 5 +17
Total 10 185 28 +157

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.

Labels

Label changes:

  • add P1: Background-command results can silently fail to reach an active conversation, breaking the agent’s follow-up workflow.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P1: Background-command results can silently fail to reach an active conversation, breaking the agent’s follow-up workflow.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 November 24, 2026, 4:40 AM ET / 09:40 UTC.

@obviyus

obviyus commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override for the red check on head 434ca102:

All shards that run the 5 previously red exec-notification files, the new store-failure test and the planner integration test passed on this head.

…toring them fails

The exec completion runs in the async context of the turn that started the command. An
incognito turn's session-actor binding and work signal end with that turn, so the owed
row write (and, before #204265, the live wake) failed and the result was only logged.
Store and wake outside that context. If owe() still fails, wake the chat once live.

Key the durable restart notice test by the adopted process instance, and declare the
exec completion tests for src/sessions/owed.ts in the changed-test planner, which
missed them for #204265.

Co-authored-by: obviyus <[email protected]>
@obviyus
obviyus force-pushed the fix/owed-exec-notify-tests branch from 434ca10 to 84c1503 Compare November 24, 2026 09:52
@obviyus
obviyus merged commit 0164469 into main Nov 24, 2026
158 of 159 checks passed
@obviyus
obviyus deleted the fix/owed-exec-notify-tests branch November 24, 2026 10:12
obviyus added a commit that referenced this pull request Nov 24, 2026
…204572)

## Problem

When a background command's completion fails to reach its chat, the Gateway log does not say whether the chat was incognito. #204532 fixed a loss that hit only incognito chats, and these lines could not tell the two kinds apart.

## Solution

Every exec completion failure line in `bash-tools.exec-notify.ts` now names the session kind (`incognito` or `normal`): no destination, delivery failed, stays owed, no admitted destination, not stored (fallback), not admitted, and not queued. The lines add no session key or session id. The process slug and owed id stay; they identify the command, not the chat.

Error text from the failing operation is still logged as it is. Logs are written raw and redacted at egress (repository logging rule).

## Impact

Log text only. No behavior change.

## Evidence

- `bash-tools.exec-notify.store-failure.test.ts`, `bash-tools.exec-runtime.test.ts` and `bash-tools.notify-on-exit-ack.test.ts` pass.
- `pnpm tsgo:core` passes.

Co-authored-by: Ayaan Zaidi <[email protected]>
vincentkoc added a commit that referenced this pull request Nov 24, 2026
Carry only the durable-process fixture correction from
0164469 (#204532). Preserve the
exact notice count, fate text, collision guard and cleanup assertions.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 25, 2026
…toring them fails (#204532)

1. **Incognito chats never get a background command's completion turn.** On a scratch Gateway with a real model, an incognito chat runs a background command, replies, and then nothing happens when the command finishes. The completion runs in the async context of the turn that started the command. For an incognito chat, that context holds the turn's session-actor binding and work signal, and both end with the turn.
   - Before #204265 (`463d7748^`): the live wake fails with `SessionDeliveryGenerationUnavailableError`.
   - On `main`: `owe()` fails first, and the Gateway logs `[exec] completion was not admitted (Chat session storage admission ended)`.

   So this predates #204265. #204265 only moved the failure point.
2. **A failed `owe()` drops the result.** Since #204265, `notifyOnExit` stores the result (`owe()`) before it wakes the chat, and its catch only logs a failed `owe()`. Any store failure (busy database, store fence) silently drops a produced result.
3. **Five exec-notification test files went red on scheduled `main`** (run 45348156095); #204507 fixed four. #204265's PR CI did not select them. It changed `src/sessions/owed.ts`, and these tests live in `src/agents/`, past the two-import walk. This is the cross-directory miss the #204346 closing loop covers.

- `notifyOnExit` stores and wakes outside the producing turn's session-actor binding and work scope (`runWithoutSessionActorStorage`, `runOutsideAsyncWorkScope`). Both are existing helpers for independent work. The completion acquires its own session actor, so incognito chats store the owed row and get their completion turn.
- If `owe()` still fails, the completion wakes its chat once through the same live wake, without a stored row. That one result loses restart recovery, and the Gateway logs why. It is never only logged.
- #204507 already moved four of the five red files to the owed-row contract (owed-id context keys). The fifth, `bash-process-durable.test.ts`, still counted restart notices by the old slug key `exec:<slug>`; its helper now resolves the adopted process instance (`processSessionInstanceId`).
- New `bash-tools.exec-notify.store-failure.test.ts`: `owe()` rejects, and the completion still wakes its chat once.
- #204346 closing loop: `src/sessions/owed.ts` is now an owner in `scripts/lib/ci-changed-node-test-plan.mts`. A change to it selects a declared set: the 5 test files and the new store-failure test. A planner test checks that selection.

- Fixes a pre-existing loss: incognito exec results were also lost before #204265 (baseline b8c95a3 repro). On the measured production deployment: 0 events in the retained ~3.8-day window.

- Incognito chats get background command completion turns.
- A produced exec result is never only logged when its row cannot be stored.
- Ordinary chats: no change (Goal ordering and restart exactly-once re-proven below).
- Production: 1 file, +27 −7.

- **Incognito, real Gateway** (scratch state and ports, real model; the chat runs a background command, replies `STARTED`, then must answer the completion):
  - before #204265 (`463d7748^`): no completion turn; `[exec] completion delivery failed (SessionDeliveryGenerationUnavailableError …)`.
  - `main`: no completion turn; `[exec] completion was not admitted (Chat session storage admission ended)`.
  - this PR: the completion turn runs (`SEEN_…` reply); no exec warnings, so the owed row was stored.
- **Ordinary chats, real Gateway, this PR:** `Exec completed` precedes the Goal's Advance turn and is appended once; a result pending across a Gateway restart is appended exactly once after it (4/4 checks).
- **Store failure:** `bash-tools.exec-notify.store-failure.test.ts` fails on `main` (the wake is called 0 times) and passes here.
- **Tests (rebased on `main`):** the 5 files plus exec background follow-up, requester, queue-full, yield sweep and planner integration: all pass, except that locally on macOS `bash-process-durable.test.ts` stops at the Darwin ACL guard in `@openclaw/fs-safe` before its assertion (CI on Linux runs it). `server.chat-goal.test.ts` 72/72. `pnpm tsgo:core` passes.
- **Planner:** `ci-changed-node-test-plan.integration.test.ts` checks that a change to `src/sessions/owed.ts` selects the 6 declared tests.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 0164469)
Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 25, 2026
…toring them fails (openclaw#204532)

## Problem

1. **Incognito chats never get a background command's completion turn.** On a scratch Gateway with a real model, an incognito chat runs a background command, replies, and then nothing happens when the command finishes. The completion runs in the async context of the turn that started the command. For an incognito chat, that context holds the turn's session-actor binding and work signal, and both end with the turn.
   - Before openclaw#204265 (`7a8c93cd^`): the live wake fails with `SessionDeliveryGenerationUnavailableError`.
   - On `main`: `owe()` fails first, and the Gateway logs `[exec] completion was not admitted (Chat session storage admission ended)`.

   So this predates openclaw#204265. openclaw#204265 only moved the failure point.
2. **A failed `owe()` drops the result.** Since openclaw#204265, `notifyOnExit` stores the result (`owe()`) before it wakes the chat, and its catch only logs a failed `owe()`. Any store failure (busy database, store fence) silently drops a produced result.
3. **Five exec-notification test files went red on scheduled `main`** (run 45348156095); openclaw#204507 fixed four. openclaw#204265's PR CI did not select them. It changed `src/sessions/owed.ts`, and these tests live in `src/agents/`, past the two-import walk. This is the cross-directory miss the openclaw#204346 closing loop covers.

## Solution

- `notifyOnExit` stores and wakes outside the producing turn's session-actor binding and work scope (`runWithoutSessionActorStorage`, `runOutsideAsyncWorkScope`). Both are existing helpers for independent work. The completion acquires its own session actor, so incognito chats store the owed row and get their completion turn.
- If `owe()` still fails, the completion wakes its chat once through the same live wake, without a stored row. That one result loses restart recovery, and the Gateway logs why. It is never only logged.
- openclaw#204507 already moved four of the five red files to the owed-row contract (owed-id context keys). The fifth, `bash-process-durable.test.ts`, still counted restart notices by the old slug key `exec:<slug>`; its helper now resolves the adopted process instance (`processSessionInstanceId`).
- New `bash-tools.exec-notify.store-failure.test.ts`: `owe()` rejects, and the completion still wakes its chat once.
- openclaw#204346 closing loop: `src/sessions/owed.ts` is now an owner in `scripts/lib/ci-changed-node-test-plan.mts`. A change to it selects a declared set: the 5 test files and the new store-failure test. A planner test checks that selection.

## Impact

- Fixes a pre-existing loss: incognito exec results were also lost before openclaw#204265 (baseline e5607f8 repro). On the measured production deployment: 0 events in the retained ~3.8-day window.

- Incognito chats get background command completion turns.
- A produced exec result is never only logged when its row cannot be stored.
- Ordinary chats: no change (Goal ordering and restart exactly-once re-proven below).
- Production: 1 file, +27 −7.

## Evidence

- **Incognito, real Gateway** (scratch state and ports, real model; the chat runs a background command, replies `STARTED`, then must answer the completion):
  - before openclaw#204265 (`7a8c93cd^`): no completion turn; `[exec] completion delivery failed (SessionDeliveryGenerationUnavailableError …)`.
  - `main`: no completion turn; `[exec] completion was not admitted (Chat session storage admission ended)`.
  - this PR: the completion turn runs (`SEEN_…` reply); no exec warnings, so the owed row was stored.
- **Ordinary chats, real Gateway, this PR:** `Exec completed` precedes the Goal's Advance turn and is appended once; a result pending across a Gateway restart is appended exactly once after it (4/4 checks).
- **Store failure:** `bash-tools.exec-notify.store-failure.test.ts` fails on `main` (the wake is called 0 times) and passes here.
- **Tests (rebased on `main`):** the 5 files plus exec background follow-up, requester, queue-full, yield sweep and planner integration: all pass, except that locally on macOS `bash-process-durable.test.ts` stops at the Darwin ACL guard in `@openclaw/fs-safe` before its assertion (CI on Linux runs it). `server.chat-goal.test.ts` 72/72. `pnpm tsgo:core` passes.
- **Planner:** `ci-changed-node-test-plan.integration.test.ts` checks that a change to `src/sessions/owed.ts` selects the 6 declared tests.

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

## Problem

When a background command's completion fails to reach its chat, the Gateway log does not say whether the chat was incognito. openclaw#204532 fixed a loss that hit only incognito chats, and these lines could not tell the two kinds apart.

## Solution

Every exec completion failure line in `bash-tools.exec-notify.ts` now names the session kind (`incognito` or `normal`): no destination, delivery failed, stays owed, no admitted destination, not stored (fallback), not admitted, and not queued. The lines add no session key or session id. The process slug and owed id stay; they identify the command, not the chat.

Error text from the failing operation is still logged as it is. Logs are written raw and redacted at egress (repository logging rule).

## Impact

Log text only. No behavior change.

## Evidence

- `bash-tools.exec-notify.store-failure.test.ts`, `bash-tools.exec-runtime.test.ts` and `bash-tools.notify-on-exit-ack.test.ts` pass.
- `pnpm tsgo:core` passes.

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

agents Agent runtime and tooling docs Improvements or additions to documentation P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant