Skip to content

fix: clear pending delivery when background tasks are cancelled - #153226

Merged
steipete merged 1 commit into
mainfrom
codex/fix-task-cancellation-publication-clock
Sep 20, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/fix-task-cancellation-publication-clock

Conversation

@steipete

@steipete steipete commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes cancelled background tasks remaining labeled “Waiting to send to parent” until the operator refreshes the task list.

User Impact

The live Control UI receives the final cancellation and delivery state immediately. Execution duration and task cleanup deadlines remain unchanged; no configuration or migration is needed.

Why This Change Was Made

Cancellation can publish a provisional terminal update before finalization arrives with an earlier execution timestamp. The shared task transition owner now gives substantive terminal corrections a newer publication timestamp while preserving their execution timestamps. Repeating the same finalization remains a no-op. Cleanup-only bookkeeping still persists without advancing activity or reordering the task list. This preserves the UI’s protection against stale responses.

Evidence

Reproduced through a real Gateway and the shared Chrome profile: cancel an OpenClaw-created child and observe “Cancelled” alongside “Waiting to send to parent.” The durable row already had delivery disabled, but its older timestamp caused the UI to reject the correction.

Regression cases fail on the original source and pass with the fix for earlier and equal timestamps. The synchronous registry/publication path and worker transition path are covered, including persistence, unchanged cleanup deadlines, and duplicate-finalization idempotence. The selected sibling run passed 291 cases; the final extracted timestamp and worker run passed 18 cases. CI exposed a cleanup-only ordering regression and two retirement assertions that needed to protect the new freshness contract. The correction passes 254 selected cases, including the unchanged Gateway pagination test and both rotated-parent cases. Production and selected test type checks, scoped lint/format, ratchets, docs sanity, and diff checks passed. Independent Codex reviews found no actionable issues.

Live after-fix proof passed on the same local Gateway and shared Chrome profile with the final reviewed source integrated onto main. With the Tasks panel already open, one click on Stop cancelled a newly spawned child; the card changed to “Cancelled” and “No delivery required” without refreshing or reopening the panel. The persisted publication timestamp advanced 437 ms beyond the cancellation timestamp while execution duration remained unchanged. Both screenshots were inspected and delivered in the originating chat.

The earlier Codex orphan-reaping failure was repaired in #153282, and shared-worker cleanup fixture isolation was repaired in #153286. This branch now includes both landed fixes through main at 044f78e; the six task-clock files remain unchanged. An earlier integration run passed 362 tests across 14 files.

CI also exposed a private-completion test race: its abandoned-run scenario intentionally removes a controller while its terminal write is still pending, then incorrectly waits for registration removal to prove persistence. The test now waits on the captured terminal-persistence owner in that case. A deferred real write reproduces the original failure deterministically; the repair passes 72 cases across three files, the owning Gateway test typegraph, scoped lint/format, and independent review. Existing timeout and durable-outcome assertions remain. These local checks ran against the prior CI merge context; relevant task-clock and persistence owners are unchanged in the new base. Exact-head hosted CI passed all 156 jobs, including the repaired private-completion scenario. All required status contexts are also successful.

Before

Before: a cancelled child still waits to send to its parent

After

After: cancellation settles with no delivery required without refresh

@clawsweeper

clawsweeper Bot commented Sep 19, 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.

@steipete
steipete marked this pull request as ready for review September 19, 2026 22:56
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S maintainer Maintainer-authored PR labels Sep 19, 2026
@steipete steipete self-assigned this Sep 19, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 19, 2026
@clawsweeper

clawsweeper Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 19, 2026, 9:30 PM ET / September 20, 2026, 01:30 UTC (Revision 5).

ClawSweeper review

What this changes

The PR gives final background-task corrections newer update timestamps so cancellation clears stale delivery labels, with regression tests and task documentation.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix absent from fetched main. The inspected proof supports the visible improvement, and no actionable correctness or security findings remain.

Priority: P2
Reviewed head: 09b2d6bbca150e380d3151f7b65d773059b58b8e

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A narrow owner-level repair with relevant regression coverage and convincing before/after evidence.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): Inspected before/after screenshots show the changed task label, supported by the captured real-Gateway cancellation run with the panel open and no refresh; timestamp and duration observations align with the shared transition repair.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (screenshot): Inspected before/after screenshots show the changed task label, supported by the captured real-Gateway cancellation run with the panel open and no refresh; timestamp and duration observations align with the shared transition repair.
Evidence reviewed 10 items Shared production repair: The introduced terminal-update logic advances lastEventAt only for substantive corrections when the incoming timestamp would not advance. It excludes cleanup-only bookkeeping and leaves execution timestamps untouched. Both native and worker transition adapters consume this owner.
Observable failure mechanism: Gateway summaries expose lastEventAt as updatedAt. The UI rejects lower-timestamp snapshots, while finished duration uses endedAt minus startedAt. This connects the registry correction directly to the stale delivery label without extending execution duration.
Still necessary on main: Fetched main retains the prior prepareTaskRecordUpdate implementation without the monotonic terminal-correction logic. No merged replacement for this behavior was established; no released-fix claim is made.
Findings None None.
Security None None.

How this fits together

The task registry records background execution and delivery outcomes, then publishes summaries through the Gateway. The Control UI uses those timestamps to reject stale updates and display task status.

flowchart LR
 A[Background task cancellation] --> B[Task registry]
 C[Final outcome correction] --> B
 B --> D[Advance update timestamp]
 D --> E[Persist task record]
 E --> F[Gateway task event]
 F --> G[Control UI freshness check]
 G --> H[Updated delivery label]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +14, Tests +187, Docs 0. Total +201 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 1 14 0 +14
Tests 5 228 41 +187
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 243 42 +201

Review metrics

None.

Technical review

Best possible solution:

Keep timestamp freshness in the shared task owner while preserving execution duration, retention, idempotence, and the UI’s stale-update protection.

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

Yes: provisional cancellation followed by an earlier-timestamp finalization reaches the UI’s stale-update rejection path on fetched main; supplied screenshots corroborate the symptom. This review did not execute the application.

Is this the best way to solve the issue?

Yes: repairing the shared producer fixes both transition paths without weakening UI freshness checks or adding configuration or migration machinery.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: Cancelled tasks can retain a misleading delivery label until refresh, with limited impact on task monitoring.
  • 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 (screenshot): Inspected before/after screenshots show the changed task label, supported by the captured real-Gateway cancellation run with the panel open and no refresh; timestamp and duration observations align with the shared transition repair.
  • proof: sufficient: Contributor real behavior proof is sufficient. Inspected before/after screenshots show the changed task label, supported by the captured real-Gateway cancellation run with the panel open and no refresh; timestamp and duration observations align with the shared transition repair.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. Inspected before/after screenshots show the changed task label, supported by the captured real-Gateway cancellation run with the panel open and no refresh; timestamp and duration observations align with the shared transition repair.

Evidence

What I checked:

  • Shared production repair: The introduced terminal-update logic advances lastEventAt only for substantive corrections when the incoming timestamp would not advance. It excludes cleanup-only bookkeeping and leaves execution timestamps untouched. Both native and worker transition adapters consume this owner. (src/tasks/task-registry-transition.operation.ts:86, 09b2d6bbca15)
  • Observable failure mechanism: Gateway summaries expose lastEventAt as updatedAt. The UI rejects lower-timestamp snapshots, while finished duration uses endedAt minus startedAt. This connects the registry correction directly to the stale delivery label without extending execution duration. (ui/src/lib/tasks/data.ts:129, 09b2d6bbca15)
  • Still necessary on main: Fetched main retains the prior prepareTaskRecordUpdate implementation without the monotonic terminal-correction logic. No merged replacement for this behavior was established; no released-fix claim is made. (src/tasks/task-registry-transition.operation.ts:80, a0ec9f5c09d8)
  • Regression coverage: The timestamp tests cover earlier/equal cancellation timestamps, persistence, observer publication, unchanged cleanup deadlines, and duplicate-finalization idempotence. The worker test covers a clock behind the previous observation. Tests were inspected, not executed during this read-only review. (src/tasks/task-registry-timestamps.test.ts:52, 09b2d6bbca15)
  • Gateway test race repair: The abandoned-run case deliberately delays real lifecycle persistence beyond registration retirement, then joins the captured terminal-persistence owner. Existing timeout outcomes and retry assertions remain intact. (src/gateway/server.private-completion.test.ts:698, 09b2d6bbca15)
  • Inspected real UI proof: Both prepared screenshots were inspected locally. The before image shows a cancelled child waiting to send to its parent; the after image shows a newly cancelled child with no delivery required. The captured PR body reports a real Gateway and Chrome run with the panel already open, no refresh, and a publication timestamp advancing 437 ms beyond cancellation while execution duration stayed unchanged. Snapshot sourceRevision: 04a546943280b7038bb074a0cec44ac4dc25d67db05eaeab85573e4ca7986fbf.

