Skip to content

feat(agents): record run-end worktree cleanup outcome; prove Workboard dirty retention - #120434

Merged
steipete merged 17 commits into
mainfrom
claude/worktree-cleanup-outcome
Aug 9, 2026
Merged

steipete merged 17 commits into
mainfrom
claude/worktree-cleanup-outcome

Conversation

@steipete

@steipete steipete commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Follow-up recorded in #120362: the Workboard dirty-retention QA case had to be dropped because run-end worktree cleanup left no observable fact. agent.wait can resolve before the async subagent_ended cleanup hook, and nothing recorded whether cleanup ran or why it kept a checkout — so a retention assertion would have been false proof, and an operator looking at a surviving worktree had no way to know it was retained deliberately.

Why This Change Was Made

Per the Product Doctrine ("record facts where they happen; every action ends in a visible outcome or a recorded non-outcome"), removeIfLossless — the single lifecycle owner where the lossless/retain decision is made — now persists a durable outcome on the worktree registry row at every exit: removed-lossless, retained-busy (live run lease or competing remover), retained-dirty, retained-unpushed, retained-provisioned-drift, or failed with a bounded reason. Storage is a single additive run_end_cleanup_json column (declared in the canonical schema plus the idempotent lazy ensure; no schema-version bump — older readers tolerate it). The fact flows through the existing worktrees.list RPC and openclaw worktrees list --json via an additive optional field on the protocol record schema; the plugin SDK surface is untouched (removeIfLossless still returns boolean).

The generic owner boundary means every run-end cleanup path records the fact — Workboard today, any future session run-end path for free.

User Impact

Operators can see why a worktree survived run-end cleanup instead of guessing. QA now proves dirty retention at a real product boundary: the e2e dirty-retention case waits on the recorded fact rather than racing the async cleanup hook. Taxonomy (agent-runtime.managed-worktrees-workboard-lifecycle) and the scenario successCriteria claim exactly what is proven.

Evidence

  • Production +~120/−4 (service recording, registry parse/write, types, protocol schema, additive column); tests +~215.
  • Unit matrix (src/agents/worktrees/service.run-end-cleanup.test.ts): clean → removed-lossless on the removed row; dirty → retained-dirty with checkout intact; unpushed → retained-unpushed; held run lease → retained-busy.
  • Worktree module suite: 309 passed, 3 skipped.
  • Workboard lifecycle e2e (real child gateway, mock provider): clean-removal case now also asserts removed-lossless; new dirty-retention case passes — 2/2, run twice green. Two initial test-side synchronization races (global owner capacity, observing removedAt before the outcome write) were fixed in the test without changing production semantics or timeouts.
  • Scenario catalog 58/58; maturity:check clean; targeted lint/format clean; autoreview (Codex gpt-5.6-sol, high) clean.

Red-main merge-gate repair

This branch also repairs the unrelated context-freshness test breakage introduced on main by #120497. The repair preserves the historical assertions and adds the versioned token provenance now required by the shipped runtime; no memory-flush runtime behavior changes.

@steipete
steipete marked this pull request as ready for review August 8, 2026 02:36
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling extensions: qa-lab size: M maintainer Maintainer-authored PR labels Aug 8, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 8, 2026
@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 8, 2026, 6:47 PM ET / 22:47 UTC.

ClawSweeper review

What this changes

This PR records managed-worktree run-end cleanup outcomes in SQLite, exposes them through Gateway and CLI worktree listings, and adds Workboard dirty-retention coverage.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open: the exact-head ABA fence can reuse the same millisecond timestamp after restore, allowing a delayed prior-lifecycle cleanup write to overwrite the restored worktree’s newer state.

Priority: P2
Reviewed head: e4da939e3a0428c232ff1ecc692e3c738a89455f

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The owner-boundary design and additive compatibility work are strong, but the exact-head lifecycle fence has a concrete P2 correctness hole.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its supplied child-Gateway Workboard harness is useful product-boundary evidence but does not cover the discovered stale-writer interleaving.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its supplied child-Gateway Workboard harness is useful product-boundary evidence but does not cover the discovered stale-writer interleaving.
Evidence reviewed 5 items ABA fence is not unique: Restore assigns the wall-clock timestamp directly, while delayed retained and failed outcomes are authorized by equality with the earlier lifecycle timestamp; a same-millisecond restore leaves the stale writer authorized.
Regression misses equal-clock interleaving: The new ABA coverage injects an incrementing clock and asserts distinct timestamps, so it cannot exercise the timestamp collision that defeats the intended fence.
Correct lifecycle owner: Workboard invokes generic lossless cleanup asynchronously at run end; recording the result in the generic worktree owner is preferable to a Workboard-only marker.
Findings 1 actionable finding [P2] Make the restore lifecycle fence monotonic
Security None None.

How this fits together

Agent and Workboard runs create managed worktrees that are cleaned up after the run ends. The cleanup owner records the result in the worktree registry, which Gateway and the CLI expose to operators and QA.

flowchart LR
  A[Agent or Workboard run] --> B[Managed worktree]
  B --> C[Run-end cleanup decision]
  C --> D[Worktree registry]
  D --> E[Gateway worktree listing]
  E --> F[CLI and QA evidence]
Loading

Before merge

  • Make the restore lifecycle fence monotonic (P2) - onlyIfActiveAt uses the stale lifecycle’s millisecond timestamp, but restore can write that same value back. A delayed retained/failed writer can then pass both predicates after remove → restore and overwrite the new lifecycle’s outcome. The new test forces timestamps to differ, so add an equal-clock ABA case and use a true lifecycle generation.
  • Resolve merge risk (P1) - A same-millisecond remove-and-restore can let a stale retained or failed outcome overwrite the current lifecycle’s cleared or newer outcome.
  • Resolve merge risk (P1) - The latest ClawSweeper comment body and its Rank-up moves were unavailable to this read-only review after GitHub DNS failure; confirm them after the repair before merging.
  • Complete next step (P2) - A narrowly scoped mechanical repair can preserve the intended owner boundary and close the remaining race.

Findings

  • [P2] Make the restore lifecycle fence monotonic — src/agents/worktrees/service.ts:1082
Agent review details

Security

None.

PR surface

Source +194, Tests +430, Docs +2, Generated +1, Other +6. Total +633 across 57 files.

View PR surface stats
Area Files Added Removed Net
Source 7 209 15 +194
Tests 45 618 188 +430
Docs 1 2 0 +2
Config 0 0 0 0
Generated 1 1 0 +1
Other 3 11 5 +6
Total 57 841 208 +633

Review metrics

Metric Value Why it matters
Stored-state and wire contract 1 nullable SQLite registry column; 1 optional Gateway record field The additive shape has upgrade coverage, while lifecycle correctness of the newly stored fact remains merge-critical.
Central feature LOC production +~120/-4; tests +~215 The PR body identifies the positive production growth as the operator-visible cleanup-outcome capability and pairs it with focused regression coverage.

Stored data model

Persistent data-model change detected: database schema: src/infra/state-migrations.worktree-paths.test.ts, database schema: src/state/openclaw-state-db.test.ts, migration/backfill/repair: src/state/openclaw-state-db.test.ts, persistent cache schema: test/scripts/ensure-playwright-chromium.test.ts, serialized state: src/agents/worktrees/registry.ts, serialized state: src/infra/state-migrations.worktree-paths.test.ts, and 10 more. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Root-cause cluster

Relationship: canonical
Canonical: #120434
Summary: This PR is the canonical implementation of observable Workboard cleanup outcomes; the remaining defect is in its lifecycle fence.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Use a real lifecycle generation (recommended)
    Replace the timestamp-equality fence with a strictly advancing persisted lifecycle generation and add an equal-clock remove–restore–stale-write regression before merge.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Repair the lifecycle fence with a strictly advancing persisted generation and add equal-clock ABA regression coverage; preserve the additive public record shape.

Technical review

Best possible solution:

Keep outcome recording at the generic cleanup owner, but fence delayed writes with an atomically advancing lifecycle generation rather than a wall-clock timestamp and prove the equal-clock ABA sequence.

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

Yes, from source: hold a stale cleanup writer, remove and restore the row in the same clock millisecond, then allow the stale retained/failed write to resume.

Is this the best way to solve the issue?

No. Recording the fact at the generic cleanup owner is the best layer, but lastActiveAt is not a unique lifecycle identity and cannot safely serve as the ABA fence.

Full review comments:

  • [P2] Make the restore lifecycle fence monotonic — src/agents/worktrees/service.ts:1082
    onlyIfActiveAt uses the stale lifecycle’s millisecond timestamp, but restore can write that same value back. A delayed retained/failed writer can then pass both predicates after remove → restore and overwrite the new lifecycle’s outcome. The new test forces timestamps to differ, so add an equal-clock ABA case and use a true lifecycle generation.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: A concurrent cleanup race can show operators the wrong lifecycle outcome without affecting unrelated runs.
  • merge-risk: 🚨 session-state: The patch persists lifecycle state and the current fence can associate a previous lifecycle’s outcome with a restored worktree.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its supplied child-Gateway Workboard harness is useful product-boundary evidence but does not cover the discovered stale-writer interleaving.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/agents/worktrees/service.run-end-cleanup.test.ts.
  • [P1] node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/managed-worktrees-workboard-lifecycle-product-proof.e2e.test.ts.
  • [P1] node scripts/run-vitest.mjs src/state/openclaw-state-db.test.ts.

What I checked:

Likely related people:

  • steipete: Current-main history and the full PR series connect this contributor to the managed-worktree lifecycle and cleanup-outcome work. (role: feature owner; confidence: high; commits: c55ee68e461d, e4da939e3a04; files: src/agents/worktrees/service.ts, src/agents/worktrees/registry.ts)
  • Yuval Dinodia: History of run leases and lossless worktree cleanup connects this contributor to the concurrency boundary affected by the fence. (role: adjacent lifecycle contributor; confidence: medium; commits: 7cd2e482, af05f64; files: src/agents/worktrees/run-lease.ts, src/agents/worktrees/service.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Use an atomically advancing lifecycle generation instead of a wall-clock equality fence.
  • Add a deterministic ABA regression where restore receives the same timestamp as the stale cleanup attempt.
  • Re-run the focused worktree suite and exact-head checks after repair.

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 (11 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-08T10:38:28.395Z sha 6f72657 :: found issues before merge. :: [P2] Guard post-abort cleanup outcomes against finalization
  • reviewed 2026-08-08T10:53:00.562Z sha 2f27218 :: needs changes before merge. :: [P2] Persist the removal outcome with finalization
  • reviewed 2026-08-08T13:45:37.646Z sha e8755b9ce60c5f49a17b84df391cca92fb97400d :: found issues before merge. :: [P2] Keep the cached-response metadata assertion strict
  • reviewed 2026-08-08T14:41:14.858Z sha 0684922412864abd5af171dbaab64e57c2fb2156 :: found issues before merge. :: [P1] Preserve the newer context-provenance retry ordering
  • reviewed 2026-08-08T15:43:02.060Z sha 3854e51 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-08T15:51:09.868Z sha 3854e51 :: found issues before merge. :: [P1] Retain the bulk-archive protocol after rebasing | [P2] Clear the prior cleanup outcome during restore
  • reviewed 2026-08-08T19:43:00.070Z sha 3b04a59 :: needs changes before merge. :: [P2] Clear the cleanup outcome when restoring a worktree
  • reviewed 2026-08-08T21:46:50.209Z sha 0836780 :: found issues before merge. :: [P2] Fence retained outcomes by lifecycle generation

@steipete
steipete force-pushed the claude/worktree-cleanup-outcome branch from b24b0eb to 2faf1be Compare August 8, 2026 03:27
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XL and removed size: M labels Aug 8, 2026
@steipete
steipete force-pushed the claude/worktree-cleanup-outcome branch from 52bb200 to 5fe0abc Compare August 8, 2026 04:42
@openclaw-barnacle openclaw-barnacle Bot added size: M and removed cli CLI command changes size: XL labels Aug 8, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 8, 2026
@steipete
steipete force-pushed the claude/worktree-cleanup-outcome branch from 71834a8 to 9f1ceb4 Compare August 8, 2026 06:13
@steipete steipete self-assigned this Aug 8, 2026
@steipete
steipete force-pushed the claude/worktree-cleanup-outcome branch 2 times, most recently from 791a567 to 0eb5e85 Compare August 8, 2026 08:50
steipete added 10 commits August 8, 2026 12:17
The red-main landing rule requires this PR to repair repository-wide merge-gate debt instead of bypassing it. Apply the current lint contracts mechanically and split turn-transition coverage into a concept-named sibling with per-file-safe test state.

Exact line delta: +676/-574 (net +102) across 44 test/support files.
Require the public refresh call to exist before accepting that sensitive fields were omitted, so the boundary proof cannot pass on a missing call.
Literal-widened totalTokensVersion fixtures, a WebSocket RawData overload
mismatch, and the protocol schema document cast broke check-test-types
after the repo-wide lint repair. Aligns the fixtures with SessionEntry,
narrows Buffer handling per RawData, and keeps the JSON-shaped undefined
omission under structuredClone.
The session-loop split and #120463's helper extraction landed the same
createResourceLoader/createCompactionHandlers twice; the rebase kept both,
orphaning main's agent-session-loop-resource-loader.test-support.ts and
failing the dead-code gate. Import the upstream helpers and delete the
duplicates.
Address the accepted ClawSweeper late-claim finding by rereading and rejecting missing or finalized worktree rows inside the synchronous removal-claim transaction.

Preserve the authoritative cleanup invariant: finalized contenders record nothing, while retained-busy is written only while the row remains live.
Keep the live-row conditional write in the canonical registry update path so the finalized-claim repair stays below the registry max-lines ratchet without weakening the authoritative-outcome invariant.
Keep current main as the canonical owner of next-turn lifecycle coverage and correctness test support after replaying the older lint-debt split.
After abortWorktreeRemoval releases a stale remover's claim, its retained or
failed write raced a finalizing remover and could overwrite the authoritative
removed-lossless fact. Route every retained/failed write through the live-row
condition; only the finalizing remover's own removed-lossless write stays
unconditional.
A delayed removed-lossless write after remove() finalized could race a
restore plus newer cleanup and overwrite the newer operator-visible fact.
The run-end outcome now rides remove()'s finalization update; every other
cleanup write stays live-row conditional, so no post-finalize write path
remains.
The lint sweep's Boolean() coercions let truthy non-booleans satisfy the
wire-typed cached-meta contract. Assert the literal boolean for unknown-typed
fields and use nullish-coalesced strict equivalents for boolean chains.
@steipete
steipete force-pushed the claude/worktree-cleanup-outcome branch from 3854e51 to 3b04a59 Compare August 8, 2026 19:23
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — rebased across main's overnight advance on head 3b04a59: all eight worktree-feature commits patch-identical (only an import-context conflict in service.ts, both imports retained), generated Swift/SDK outputs regenerated and unchanged, CI green on this exact head.

@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. and removed P1 High-priority user-facing bug, regression, or broken workflow. labels Aug 8, 2026
A restored checkout begins a new lifecycle; leaving the removed-lossless
fact on the live row showed operators a stale result until the next
cleanup. Restore clears the recorded outcome and the regression asserts
the cleared state before the next cleanup records fresh truth.
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — the restore-staleness P2 is fixed on head 0836780: restore clears the recorded cleanup outcome (a restored checkout starts a new lifecycle), with the generation regression asserting the cleared state before the next cleanup records fresh truth. CI green on this exact head.

@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Aug 8, 2026
A stale remover's retained/failed write raced a concurrent remove-plus-
restore: the revived row is live again, so the live-row condition alone
could stamp a prior-lifecycle outcome. Condition those writes on the
activity stamp the remover observed; restore bumps lastActiveAt, making
any prior-lifecycle write a no-op.
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — the prior-lifecycle ABA P2 is fixed on head e4da939, closing the write-race class: stale retained/failed writes are now conditioned on both the live row AND the activity stamp the remover observed. Every lifecycle transition either sets removed_at (blocked by the live condition) or bumps last_active_at via restore (blocked by the stamp condition), so no stale cleanup can stamp another lifecycle's row. ABA regression included. CI green on this exact head.

@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

Stale cleanup writes fence on the activity stamp they observed; a restore
completing in the same millisecond could revive the row with an identical
stamp and let the fence match. Restore now always advances past the
stored value, and the ABA regression pins the clock to prove the
same-millisecond case.
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — the same-millisecond fence P2 is fixed on head f8a80c7: restore now always advances the activity stamp past the stored value (Math.max(now, prior+1)), so the stale writer's fence can never match a revived row even within one millisecond; the ABA regression pins the clock to prove exactly that case. The write-race class is closed: live-row condition blocks post-finalization writes, the observed-stamp fence blocks prior-lifecycle writes, and restore stamps are strictly monotonic. CI green on this exact head.

@clawsweeper

clawsweeper Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete merged commit 73bdb4b into main Aug 9, 2026
122 checks passed
@steipete
steipete deleted the claude/worktree-cleanup-outcome branch August 9, 2026 03:32
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 9, 2026
…d dirty retention (openclaw#120434)

* feat(agents): record run-end worktree cleanup outcome

Persist removed, retained, and failed run-end cleanup outcomes on managed worktree records. Operators and QA can inspect the durable fact through worktrees.list and openclaw worktrees list --json.

Release note: Managed worktree run-end cleanup now records why a checkout was removed or retained in worktree list JSON.

* test(qa): prove dirty worktree retention outcome

* chore(protocol): regenerate swift gateway models

* fix(agents): harden worktree cleanup recovery

Register run_end_cleanup_json as a lazy compatible column so same-version v6 index repair and read-only doctor migration can recover databases created before the column existed.

Type removal contention at the registry boundary; unexpected claim failures now best-effort record a bounded failed outcome and rethrow the original error.

* fix(ci): clear repo-wide lint debt blocking merge gates

The red-main landing rule requires this PR to repair repository-wide merge-gate debt instead of bypassing it. Apply the current lint contracts mechanically and split turn-transition coverage into a concept-named sibling with per-file-safe test state.

Exact line delta: +676/-574 (net +102) across 44 test/support files.

* fix(ci): preserve cached health refresh proof

Require the public refresh call to exist before accepting that sensitive fields were omitted, so the boundary proof cannot pass on a missing call.

* fix(ci): correct test typing left by the lint sweep

Literal-widened totalTokensVersion fixtures, a WebSocket RawData overload
mismatch, and the protocol schema document cast broke check-test-types
after the repo-wide lint repair. Aligns the fixtures with SessionEntry,
narrows Buffer handling per RawData, and keeps the JSON-shaped undefined
omission under structuredClone.

* test(agents): reuse upstream resource-loader test support

The session-loop split and openclaw#120463's helper extraction landed the same
createResourceLoader/createCompactionHandlers twice; the rebase kept both,
orphaning main's agent-session-loop-resource-loader.test-support.ts and
failing the dead-code gate. Import the upstream helpers and delete the
duplicates.

* fix(agents): reject finalized rows at the worktree removal claim

Address the accepted ClawSweeper late-claim finding by rereading and rejecting missing or finalized worktree rows inside the synchronous removal-claim transaction.

Preserve the authoritative cleanup invariant: finalized contenders record nothing, while retained-busy is written only while the row remains live.

* refactor(agents): reuse registry update for busy outcomes

Keep the live-row conditional write in the canonical registry update path so the finalized-claim repair stays below the registry max-lines ratchet without weakening the authoritative-outcome invariant.

* test(agents): drop session test duplicates after rebase

Keep current main as the canonical owner of next-turn lifecycle coverage and correctness test support after replaying the older lint-debt split.

* fix(agents): guard post-abort cleanup outcomes against finalization

After abortWorktreeRemoval releases a stale remover's claim, its retained or
failed write raced a finalizing remover and could overwrite the authoritative
removed-lossless fact. Route every retained/failed write through the live-row
condition; only the finalizing remover's own removed-lossless write stays
unconditional.

* fix(agents): persist the removal outcome atomically with finalization

A delayed removed-lossless write after remove() finalized could race a
restore plus newer cleanup and overwrite the newer operator-visible fact.
The run-end outcome now rides remove()'s finalization update; every other
cleanup write stays live-row conditional, so no post-finalize write path
remains.

* test(qa): restore strict cached-health contract assertions

The lint sweep's Boolean() coercions let truthy non-booleans satisfy the
wire-typed cached-meta contract. Assert the literal boolean for unknown-typed
fields and use nullish-coalesced strict equivalents for boolean chains.

* fix(agents): clear the stale cleanup outcome when restoring a worktree

A restored checkout begins a new lifecycle; leaving the removed-lossless
fact on the live row showed operators a stale result until the next
cleanup. Restore clears the recorded outcome and the regression asserts
the cleared state before the next cleanup records fresh truth.

* fix(agents): scope stale cleanup outcomes to their observed lifecycle

A stale remover's retained/failed write raced a concurrent remove-plus-
restore: the revived row is live again, so the live-row condition alone
could stamp a prior-lifecycle outcome. Condition those writes on the
activity stamp the remover observed; restore bumps lastActiveAt, making
any prior-lifecycle write a no-op.

* fix(agents): advance the restore activity stamp within one millisecond

Stale cleanup writes fence on the activity stamp they observed; a restore
completing in the same millisecond could revive the row with an identical
stamp and let the fence match. Restore now always advances past the
stored value, and the ABA regression pins the clock to prove the
same-millisecond case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation extensions: qa-lab gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant