Skip to content

fix(exec): avoid gateway stalls during background task writes - #157177

Merged
steipete merged 4 commits into
mainfrom
codex/background-exec-task-worker
Sep 24, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/background-exec-task-worker

Conversation

@steipete

@steipete steipete commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Gateway pauses when a background command starts or finishes while another writer holds the task database lock.

User Impact

Background task bookkeeping waits through the existing worker without blocking other Gateway work. A promoted background command keeps its process handle even if it exits during registration. Task writes settle before completion notifications and process-scope cleanup.

Why This Change Was Made

Registration and completion reuse the existing task worker and its creation receipt. The process retains ownership through pending registration, terminal writes, and notification-error recovery. Raw process exit metadata remains intact when task callbacks fail, and registered V1 runtimes keep their synchronous contract. Terminal metadata cannot overwrite child, session, or owner authority fields.

Registration stays with the existing settlement owner; terminal exit settlement moves into a focused sibling module. Related lifecycle tests move into their existing cleanup owners. No configuration, schema, durability, migration, or retention change is required.

Evidence

Source-bound Blacksmith Testbox proof passed 122 selected runtime checks, including real command creation and exit under database contention, fast exit during registration, same-run session isolation, repeated callback failures, notification ordering, per-agent result retention, and joined worker-environment cleanup. The affected 24-case cleanup group was rerun successfully after completing its stdin mock. The unchanged 75 receipt-owner checks are retained.

Negative controls reproduce premature task/result settlement on the original implementation and the lost-process-handle regression on the earlier revision. The repaired path passes those same contracts. Assertions and deadlines remain intact.

Single-worker test-cost comparison for the same three contention/fast-exit cases:

Revision Result Wall time Peak RSS
Original implementation 3 expected failures 41.52 s 2.92 GiB
Corrected implementation 3 passes 28.36 s 2.89 GiB

The broader 120-case command group took 46.20 s with 2.84 GiB peak RSS; the two worker-environment cases took 22.80 s with 2.89 GiB peak RSS. These are whole-process test costs, including compilation/setup and cache effects, not production latency or per-message transfer measurements.

Production types, all 25 core-test type graphs, targeted lint, formatting/size ratchets, export and import-cycle checks, and the remaining selected guards passed. Independent review has no remaining actionable findings. Required exact-head CI is tracked by this PR's openclaw/ci-gate.

Warm writes use scoped task results through the existing worker transport. Cold registry restoration and large-result deserialization retain their existing behavior; large cold ledgers and deployed latency gains remain unmeasured.

@clawsweeper

clawsweeper Bot commented Sep 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 agents Agent runtime and tooling size: XL labels Sep 24, 2026
@steipete
steipete marked this pull request as ready for review September 24, 2026 09:28
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 24, 2026, 10:44 AM ET / 14:44 UTC (Revision 4).

ClawSweeper review

What this changes

The branch routes background command registration and terminal task-ledger writes through OpenClaw's task worker while retaining process cleanup ownership until settlement finishes.

Merge readiness

⛔ Blocked before merge - 1 item remains

Current main still performs synchronous background-task writes, so this PR addresses a remaining Gateway stall. The reported real-command contention proof supports the repair, and the prior upgrade concern does not apply to the unchanged stored-data contract.

Priority: P1
Reviewed head: 0ed5c3c5888acc19ad1072453b5fa8cb847b210d

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Real-command contention and negative-control evidence support a coherent worker-owner repair with focused authority and cleanup coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed exec-to-task-worker path is exercised by real child commands and SQLite coordinator contention in the supplied Blacksmith Testbox run; the reported original-path failures become passing ordered ledger writes after the fix. Existing task fields and the existing worker transition are reused, so no stored-data contract change needs migration proof.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed exec-to-task-worker path is exercised by real child commands and SQLite coordinator contention in the supplied Blacksmith Testbox run; the reported original-path failures become passing ordered ledger writes after the fix. Existing task fields and the existing worker transition are reused, so no stored-data contract change needs migration proof.
Evidence reviewed 9 items Current main still uses synchronous registration: The background promotion path calls createBackgroundExecTask before resolving the background result; the relevant current-main files match the PR base.
Introduced promotion ordering: The introduced path awaits registration before returning a promoted process handle, including when the command exits during registration.
Exact task authority: The receipt's finalizer checks the active process owner, exact task ID, and absence of a replacement run owner before requesting the terminal write.
Findings None None.
Security None None.

How this fits together

