Repository navigation
feat(webhooks): custom webhook verification - #4241
Closed
bradleypriest wants to merge 2 commits into
Closed
bradleypriest wants to merge 2 commits into
bradleypriest wants to merge 2 commits into
Conversation
Add Transform Functions section to webhook docs covering: - Basic config and JS example - Context object type (HookMappingContext) - Return values for agent/wake actions - Returning null to skip webhooks - Async transforms - TypeScript loader requirements - JS works out of the box
bradleypriest
force-pushed
the
feat/hooks-custom-auth
branch
from
January 29, 2026 23:19
de8892b to
f4ffaf3
Compare
Contributor
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f4ffaf3c71
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
shellbytherobot
force-pushed
the
feat/hooks-custom-auth
branch
3 times, most recently
from
January 29, 2026 23:42
0fe61c3 to
6f3726e
Compare
bradleypriest
marked this pull request as draft
January 29, 2026 23:43
Add ability for hook mapping transform modules to export a verifyAuth function for custom authentication (e.g., GitHub HMAC signatures). When a transform module exports verifyAuth, it runs BEFORE standard token auth. This enables external webhook signature verification (GitHub, Stripe, Linear, etc.). Changes: - hooks.ts: Add verifyAndParseWebhook() with custom/token auth paths - hooks-mapping.ts: Add HookVerifyAuthContext type, loadVerifyAuth() - server-http.ts: Use verifyAndParseWebhook() for cleaner auth flow - webhook.md: Document verifyAuth with GitHub example - Tests for verifyAndParseWebhook and loadVerifyAuth
shellbytherobot
force-pushed
the
feat/hooks-custom-auth
branch
from
January 29, 2026 23:45
6f3726e to
920551a
Compare
obviyus
added a commit
that referenced
this pull request
Nov 14, 2026
) ## What Problem This Solves Fixes: a background command that waits silently (it exits 0 with no output when the awaited thing is true, for example `ci-wait`, `sleep 600` or `gh run watch --exit-status`) never wakes a Control UI, dashboard or API conversation. These sessions default to `tools.exec.notifyOnExitEmptySuccess=false`. The agent is told this, so it keeps the turn open and polls the command every 30 s until it exits. When the automations tool is available, OpenAI agents instead schedule a one-shot automation that re-checks every minute. Each re-check is a model turn, and most of them answer `NO_REPLY`. ## User Impact User impact: an agent that waits for CI, a deploy or a delay starts one background command and ends its turn. The command's exit wakes the conversation, and the wake already contains the result. This holds for a silent success too. Fewer model round trips and tokens per wait. Saved, recurring and cross-session follow-ups still use automations. ## Why This Change Was Made **Root cause (current `main`):** - `resolveExecNotificationDefaults` defaults `notifyOnExitEmptySuccess` to true only for chat-channel providers. A wake-armed command in any other session wakes nobody on silent success. The running result therefore says "Its exit wakes this conversation if it prints output or fails, not after a silent success … If it may succeed silently, collect it with poll." The agent follows that and polls. - The wake text compacts output to 180 chars. Woken agents re-read the result with `process log` or re-run the check. - The automations description offers "To come back here later (wait for CI, recheck), add an at + agentTurn job", and the exec description says "No sleep loops for reminders/follow-ups; use automations". So an in-conversation one-time wait becomes a polling automation. **Fix (inside the existing exec/process, automations and skill owners; no new tool, state or stored-row change):** - Default flip (approved): `tools.exec.notifyOnExitEmptySuccess` now defaults to true for every session. The knob stays as an opt-out. Retiring it would change the durable process record, which stores the captured value. `hasExitWake` now also requires the captured empty-success wake, so an opt-out session gets the manual-collection guidance. The Control UI waiting card (`wakesSession`) reads the same fact, so it no longer appears for an opt-out session that a silent success would not continue. The "may succeed silently, collect with poll" branch is gone. Existing suppressions are unchanged: cancel, request Stop, manual kill, terminal poll observed, hidden subagents and ended cron runs. - One contract on every surface (running result, idle poll, exec description): the exit wakes the conversation with the result, silent success included; end the turn if only waiting remains; do not poll or start another command for the same result. To wait for a condition or a time, run one command that loops until it holds, exits non-zero on failure states and prints the result. The running result now shows the deadline (`…, pid 123), times out in 29m59s.`) instead of an ISO timestamp. The sibling list and the `yieldMs` cap note stay. - Wake message: `Exec completed (<id>, code 0, 4m3s):` followed by the retained output tail (last 2,000 chars, raw newlines). Longer output says `last 2000 of N output chars (process log has the rest)`. If the retention cap already discarded the start, it says `process log keeps the last N; earlier output was discarded`. A silent exit says `… with no output.`. Timeout retry guidance is unchanged. Memory export's exec-notice filter (`memory-host-sdk` `isExecCompletionEvent`) recognizes the new format as well as the historical ones, so notices and output tails stay out of searchable memory. - Automations description: a one-time wait inside this conversation is one background exec, not an automation. Automations are for saved reminders, recurring work and cross-session follow-ups. - GitHub skill: a "Wait for CI" recipe (`gh pr checks <n> --watch --fail-fast`, `gh run watch <id> --exit-status`) as one background exec. - Docs: `docs/tools/exec.md`, `docs/gateway/background-process.md`, `docs/gateway/config-tools/built-in-tools.md`, `docs/web/control-ui/chat.md`, config help. Prompt snapshots refreshed for the automations text. Accepted edge cases: subagent sessions and active cron runs now also get an event on silent success. Before, this happened only when they had a chat provider. Subagents get it as a queued system event, not a wake. An active cron run gets it as a follow-up after the run. An operator who wants quiet successes sets `notifyOnExitEmptySuccess=false`. ## Evidence **Real agent, isolated source Gateway** (`ocx src`, pinned Bun fork, own state/port/HOME). Arms: `openai/gpt-6-astra` (OpenClaw runtime) and Claude Opus through the shared Claude proxy. Direct tool surface. Each trial is a fresh session. Fake CI flips to passed 240 s after the first check. 6 trials per arm. base = `f091e80650aa` (current `main`), fix = this head. Measured from the Gateway's own transcript store. **(a) Silent waiter.** "`ci-wait` blocks until all checks pass, then exits 0 without printing. Start it as a background command, by itself. After it exits, run `ci-status` once…", `automations` denied: | Arm | Silent waiter woken by its exit | `process poll` calls | Turns | Tokens / trial | |---|---|---|---|---| | base, OpenAI | **0/6** | 43 | 6 | 314k | | fix, OpenAI | **6/6** | **0** | 12 | 168k | | base, Claude | **0/6** | 48 | 6 | 420k | | fix, Claude | **6/6** | **0** | 12 | 209k | Base: start the waiter, then `process poll timeout=30000` about 8 times until it exits, in one long turn. Fix: start it, end the turn, then `Exec completed (…, code 0, 4m2s) with no output.` wakes the agent, which runs `ci-status` once and answers. All 24 trials delivered the final answer. A softer variant ("run it as is, by itself", no "background") lets the agent choose. Base OpenAI: 5 trials backgrounded the waiter; 0/5 woken, 36 polls. Fix: 3/3 woken, 0 polls; the other 3 trials blocked in turn with `awaitResults`. Claude base blocked in turn in 6/6. Claude fix: 3/3 backgrounded waiters woken, 0 polls. **(b) S2, existing scenario** (printing status check, `automations` denied). No regression: | Arm | Final delivered | `process poll` calls | `NO_REPLY` wake turns | Tokens / trial | |---|---|---|---|---| | base, OpenAI | 5/6 | 0 | 2 | 206k | | fix, OpenAI | 6/6 | 0 | 0 | 174k | | base, Claude | 6/6 | 8 | 0 | 310k | | fix, Claude | 6/6 | **0** | 0 | 203k | The undelivered base trial wrote a loop that matched `*"all checks pass"*`. That pattern never matched `all 15 checks passed`, so the loop ran past the trial window (an agent parsing bug). A separate Claude run on the parent of the previous waiter fix (`18892937`) made 69 polls in 6 trials. On `main` it made 8 polls. **(c) S1, automations allowed** (same prompt): which mechanism does the agent choose for the wait? | Arm | Trials with one-shot automation | Trials with background exec | Turns | `NO_REPLY` turns | Tokens / trial | |---|---|---|---|---|---| | base, OpenAI | **6/6** | 0/6 | 30 | 18 | 708k | | fix, OpenAI | **0/6** | 6/6 (all woken, 0 polls) | 12 | 0 | 161k | | base, Claude | 0/6 | 5/6 (7 polls) | 11 | 0 | 279k | | fix, Claude | 0/6 | 6/6 (all woken, 0 polls) | 12 | 0 | 199k | | fix (this head), OpenAI | **0/6** | 6/6 (5 woken, 0 polls) | 11 | 0 | 161k | | fix (this head), Claude | 0/6 | 6/6 (all woken, 0 polls) | 12 | 0 | 199k | The first fix rows ran before review made the automations and skill wording conditional on an actual wake. The "this head" rows reran S1 on the final text. In one OpenAI trial, the agent's waiter matched `all checks passed` and never matched `all 15 checks passed`, so it ran past the window. That is the same agent parsing bug as in (b); the trial made 0 polls and scheduled no automation. Base OpenAI scheduled an `at` job that re-ran `ci-status` every minute and answered `NO_REPLY` until CI passed. With the fix, the first wake already carried the passing line, so the agent answered without another tool call. **(d) No-wait control.** "Run `lint` (about 20 s, prints nothing when clean), then tell me whether it passed": | Arm | Final delivered | Spurious (`NO_REPLY`) wake turns | Turns | |---|---|---|---| | base, OpenAI | 6/6 | 0 | 6 | | fix, OpenAI | 6/6 | 0 | 8 | | base, Claude | 6/6 | 0 | 6 | | fix, Claude | 6/6 | 0 | 6 | The 2 extra OpenAI fix turns are not spurious. Those trials ended the turn with "lint is running". The silent exit woke them, and they reported "Lint passed (exit code 0, no output; 21 seconds)". On base, that turn shape would leave the user without an answer. Commands collected in turn (`awaitResults`, or a poll that observed the exit) produced no wake. Redacted trace, Claude silent waiter, fix: ```text +212s exec {"yieldMs": 1000} '<ws>/pr-1/ci-wait' +214s -> Command still running (session nova-valley:…, pid …), times out in 29m59s. Its exit wakes this conversation with the result, silent success included. If only waiting remains, end this turn now; do not poll it or start another command for the same result. … +218s reply: I've started `ci-wait` for PR #4241 in the background. When it exits, I'll run `ci-status` … +457s USER: Exec completed (nova-val, code 0, 4m2s) with no output. +462s exec {} '<ws>/pr-1/ci-status' +463s -> PR #4241: all 15 checks passed. Summary: build-1-… green +470s reply: PR #4241 is ready. … ``` Same scenario, base: `exec background` returns "Its exit wakes this conversation if it prints output or fails, not after a silent success…", then eight `process poll timeout=30000` calls each return `(no new output) Process still running.` until `Process exited with code 0.`. **Tests** (`vitest-source`): - `bash-tools.test.ts`: a non-chat session wakes on empty success by default; an explicit `false` stays quiet. - `bash-tools.exec-background-followup.test.ts`: the running result carries the single contract and `times out in`; a dashboard conversation is woken on silent success with exit, duration and a bounded 2,000-char tail. - `memory-host-sdk` `session-files.test.ts`: historical and current exec notices (silent, tail, retention-truncated) stay out of the memory export. - The first two files are red on `main` (7 failures) and green here. The exec/process, durable notify, descriptions, automations schema, config help, prefix-stability and system-prompt suites pass. The UTF-16 boundary test now covers the retained-tail boundary. **Upgrade:** the stored config and state shapes do not change. A saved `true` or `false` keeps its meaning (`bash-tools.test.ts` covers the explicit `false`). An omitted setting adopts the new default when the command starts. Durable records keep the policy they captured at start. **Full tier** on this head: full build with declarations, then a packed tarball install. Tarball integrity, `openclaw --version` (`2026.11.3 (f3d42f9)`, the pre-rebase head with the same code) and `gateway --help` pass, and the packed `bash-tools.exec-output` chunk carries the new guidance. **Limits:** - The E2E ran on the direct tool surface. Code Mode was not measured. - The test host was heavily loaded during the runs, and some first sends needed a longer client timeout. One Claude fix trial in (a)-soft never started (n=5). - Spurious-turn counting is structural: wake turns whose reply is exactly `NO_REPLY`. Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus
added a commit
that referenced
this pull request
Nov 15, 2026
…one-shot runs (#199283) ## What Problem This Solves Fixes: one-shot runs cannot wait for a background command without polling. A hidden subagent or an isolated cron agent turn ends with its final reply, so "end the turn and let the exit wake you" does not work there: - A hidden subagent gets the exit only as a passive system event in its next turn, which never comes. Its running result therefore says "Automatic completion wake is unavailable … use poll with a timeout", and the agent calls `process poll` every 10–30 s for the whole wait. - An isolated cron run gets the same manual-collection guidance. When the run ends first, a queued exit still arrives later as an extra follow-up turn, which answers `NO_REPLY`. - `sessions_yield` only awaited child sessions. With a running command and no child, it said "No pending child completion … did not pause the turn". In a hidden subagent it refused outright ("Use process to poll and collect it before yielding"). ## User Impact User impact: a subagent or automation that waits for CI, a deploy or any long command starts one background command and calls `sessions_yield`. The command's exit resumes the same run with the exit result, and the run reports normally. No poll loop, fewer model round trips and tokens, and no spurious `NO_REPLY` turns after a cron run. Ordinary chat sessions are unchanged: their exit still wakes the conversation when the turn ends. ## Why This Change Was Made **Owners extended (no new tool, parameter, state or stored row):** - **Exec wake target capture** (`prepareExecExitNotification`): hidden subagent and cron-run commands now capture their own session as the wake target and record `exitWakeAfterYield`, but only when `sessions_yield` is callable in that run. The exec tool reads this from the run's final callable tool set, the same way it reads `process` availability. Collectors (which never get `sessions_yield`) and tool policies that remove it keep the previous manual-collection guidance. `hasExitWake` stays the single fact that the running result, idle `process poll` text and the Control UI waiting card read. For a one-shot run it also requires a deadline, so a wait is always bounded by the command's `timeoutSeconds`. A timeout already ends the command, and that exit resumes the run. `timeoutSeconds: 0` keeps manual-collection guidance. - **Running result text** (`describeExitWake`): one-shot runs read "This run resumes with its result when it exits, silent success included, if you call sessions_yield. If only waiting remains, call sessions_yield now; do not poll it or start another command for the same result." Ordinary sessions keep the step 2 text. - **Yield claim** (`createRequesterYieldCallback`): a wake-armed running command that the current run started (`originRunId`) is a completion claim, like a pending child. An accepted yield marks those commands (`resumesYieldedRun`). The step 2 refusal of a hidden-subagent yield with uncollected background work stays for commands whose exit cannot resume the run. - **Hidden subagent resume** (`maybeNotifyOnExit` + `prepareReplySubagentContinuation`): the exit of an awaited command is sent as the ordinary exec wake turn (same content as step 2: exit code, duration, 2,000-char tail) instead of a passive event. It carries the starting run as `sourceRunId`. Reply admission treats an `exec` wake exactly like a tool handoff result: it continues the paused task only when that run is the yielded one, so the subagent's final reply still goes to its requester through the registry. A hidden subagent that did not yield still gets only the passive notice. - **Cron run resume** (`executeCronRun`): the cron executor opens a per-run resume slot. A yield on the run's own commands returns `{ resumesInPlace: true }`; the embedded runner ends the turn but keeps the reply operation open, and the executor runs the next turn in the same operation with the exit text as the prompt. The resumed turn's reply is the run's result. A cron yield for children keeps the existing scheduler-owned behavior. A requested Stop or kill releases the wait without a turn. - **Text and docs**: `sessions_yield` and exec descriptions, the cron unattended preamble (the "will not resume after `sessions_yield`" sentence now applies only to child yields), `docs/tools/exec.md`, `docs/gateway/background-process.md`, `docs/tools/subagents/tool-reference.md`, `docs/concepts/subagent-yield-handoff.md`. Prompt snapshots regenerated. **Accepted edge cases** (named, no code): a command that exits in the instant between an accepted subagent yield and the pause being published runs as a separate follow-up turn instead of continuing the paused task (same window as the existing tool-handoff resume). The Control UI waiting card in a hidden subagent session now shows for wake-armed commands, because the exit can resume the run. An interactive session that calls `sessions_yield` on a wake-armed command gets `yielded`, which ends the turn exactly as ending it normally would. Production delta: +199/−49 lines in `src` (excluding tests). ## Evidence **Real agent, isolated source Gateway** (`ocx src`, pinned Bun fork, own state/port/HOME, `env -i`). Claude Opus through the shared Claude proxy, OpenClaw runtime, direct tool surface, `automations` denied. A fake CI flips to passed 240 s after the first status check. Fresh session per trial, 6 trials per arm, measured from the Gateway's own transcript store. base = `10159aefda9c` (`main` at branch time), fix = `bfd56dc84d66` (first head). The second head (`d51e737ba7da`, manual collection kept where `sessions_yield` is not callable) reran 3 hidden-subagent and 3 cron trials: 6/6 delivered, **0** polls, 5/5 background waiters resumed by their exit (1 cron trial waited in turn). | Scenario | Arm | Final result delivered | `process poll` calls | Exit resumed the run | Spurious `NO_REPLY` turns | Tokens / trial | |---|---|---|---|---|---|---| | (a) parent spawns a hidden subagent that waits for CI, parent reports | base | 6/6 | **76** (all in the subagent) | 0/6 | 0 | 594k | | | fix | 6/6 | **0** | 5/5 waiters (1 trial waited in turn) | 0 | 314k | | (b) isolated cron agent turn waits for CI | base | 6/6 | **61** (12 idle) | 0/6 (2 exits arrived after the run) | **3** | 477k | | | fix | 6/6 | **0** | 5/5 waiters (1 trial waited in turn) | 0 | 156k | | (c) ordinary dashboard session, S2 (`ci-status`) | base | 6/6 | 12 | 6/6 | 0 | 296k | | | fix | 6/6 | **0** | 6/6 | 0 | 198k | (a) parent: in every fix trial the parent yielded for the child and received the child's final summary through the existing subagent completion; in 5/6 the child's reply came from the exec-resumed turn. (b) base: the run polled until CI passed, answered, and the queued exit then started an extra follow-up turn in 3 trials. (c): the ordinary session's running-result text is unchanged. Claude calls `sessions_yield` after starting the waiter in 4/6 trials on base and 4/6 on this head. On base that returns `nothing_pending` and the agent then polls in 3 of those trials (12 polls); here the yield is accepted, the turn ends and the exit wakes the conversation. Two fix trials ran in a supplemental 2-trial arm, because a concurrent packaging step briefly rewrote `package.json` and broke two trial sends in the first arm. Redacted trace, hidden subagent, fix (P = parent, S = subagent): ```text P +13s sessions_spawn → accepted P +17s sessions_yield → {"status":"yielded"} S +22s exec {"yieldMs":120000,"timeoutSeconds":1500} 'cd pr-1 && …loop until ci-status passes…' S +142s -> Command still running (session delta-sage:…, pid …), times out in 23m. This run resumes with its result when it exits, silent success included, if you call sessions_yield. If only waiting remains, call sessions_yield now; do not poll it … S +145s sessions_yield → {"status":"yielded"} S +263s USER: Exec completed (delta-sa, code 0, 4m1s): … PR #4241: all 15 checks passed. Summary: build-1-… green S +266s write pr-1/RESULT.md S +269s reply: All 15 CI checks on PR #4241 have passed. … PR #4241: all 15 checks passed. Summary: build-1-… green P +270s USER: [Subagent Context] Every subagent in this batch has now settled … P +279s reply: The subagent says CI on PR #4241 passed. Its summary line is: PR #4241: all 15 checks passed … ``` Same scenario, base: the subagent's running result says "Automatic completion wake is unavailable after ending this turn … use poll with a timeout", then 14 `process poll timeout=30000` calls each return `PR #4241: 4 checks pending, 11 passed … Process still running.` until it exits. Cron, fix: `exec` → running result with the `sessions_yield` text → `sessions_yield` → `{"status":"yielded"}` → `Exec completed (tender-c, code 0, 4m1s): …` as the next turn of the same run → `ci-status > RESULT.md` → final reply `PR #4241: all 15 checks passed …`, recorded as the run summary. **Tests** (`vitest` from source): - `bash-tools.exec-background-followup.test.ts`: a hidden subagent's command resumes it only after `sessions_yield` awaits it (passive notice otherwise; wake turn with `source: "exec"`, `sourceRunId` and the step 2 content when yielded); a yielded cron run resumes in place with the exit text and sends no session event; cron running results carry the `sessions_yield` text. - `bash-tools.exec-background-followup.test.ts` also keeps the `main` behavior where `sessions_yield` is not callable: a hidden subagent gets manual-collection guidance and no wake promise, and a cron run is told to collect before ending the turn. - `openclaw-tools.requester-yield.test.ts`: a wake-armed command the run started is a yield claim only when it has a deadline; only an accepted yield arms the resume. - The two new tests fail on `main`, where the resume path does not exist; the updated cron assertions also fail there. The exec/process, descriptions, `sessions_yield` tool, requester yield, embedded runner yield orchestration, cron run lifecycle, model-switch retry and prompt-snapshot suites pass. `tsgo:core` passes. **Full tier**: `ocx build --dts` on the rebased head (`cace873cdf6c`), then a packed tarball install: tarball integrity, `openclaw --version` (`2026.11.3 (cace873)`) and `gateway --help` pass; the packed `bash-tools.exec-output` chunk carries the new guidance. **Limits:** - Claude only, direct tool surface; OpenAI and Code Mode were not measured for this step. - In one trial per fix arm (a) and (b), the agent waited in turn with a capped `yieldMs` block instead of backgrounding; it made no polls. - The cron harness has no chat channel, so every run (base and fix) records `completionStatus: failed` for delivery; the run summary is the agent's final reply in both arms. - Gateway restart mid-wait is out of scope (step 5). **CI:** rebased onto `main` `92016ce978f0` (picks up #199113, which only changed the exec-completion enqueue import; no conflict in the yield/wake path). Focused yield, exec, cron and embedded-runner suites and `tsgo:core` pass on the rebased head. If `checks-ui-e2e (1/2)` fails in `ui/src/e2e/chat-cli-history-redaction.e2e.test.ts` ("preserves tool source in Activity while bounding the visible preview", waiting for `.activity-empty`), that failure is on `main`: #199168 removed the Activity element, but this test still waits for it. Locally, `pnpm test:ui:e2e ui/src/e2e/chat-cli-history-redaction.e2e.test.ts` fails the same way on `main` `92016ce978f0` and on this head (1 failed, 1 passed in both). This PR touches no `ui/` file. Other PRs pass that shard because their changed files select only 6 UI test files that do not include this one; this PR's change set selects 19. Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 15, 2026
…claw#199122) ## What Problem This Solves Fixes: a background command that waits silently (it exits 0 with no output when the awaited thing is true, for example `ci-wait`, `sleep 600` or `gh run watch --exit-status`) never wakes a Control UI, dashboard or API conversation. These sessions default to `tools.exec.notifyOnExitEmptySuccess=false`. The agent is told this, so it keeps the turn open and polls the command every 30 s until it exits. When the automations tool is available, OpenAI agents instead schedule a one-shot automation that re-checks every minute. Each re-check is a model turn, and most of them answer `NO_REPLY`. ## User Impact User impact: an agent that waits for CI, a deploy or a delay starts one background command and ends its turn. The command's exit wakes the conversation, and the wake already contains the result. This holds for a silent success too. Fewer model round trips and tokens per wait. Saved, recurring and cross-session follow-ups still use automations. ## Why This Change Was Made **Root cause (current `main`):** - `resolveExecNotificationDefaults` defaults `notifyOnExitEmptySuccess` to true only for chat-channel providers. A wake-armed command in any other session wakes nobody on silent success. The running result therefore says "Its exit wakes this conversation if it prints output or fails, not after a silent success … If it may succeed silently, collect it with poll." The agent follows that and polls. - The wake text compacts output to 180 chars. Woken agents re-read the result with `process log` or re-run the check. - The automations description offers "To come back here later (wait for CI, recheck), add an at + agentTurn job", and the exec description says "No sleep loops for reminders/follow-ups; use automations". So an in-conversation one-time wait becomes a polling automation. **Fix (inside the existing exec/process, automations and skill owners; no new tool, state or stored-row change):** - Default flip (approved): `tools.exec.notifyOnExitEmptySuccess` now defaults to true for every session. The knob stays as an opt-out. Retiring it would change the durable process record, which stores the captured value. `hasExitWake` now also requires the captured empty-success wake, so an opt-out session gets the manual-collection guidance. The Control UI waiting card (`wakesSession`) reads the same fact, so it no longer appears for an opt-out session that a silent success would not continue. The "may succeed silently, collect with poll" branch is gone. Existing suppressions are unchanged: cancel, request Stop, manual kill, terminal poll observed, hidden subagents and ended cron runs. - One contract on every surface (running result, idle poll, exec description): the exit wakes the conversation with the result, silent success included; end the turn if only waiting remains; do not poll or start another command for the same result. To wait for a condition or a time, run one command that loops until it holds, exits non-zero on failure states and prints the result. The running result now shows the deadline (`…, pid 123), times out in 29m59s.`) instead of an ISO timestamp. The sibling list and the `yieldMs` cap note stay. - Wake message: `Exec completed (<id>, code 0, 4m3s):` followed by the retained output tail (last 2,000 chars, raw newlines). Longer output says `last 2000 of N output chars (process log has the rest)`. If the retention cap already discarded the start, it says `process log keeps the last N; earlier output was discarded`. A silent exit says `… with no output.`. Timeout retry guidance is unchanged. Memory export's exec-notice filter (`memory-host-sdk` `isExecCompletionEvent`) recognizes the new format as well as the historical ones, so notices and output tails stay out of searchable memory. - Automations description: a one-time wait inside this conversation is one background exec, not an automation. Automations are for saved reminders, recurring work and cross-session follow-ups. - GitHub skill: a "Wait for CI" recipe (`gh pr checks <n> --watch --fail-fast`, `gh run watch <id> --exit-status`) as one background exec. - Docs: `docs/tools/exec.md`, `docs/gateway/background-process.md`, `docs/gateway/config-tools/built-in-tools.md`, `docs/web/control-ui/chat.md`, config help. Prompt snapshots refreshed for the automations text. Accepted edge cases: subagent sessions and active cron runs now also get an event on silent success. Before, this happened only when they had a chat provider. Subagents get it as a queued system event, not a wake. An active cron run gets it as a follow-up after the run. An operator who wants quiet successes sets `notifyOnExitEmptySuccess=false`. ## Evidence **Real agent, isolated source Gateway** (`ocx src`, pinned Bun fork, own state/port/HOME). Arms: `openai/gpt-6-astra` (OpenClaw runtime) and Claude Opus through the shared Claude proxy. Direct tool surface. Each trial is a fresh session. Fake CI flips to passed 240 s after the first check. 6 trials per arm. base = `c73a5496eba7` (current `main`), fix = this head. Measured from the Gateway's own transcript store. **(a) Silent waiter.** "`ci-wait` blocks until all checks pass, then exits 0 without printing. Start it as a background command, by itself. After it exits, run `ci-status` once…", `automations` denied: | Arm | Silent waiter woken by its exit | `process poll` calls | Turns | Tokens / trial | |---|---|---|---|---| | base, OpenAI | **0/6** | 43 | 6 | 314k | | fix, OpenAI | **6/6** | **0** | 12 | 168k | | base, Claude | **0/6** | 48 | 6 | 420k | | fix, Claude | **6/6** | **0** | 12 | 209k | Base: start the waiter, then `process poll timeout=30000` about 8 times until it exits, in one long turn. Fix: start it, end the turn, then `Exec completed (…, code 0, 4m2s) with no output.` wakes the agent, which runs `ci-status` once and answers. All 24 trials delivered the final answer. A softer variant ("run it as is, by itself", no "background") lets the agent choose. Base OpenAI: 5 trials backgrounded the waiter; 0/5 woken, 36 polls. Fix: 3/3 woken, 0 polls; the other 3 trials blocked in turn with `awaitResults`. Claude base blocked in turn in 6/6. Claude fix: 3/3 backgrounded waiters woken, 0 polls. **(b) S2, existing scenario** (printing status check, `automations` denied). No regression: | Arm | Final delivered | `process poll` calls | `NO_REPLY` wake turns | Tokens / trial | |---|---|---|---|---| | base, OpenAI | 5/6 | 0 | 2 | 206k | | fix, OpenAI | 6/6 | 0 | 0 | 174k | | base, Claude | 6/6 | 8 | 0 | 310k | | fix, Claude | 6/6 | **0** | 0 | 203k | The undelivered base trial wrote a loop that matched `*"all checks pass"*`. That pattern never matched `all 15 checks passed`, so the loop ran past the trial window (an agent parsing bug). A separate Claude run on the parent of the previous waiter fix (`39efe6fb`) made 69 polls in 6 trials. On `main` it made 8 polls. **(c) S1, automations allowed** (same prompt): which mechanism does the agent choose for the wait? | Arm | Trials with one-shot automation | Trials with background exec | Turns | `NO_REPLY` turns | Tokens / trial | |---|---|---|---|---|---| | base, OpenAI | **6/6** | 0/6 | 30 | 18 | 708k | | fix, OpenAI | **0/6** | 6/6 (all woken, 0 polls) | 12 | 0 | 161k | | base, Claude | 0/6 | 5/6 (7 polls) | 11 | 0 | 279k | | fix, Claude | 0/6 | 6/6 (all woken, 0 polls) | 12 | 0 | 199k | | fix (this head), OpenAI | **0/6** | 6/6 (5 woken, 0 polls) | 11 | 0 | 161k | | fix (this head), Claude | 0/6 | 6/6 (all woken, 0 polls) | 12 | 0 | 199k | The first fix rows ran before review made the automations and skill wording conditional on an actual wake. The "this head" rows reran S1 on the final text. In one OpenAI trial, the agent's waiter matched `all checks passed` and never matched `all 15 checks passed`, so it ran past the window. That is the same agent parsing bug as in (b); the trial made 0 polls and scheduled no automation. Base OpenAI scheduled an `at` job that re-ran `ci-status` every minute and answered `NO_REPLY` until CI passed. With the fix, the first wake already carried the passing line, so the agent answered without another tool call. **(d) No-wait control.** "Run `lint` (about 20 s, prints nothing when clean), then tell me whether it passed": | Arm | Final delivered | Spurious (`NO_REPLY`) wake turns | Turns | |---|---|---|---| | base, OpenAI | 6/6 | 0 | 6 | | fix, OpenAI | 6/6 | 0 | 8 | | base, Claude | 6/6 | 0 | 6 | | fix, Claude | 6/6 | 0 | 6 | The 2 extra OpenAI fix turns are not spurious. Those trials ended the turn with "lint is running". The silent exit woke them, and they reported "Lint passed (exit code 0, no output; 21 seconds)". On base, that turn shape would leave the user without an answer. Commands collected in turn (`awaitResults`, or a poll that observed the exit) produced no wake. Redacted trace, Claude silent waiter, fix: ```text +212s exec {"yieldMs": 1000} '<ws>/pr-1/ci-wait' +214s -> Command still running (session nova-valley:…, pid …), times out in 29m59s. Its exit wakes this conversation with the result, silent success included. If only waiting remains, end this turn now; do not poll it or start another command for the same result. … +218s reply: I've started `ci-wait` for PR openclaw#4241 in the background. When it exits, I'll run `ci-status` … +457s USER: Exec completed (nova-val, code 0, 4m2s) with no output. +462s exec {} '<ws>/pr-1/ci-status' +463s -> PR openclaw#4241: all 15 checks passed. Summary: build-1-… green +470s reply: PR openclaw#4241 is ready. … ``` Same scenario, base: `exec background` returns "Its exit wakes this conversation if it prints output or fails, not after a silent success…", then eight `process poll timeout=30000` calls each return `(no new output) Process still running.` until `Process exited with code 0.`. **Tests** (`vitest-source`): - `bash-tools.test.ts`: a non-chat session wakes on empty success by default; an explicit `false` stays quiet. - `bash-tools.exec-background-followup.test.ts`: the running result carries the single contract and `times out in`; a dashboard conversation is woken on silent success with exit, duration and a bounded 2,000-char tail. - `memory-host-sdk` `session-files.test.ts`: historical and current exec notices (silent, tail, retention-truncated) stay out of the memory export. - The first two files are red on `main` (7 failures) and green here. The exec/process, durable notify, descriptions, automations schema, config help, prefix-stability and system-prompt suites pass. The UTF-16 boundary test now covers the retained-tail boundary. **Upgrade:** the stored config and state shapes do not change. A saved `true` or `false` keeps its meaning (`bash-tools.test.ts` covers the explicit `false`). An omitted setting adopts the new default when the command starts. Durable records keep the policy they captured at start. **Full tier** on this head: full build with declarations, then a packed tarball install. Tarball integrity, `openclaw --version` (`2026.11.3 (f3d42f9)`, the pre-rebase head with the same code) and `gateway --help` pass, and the packed `bash-tools.exec-output` chunk carries the new guidance. **Limits:** - The E2E ran on the direct tool surface. Code Mode was not measured. - The test host was heavily loaded during the runs, and some first sends needed a longer client timeout. One Claude fix trial in (a)-soft never started (n=5). - Spurious-turn counting is structural: wake turns whose reply is exactly `NO_REPLY`. Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 15, 2026
…one-shot runs (openclaw#199283) ## What Problem This Solves Fixes: one-shot runs cannot wait for a background command without polling. A hidden subagent or an isolated cron agent turn ends with its final reply, so "end the turn and let the exit wake you" does not work there: - A hidden subagent gets the exit only as a passive system event in its next turn, which never comes. Its running result therefore says "Automatic completion wake is unavailable … use poll with a timeout", and the agent calls `process poll` every 10–30 s for the whole wait. - An isolated cron run gets the same manual-collection guidance. When the run ends first, a queued exit still arrives later as an extra follow-up turn, which answers `NO_REPLY`. - `sessions_yield` only awaited child sessions. With a running command and no child, it said "No pending child completion … did not pause the turn". In a hidden subagent it refused outright ("Use process to poll and collect it before yielding"). ## User Impact User impact: a subagent or automation that waits for CI, a deploy or any long command starts one background command and calls `sessions_yield`. The command's exit resumes the same run with the exit result, and the run reports normally. No poll loop, fewer model round trips and tokens, and no spurious `NO_REPLY` turns after a cron run. Ordinary chat sessions are unchanged: their exit still wakes the conversation when the turn ends. ## Why This Change Was Made **Owners extended (no new tool, parameter, state or stored row):** - **Exec wake target capture** (`prepareExecExitNotification`): hidden subagent and cron-run commands now capture their own session as the wake target and record `exitWakeAfterYield`, but only when `sessions_yield` is callable in that run. The exec tool reads this from the run's final callable tool set, the same way it reads `process` availability. Collectors (which never get `sessions_yield`) and tool policies that remove it keep the previous manual-collection guidance. `hasExitWake` stays the single fact that the running result, idle `process poll` text and the Control UI waiting card read. For a one-shot run it also requires a deadline, so a wait is always bounded by the command's `timeoutSeconds`. A timeout already ends the command, and that exit resumes the run. `timeoutSeconds: 0` keeps manual-collection guidance. - **Running result text** (`describeExitWake`): one-shot runs read "This run resumes with its result when it exits, silent success included, if you call sessions_yield. If only waiting remains, call sessions_yield now; do not poll it or start another command for the same result." Ordinary sessions keep the step 2 text. - **Yield claim** (`createRequesterYieldCallback`): a wake-armed running command that the current run started (`originRunId`) is a completion claim, like a pending child. An accepted yield marks those commands (`resumesYieldedRun`). The step 2 refusal of a hidden-subagent yield with uncollected background work stays for commands whose exit cannot resume the run. - **Hidden subagent resume** (`maybeNotifyOnExit` + `prepareReplySubagentContinuation`): the exit of an awaited command is sent as the ordinary exec wake turn (same content as step 2: exit code, duration, 2,000-char tail) instead of a passive event. It carries the starting run as `sourceRunId`. Reply admission treats an `exec` wake exactly like a tool handoff result: it continues the paused task only when that run is the yielded one, so the subagent's final reply still goes to its requester through the registry. A hidden subagent that did not yield still gets only the passive notice. - **Cron run resume** (`executeCronRun`): the cron executor opens a per-run resume slot. A yield on the run's own commands returns `{ resumesInPlace: true }`; the embedded runner ends the turn but keeps the reply operation open, and the executor runs the next turn in the same operation with the exit text as the prompt. The resumed turn's reply is the run's result. A cron yield for children keeps the existing scheduler-owned behavior. A requested Stop or kill releases the wait without a turn. - **Text and docs**: `sessions_yield` and exec descriptions, the cron unattended preamble (the "will not resume after `sessions_yield`" sentence now applies only to child yields), `docs/tools/exec.md`, `docs/gateway/background-process.md`, `docs/tools/subagents/tool-reference.md`, `docs/concepts/subagent-yield-handoff.md`. Prompt snapshots regenerated. **Accepted edge cases** (named, no code): a command that exits in the instant between an accepted subagent yield and the pause being published runs as a separate follow-up turn instead of continuing the paused task (same window as the existing tool-handoff resume). The Control UI waiting card in a hidden subagent session now shows for wake-armed commands, because the exit can resume the run. An interactive session that calls `sessions_yield` on a wake-armed command gets `yielded`, which ends the turn exactly as ending it normally would. Production delta: +199/−49 lines in `src` (excluding tests). ## Evidence **Real agent, isolated source Gateway** (`ocx src`, pinned Bun fork, own state/port/HOME, `env -i`). Claude Opus through the shared Claude proxy, OpenClaw runtime, direct tool surface, `automations` denied. A fake CI flips to passed 240 s after the first status check. Fresh session per trial, 6 trials per arm, measured from the Gateway's own transcript store. base = `8ae26d8ad99d` (`main` at branch time), fix = `bfd56dc84d66` (first head). The second head (`d51e737ba7da`, manual collection kept where `sessions_yield` is not callable) reran 3 hidden-subagent and 3 cron trials: 6/6 delivered, **0** polls, 5/5 background waiters resumed by their exit (1 cron trial waited in turn). | Scenario | Arm | Final result delivered | `process poll` calls | Exit resumed the run | Spurious `NO_REPLY` turns | Tokens / trial | |---|---|---|---|---|---|---| | (a) parent spawns a hidden subagent that waits for CI, parent reports | base | 6/6 | **76** (all in the subagent) | 0/6 | 0 | 594k | | | fix | 6/6 | **0** | 5/5 waiters (1 trial waited in turn) | 0 | 314k | | (b) isolated cron agent turn waits for CI | base | 6/6 | **61** (12 idle) | 0/6 (2 exits arrived after the run) | **3** | 477k | | | fix | 6/6 | **0** | 5/5 waiters (1 trial waited in turn) | 0 | 156k | | (c) ordinary dashboard session, S2 (`ci-status`) | base | 6/6 | 12 | 6/6 | 0 | 296k | | | fix | 6/6 | **0** | 6/6 | 0 | 198k | (a) parent: in every fix trial the parent yielded for the child and received the child's final summary through the existing subagent completion; in 5/6 the child's reply came from the exec-resumed turn. (b) base: the run polled until CI passed, answered, and the queued exit then started an extra follow-up turn in 3 trials. (c): the ordinary session's running-result text is unchanged. Claude calls `sessions_yield` after starting the waiter in 4/6 trials on base and 4/6 on this head. On base that returns `nothing_pending` and the agent then polls in 3 of those trials (12 polls); here the yield is accepted, the turn ends and the exit wakes the conversation. Two fix trials ran in a supplemental 2-trial arm, because a concurrent packaging step briefly rewrote `package.json` and broke two trial sends in the first arm. Redacted trace, hidden subagent, fix (P = parent, S = subagent): ```text P +13s sessions_spawn → accepted P +17s sessions_yield → {"status":"yielded"} S +22s exec {"yieldMs":120000,"timeoutSeconds":1500} 'cd pr-1 && …loop until ci-status passes…' S +142s -> Command still running (session delta-sage:…, pid …), times out in 23m. This run resumes with its result when it exits, silent success included, if you call sessions_yield. If only waiting remains, call sessions_yield now; do not poll it … S +145s sessions_yield → {"status":"yielded"} S +263s USER: Exec completed (delta-sa, code 0, 4m1s): … PR openclaw#4241: all 15 checks passed. Summary: build-1-… green S +266s write pr-1/RESULT.md S +269s reply: All 15 CI checks on PR openclaw#4241 have passed. … PR openclaw#4241: all 15 checks passed. Summary: build-1-… green P +270s USER: [Subagent Context] Every subagent in this batch has now settled … P +279s reply: The subagent says CI on PR openclaw#4241 passed. Its summary line is: PR openclaw#4241: all 15 checks passed … ``` Same scenario, base: the subagent's running result says "Automatic completion wake is unavailable after ending this turn … use poll with a timeout", then 14 `process poll timeout=30000` calls each return `PR openclaw#4241: 4 checks pending, 11 passed … Process still running.` until it exits. Cron, fix: `exec` → running result with the `sessions_yield` text → `sessions_yield` → `{"status":"yielded"}` → `Exec completed (tender-c, code 0, 4m1s): …` as the next turn of the same run → `ci-status > RESULT.md` → final reply `PR openclaw#4241: all 15 checks passed …`, recorded as the run summary. **Tests** (`vitest` from source): - `bash-tools.exec-background-followup.test.ts`: a hidden subagent's command resumes it only after `sessions_yield` awaits it (passive notice otherwise; wake turn with `source: "exec"`, `sourceRunId` and the step 2 content when yielded); a yielded cron run resumes in place with the exit text and sends no session event; cron running results carry the `sessions_yield` text. - `bash-tools.exec-background-followup.test.ts` also keeps the `main` behavior where `sessions_yield` is not callable: a hidden subagent gets manual-collection guidance and no wake promise, and a cron run is told to collect before ending the turn. - `openclaw-tools.requester-yield.test.ts`: a wake-armed command the run started is a yield claim only when it has a deadline; only an accepted yield arms the resume. - The two new tests fail on `main`, where the resume path does not exist; the updated cron assertions also fail there. The exec/process, descriptions, `sessions_yield` tool, requester yield, embedded runner yield orchestration, cron run lifecycle, model-switch retry and prompt-snapshot suites pass. `tsgo:core` passes. **Full tier**: `ocx build --dts` on the rebased head (`cace873cdf6c`), then a packed tarball install: tarball integrity, `openclaw --version` (`2026.11.3 (cace873)`) and `gateway --help` pass; the packed `bash-tools.exec-output` chunk carries the new guidance. **Limits:** - Claude only, direct tool surface; OpenAI and Code Mode were not measured for this step. - In one trial per fix arm (a) and (b), the agent waited in turn with a capped `yieldMs` block instead of backgrounding; it made no polls. - The cron harness has no chat channel, so every run (base and fix) records `completionStatus: failed` for delivery; the run summary is the agent's final reply in both arms. - Gateway restart mid-wait is out of scope (step 5). **CI:** rebased onto `main` `d0193c2d8434` (picks up openclaw#199113, which only changed the exec-completion enqueue import; no conflict in the yield/wake path). Focused yield, exec, cron and embedded-runner suites and `tsgo:core` pass on the rebased head. If `checks-ui-e2e (1/2)` fails in `ui/src/e2e/chat-cli-history-redaction.e2e.test.ts` ("preserves tool source in Activity while bounding the visible preview", waiting for `.activity-empty`), that failure is on `main`: openclaw#199168 removed the Activity element, but this test still waits for it. Locally, `pnpm test:ui:e2e ui/src/e2e/chat-cli-history-redaction.e2e.test.ts` fails the same way on `main` `d0193c2d8434` and on this head (1 failed, 1 passed in both). This PR touches no `ui/` file. Other PRs pass that shard because their changed files select only 6 UI test files that do not include this one; this PR's change set selects 19. Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus
added a commit
that referenced
this pull request
Nov 15, 2026
… a Gateway crash (#199499) ## What Problem This Solves Fixes: a conversation that ended its turn waiting for a background command to exit never hears about it again when the Gateway crashes or is killed mid-wait. The exit wake lived only in memory, and the restart resume marker is written only by a graceful shutdown, so after a crash the conversation hung silently. ## User Impact User impact: after any Gateway restart, crashes included, each conversation that was waiting on an ordinary background command gets one notice for that command. The notice names the process handle and start time and says what happened to the command, so the agent can check its output and run it again. Durable commands (`durable: true`) keep their existing adopted exit wake and get no notice. Behavior changes: - The generic "Background exec processes were stopped; rerun them if still needed" sentence in the graceful-restart resume input is gone. The per-command notice replaces it. - A background command whose exit would not wake the conversation, such as a service with `notifyOnExit` off, no longer causes a restart resume turn. ## Why This Change Was Made The process registry already owns the `durable_background_processes` table, its startup pass and the lost-process wake. It now also keeps a best-effort row for each running ordinary command whose exit would wake its conversation, on every platform: - The row reuses the existing table with `kind: "ordinary"` and the generic command summary. It needs no new table, column or schema version. - The row is written when the command is backgrounded and deleted when the command exits. - Incognito sessions are never recorded, because their state stays in memory. - Sandbox commands are recorded with a `sandboxed` flag. The Gateway cannot see inside the container, so their notice says the command may still be running. - Windows runs the startup pass too (durable launches stay Linux and macOS only), so Windows waiters keep a restart notice. On startup, the existing durable pass: - reports every remaining row once through the existing completion path, under the session's current authority, then deletes it; - rechecks eligibility as for durable outcomes (reset, archived and hidden subagent sessions, or `notifyOnExit` off, get nothing); - waits for agent database readiness, which finishes after the listener binds after a crash. The graceful-restart marker no longer tracks background processes (`hadBackgroundExec` is removed), so one owner reports lost commands. The notice text follows a measured fact. In each case below, the Gateway process alone was killed and a real agent's background commands were watched: | Host | Gateway killed (SIGKILL) | Graceful stop | | --- | --- | --- | | macOS, plain and under a launchd LaunchAgent | A silent command keeps running as an orphan; one that writes output dies at its next write | All stopped | | Linux (systemd 255 user service with the installed policy, and plain) | All stopped within 2 s | All stopped | The startup pass reads the Gateway boot record to tell a crash from a shutdown. After a shutdown, or a crash on Linux, the notice says the command was stopped. After a crash on macOS it says the command may still be running, but its result will not wake this conversation. No orphan tracking is added; `durable: true` remains the way to keep a command alive. ## Evidence Real-agent E2E on an isolated source Gateway (`openai/gpt-6-astra`, 6 concurrent conversations per arm, automations tool denied). Each conversation waits on a fake CI that turns green about 300 s after its first check. The Gateway is stopped about 90 s after every conversation has started its wait and ended its turn, then a new Gateway starts on the same state. | Arm | Waiting, turn ended | Conversations resumed | Re-armed a waiter | Finished the task | | --- | --- | --- | --- | --- | | base `669576890a1f`, crash (SIGKILL) | 6/6 | **0/6** | 0/6 | 0/6 | | fix, crash (SIGKILL) | 6/6 | **6/6** | 6/6 | 6/6 | | fix, graceful (SIGTERM) | 6/6 | 6/6, one notice each | 6/6 | 5/6 (one model-written loop's pattern never matched "all 15 checks passed") | | fix, `durable: true` waiter, graceful | 6/6 | 0 restart notices, 0 polls; 6/6 woken by the adopted exit | n/a | 6/6 | <details><summary>Public trace, crash on macOS, base vs fix (trial 1, paths redacted)</summary> Base: the conversation waits forever. ``` + 28s exec {"yieldMs": 1000, "timeoutSeconds": 3660} "python3 -u - <<'PY' …" + 29s -> Command still running (session quiet-ocean:…). Its exit wakes this conversation … + 32s sessions_yield (Gateway SIGKILLed at +137 s, new Gateway ready; nothing else ever arrives) ``` Fix: one notice, the agent checks and re-arms, then finishes. ``` + 32s exec {"background": true, "timeoutSeconds": 1830} "python3 -u - <<'PY' …" + 32s -> Command still running (session briny-falcon:…). Its exit wakes this conversation … + 36s sessions_yield +166s USER: Exec failed (briny-fa, unknown exit code, 2m9s): The Gateway restarted unexpectedly while this background command (started 2026-11-15T05:37:58.662Z) was running. It may still be running, but its result will not wake this conversation. Check its output and side effects before running it again. +176s exec "ps -p 13156 …; ./ci-status" +176s -> PR #4241: 4 checks pending, 11 passed +190s exec {"background": true, "timeoutSeconds": 1830} "python3 -u - <<'PY' …" +326s USER: Exec completed (neat-bre, code 0, 2m15s): … all 15 checks passed … +328s reply: PR #4241 is ready—all 15 checks passed. Saved and verified the summary in `pr-1/RESULT.md` … ``` Graceful stop with the fix: `Exec failed (vivid-du, unknown exit code, 2m12s): This background command (started …) was stopped when the Gateway shut down, so its result will not arrive. If you still need it, check its output and side effects, then run it again.` </details> Upgrade from latest stable (v2026.11.3, `847611dcaa3b`), real agent, isolated state: 1. A v2026.11.3 Gateway ran 3 waiting conversations, then got a graceful stop. 2. This branch ran `openclaw doctor --fix --yes`, which migrated state schema 22 to 40 (exit 0), then started on the same state. Sessions and transcripts loaded (transcript backfill 3/3 sessions, 122 rows). The startup pass found no `durable_background_processes` table, because the table is created on first use, and logged nothing. 3. A new conversation on the upgraded state started a waiter and ended its turn. The table was created and held one row: `ordinary:cool-ridge:…`. 4. The Gateway got SIGKILL. The next start sent `Exec failed (cool-rid, unknown exit code, 1m5s): The Gateway restarted unexpectedly while this background command (started 2026-11-15T07:22:46.300Z) was running. It may still be running, …`. The agent checked for survivors, re-armed, and finished (`PR #4249 is ready—all 15 checks passed`). 0 rows remained. v2026.11.3 writes neither restart markers nor process rows. Commands running when it stops therefore get no notice after the upgrade. This PR does not change the legacy upgrade bridge. Tests: - `src/agents/bash-process-durable.test.ts` adds "reports each wake-armed ordinary command a restart lost, once, with what happened to it". It fails on base and passes with the fix. It covers: a command that exits leaves no row; a crashed command and a stopped command are each reported once with the right text; rows are gone afterwards. - Restart marker tests now mark sessions through a live run instead of a background process, because background processes no longer create a marker. - `test/gateway-restart-resume.e2e.test.ts` now expects the stopped background case to receive the per-command notice instead of the resume sentence. It passes 5/5 on 4 consecutive runs. Under heavy host load, both base and this branch hit an intermittent mock-provider `JSON Parse error: Unexpected EOF`. - The durable registry test also records a sandbox command (cautious notice) and an incognito command (no row); removing the incognito check turns it red (4 rows instead of 3). - Focused suites pass: restart resume, session event context, lifecycle state, startup resume, process registry, durable notify, post-attach startup, and the restart recovery integrity suite. Known gaps: - Worker and `host=node` commands are not recorded, as before; their processes are owned elsewhere. - A best-effort row write can fail; the command still runs normally and only the restart notice is missing. - If the boot record is unavailable, a macOS crash would be reported as a shutdown. Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 16, 2026
… a Gateway crash (openclaw#199499) ## What Problem This Solves Fixes: a conversation that ended its turn waiting for a background command to exit never hears about it again when the Gateway crashes or is killed mid-wait. The exit wake lived only in memory, and the restart resume marker is written only by a graceful shutdown, so after a crash the conversation hung silently. ## User Impact User impact: after any Gateway restart, crashes included, each conversation that was waiting on an ordinary background command gets one notice for that command. The notice names the process handle and start time and says what happened to the command, so the agent can check its output and run it again. Durable commands (`durable: true`) keep their existing adopted exit wake and get no notice. Behavior changes: - The generic "Background exec processes were stopped; rerun them if still needed" sentence in the graceful-restart resume input is gone. The per-command notice replaces it. - A background command whose exit would not wake the conversation, such as a service with `notifyOnExit` off, no longer causes a restart resume turn. ## Why This Change Was Made The process registry already owns the `durable_background_processes` table, its startup pass and the lost-process wake. It now also keeps a best-effort row for each running ordinary command whose exit would wake its conversation, on every platform: - The row reuses the existing table with `kind: "ordinary"` and the generic command summary. It needs no new table, column or schema version. - The row is written when the command is backgrounded and deleted when the command exits. - Incognito sessions are never recorded, because their state stays in memory. - Sandbox commands are recorded with a `sandboxed` flag. The Gateway cannot see inside the container, so their notice says the command may still be running. - Windows runs the startup pass too (durable launches stay Linux and macOS only), so Windows waiters keep a restart notice. On startup, the existing durable pass: - reports every remaining row once through the existing completion path, under the session's current authority, then deletes it; - rechecks eligibility as for durable outcomes (reset, archived and hidden subagent sessions, or `notifyOnExit` off, get nothing); - waits for agent database readiness, which finishes after the listener binds after a crash. The graceful-restart marker no longer tracks background processes (`hadBackgroundExec` is removed), so one owner reports lost commands. The notice text follows a measured fact. In each case below, the Gateway process alone was killed and a real agent's background commands were watched: | Host | Gateway killed (SIGKILL) | Graceful stop | | --- | --- | --- | | macOS, plain and under a launchd LaunchAgent | A silent command keeps running as an orphan; one that writes output dies at its next write | All stopped | | Linux (systemd 255 user service with the installed policy, and plain) | All stopped within 2 s | All stopped | The startup pass reads the Gateway boot record to tell a crash from a shutdown. After a shutdown, or a crash on Linux, the notice says the command was stopped. After a crash on macOS it says the command may still be running, but its result will not wake this conversation. No orphan tracking is added; `durable: true` remains the way to keep a command alive. ## Evidence Real-agent E2E on an isolated source Gateway (`openai/gpt-6-astra`, 6 concurrent conversations per arm, automations tool denied). Each conversation waits on a fake CI that turns green about 300 s after its first check. The Gateway is stopped about 90 s after every conversation has started its wait and ended its turn, then a new Gateway starts on the same state. | Arm | Waiting, turn ended | Conversations resumed | Re-armed a waiter | Finished the task | | --- | --- | --- | --- | --- | | base `0a8e0b7d9cd0`, crash (SIGKILL) | 6/6 | **0/6** | 0/6 | 0/6 | | fix, crash (SIGKILL) | 6/6 | **6/6** | 6/6 | 6/6 | | fix, graceful (SIGTERM) | 6/6 | 6/6, one notice each | 6/6 | 5/6 (one model-written loop's pattern never matched "all 15 checks passed") | | fix, `durable: true` waiter, graceful | 6/6 | 0 restart notices, 0 polls; 6/6 woken by the adopted exit | n/a | 6/6 | <details><summary>Public trace, crash on macOS, base vs fix (trial 1, paths redacted)</summary> Base: the conversation waits forever. ``` + 28s exec {"yieldMs": 1000, "timeoutSeconds": 3660} "python3 -u - <<'PY' …" + 29s -> Command still running (session quiet-ocean:…). Its exit wakes this conversation … + 32s sessions_yield (Gateway SIGKILLed at +137 s, new Gateway ready; nothing else ever arrives) ``` Fix: one notice, the agent checks and re-arms, then finishes. ``` + 32s exec {"background": true, "timeoutSeconds": 1830} "python3 -u - <<'PY' …" + 32s -> Command still running (session briny-falcon:…). Its exit wakes this conversation … + 36s sessions_yield +166s USER: Exec failed (briny-fa, unknown exit code, 2m9s): The Gateway restarted unexpectedly while this background command (started 2026-11-15T05:37:58.662Z) was running. It may still be running, but its result will not wake this conversation. Check its output and side effects before running it again. +176s exec "ps -p 13156 …; ./ci-status" +176s -> PR openclaw#4241: 4 checks pending, 11 passed +190s exec {"background": true, "timeoutSeconds": 1830} "python3 -u - <<'PY' …" +326s USER: Exec completed (neat-bre, code 0, 2m15s): … all 15 checks passed … +328s reply: PR openclaw#4241 is ready—all 15 checks passed. Saved and verified the summary in `pr-1/RESULT.md` … ``` Graceful stop with the fix: `Exec failed (vivid-du, unknown exit code, 2m12s): This background command (started …) was stopped when the Gateway shut down, so its result will not arrive. If you still need it, check its output and side effects, then run it again.` </details> Upgrade from latest stable (v2026.11.3, `847611dcaa3b`), real agent, isolated state: 1. A v2026.11.3 Gateway ran 3 waiting conversations, then got a graceful stop. 2. This branch ran `openclaw doctor --fix --yes`, which migrated state schema 22 to 40 (exit 0), then started on the same state. Sessions and transcripts loaded (transcript backfill 3/3 sessions, 122 rows). The startup pass found no `durable_background_processes` table, because the table is created on first use, and logged nothing. 3. A new conversation on the upgraded state started a waiter and ended its turn. The table was created and held one row: `ordinary:cool-ridge:…`. 4. The Gateway got SIGKILL. The next start sent `Exec failed (cool-rid, unknown exit code, 1m5s): The Gateway restarted unexpectedly while this background command (started 2026-11-15T07:22:46.300Z) was running. It may still be running, …`. The agent checked for survivors, re-armed, and finished (`PR openclaw#4249 is ready—all 15 checks passed`). 0 rows remained. v2026.11.3 writes neither restart markers nor process rows. Commands running when it stops therefore get no notice after the upgrade. This PR does not change the legacy upgrade bridge. Tests: - `src/agents/bash-process-durable.test.ts` adds "reports each wake-armed ordinary command a restart lost, once, with what happened to it". It fails on base and passes with the fix. It covers: a command that exits leaves no row; a crashed command and a stopped command are each reported once with the right text; rows are gone afterwards. - Restart marker tests now mark sessions through a live run instead of a background process, because background processes no longer create a marker. - `test/gateway-restart-resume.e2e.test.ts` now expects the stopped background case to receive the per-command notice instead of the resume sentence. It passes 5/5 on 4 consecutive runs. Under heavy host load, both base and this branch hit an intermittent mock-provider `JSON Parse error: Unexpected EOF`. - The durable registry test also records a sandbox command (cautious notice) and an incognito command (no row); removing the incognito check turns it red (4 rows instead of 3). - Focused suites pass: restart resume, session event context, lifecycle state, startup resume, process registry, durable notify, post-attach startup, and the restart recovery integrity suite. Known gaps: - Worker and `host=node` commands are not recorded, as before; their processes are owned elsewhere. - A best-effort row write can fail; the command still runs normally and only the restart notice is missing. - If the boot record is unavailable, a macOS crash would be reported as a shutdown. Co-authored-by: Ayaan Zaidi <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two changes:
Document existing transform functions — the
hooks.mappingstransform feature was only mentioned in bullet points with no examples, context type, or return value documentation.Add custom
verifyAuthsupport — transform modules can now export averifyAuthfunction for custom webhook authentication (e.g., GitHub HMAC signatures), bypassing standard token auth.Motivation
External webhooks (GitHub, Stripe, Linear, etc.) use their own authentication schemes like HMAC signatures.
Currently, hooks only support bearer token auth, making it difficult to receive webhooks from these services securely.
Changes
Commit 1: docs(hooks): document transform functions
docs/automation/webhook.mdHookMappingContexttype, return values,nullto skip, async supportCommit 2: feat(hooks): support custom verifyAuth in transform modules
readJsonBodyintoreadRawBody+parseJsonBody; addverifyAndParseWebhook()with custom auth and token auth pathsHookVerifyAuthContexttype,HookVerifyAuthFntype,loadVerifyAuth()exportverifyAndParseWebhook()verifyAndParseWebhook(token auth, invalid token, query token),loadVerifyAuth(with/without export)Usage
When a mapping's transform exports
verifyAuth, it replaces standard token auth for that mapping.Return
trueto allow,falseto reject with 401. Mappings withoutverifyAuthuse standard token auth as before.Checklist
Implemented by Shellby (assistant) working with Bradley