Repository navigation
perf(sessions): reuse startup deletion discovery - #174408
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Integrates the upstream cli-parent-lifetime scan-target fix. The restart startup-discovery change is unchanged.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 397c7db73d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| databases.add(databasePath); | ||
| // Discovery is fixed for this startup pass; database owners fence later deletion effects. | ||
| const { snapshot } = await (deletionSnapshot ??= deletionRead.read()); |
There was a problem hiding this comment.
Recheck deletion before database maintenance and handoff
When an agent deletion commits after this one-time snapshot, the rest of the startup pass never observes its tombstone: a deleteFiles: true deletion can be followed by withOpenClawAgentDatabaseAsync recreating the database after the earlier existence check, while deleteFiles: false can hand the retained deleted store to runtime. The removed regression covered the latter interleaving, and neither the optional params.assertCurrent nor a previously successful agent-database admission is invalidated by an ordinary completed deletion, so the database owner does not provide the claimed fence. Recheck deletion at the maintenance/handoff boundary or make deletion invalidate that authority.
AGENTS.md reference: AGENTS.md:L7-L8
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Traced this against the production callers at 397c7db73d1c; the proposed interleaving does not establish a regression here.
Full Gateway startup awaits session migration in server-startup-bootstrap.ts:490–509, before kernel/runtime construction (server-kernel.ts:159–193) and HTTP transport (server-start.ts:45–62). An agents.delete request cannot overlap that pass. The live deferred caller (server-agent-database-startup.ts:99–105) runs open, migration, publication, and its final deletion check inside preparePendingAgentDatabase (agent-database-startup.ts:488–544). Its pending refusal remains until the callback completes (agent-database-admission.ts:281–304); deletion invalidates that preparation on commit (agent-lifecycle-registry.ts:302–335). Failed preparation cannot publish readiness or run its later maintenance. The observation about previously successful admission does not apply: migration runs before that success.
The fresh-open claim is independently prevented by the existing lease owner: openclaw-agent-db.ts:302–308 claims the lease before directory creation/open at lines 328–339. That claim checks the deletion fence (openclaw-agent-db-lease.ts:209), which rejects the same deleted identity before skipping completed rows (agent-deletion-journal.ts:195–196). Only explicit creation/cleanup authority has exceptions; startup migration has neither. Embedded TUI startup exposes no deletion operation and gates store/chat work on its startup promise.
Therefore I am retaining the owner's existing checks and removing the duplicate discovery reads as proposed. The accepted edge is that overlapping deferred deletion may produce an admission refusal instead of an earlier discovery skip. The removed helper-level interleaving test bypassed the production preparation owner; the retained regression now verifies fresh discovery after an in-process deletion on the next invocation.
* commit 'a4c73619a5c': (29 commits) test: align model and Discord fixtures with runtime owners perf(sessions): reuse startup deletion discovery (#174408) fix(gateway): attribute ephemeral connections in normal logs (#174406) test(telegram): consolidate duplicate coverage (batch d117) (#173112) perf(doctor): avoid redundant backup and transcript reads (#174416) fix(update): avoid redundant reads for closed SQLite generations (#174426) fix(ui): Activity page tabs collapse to a few pixels on desktop (#173856) fix(decisions): skip prefilter for empty tool surfaces (#174269) perf(sqlite): retain unchanged database proofs across schema updates (#174409) refactor(test): remove duplicate export collision checks (#174391) fix: clear unused MCP and identity helper exports (#174421) fix(test): supply SQLite reliability fixture catalog refactor(mattermost): use the guarded transport directly (#174419) refactor(agents): trust prepared provider facts (#174388) fix(control-ui): open submenus immediately on click (#174292) test(anthropic): synchronize the late-send fixture with initialization refactor(ui): scope Plugins page state to Solid owners (#174281) perf(chat): pace board history refreshes and reuse cursors (#174407) perf(sqlite): bound session receipt scope publication (#174395) refactor(openrouter): share key budget test fixtures (#174340) ...
…157433 * commit '2e8bfec53fc1cf06c9e438f42b027a82e04ace9a': (29 commits) test: align model and Discord fixtures with runtime owners perf(sessions): reuse startup deletion discovery (#174408) fix(gateway): attribute ephemeral connections in normal logs (#174406) test(telegram): consolidate duplicate coverage (batch d117) (#173112) perf(doctor): avoid redundant backup and transcript reads (#174416) fix(update): avoid redundant reads for closed SQLite generations (#174426) fix(ui): Activity page tabs collapse to a few pixels on desktop (#173856) fix(decisions): skip prefilter for empty tool surfaces (#174269) perf(sqlite): retain unchanged database proofs across schema updates (#174409) refactor(test): remove duplicate export collision checks (#174391) fix: clear unused MCP and identity helper exports (#174421) fix(test): supply SQLite reliability fixture catalog refactor(mattermost): use the guarded transport directly (#174419) refactor(agents): trust prepared provider facts (#174388) fix(control-ui): open submenus immediately on click (#174292) test(anthropic): synchronize the late-send fixture with initialization refactor(ui): scope Plugins page state to Solid owners (#174281) perf(chat): pace board history refreshes and reuse cursors (#174407) perf(sqlite): bound session receipt scope publication (#174395) refactor(openrouter): share key budget test fixtures (#174340) ...
…/decision-onnx-v2-proof-20261016 * commit '2e8bfec53fc1cf06c9e438f42b027a82e04ace9a': (29 commits) test: align model and Discord fixtures with runtime owners perf(sessions): reuse startup deletion discovery (#174408) fix(gateway): attribute ephemeral connections in normal logs (#174406) test(telegram): consolidate duplicate coverage (batch d117) (#173112) perf(doctor): avoid redundant backup and transcript reads (#174416) fix(update): avoid redundant reads for closed SQLite generations (#174426) fix(ui): Activity page tabs collapse to a few pixels on desktop (#173856) fix(decisions): skip prefilter for empty tool surfaces (#174269) perf(sqlite): retain unchanged database proofs across schema updates (#174409) refactor(test): remove duplicate export collision checks (#174391) fix: clear unused MCP and identity helper exports (#174421) fix(test): supply SQLite reliability fixture catalog refactor(mattermost): use the guarded transport directly (#174419) refactor(agents): trust prepared provider facts (#174388) fix(control-ui): open submenus immediately on click (#174292) test(anthropic): synchronize the late-send fixture with initialization refactor(ui): scope Plugins page state to Solid owners (#174281) perf(chat): pace board history refreshes and reuse cursors (#174407) perf(sqlite): bound session receipt scope publication (#174395) refactor(openrouter): share key budget test fixtures (#174340) ...
…ision-accounting-native * commit '2e8bfec53fc1cf06c9e438f42b027a82e04ace9a': (29 commits) test: align model and Discord fixtures with runtime owners perf(sessions): reuse startup deletion discovery (#174408) fix(gateway): attribute ephemeral connections in normal logs (#174406) test(telegram): consolidate duplicate coverage (batch d117) (#173112) perf(doctor): avoid redundant backup and transcript reads (#174416) fix(update): avoid redundant reads for closed SQLite generations (#174426) fix(ui): Activity page tabs collapse to a few pixels on desktop (#173856) fix(decisions): skip prefilter for empty tool surfaces (#174269) perf(sqlite): retain unchanged database proofs across schema updates (#174409) refactor(test): remove duplicate export collision checks (#174391) fix: clear unused MCP and identity helper exports (#174421) fix(test): supply SQLite reliability fixture catalog refactor(mattermost): use the guarded transport directly (#174419) refactor(agents): trust prepared provider facts (#174388) fix(control-ui): open submenus immediately on click (#174292) test(anthropic): synchronize the late-send fixture with initialization refactor(ui): scope Plugins page state to Solid owners (#174281) perf(chat): pace board history refreshes and reuse cursors (#174407) perf(sqlite): bound session receipt scope publication (#174395) refactor(openrouter): share key budget test fixtures (#174340) ...
…158510 * commit '26cbd409b9753a9318a6dc09f97b2f0b4b776a09': (29 commits) test: align model and Discord fixtures with runtime owners perf(sessions): reuse startup deletion discovery (#174408) fix(gateway): attribute ephemeral connections in normal logs (#174406) test(telegram): consolidate duplicate coverage (batch d117) (#173112) perf(doctor): avoid redundant backup and transcript reads (#174416) fix(update): avoid redundant reads for closed SQLite generations (#174426) fix(ui): Activity page tabs collapse to a few pixels on desktop (#173856) fix(decisions): skip prefilter for empty tool surfaces (#174269) perf(sqlite): retain unchanged database proofs across schema updates (#174409) refactor(test): remove duplicate export collision checks (#174391) fix: clear unused MCP and identity helper exports (#174421) fix(test): supply SQLite reliability fixture catalog refactor(mattermost): use the guarded transport directly (#174419) refactor(agents): trust prepared provider facts (#174388) fix(control-ui): open submenus immediately on click (#174292) test(anthropic): synchronize the late-send fixture with initialization refactor(ui): scope Plugins page state to Solid owners (#174281) perf(chat): pace board history refreshes and reuse cursors (#174407) perf(sqlite): bound session receipt scope publication (#174395) refactor(openrouter): share key budget test fixtures (#174340) ...
…esafe-decision-native * commit '26cbd409b9753a9318a6dc09f97b2f0b4b776a09': (29 commits) test: align model and Discord fixtures with runtime owners perf(sessions): reuse startup deletion discovery (#174408) fix(gateway): attribute ephemeral connections in normal logs (#174406) test(telegram): consolidate duplicate coverage (batch d117) (#173112) perf(doctor): avoid redundant backup and transcript reads (#174416) fix(update): avoid redundant reads for closed SQLite generations (#174426) fix(ui): Activity page tabs collapse to a few pixels on desktop (#173856) fix(decisions): skip prefilter for empty tool surfaces (#174269) perf(sqlite): retain unchanged database proofs across schema updates (#174409) refactor(test): remove duplicate export collision checks (#174391) fix: clear unused MCP and identity helper exports (#174421) fix(test): supply SQLite reliability fixture catalog refactor(mattermost): use the guarded transport directly (#174419) refactor(agents): trust prepared provider facts (#174388) fix(control-ui): open submenus immediately on click (#174292) test(anthropic): synchronize the late-send fixture with initialization refactor(ui): scope Plugins page state to Solid owners (#174281) perf(chat): pace board history refreshes and reuse cursors (#174407) perf(sqlite): bound session receipt scope publication (#174395) refactor(openrouter): share key budget test fixtures (#174340) ...
…/decision-tool-v2-proof-20261016 * commit '26cbd409b9753a9318a6dc09f97b2f0b4b776a09': (29 commits) test: align model and Discord fixtures with runtime owners perf(sessions): reuse startup deletion discovery (#174408) fix(gateway): attribute ephemeral connections in normal logs (#174406) test(telegram): consolidate duplicate coverage (batch d117) (#173112) perf(doctor): avoid redundant backup and transcript reads (#174416) fix(update): avoid redundant reads for closed SQLite generations (#174426) fix(ui): Activity page tabs collapse to a few pixels on desktop (#173856) fix(decisions): skip prefilter for empty tool surfaces (#174269) perf(sqlite): retain unchanged database proofs across schema updates (#174409) refactor(test): remove duplicate export collision checks (#174391) fix: clear unused MCP and identity helper exports (#174421) fix(test): supply SQLite reliability fixture catalog refactor(mattermost): use the guarded transport directly (#174419) refactor(agents): trust prepared provider facts (#174388) fix(control-ui): open submenus immediately on click (#174292) test(anthropic): synchronize the late-send fixture with initialization refactor(ui): scope Plugins page state to Solid owners (#174281) perf(chat): pace board history refreshes and reuse cursors (#174407) perf(sqlite): bound session receipt scope publication (#174395) refactor(openrouter): share key budget test fixtures (#174340) ...
Reuse one lazy deletion/registered-owner snapshot per startup invocation instead of rediscovering the same facts between maintenance phases. Preserve deletion status, retained-store handling, database admission, canonical validation, and pending-startup authority. The next invocation reads fresh facts; the regression verifies an in-process deletion and a surviving shared store. Existing startup owners prevent deleted database recreation or readiness publication without restoring repeated discovery checks. Initial matched restart evidence saves 15 statements and 3 requests after accounting for the required status read relocated to first ingress. Warm causal counts and owned T1 remain unchanged. Integrated CI, 36 focused startup tests, and review passed. Knip findings are inherited; the published-driver update cell was blocked before execution by the independently reproduced missing Windows-helper packaging error. Remaining alternating measurements are being recorded in the PR.
What Problem This Solves
Session startup repeatedly reloads the same deletion and registered-owner facts between maintenance phases, even when restarting against unchanged committed state.
User Impact
Startup uses fewer shared-state database statements and worker requests. Pending deletion recovery, retained database protection, and surviving shared stores keep their existing owners and effect guards. No configuration, schema, retention, or migration-format change is required.
Why This Change Was Made
Read one lazy worker snapshot per startup invocation and use its existing
deletedAgentsfield for pending/completed status. All targets in that invocation share the snapshot. A later invocation reads fresh facts. Remove the per-phase discovery wrapper and its separate status lookup; keep admission, canonical validation, cleanup, and runtime-handoff authority with their existing owners.Removed checks and accepted edges:
Evidence
The existing pending/completed deletion regression now runs startup, commits deletion in process, and runs startup again. It checks retained bytes, deletion diagnostics, and maintenance of the surviving shared store. Removed the obsolete test that paused the third discovery snapshot.
The automated deletion-race finding was checked against every production caller: full startup precedes HTTP ingress, deferred migration runs inside pending preparation that deletion invalidates, and a fresh open rejects completed deletion tombstones before creating files. Embedded TUI gates store/chat work on startup and exposes no deletion operation. The claimed already-successful-admission migration path is not present; no replacement discovery guard is needed.
SQL harness v3 completed all three alternating pairs (M1, C1, M2, C2, M3, C3). Every run passed 14 turns, spawn, cron, compaction, five-minute connected idle, same-state restart, and both clean shutdowns, with zero native execution or prepare errors. The frozen base is
0dc31f5f6430; candidate isf5a7b1a2a281. The integrated PR head397c7db73d1cand merge50ef1857adb24retain byte-identical versions of all three changed files. All pairs used identical workload/observer hashes and workload options with Node 24.22.0 / SQLite 3.54.0 and compile caching disabled. This loaded host supplies counts, not latency evidence. Before M3 began, the driver failed on a zero tick delta in its optional macOS idle observation. A task-owned driver copy records that observation as unavailable; the shared harness and all workload/observer hashes are unchanged. M3 reused its verified matching build through the documented skip-build option; no workload was discarded or repeated. Each cell is median [min–max]: three runs per restart/workload row and 30 turns per warmed row.Changed discovery executes through the existing shared-state worker. This slice has zero direct T1 inventory calls before and after; remaining native boot admission is a separate owner and is not claimed as removed here.
Passed: changed-file formatting/lint,
git diff --check, isolated Codex review (no actionable P0–P2 findings), and 36 startup tests across ACP (10), concurrency (6), registry recovery (13), and worktree/workspace behavior (7). Integrated CI 38932276035 has green type-aware lint, production/test types, source contracts, architecture/Madge checks, and database worker/dialect ratchets; PostgreSQL conformance is green; the integrated CI run completed successfully (37 successful jobs, 25 skipped). The initial duplicate-scan coverage and mock-isolation failures were fixed upstream and are green after merging main. Global T1 stays 222→222; changed-file dialect groups stay 0→0. Knip on the exact base, candidate, and integrated head reports identical inherited findings (production 3, full-tree 4, scripts 0) outside this patch, in byte-identical files on main07667dcc8f4d. The published-driver update workflow 38930637665 failed during image preparation, before the update cell executed: two untouched sealed runtime bundles reference a missingdist/windows-security-helper.exe. The exact main scanner reproduces both diagnostics; 13 relevant scanner/build/staging inputs are byte-identical on base, candidate, and main07667dcc8f4d. This is narrow inherited-failure proof, not a fresh main build or a passing update test; the packaging repair has been routed separately. No SDK surface changes.Every pair attributes 23 SQL / 5 requests / 0 MAIN to baseline startup deletion discovery: status 1 SQL plus four snapshots of 7, 5, 5, and 5 SQL. The candidate executes one 7-SQL snapshot: 16 fewer SQL statements and 4 fewer requests at startup. One required deletion-status read moves to first ingress because startup no longer warms that owner cache (causal restart first turn 151→152 SQL / 47→48 requests in every pair). Including it gives a stable net owner saving of 15 SQL / 3 requests, repeated in all three pairs. Warmed causal observations and the five shared read families/shapes are identical; raw windows include varying background work. For example, baseline M2 has a 34-statement background transcript-index publication in its restart-first window, and 17 statements of memory reads fall in a different window from M1. Raw phase and whole-workload differences are reported above but are not all attributed to this change. The required first-ingress check remains because it guards a real effect.
Shared warmed read families are unchanged in all six runs: exact-entry facts use 2 [2–4] SQL / 2 [2–3] requests per turn; actor hydration, entry-cache snapshots, row facts, and watermark reads each use 0 SQL / 0 requests. Exact SQL-shape counts also match.
Initial first-turn raw medians are 885→888 SQL (+3, 0.339%), 150→155 requests, and 5→9 MAIN, while causal medians remain 217 SQL / 62 requests / 0 MAIN. The complete site ledger attributes the pooled +29 SQL to placement of the unchanged 195-statement agent-store open (+19), unchanged lifecycle lease-expiry reads (+4), and other unchanged entry-list, context, admission, and maintenance sites (+6 net). The initial agent-store open totals 195 SQL in every run and lease-expiry work totals 13 SQL in every workload. Direct deletion reads match within each pair, and the changed startup-migration owner issues no request in this window. Initial boot+connect+first-turn SQL medians remain 1358. Whole-workload SQL/requests decrease in every pair: −11/−3, −62/−7, and −9/−1. Restart-connect's +4 SQL / +2 requests comes from background maintenance, cleanup, publication, and dispatch; combined restart costs still fall. Initial boot's +1 MAIN median is an unchanged shared-state opening site; warmed and restart MAIN do not rise.
All target restart and warmed phase duration ratios are below 1.5. The short restart-shutdown window has a 2.137 duration ratio and is excluded from timing comparisons; its SQL median remains 28 and request median falls 7→6. No latency improvement is claimed.
LOC against the base: production +71/−89 (net −18), tests +6/−108 (net −102), documentation +6/−2; total net −116.