The agent exec tool starts commands and records promoted background processes in a SQLite task ledger. That ledger supplies task status, while process-scope cleanup waits for terminal writes and notifications.

flowchart LR
 A[Agent exec request] --> B[Process supervisor]
 B --> C{Background promotion}
 C -->|Yes| D[Task worker]
 D --> E[SQLite task ledger]
 B --> F[Process exit]
 E --> G[Completion notification]
 F --> G
 G --> H[Scope cleanup]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +233, Tests +408, Docs +8. Total +649 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 10 340 107 +233
Tests 7 704 296 +408
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 1052 403 +649

Review metrics

Metric Value Why it matters
Production and test LOC production +243/-104 (+139 net); tests +801/-299 (+502 net) The production growth supports async settlement and exact-owner handling; most added lines are focused contention and lifecycle coverage.

Stored data model

Persistent data-model change detected: serialized state: src/worker/worker-runtime-background-exec.suite.ts, unknown-data-model-change: src/worker/worker-runtime-background-exec.suite.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep background exec writes with the existing task worker and exact receipt, preserving synchronous V1 adapters and holding process ownership through terminal settlement and cleanup.

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

Yes. Current main retains the synchronous write path, and the supplied Testbox negative controls report three original-path failures under task database contention; this read-only review did not execute them.

Is this the best way to solve the issue?

Yes. Reusing the task worker and its exact creation receipt addresses the blocking write at its owner while preserving the existing synchronous V1 runtime contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1b32a8b3c7fc.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: The current synchronous path can pause Gateway work during background-command task writes.
  • merge-risk: 🚨 availability: The changed worker settlement gates process-scope release, making ordering and worker completion an availability-sensitive merge surface.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed exec-to-task-worker path is exercised by real child commands and SQLite coordinator contention in the supplied Blacksmith Testbox run; the reported original-path failures become passing ordered ledger writes after the fix. Existing task fields and the existing worker transition are reused, so no stored-data contract change needs migration proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed exec-to-task-worker path is exercised by real child commands and SQLite coordinator contention in the supplied Blacksmith Testbox run; the reported original-path failures become passing ordered ledger writes after the fix. Existing task fields and the existing worker transition are reused, so no stored-data contract change needs migration proof.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • roboclaw-bot: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Shakker: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-24T09:40:06.041Z sha 7336608 :: blocked before merge. :: none
  • reviewed 2026-09-24T10:37:29.722Z sha f75fa85 :: blocked before merge. :: none
  • reviewed 2026-09-24T12:43:35.176Z sha a7cf7a2 :: blocked before merge. :: none

Keep the background process handle after promotion even when the command exits during task registration. Preserve joined terminal cleanup and the synchronous registered runtime contract, and strengthen the fast-exit race regression.
Provide the required stdin end method while preserving the destroy-failure ordering and scope-cleanup assertions.
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 24, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 24, 2026
@steipete
steipete enabled auto-merge (squash) September 24, 2026 14:46
@steipete
steipete merged commit 9ccfc7d into main Sep 24, 2026
202 checks passed
@steipete
steipete deleted the codex/background-exec-task-worker branch September 24, 2026 15:00
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