Likely related people:

  • steipete: 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 (4 earlier review cycles)
  • reviewed 2026-09-19T23:09:53.505Z sha 6043ba7 :: needs changes before merge. :: none
  • reviewed 2026-09-19T23:29:04.303Z sha 93794fe :: needs changes before merge. :: none
  • reviewed 2026-09-19T23:51:35.789Z sha 93794fe :: needs maintainer review before merge. :: none
  • reviewed 2026-09-20T00:59:30.197Z sha b9468250290f04cd60ab6baba900c35ca90b37ae :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. 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 19, 2026
@steipete
steipete force-pushed the codex/fix-task-cancellation-publication-clock branch from 93794fe to b946825 Compare September 20, 2026 00:51
@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 20, 2026
@steipete
steipete force-pushed the codex/fix-task-cancellation-publication-clock branch from b946825 to 09b2d6b Compare September 20, 2026 01:23
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Sep 20, 2026
@steipete
steipete merged commit 90fccee into main Sep 20, 2026
223 checks passed
@steipete
steipete deleted the codex/fix-task-cancellation-publication-clock branch September 20, 2026 01:56
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 20, 2026
Reuse the isolated cleanup fixture from #153286 and the held-terminal-write private completion fixture from #153226. Retain the curator cleanup await. The combined 36-case proof, targeted types/lint, and independent review pass; production is unchanged.
steipete added a commit that referenced this pull request Sep 20, 2026
Resolve the real main conflict with its complete held-terminal-write fixture
from #153226. Drop the superseded pre-grace await, which cannot be combined
with a write deliberately held through abandonment.

Placement source and tests remain unchanged. Qualify the canonical timeout,
prepared binding, and cleanup contracts with 77 controls, core types,
import checks, review, and compiled startup retirement proof.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 20, 2026
steipete added a commit that referenced this pull request Sep 20, 2026
…read (#152319)

* refactor(skills): move usage and curator status SQL off the caller thread

* fix(skills): preserve worker errors and await usage test persistence

* fix: drain delivery queue maintenance during shutdown

* fix: keep Workshop event reads off the Gateway request thread

* test: isolate retired agent cleanup transport fixture (#153286)

* test(gateway): align curator checks with canonical lifecycle fixtures

Reuse the isolated cleanup fixture from #153286 and the held-terminal-write private completion fixture from #153226. Retain the curator cleanup await. The combined 36-case proof, targeted types/lint, and independent review pass; production is unchanged.

* test(outbound): clean up ACK fixtures with their owner

* test(outbound): clean up ACK fixtures with their captured owner

Carry the exact reviewed cleanup line from #153367, now covered by main #153296. Preserve the negative null and undefined ownership assertions. The postimage matches the canonical reviewed fixture and all four focused cases pass.

* test: join Doctor database cleanup before snapshots

* refactor(skills): consolidate workshop worker dispatch
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 21, 2026
…read (openclaw#152319)

* refactor(skills): move usage and curator status SQL off the caller thread

* fix(skills): preserve worker errors and await usage test persistence

* fix: drain delivery queue maintenance during shutdown

* fix: keep Workshop event reads off the Gateway request thread

* test: isolate retired agent cleanup transport fixture (openclaw#153286)

* test(gateway): align curator checks with canonical lifecycle fixtures

Reuse the isolated cleanup fixture from openclaw#153286 and the held-terminal-write private completion fixture from openclaw#153226. Retain the curator cleanup await. The combined 36-case proof, targeted types/lint, and independent review pass; production is unchanged.

* test(outbound): clean up ACK fixtures with their owner

* test(outbound): clean up ACK fixtures with their captured owner

Carry the exact reviewed cleanup line from openclaw#153367, now covered by main openclaw#153296. Preserve the negative null and undefined ownership assertions. The postimage matches the canonical reviewed fixture and all four focused cases pass.

* test: join Doctor database cleanup before snapshots

* refactor(skills): consolidate workshop worker dispatch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: codex gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant