Skip to content

perf(state): reuse committed agent deletion status on turn admission - #169738

Merged
steipete merged 3 commits into
mainfrom
dbasync/deljournal
Oct 12, 2026
Merged

steipete merged 3 commits into
mainfrom
dbasync/deljournal

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session admission rereads the agent deletion journal eight times per warmed turn, adding eight SQLite statements and eight worker requests after #168199.

User Impact

Admission now reuses the Gateway's committed deletion status. Pending and completed deletion still refuse new runs, queued work is revoked, active runs retain their existing drain/settlement owner, and persisted tombstones survive restart. No schema, retention, durability, permission, or update-policy change.

Why This Change Was Made

The existing physical-database fact owner retains one status per agent. First admission loads it; journal writers publish replacements through the existing commit/rollback and worker transport. Execution workers consume those transferred facts. No new polling, generation, timer, or cross-thread handshake.

Writer coverage:

  • beginAgentDeletionJournalInDatabase, completeAgentDeletionJournalInDatabase, and deleteAgentDeletionJournalInDatabase publish pending, complete, and absent respectively. These leaf writers cover native workers, Claw removal, CLI, and journal helpers; rollback retains the previous fact.
  • Doctor's direct offline quarantine writes invalidate the affected fact for reload. Raw fixture inserts, clears, completion changes, and identity renames now publish or invalidate too.
  • Recovery/schema reconstruction invalidates schema-dependent facts. Path, operation-handoff, and phase-only updates do not change deletion status.

Removed checks and accepted edges:

  • Per-admission journal SQL: unsupported outside writers are observed on restart; runtime writers must use the Gateway owner or exclusive offline ownership.
  • Second journal read after the session FIFO wait: the deletion owner's existing ingress closure revokes queued work. No duplicate read is needed.
  • Concurrent first loads share the initial read; cancelling that first load may reject another waiting cold admission, which can retry normally.

Uncached execution-worker reads remain only in deferred startup preparation. Current journal/lease checks at destructive cleanup and cancellation boundaries remain intact.

Evidence

One live baseline/candidate pair used isolated state and the shared SQL workload. Baseline: cdb57ac7acdc; candidate: 87010686ac26. Later corrections only register the test pool/wrapper and invalidate offline Doctor facts; they do not change the measured warmed path. Final head 1422875e896f also merges main without conflicts to include its tooling inventory fix.

Warmed metric Baseline Candidate
All-thread statements, mean 308.7 378.4
Worker requests, mean 84.7 102.2
Statements, median [min–max] 296 [291–346] 369.5 [335–517]
Requests, median [min–max] 81 [79–96] 97.5 [84–135]
MAIN statements, mean 0 0.4
MAIN statements, median [min–max] 0 [0–0] 0 [0–2]
Journal statements / requests per turn 8 / 8 0 / 0

Whole-workload deletion-status SQL and worker requests both fell from 124 to 1, with only first admission reading the journal.

The candidate's warmed turns took 7.5× longer on the loaded host (one-minute load 146.4 versus 59.9). Raw counts increased in unchanged work; the changed journal operation adds none. Mean per-turn attribution reconciles the full increase:

Operation family Statements delta Requests delta
Unchanged memory cache/index work +42.7 +10.3
Unchanged session/preparation work +20.0 +7.7
Handle admission and unassigned maintenance +3.7 0
Other timed background/worker operations +11.3 +7.5
Deletion-journal status −8.0 −8.0
Total +69.7 +17.5

The retained agentDatabaseDeletion.snapshot operation also runs more often in the longer windows (+1.2 SQL/+0.2 requests per warmed turn); its snapshot reader is unchanged and remains outside the removed status-read family.

The four extra warmed MAIN statements are unchanged scheduled GitHub OAuth maintenance reads. First-turn SQL/requests/MAIN: 1,029/209/40 → 822/177/40. Whole-workload SQL/requests/MAIN: 9,233/1,654/1,983 → 10,191/1,909/1,996.

All 13 chat turns, child work, cron, compaction, and shutdown completed. The harness wrapper returned 1 because the auxiliary mentions.dismiss RPC returned retryable UNAVAILABLE; its unchanged owner swallows the underlying cause, so this is not claimed as a fully passing harness. Shutdown also logged an agent-database lease-release BEGIN IMMEDIATE lock refusal. Neither diagnostic adds journal work; both are retained as proof limitations.

T1: the status-read family is worker tier W (0 → 0 T1). Two existing T1 calls in the broader touched journal modules—deletion-history and path-fence reads—remain 2 → 2; this lane changes no T1 callsite.

Validation and CI disposition

  • All 129 cases across 11 changed test files passed, including native-worker deletion publication, queued/next-turn refusal without journal requests, commit/rollback, completion/removal, reload, restart, approvals, and fixture coverage. New test bodies took 874 ms and 82 ms; their owning shard passed 22 tests in 46.76 s. No local Vitest suite was run under the CI-first proof policy.
  • Formatting, targeted lint, and diff sanity passed. Two Codex autoreview rounds were scoped-clean (full patch P0–P2; corrective changes P0–P1). ClawSweeper reports no code findings; its broader combined live recording is recorded as a follow-up in the review-disposition comment.
  • Final-head PR CI passed production/test types, all lint stripes, source contracts, architecture, security, T1 (552 → 552), dialect groups (0 → 0), and Madge (0 cycles). Its sole test failure is the inherited rewind count (two upstream reads versus one expected), identical to main run 38216343022.
  • The first CI run found missing worker-pool and wrapper-inventory registration; both were fixed. Main integration includes 64f11ced232c7, fixing the inherited Bun suppression inventory mismatch.
  • Ordinary PR planning omits Knip, so manual CI ran pnpm deadcode:full. Its only findings are unused gateway-prewarm.mjs and unused renderPublicSessionCardSvg in src/gateway/control-ui-public-session-card-render.ts. Current main, at b82b033920ee, reports the exact same rule/file set. Remaining manual jobs were cancelled after the required scan.
  • Published-driver × candidate update passed at 391d4ca5dfea: published driver 2026.10.2, all 22 phases successful, readiness HTTP 200, running version verified, and durable/incognito state checks passed. The canonical fixture relabeled candidate version 2026.10.1 to 2026.10.2 while retaining the tested source SHA. Lane time: 661 s; update command: 544.23 s. Doctor's writer is touched, so this cell is required; the conflict-free main integration does not change this lane's Doctor behavior.

LOC: +278/−12 across 19 files (production +107/−10, tests +162/−2, docs +8, wrapper inventory +1). No dependency or SDK change.

@clawsweeper

clawsweeper Bot commented Oct 12, 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 gateway Gateway runtime commands Command implementations agents Agent runtime and tooling size: M labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR reuses committed agent-deletion status during session admission instead of repeatedly querying SQLite.

Example: Agent doomed admits another turn after its deletion status was loaded.

  • Before: Admission requests deletion status from the database worker again.
  • After: Admission reuses the committed status, while deletion publication and the existing ingress closure refuse new work.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The source change is coherent, but final-effect authority proof is absent and the current CI failure remains unattributed.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Normal chat turns incur redundant database-worker work checking whether their agent is deleted.
Reason: The maintainer-directed change is focused, reuses existing ownership machinery, and adds no public configuration or persisted format.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this useful maintainer-directed optimization open; prior findings are resolved, and no new discrete code defect was identified.

Priority: P2
Reviewed head: 1422875e896f8a04f6e1a1d93ff67f5bfbc2cf99

Before merge

  • Add real behavior proof - Authority-chain proof required: exercise committed deletion through the production admission and execution owners, showing warmed, queued, and subsequent doomed-agent work rejected before session writes or tool execution, surviving-agent work allowed, and tombstones retained after restart; candidate performance results and the promised published-driver update run remain pending. Supply redacted logs or terminal evidence without credentials, IPs, phone numbers, or private endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Complete next step - Classify the current-head session-fork query-count failure using independent baseline evidence or a controlled comparison, and repair it only if attributable to this PR.

Findings

None.

Tests

  • Missing end-to-end proof: Completed candidate deletion/restart and performance observations, the promised published-driver update run, and base-fail/head-pass regression evidence are not supplied.
Agent review details

How this fits together

Journal writers publish committed per-agent facts through the physical database owner; session admission consumes them before admitting work.