vincentkoc added a commit that referenced this pull request Sep 24, 2026
* commit '9ccfc7d1bea21e34da48edbd54afd2e1be57db40': (89 commits)
  fix(exec): avoid gateway stalls during background task writes (#157177)
  test(cli): isolate preaction title setter state
  fix(test): synchronize Git backoff cancellation readiness (#157315)
  fix: validate Codex model references in Docker (#157175)
  fix(state): tolerate brief WAL coordinator contention (#157121)
  fix: unblock conversations after recovery preparation fails (#157214)
  test(telegram): avoid wall-clock pacing in HTTP conformance (#157281)
  fix: keep independent database work responsive under load (#157230)
  refactor(sqlite): centralize WAL checkpoint execution (#157263)
  improve(android): show tool outcomes in collapsed work (#156950)
  fix: remove tracked release scratch blocking source capture (#157308)
  test(update): remove legacy probe stream ordering race
  fix: preserve steering across reconnects and show queued input (#157135)
  fix(ui): keep typing focus when the GitHub reader opens (#157202)
  fix(ios): keep screenshot logs outside capture evidence
  test(codex): await startup teardown in lifecycle fixtures
  chore(ui): refresh control ui locales (#157311)
  refactor(memory): deslop memory plugins (#156867)
  refactor(test): share CLI diagnostics fixture setup (#157201)
  fix(release): retry notarization submit/wait on transport failures and name the resume command (#157116)
  ...
vincentkoc added a commit that referenced this pull request Sep 24, 2026
* commit '02ad6b76b1a2ee2b414b170072e6e3e606fda3d4': (134 commits)
  fix(build): scope normalization declarations to package sources (#157174)
  fix: exit after validating Codex model references (#157323)
  fix(gateway): guard workspace adoption during active work (#157259)
  fix(update): rebuild stale Git runtimes when source is already current (#156996)
  fix: require a click before diagnosing failed updates (#157359)
  test(release): provide sealed artifact inputs to writer fixtures
  fix(ios): preserve chat state and adapt layout when iPad windows resize (#156683)
  fix(test): prepare native UI fixtures before compilation
  fix(test): await outbound delivery readiness before assertions
  fix: clarify deferred Codex catalog refresh warnings (#157352)
  fix(skills): refresh skills after watched directories are replaced (#156324)
  ci: reduce Node fixture overhead and defer seven release matrices (#157341)
  chore(test): stop Codex Computer Use and Signal batching tests flaking under load (#157334)
  fix(gateway): retain owned suspension status during restart (#157258)
  fix(ci): scope desktop status assertions to the selected worker
  chore(i18n): refresh native locales (#157337)
  test(daemon): use the native PowerShell probe budget (#157289)
  fix(exec): avoid gateway stalls during background task writes (#157177)
  test(cli): isolate preaction title setter state
  fix(test): synchronize Git backoff cancellation readiness (#157315)
  ...
vincentkoc added a commit that referenced this pull request Sep 24, 2026
* commit 'c4333da677cbdfe1bbaf783ed01c363ff39e93b8': (100 commits)
  fix(test): stop preflight mocks leaking into shared workers (#157207)
  fix(build): scope normalization declarations to package sources (#157174)
  fix: exit after validating Codex model references (#157323)
  fix(gateway): guard workspace adoption during active work (#157259)
  fix(update): rebuild stale Git runtimes when source is already current (#156996)
  fix: require a click before diagnosing failed updates (#157359)
  test(release): provide sealed artifact inputs to writer fixtures
  fix(ios): preserve chat state and adapt layout when iPad windows resize (#156683)
  fix(test): prepare native UI fixtures before compilation
  fix(test): await outbound delivery readiness before assertions
  fix: clarify deferred Codex catalog refresh warnings (#157352)
  fix(skills): refresh skills after watched directories are replaced (#156324)
  ci: reduce Node fixture overhead and defer seven release matrices (#157341)
  chore(test): stop Codex Computer Use and Signal batching tests flaking under load (#157334)
  fix(gateway): retain owned suspension status during restart (#157258)
  fix(ci): scope desktop status assertions to the selected worker
  chore(i18n): refresh native locales (#157337)
  test(daemon): use the native PowerShell probe budget (#157289)
  fix(exec): avoid gateway stalls during background task writes (#157177)
  test(cli): isolate preaction title setter state
  ...
vincentkoc added a commit that referenced this pull request Sep 24, 2026
* commit '02ad6b76b1a2ee2b414b170072e6e3e606fda3d4': (122 commits)
  fix(build): scope normalization declarations to package sources (#157174)
  fix: exit after validating Codex model references (#157323)
  fix(gateway): guard workspace adoption during active work (#157259)
  fix(update): rebuild stale Git runtimes when source is already current (#156996)
  fix: require a click before diagnosing failed updates (#157359)
  test(release): provide sealed artifact inputs to writer fixtures
  fix(ios): preserve chat state and adapt layout when iPad windows resize (#156683)
  fix(test): prepare native UI fixtures before compilation
  fix(test): await outbound delivery readiness before assertions
  fix: clarify deferred Codex catalog refresh warnings (#157352)
  fix(skills): refresh skills after watched directories are replaced (#156324)
  ci: reduce Node fixture overhead and defer seven release matrices (#157341)
  chore(test): stop Codex Computer Use and Signal batching tests flaking under load (#157334)
  fix(gateway): retain owned suspension status during restart (#157258)
  fix(ci): scope desktop status assertions to the selected worker
  chore(i18n): refresh native locales (#157337)
  test(daemon): use the native PowerShell probe budget (#157289)
  fix(exec): avoid gateway stalls during background task writes (#157177)
  test(cli): isolate preaction title setter state
  fix(test): synchronize Git backoff cancellation readiness (#157315)
  ...
vincentkoc added a commit that referenced this pull request Sep 24, 2026
* test(ui): cover stack-free tooltip disconnect cleanup

* fix(build): scope normalization declarations to package sources

Give normalization-core its own TypeScript project so declaration generation does not load the repository-wide source set. Preserve the existing DTS build command and compiler policy.

* Merge normalization declaration scope for tooltip proof

* commit '81aeccb3db80136a118d6d2f98b67d836ec25e51':
  fix(build): scope normalization declarations to package sources

* fix(ui): avoid retaining tooltip anchors in abort reasons

* Merge main to include native wrapper source inventory repair

* commit '02ad6b76b1a2ee2b414b170072e6e3e606fda3d4': (134 commits)
  fix(build): scope normalization declarations to package sources (#157174)
  fix: exit after validating Codex model references (#157323)
  fix(gateway): guard workspace adoption during active work (#157259)
  fix(update): rebuild stale Git runtimes when source is already current (#156996)
  fix: require a click before diagnosing failed updates (#157359)
  test(release): provide sealed artifact inputs to writer fixtures
  fix(ios): preserve chat state and adapt layout when iPad windows resize (#156683)
  fix(test): prepare native UI fixtures before compilation
  fix(test): await outbound delivery readiness before assertions
  fix: clarify deferred Codex catalog refresh warnings (#157352)
  fix(skills): refresh skills after watched directories are replaced (#156324)
  ci: reduce Node fixture overhead and defer seven release matrices (#157341)
  chore(test): stop Codex Computer Use and Signal batching tests flaking under load (#157334)
  fix(gateway): retain owned suspension status during restart (#157258)
  fix(ci): scope desktop status assertions to the selected worker
  chore(i18n): refresh native locales (#157337)
  test(daemon): use the native PowerShell probe budget (#157289)
  fix(exec): avoid gateway stalls during background task writes (#157177)
  test(cli): isolate preaction title setter state
  fix(test): synchronize Git backoff cancellation readiness (#157315)
  ...

Co-authored-by: Vincent Koc <[email protected]>
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
…aw#157177)

* perf(exec): move background task writes off the main thread

* fix(exec): preserve promoted process handles during registration

Keep the background process handle after promotion even when the command exits during task registration. Preserve joined terminal cleanup and the synchronous registered runtime contract, and strengthen the fast-exit race regression.

* test(exec): complete stdin settlement failure fixture

Provide the required stdin end method while preserving the destroy-failure ordering and scope-cleanup assertions.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
* test(ui): cover stack-free tooltip disconnect cleanup

* fix(build): scope normalization declarations to package sources

Give normalization-core its own TypeScript project so declaration generation does not load the repository-wide source set. Preserve the existing DTS build command and compiler policy.

* Merge normalization declaration scope for tooltip proof

* commit '81aeccb3db80136a118d6d2f98b67d836ec25e51':
  fix(build): scope normalization declarations to package sources

* fix(ui): avoid retaining tooltip anchors in abort reasons

* Merge main to include native wrapper source inventory repair

* commit 'f11e16cd65951f284264bd202b49984e21091cf5': (134 commits)
  fix(build): scope normalization declarations to package sources (openclaw#157174)
  fix: exit after validating Codex model references (openclaw#157323)
  fix(gateway): guard workspace adoption during active work (openclaw#157259)
  fix(update): rebuild stale Git runtimes when source is already current (openclaw#156996)
  fix: require a click before diagnosing failed updates (openclaw#157359)
  test(release): provide sealed artifact inputs to writer fixtures
  fix(ios): preserve chat state and adapt layout when iPad windows resize (openclaw#156683)
  fix(test): prepare native UI fixtures before compilation
  fix(test): await outbound delivery readiness before assertions
  fix: clarify deferred Codex catalog refresh warnings (openclaw#157352)
  fix(skills): refresh skills after watched directories are replaced (openclaw#156324)
  ci: reduce Node fixture overhead and defer seven release matrices (openclaw#157341)
  chore(test): stop Codex Computer Use and Signal batching tests flaking under load (openclaw#157334)
  fix(gateway): retain owned suspension status during restart (openclaw#157258)
  fix(ci): scope desktop status assertions to the selected worker
  chore(i18n): refresh native locales (openclaw#157337)
  test(daemon): use the native PowerShell probe budget (openclaw#157289)
  fix(exec): avoid gateway stalls during background task writes (openclaw#157177)
  test(cli): isolate preaction title setter state
  fix(test): synchronize Git backoff cancellation readiness (openclaw#157315)
  ...

Co-authored-by: Vincent Koc <[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 merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant