Skip to content

fix: avoid database cleanup errors after temporary agent runs - #148674

Merged
steipete merged 1 commit into
mainfrom
codex/agent-exec-temp-drain-20260915
Sep 15, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/agent-exec-temp-drain-20260915

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes database cleanup errors when openclaw agent exec removes its temporary state while database workers still own resources there.

User Impact

Temporary runs finish their database cleanup before removing state. Explicit --state-dir ownership and retained state are unchanged; uncertain runtime or process cleanup still preserves state for inspection. No configuration or schema migration is required.

Why This Change Was Made

Temporary execution now uses the existing lexical database resource owner, which drains accepted work and closes the run’s exact resources before the environment is restored. Independent cached handles keep their existing owner. The scope distinguishes resource custody from schema maintenance and preserves real maintenance delegation through nested scopes.

Evidence

Both ordinary success/error regressions pass through the real command with a mocked agent, synthetic session creation/deletion, and an asynchronous audit write. They verify native handle closure before removal and preserve an independent database. Both fail on the original command because its temporary handles remain open; the control prevents deletion until test-owned cleanup runs.

The pure scope inheritance/delegation test and three retained-state/config-restoration checks pass. Fresh independent P2 review is clean. All changed-file gates and the normal build pass. No real provider calls or native fault, held-worker, or path-replacement scenarios were run.

@clawsweeper

clawsweeper Bot commented Sep 15, 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.

@steipete
steipete marked this pull request as ready for review September 15, 2026 01:24
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation commands Command implementations size: S maintainer Maintainer-authored PR labels Sep 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 9:31 PM ET / September 15, 2026, 01:31 UTC.

ClawSweeper review

What this changes

Temporary agent runs now finish accepted database work and close their owned database resources before removing temporary state.

Merge readiness

✅ Ready for maintainer review

The PR remains useful: current main and v2026.9.4 lack the temporary-run database drain. No blocking defect was found in the introduced changes.

Priority: P2
Reviewed head: b9eb5ad641ad14dc60b2145138e2ce2d0292e384

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair using the existing lifecycle owner, with meaningful regression coverage and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied maintainer classification exempts this PR from the external-contributor proof gate. Its command-boundary SQLite regressions support cleanup ordering but do not establish live-provider, held-worker, or native-fault behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied maintainer classification exempts this PR from the external-contributor proof gate. Its command-boundary SQLite regressions support cleanup ordering but do not establish live-provider, held-worker, or native-fault behavior.
Evidence reviewed 8 items Introduced change boundary: The host verified the complete merge-base-to-head patch and the test merge against its pinned main parent. The introduced changes concern command cleanup, resource-scope delegation, two regression tests, and command documentation; endpoint drift was excluded.
Cleanup ordering: Temporary runs enter the resource scope, including audit-writer creation and shutdown. Scope closure precedes environment restoration and directory removal. Existing runtime/process cleanup uncertainty and database-close failures preserve the directory.
Existing resource and authority owners: The scope drains pending operations and closes resources in agent-to-shared order. Ordinary scopes create no schema delegate; inherited delegation calls the parent scope, whose closed check remains active. The coordinator also checks the requested database and live maintenance lease. These are OpenClaw-owned database contracts, with no affirmative dependency on the Codex harness.
Findings None None.
Security None None.

How this fits together

The agent exec command runs a single embedded agent turn and owns its temporary state directory. Database lifecycle scopes coordinate pending work, worker resources, and native handles before that directory is removed.

flowchart TD
  A[Agent exec invocation] --> B{Temporary state?}
  B -->|Yes| C[Database resource scope]
  B -->|No| D[Existing retained-state ownership]
  C --> E[Agent turn and audit writes]
  E --> F[Drain work and close owned resources]
  F --> G{Cleanup confirmed?}
  G -->|Yes| H[Remove temporary state]
  G -->|No| I[Preserve state and report failure]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +27, Tests +136, Docs 0. Total +163 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 44 17 +27
Tests 2 136 0 +136
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 181 18 +163

Review metrics

None.

Technical review

Best possible solution:

Keep temporary-state deletion behind the existing resource owner's completed drain, preserving independent clients and retaining state whenever cleanup is uncertain.

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

Yes, from source: current main can remove temporary state without draining its database resources, and the supplied regression targets that ordering. No runtime reproduction was executed in this review.

Is this the best way to solve the issue?

Yes. Reusing the existing resource scope addresses ownership directly and preserves cleanup-error reporting, unlike retrying deletion or suppressing its failure.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This repairs bounded cleanup failures in temporary agent runs without changing configuration or stored-data contracts.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied maintainer classification exempts this PR from the external-contributor proof gate. Its command-boundary SQLite regressions support cleanup ordering but do not establish live-provider, held-worker, or native-fault behavior.

Label justifications:

  • P2: This repairs bounded cleanup failures in temporary agent runs without changing configuration or stored-data contracts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied maintainer classification exempts this PR from the external-contributor proof gate. Its command-boundary SQLite regressions support cleanup ordering but do not establish live-provider, held-worker, or native-fault behavior.

Evidence

What I checked:

  • Introduced change boundary: The host verified the complete merge-base-to-head patch and the test merge against its pinned main parent. The introduced changes concern command cleanup, resource-scope delegation, two regression tests, and command documentation; endpoint drift was excluded. (b9eb5ad641ad)
  • Cleanup ordering: Temporary runs enter the resource scope, including audit-writer creation and shutdown. Scope closure precedes environment restoration and directory removal. Existing runtime/process cleanup uncertainty and database-close failures preserve the directory. (src/commands/agent-exec.ts:529, b9eb5ad641ad)
  • Existing resource and authority owners: The scope drains pending operations and closes resources in agent-to-shared order. Ordinary scopes create no schema delegate; inherited delegation calls the parent scope, whose closed check remains active. The coordinator also checks the requested database and live maintenance lease. These are OpenClaw-owned database contracts, with no affirmative dependency on the Codex harness. (src/state/openclaw-state-db-async-lifecycle.ts:127, b9eb5ad641ad)
  • Regression evidence and limits: The complete tests exercise the real command with a stubbed agent, native SQLite handles, session deletion, and asynchronous audit writes for success and failure. They assert handle closure before removal and preservation of an independent handle. The captured PR body reports original-red/candidate-green results, but no held-worker or native-fault scenarios. Tests were inspected, not executed during this read-only review. (src/commands/agent-exec.database-cleanup.test.ts:29, b9eb5ad641ad)
  • Current-main and release comparison: Inspection of agent-exec.ts at fetched main and v2026.9.4 found audit shutdown followed by state-lock release and eventual directory removal, without the new temporary database scope. The central repair is therefore absent from both inspected revisions. (src/commands/agent-exec.ts, 55e261df56a4)
  • Related merged lifecycle work and routing: Git history and GitHub identify fix: Doctor maintenance closes unrelated database clients #148126 as the merged resource-ownership prerequisite, with commit author login steipete. Its Doctor cleanup repair does not add this command integration. Some older parent blobs were unavailable, so no source-line introduction attribution is claimed. (src/state/openclaw-state-db-async-lifecycle.ts, cb24f207229d)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 4b8fd85 into main Sep 15, 2026
400 of 402 checks passed
@steipete
steipete deleted the codex/agent-exec-temp-drain-20260915 branch September 15, 2026 02:30
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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.

1 participant