flowchart LR
 A[Journal writers] --> B[SQLite transaction]
 B --> C[Committed database facts]
 C --> D[Session admission]
 E[Deletion ingress closure] --> D
 D --> F[Session work]
Loading

Technical review

Best possible solution:

Reuse the existing committed-fact transport and deletion closure while preserving final-effect refusal and recovery behavior.

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

Current main visibly repeats deletion-status worker reads during admission; the reported eight-per-turn cost was not independently measured in this read-only review.

Is this the best way to solve the issue?

The existing physical-database fact owner fits the documented writer contract and avoids introducing another synchronization owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Deletion-status reads changes intended behavior with a stated reason (e0d8000: Moved deletion-status reads into the existing shared-state worker while preserving deletion refusal.)
  • Second admission journal check changes intended behavior with a stated reason (be2850e: Prevented admission during durable deletion draining; this PR explicitly substitutes the existing deletion closure after queue waits.)
  • Doctor quarantine keeps the original intent (4bcd695: Preserved unusable journal records and held stores while allowing updates; the patch adds fact invalidation without changing those persisted writes.)
  • Foreign-writer fixtures changes intended behavior with a stated reason (7d88b6f: Exercised retained-actor deletion fencing; fixture mutations now publish facts under the explicitly documented process-owned writer contract.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit be2850e adds src/sessions/session-lifecycle-admission.ts:559 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: be2850e6d25e; files: src/sessions/session-lifecycle-admission.ts)
  • Josh Avant: Raw commit 487ab99 adds src/sessions/session-lifecycle-admission.ts:402 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 487ab99dc237; files: src/sessions/session-lifecycle-admission.ts)

PR surface

Source +97, Tests +160, Docs +8, Other +1. Total +266 across 19 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 5 107 10 +97
Tests 12 162 2 +160
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 19 278 12 +266

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded runtime performance improvement without a demonstrated production outage.
  • merge-risk: 🚨 session-state: Committed status replaces admission reads, making preserved deletion refusal before session effects material.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

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

  • Add final-effect proof that deleted-agent work is rejected before writes or tool execution while surviving-agent work remains allowed.

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 (2 earlier review cycles)
  • reviewed 2026-10-12T08:04:19.454Z sha 8701068 :: needs real behavior proof before merge. :: [P2] Include the new status module in the PR wrapper inventory | [P2] Run the deletion regression in an existing host-process suite
  • reviewed 2026-10-12T08:30:54.200Z sha 391d4ca :: needs real behavior proof before merge. :: none

Reviewed October 12, 2026, 4:52 AM ET / 08:52 UTC (Revision 3).

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 12, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. label Oct 12, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

The latest completed ClawSweeper review has no code findings. Its earlier wrapper-inventory and worker-test-pool findings are fixed. CI passed all 129 cases across the 11 changed test files, including native-worker deletion publication, queued-work rejection, next-turn rejection without journal requests, rollback, and tombstone reload. Existing final-effect and destructive-cleanup guards remain unchanged.

The final PR run's only failing test is the rewind query-count assertion, which fails identically on main run 38216343022. The two Knip findings also match current main exactly. The suppression-inventory failure was fixed by integrating main.

The requested additional combined live recording of surviving-agent work, deleted-agent refusal, and tool execution remains a follow-up. No demonstrated defect requires extending this patch; the changed admission boundary is covered by the passing owner regressions. The completed SQL run confirms journal work fell from eight statements and eight requests per warmed turn to zero; full measurement attribution and the update-cell result are being recorded in the PR body.

@steipete
steipete merged commit 044f8ea into main Oct 12, 2026
196 of 316 checks passed
@steipete
steipete deleted the dbasync/deljournal branch October 12, 2026 09:00
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…penclaw#169738)

Warm session admission added eight deletion-journal statements and eight worker requests per turn after openclaw#168199. Reuse committed per-agent facts through the existing database admission transport, and publish or invalidate them at every journal writer. Preserve queued-work revocation, active-run draining, persisted tombstones, and final cleanup authority.

The live comparison removes all eight statements and requests from warmed turns; whole-workload deletion-status calls fall from 124 to one. Owner regressions cover native-worker deletion, queued and next-turn refusal, commit/rollback, completion/removal, and reload. Full measurement attribution, static-check evidence, inherited CI failures, and update proof are recorded in the PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant