Skip to content

fix: bound workers retained after deleting sessions across agents - #197409

Merged
vincentkoc merged 2 commits into
openclaw:mainfrom
1052326311:fix/reclamation-worker-cap
Nov 26, 2026
Merged

vincentkoc merged 2 commits into
openclaw:mainfrom
1052326311:fix/reclamation-worker-cap

Conversation

@1052326311

@1052326311 1052326311 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes retained deletion-worker growth when a long-running Gateway deletes sessions across many agent databases.

Closes #197331.

User Impact

Deleting sessions across more agents now keeps at most four ordinary reclamation workers. Recently used databases keep their warm connection; revisiting an evicted database opens a new one. A failed retirement remains visible and blocks admission of another database until cleanup can succeed.

Why This Change Was Made

The archive queue already serializes ordinary reclamation, but its retained registry had no capacity limit. Bound that existing registry with LRU eviction and await the existing native close owner before admitting a replacement. Scoped canonical-validation workers keep their separate lifecycle. This adds no configuration, schema, or session-data retention change.

Evidence

  • The two added regressions fail on the base: the fifth database leaves five workers, and a capacity-close failure is never consulted. Both pass with the fix. The tests use real transcript-bearing SQLite databases/workers for capacity, peak count, warm reuse, lease release and reopening; the failure case injects one close rejection to check registry custody and retry.
  • Final changed reuse suite: 18 passed, 48.91s command wall time / 45.59s Vitest duration, including worker compilation. The two unchanged adjacent worker/deletion-receipt suites also passed (24 tests in the earlier combined 42-test run). Real worker/native cleanup is the boundary the capacity regression must exercise; no added sleeps or production test hooks. CI seconds are not yet available.
  • Built isolated Gateway: 37 token-authenticated CLI RPCs, six configured agents, 13 sessions with injected synthetic transcripts and nine deletions. Observed live reclamation workers: 1,2,3,4,4,4,4,4,4; warm reuse did not spawn, revisiting an evicted database did. Peak was four; both health checks succeeded and shutdown exited 0 with zero remaining reclamation workers.
  • pnpm build:runtime, pnpm tsgo:core, the agents/sessions test typecheck leaf, targeted oxlint/format, the changed document's MDX check, test-line ratchet and git diff --check passed on macOS arm64 / Node 26.12.1. Runtime build emitted asset-budget warnings. No package/release build, live model/channel call, or independent measurement of the reporter's per-worker memory estimate is claimed.
  • The maintainer correction in 768edfa29ef5 checks the queued request and its database identity before evicting another worker. The fork CI passed all 18 tests in the reclamation reuse suite, including the case where a stale fifth request leaves four live thread IDs and the oldest database lease intact, followed by a failed close and successful retry. The final change is +19/−2 production lines and +83 test lines. Hosted worker regression.

@clawsweeper

clawsweeper Bot commented Nov 11, 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 size: S labels Nov 11, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Caps retained ordinary session-reclamation workers at four and closes the least recently used worker before admitting another database.

Example: Delete sessions across six agent databases in one Gateway process.

  • Before: Six reclamation workers can remain alive until idle retirement.
  • After: At most four ordinary reclamation workers remain, with recently used databases kept warm.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, worthwhile fix with shipped-entry-point evidence, distinct native-worker regressions and no actionable findings; aggregate CI is still pending.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The recorded isolated built-Gateway CLI RPC run exercises cross-agent session deletion, the four-worker ceiling, warm reuse, eviction reopening and shutdown drainage; exact-head native-worker CI additionally covers the currentness correction.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Bulk session deletion across many agents can accumulate worker isolates until the Gateway becomes unresponsive or exhausts host memory.
Reason: The reported failure is concrete, the fix bounds its responsible resource, and the maintainer correction preserves the chosen direction.

Merge readiness

✅ Ready for maintainer review

Keep open: current main still retains an unbounded number of ordinary reclamation workers, and this maintainer-engaged PR provides a focused fix with no actionable findings.

Reviewed head: 768edfa29ef5c13565fa2a4949b396421847346a

Before merge

None.

Findings

None.

Agent review details

How this fits together

Session deletion and archive reclamation enter a shared FIFO, reuse workers by database path, and return deletion results after worker-owned SQLite operations.

flowchart TD
A[Session deletion] --> B[Archive FIFO]
B --> C[Request and database checks]
C --> D[Retained worker registry]
D --> E[Least recently used worker close]
E --> D
D --> F[SQLite reclamation worker]
F --> G[Deletion result]
Loading

Technical review

Best possible solution:

Retain the four-worker LRU bound in the existing registry while preserving native-close custody, FIFO ordering and per-request currentness checks.

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

Current-main source retains one worker per visited database without a capacity bound, matching the official-release report at #197331; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch fixes retention at its existing owner with a small capacity check and Map-order refresh, preserving the established cleanup and admission contracts.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Per-database worker retention changes intended behavior with a stated reason (9c7324e: Reduce repeated worker startup when maintenance alternates between databases while retaining FIFO and failed-cleanup custody.)
  • Completed-request isolation and retirement ownership keeps the original intent (db490ef: Prevent warm workers from retaining completed request payloads and async context; the patch keeps scalar retirement binding and existing close ownership.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 9c7324e adds src/config/sessions/session-accessor.sqlite-reclamation-worker.ts:111 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9c7324ea034a; files: src/config/sessions/session-accessor.sqlite-reclamation-worker.ts)

PR surface

Source +17, Tests +83, Docs +4. Total +104 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 19 2 +17
Tests 1 83 0 +83
Docs 1 5 1 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 107 3 +104

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Root-cause cluster

Relationship: same_root_cause
Canonical: #197331
Summary: This PR directly addresses the reported accumulation of retained reclamation workers across agent databases.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-11T23:12:27.792Z sha 80c72bb :: needs maintainer review before merge. :: none

Reviewed November 26, 2026, 5:20 AM ET / 10:20 UTC (Revision 2).

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

Please check 768edfa29ef5c13565fa2a4949b396421847346a, including request and database currentness before full-cache eviction. The corrected reclamation suite passed all 18 tests in fork CI.

@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc
vincentkoc merged commit 3bd892f into openclaw:main Nov 26, 2026
127 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

vincentkoc added a commit that referenced this pull request Nov 26, 2026
…oid-chat-preview-grapheme-boundary

* commit '0bea7ecb3029583dd49d83f760d4f40c9e1f543c': (129 commits)
  fix(android): settle startup before checking archive refresh (#205891)
  fix: Gateway retains completed reply runtimes after catalog reloads (#195479)
  fix: clear unused-export failures in dependency checks (#205905)
  refactor: share browser routing for meeting captions and cleanup (#205916)
  fix(ui): update Workshop file preview mode (#205872)
  refactor(android): decouple shared JSON values from node handlers (#202840)
  fix(ci): remove bot credit from release notes (#205914)
  fix: pause interrupted shell turns when their result is unknown (#205859)
  fix(ui): skip publication options for removed workspaces (#205909)
  fix: preserve indentation in document previews (#205834)
  improve(ci): avoid full fixture builds for volume checks (#205903)
  refactor(android): derive connection readiness from its owner (#202898)
  fix: preserve side chat text when dictating at the limit (#205710)
  improve(telegram): polling workers start faster and use half the memory (#190890)
  fix: keep speaker identities distinct in meeting notes (#205860)
  fix: wait for cancellation before releasing ACP test preparation (#205893)
  fix: bound workers retained after deleting sessions across agents (#197409)
  fix(memory): keep a child's memory audience after its parent resets (#205887)
  refactor(android): give installed skills one data owner (#202892)
  fix(cli): share process failure listeners across invocations (#205732)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 27, 2026
…enclaw#197409)

* fix(sessions): bound workers retained after cross-agent deletion

* fix(sessions): validate queued deletes before evicting a worker

---------

Co-authored-by: Vincent Koc <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
…97409)

* fix(sessions): bound workers retained after cross-agent deletion

* fix(sessions): validate queued deletes before evicting a worker

---------

Co-authored-by: Vincent Koc <[email protected]>
(cherry picked from commit 3bd892f)
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
…97409)

* fix(sessions): bound workers retained after cross-agent deletion

* fix(sessions): validate queued deletes before evicting a worker

---------

Co-authored-by: Vincent Koc <[email protected]>
(cherry picked from commit 3bd892f)
Co-authored-by: RomneyDa <[email protected]>
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 P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

2026.10.10: each sessions.delete can leave a ~150 MB SQLite reclamation worker alive for 30 min; bulk deletes exhaust host memory

2 participants