Skip to content

test(agents): reuse worktree state database fixture - #118550

Merged
steipete merged 1 commit into
mainfrom
codex/test-perf-compact-large-7-state-db
Aug 3, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/test-perf-compact-large-7-state-db

Conversation

@steipete

@steipete steipete commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • reuse one suite-scoped OpenClaw state database for the managed-worktree service tests
  • retain a fresh reflinked Git repository and filesystem root for every case
  • explicitly clear worktree registry rows, run leases, provisioned chunks, and the managed worktree directory after each case

Root cause

Production keeps the shared state database open for the process lifetime, but this suite created a new OPENCLAW_STATE_DIR and physically reopened the full state database for nearly every one of its 48 cases. Each cold open repeated database validation, pragmas, and schema setup before the test could exercise the worktree behavior it owned.

The Git fixture was already suite-templated and reflinked. Reusing the process-owned SQLite fixture is therefore the owner-aligned simplification: Git repositories remain isolated per case, while shared state now follows the production lifecycle.

Coverage and isolation

  • all 48 managed-worktree service tests remain unchanged
  • each case still receives a distinct source repository, worktree common directory, remotes, branches, and filesystem root
  • teardown clears every worktree record and its lease/provisioned rows, then removes the shared managed-worktree directory
  • the state database closes once before suite teardown removes the shared state directory

Performance

Paired focused runs on the same ready dependency install at base 4b3d0b37be5eb07608b315ecb35453d0df39ec0c:

  • before: 28.36s Vitest / 31.01s wrapper, 48 passed
  • after: 18.00s Vitest / 21.27s wrapper, 48 passed
  • improvement: 36.5% (10.36s Vitest)

In the profiled compact-large-7 environment, this file was the agents-support critical tail at 92.43s. The focused reduction clears the lane's updated 10s execution target without changing sharding or concurrency.

Proof

  • managed-worktree service: 48/48
  • service plus provisioned, run-lease, naming, and removal siblings: 77 passed, 1 skipped
  • targeted formatting, Oxlint, and git diff --check: clean
  • autoreview against current origin/main: clean

Core test typechecking reaches two pre-existing errors outside this change in packages/terminal-core/src/ansi.ts and ui/src/app-session-route-paths.ts; it reports no changed-file errors.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS maintainer Maintainer-authored PR labels Aug 3, 2026
@steipete steipete self-assigned this Aug 3, 2026
@clawsweeper clawsweeper Bot added 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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 2:57 AM ET / 06:57 UTC.

ClawSweeper review

What this changes

The PR reuses one suite-scoped SQLite state database for managed-worktree service tests while retaining a fresh Git repository and filesystem root for every test case.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this PR open for normal maintainer merge handling. It is a narrow, current test-fixture performance change, is not present on current main, and its cleanup follows the existing registry and state-database ownership boundaries; the protected maintainer label also requires explicit maintainer handling rather than automated cleanup.

Priority: P3
Reviewed head: 2195f94ad2e08bde8a57f8fbed8ccdbd5fdb90ff

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A narrowly scoped fixture simplification with credible focused performance proof and cleanup that follows the existing state ownership APIs.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body provides after-fix focused terminal-run results for the changed fixture, including passing counts, sibling coverage, and paired timing measurements.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body provides after-fix focused terminal-run results for the changed fixture, including passing counts, sibling coverage, and paired timing measurements.
Evidence reviewed 7 items Patch uses one suite-owned state directory: The branch moves OPENCLAW_STATE_DIR from each test root to stateDir created in suite setup, and defers database closure until suite teardown.
Teardown uses canonical registry cleanup: Each suite-shared worktree record is cleared through the existing removal-row and registry-delete helpers before its managed worktree directory is removed.
Registry helpers cover the persisted dependent rows: finalizeWorktreeRemovalRows deletes the worktree-scoped run leases, while deleteRegistryWorktree deletes provisioned-file chunks and the primary worktree row.
Findings None None.
Security None None.

How this fits together

Managed-worktree service tests create temporary Git repositories and persist worktree metadata, run leases, and provisioned-file chunks in OpenClaw’s shared SQLite state database. The fixture sets up a service for each case, then must remove that case’s registry rows and worktree files before the next case runs.

flowchart LR
  A[Per-test Git repository] --> C[Managed worktree service]
  B[Suite SQLite state database] --> C
  C --> D[Worktree registry row]
  D --> E[Lease and provisioned rows]
  E --> F[Per-test registry cleanup]
  F --> G[Managed worktree files removed]
  G --> H[Next isolated test case]
Loading

Before merge

  • Resolve merge risk (P1) - The branch is reported as behind current main; refresh the merge result and required checks before landing, although current-main history shows no intervening change to this test file since the PR base.
  • Complete next step (P2) - No repair lane is warranted because no concrete defect was found; the remaining action is ordinary maintainer merge review after the branch/check refresh.
Agent review details

Security

None.

PR surface

Tests +10. Total +10 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 12 2 +10
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 12 2 +10

Review metrics

Metric Value Why it matters
Production versus test delta production +0/-0; tests +12/-2 The change is confined to test lifecycle code; the added lines implement explicit cleanup for the shared test database rather than expanding product behavior.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the suite-scoped fixture after the clean merge result and required checks are refreshed, preserving the canonical registry cleanup calls and per-case Git/filesystem isolation.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the suite-scoped fixture after the clean merge result and required checks are refreshed, preserving the canonical registry cleanup calls and per-case Git/filesystem isolation.

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

Not applicable: the change targets test-fixture startup cost and isolation, and the PR body supplies focused before/after test-run evidence rather than a user-facing defect report.

Is this the best way to solve the issue?

Yes. Reusing the process-lifetime state database matches the production ownership model while using the existing registry helpers to remove worktree rows, leases, and provisioned chunks between isolated cases.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a focused test-fixture performance and cleanup improvement with no direct production behavior change.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix focused terminal-run results for the changed fixture, including passing counts, sibling coverage, and paired timing measurements.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides after-fix focused terminal-run results for the changed fixture, including passing counts, sibling coverage, and paired timing measurements.

Label justifications:

  • P3: This is a focused test-fixture performance and cleanup improvement with no direct production behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides after-fix focused terminal-run results for the changed fixture, including passing counts, sibling coverage, and paired timing measurements.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix focused terminal-run results for the changed fixture, including passing counts, sibling coverage, and paired timing measurements.

Evidence

What I checked:

  • Patch uses one suite-owned state directory: The branch moves OPENCLAW_STATE_DIR from each test root to stateDir created in suite setup, and defers database closure until suite teardown. (src/agents/worktrees/service.test.ts:87, 2195f94ad2e0)
  • Teardown uses canonical registry cleanup: Each suite-shared worktree record is cleared through the existing removal-row and registry-delete helpers before its managed worktree directory is removed. (src/agents/worktrees/service.test.ts:113, 2195f94ad2e0)
  • Registry helpers cover the persisted dependent rows: finalizeWorktreeRemovalRows deletes the worktree-scoped run leases, while deleteRegistryWorktree deletes provisioned-file chunks and the primary worktree row. (src/agents/worktrees/registry.ts:336, 4281e90012fe)
  • Suite teardown matches shared database lifecycle: The state database is process-cached and closeOpenClawStateDatabaseForTest closes all cached handles and clears test failure latches, so closing it once after the suite is consistent with the proposed shared fixture. (src/state/openclaw-state-db.ts:699, 4281e90012fe)
  • Current main has not absorbed the branch change: The PR commit is not an ancestor of current main, and the direct current-main-to-branch diff still contains the 12 added and 2 removed test lines. (src/agents/worktrees/service.test.ts:76, 2195f94ad2e0)
  • Feature-history provenance: Blame attributes the existing managed-worktree fixture and its original per-test database-close lifecycle to Shakker in the current worktree-service test introduction. (src/agents/worktrees/service.test.ts:70, 5d2cc051b407)

Likely related people:

  • Shakker: Current-file blame attributes the managed-worktree service fixture and the registry cleanup helpers to the same recent current-main introduction. (role: feature introducer and recent area contributor; confidence: medium; commits: 5d2cc051b407; files: src/agents/worktrees/service.test.ts, src/agents/worktrees/registry.ts)

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.

@steipete
steipete merged commit 938980d into main Aug 3, 2026
102 of 111 checks passed
@steipete
steipete deleted the codex/test-perf-compact-large-7-state-db branch August 3, 2026 07:00
@steipete

steipete commented Aug 3, 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 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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