Skip to content

fix: agent replies stay refused with "admission is closed" after a failed operation cleanup until the gateway restarts - #159451

Merged
obviyus merged 5 commits into
openclaw:mainfrom
aspalagin:repro/agent-execution-close-wedge
Sep 27, 2026
Merged

obviyus merged 5 commits into
openclaw:mainfrom
aspalagin:repro/agent-execution-close-wedge

Conversation

@aspalagin

@aspalagin aspalagin commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #159438
Related: #157325

What Problem This Solves

Fixes: every turn of an agent fails with Agent database execution admission is closed until the Gateway restarts when an agent database operation fails and its native cleanup also fails.

User Impact

User impact: the affected agent can use its database again on the next request after a transient cleanup failure clears, without a Gateway restart. Explicit resource revocation remains terminal. No configuration, schema, permissions, migration, or public API changes.

Why This Change Was Made

A failed native close left its execution owner permanently retired but still registered. Re-admitting the non-revoked owner preserves custody of its native generation and lease: later operations retry cleanup before replacement work is allowed. The native close waits for the stopped worker before releasing its retained lease, and a failed lease-release attempt still closes its cleanup worker. No failed user operation is replayed.

No overlap with Pash/Sarah changes.

Evidence

Real execution owner and SQLite workers, with worker exit injected during a marked operation and disk I/O error injected at lease release:

  • Main aaf0be1026c4: both failure/recovery cases fail with Agent database execution admission is closed after the operation and cleanup fail.
  • Candidate: all three cases pass. Failed-close recovery performs a real session.entry.read successfully after the fault clears.
  • Successful-close control passes on both main and the candidate: a worker exit without the lease-release failure does not wedge the agent.
  • Persistent fault: two rounds of two concurrent borrowers each share exactly one cleanup attempt. Every borrower receives disk I/O error, not admission is closed; the tracked live-worker count stays constant. Once the fault clears, the very next native read succeeds. Another agent remains usable.
  • The retained logical owner remains registered throughout failed cleanup, so concurrent borrowers cannot install another owner for that path. Replacement native generation creation remains behind successful cleanup.
  • The new file is selected by vitest.infra.config.ts through databaseWorkerCoreTestFiles; the repository test wrapper ran it as |infra|.

Command: node scripts/run-vitest.mjs src/state/openclaw-agent-execution.close-wedge.test.ts --maxWorkers=1. Measured candidate cost on macOS arm64: 9.00 s Vitest, 28.60 s whole invocation including worker bundle preparation; cases 1.96 s, 1.32 s, and 2.95 s. No sleeps or polling; real worker lifecycle is needed to exercise native retirement and lease cleanup.

Gap: this reproduces the recovery failure with injected native faults, not the original filesystem cause of the production I/O error. No isolated Gateway/provider turn is claimed.

Final focused lifecycle run: 4 files, 46 tests passed (close-wedge, integrity, creation-witness, and execution-cleanup), 30.79 s Vitest / 45.67 s command. Scoped Oxlint, formatting, diff whitespace checks, and all consumer type graphs selected for the execution owner passed.

@clawsweeper

clawsweeper Bot commented Sep 27, 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 channel: msteams Channel integration: msteams gateway Gateway runtime agents Agent runtime and tooling channel: feishu Channel integration: feishu size: XL labels Sep 27, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 27, 2026, 3:02 AM ET / 07:02 UTC (Revision 4).

ClawSweeper review

What this changes

The branch lets an agent database execution owner retry failed native cleanup on a later request and adds worker-backed recovery tests.

Merge readiness

✅ Ready for maintainer review

Current main still leaves an execution owner retired after native cleanup fails. This PR addresses that distinct failure path, and its worker-backed before-and-after evidence supports recovery without a Gateway restart.

Priority: P0
Reviewed head: 2ebef57f58fa183b6c623eac9f6f0fe78cf1864c

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-level repair has strong before-and-after worker-boundary evidence and no identified blocking defect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed execution owner was exercised through its production SQLite worker path with injected worker exit and lease-release failure; the PR body reports a failing main baseline and a successful after-fix session read once the fault cleared. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed execution owner was exercised through its production SQLite worker path with injected worker exit and lease-release failure; the PR body reports a failing main baseline and a successful after-fix session read once the fault cleared. No stored-data contract changes.
Evidence reviewed 8 items Current main retains the refusal path: The current-main owner marks itself retired before native close and clears that state only through successful retirement; a failed close leaves the owner registered and later borrowers encounter the admission guard.
Introduced recovery change: The pinned introduced diff resets retirement only after a rejected native close and only when explicit revocation has not occurred.
Cleanup custody and admission: A failed native close retains the generation and cleanup failure; the next run retries cleanup before creating replacement work and rechecks current authority.
Findings None None.
Security None None.

How this fits together

Agent turns use a per-agent SQLite execution owner to admit database operations and manage a native worker and lease. Failed operations pass through that owner's cleanup before a later turn can use the database.

flowchart LR
  A[Agent request] --> B[Execution owner]
  B --> C{Cleanup pending?}
  C -->|Yes| D[Retry native cleanup]
  C -->|No| E[SQLite worker]
  D --> E
  E --> F[Database result]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +10, Tests +219. Total +229 across 3 files.

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

Review metrics

Metric Value Why it matters
Production and test growth production +10 lines, tests +218 lines The larger test fixture exercises worker exit and lease cleanup through the production owner; the PR body reports 9.00 seconds of test time.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #159438
Summary: This PR is the candidate fix for the specifically reported failed-operation close wedge; the broader cleanup reports describe distinct paths.

Members:

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

Technical review

Best possible solution:

Keep the failed generation and lease with one owner, retry native cleanup before new database work, and preserve terminal explicit revocation.

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

Yes. The source and worker-backed fixture define a specific worker-exit plus lease-release-failure path; the PR body reports the admission refusal on main, although this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. The repair stays in the existing execution owner, retries cleanup before replacement work, and preserves explicit revocation.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P0: The reported failure can leave an affected agent unable to reply on every turn until the Gateway restarts.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed execution owner was exercised through its production SQLite worker path with injected worker exit and lease-release failure; the PR body reports a failing main baseline and a successful after-fix session read once the fault cleared. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed execution owner was exercised through its production SQLite worker path with injected worker exit and lease-release failure; the PR body reports a failing main baseline and a successful after-fix session read once the fault cleared. No stored-data contract changes.

Evidence

What I checked:

  • Current main retains the refusal path: The current-main owner marks itself retired before native close and clears that state only through successful retirement; a failed close leaves the owner registered and later borrowers encounter the admission guard. (src/state/openclaw-agent-execution.ts:557, cd481e80875d)
  • Introduced recovery change: The pinned introduced diff resets retirement only after a rejected native close and only when explicit revocation has not occurred. (src/state/openclaw-agent-execution.ts:564, 2ebef57f58fa)
  • Cleanup custody and admission: A failed native close retains the generation and cleanup failure; the next run retries cleanup before creating replacement work and rechecks current authority. (src/state/openclaw-agent-execution.ts:293, 2ebef57f58fa)
  • Explicit revocation remains terminal: The resource owner revokes admission before invoking asynchronous close; the patch records that revocation so failed cleanup cannot reopen the logical owner. (src/state/openclaw-agent-db-resources.ts:205, 2ebef57f58fa)
  • Worker-backed regression coverage: The added test runs through the execution owner and real SQLite workers, injects worker exit and lease-release failure, checks concurrent cleanup, and reads again after the fault clears. (src/state/openclaw-agent-execution.close-wedge.test.ts:138, 2ebef57f58fa)
  • Contributor's before-and-after execution evidence: The pinned PR body reports the baseline failing with the admission error, the candidate recovering a real session read, and three worker-backed cases passing. It states that the original production filesystem trigger and a full Gateway turn were not reproduced. (2ebef57f58fa)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Josh Avant: 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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-27T05:35:50.988Z sha c62623c14d3270909c1ad9dec41564865eacd9c7 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-27T05:57:59.009Z sha 9f9f80b :: blocked before merge. :: none
  • reviewed 2026-09-27T06:10:21.950Z sha ff146a0 :: needs maintainer review before merge. :: none

@aspalagin
aspalagin marked this pull request as ready for review September 27, 2026 05:37
@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

Current revision: 2ebef57f58fa183b6c623eac9f6f0fe78cf1864c

This PR no longer changes files in the maintainer security-review tier.

Separate CODEOWNERS requirements still apply to security policy and enforcement files.

Arseniy Palagin and others added 2 commits September 27, 2026 05:42
…leanup

When an agent-DB operation fails with an unavailable native store, run()
calls owner.close(). close() sets retired = true before closeNative()
settles and only evicts the owner from `executions` after a successful
close, so a rejected native close (transient SQLITE_IOERR on the lease
release) leaves a retired owner registered. Every later borrow() for that
agent path then throws "Agent database execution admission is closed"
until the process drains (gateway restart).

The new test kills the SQLite worker mid-command and refuses the lease
release while the fault is enabled, then expects the same agent to be
re-admitted once the fault is gone. It fails on 2026.9.6 and current main
with the production error text; the second case documents the scope
(other agents unaffected, full drain clears it).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D2bGxAUAa1avrRxf5iU2iG
…d operation

owner.close() marked the execution owner retired before its native close
settled and only evicted it from `executions` after a successful close.
When the close rejected (a transient SQLite I/O error on the lease
release), the retired owner stayed registered for the agent path and
every later borrow() was refused with "Agent database execution admission
is closed" until the gateway restarted; nothing on the request path ever
called close() again.

Re-admit the owner when a non-revoked close fails. It keeps its
generation, lease and cleanupFailure, so the next request retries the
native close through the existing cleanup path before any new work and
surfaces the native cause while it persists. Explicit revoke() stays
terminal.

The regression test now expects recovery and adds the retry-while-failing
case (native cause instead of the generic refusal, then recovery once the
cause clears).

Closes openclaw#159438

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D2bGxAUAa1avrRxf5iU2iG
@aspalagin
aspalagin force-pushed the repro/agent-execution-close-wedge branch from c62623c to 9f9f80b Compare September 27, 2026 05:50
@openclaw-barnacle openclaw-barnacle Bot added size: M and removed docs Improvements or additions to documentation channel: msteams Channel integration: msteams gateway Gateway runtime agents Agent runtime and tooling channel: feishu Channel integration: feishu size: XL labels Sep 27, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 27, 2026
@clawsweeper clawsweeper Bot added 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 rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 27, 2026
Current main hands the fixture admission a binding attachment; without it
every prepare() is refused with "SQLite operation attachment is
unavailable" before the scenario starts.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D2bGxAUAa1avrRxf5iU2iG
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. and removed P1 High-priority user-facing bug, regression, or broken workflow. labels Sep 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 27, 2026
@obviyus
obviyus merged commit f0423d5 into openclaw:main Sep 27, 2026
233 of 235 checks passed
@obviyus

obviyus commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

Merged as f0423d5. Thank you @aspalagin for reporting this and contributing the fix and real-worker reproduction.

Confirmed current main wedges after worker exit plus a failed lease release; the fix retains cleanup custody and allows the next native read after the fault clears. Successful close remains unchanged. Concurrent persistent-fault borrowers share one bounded cleanup attempt, receive the actual disk I/O error rather than an admission refusal, and do not accumulate live workers.

All 46 focused lifecycle tests, selected consumer type graphs, and scoped lint/format checks passed. Fresh CI run 36301545164 and required gates were green, with hosted review ready on the exact merged head. CI selected and passed all three new cases in core-runtime-infra-storage-state-hosted-15: 1.877 s, 1.442 s, and 3.893 s (7.212 s total test time).

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 28, 2026
…claw#159451)

Closes openclaw#159438
Related: openclaw#157325

## What Problem This Solves

Fixes: every turn of an agent fails with `Agent database execution admission is closed` until the Gateway restarts when an agent database operation fails and its native cleanup also fails.

## User Impact

User impact: the affected agent can use its database again on the next request after a transient cleanup failure clears, without a Gateway restart. Explicit resource revocation remains terminal. No configuration, schema, permissions, migration, or public API changes.

## Why This Change Was Made

A failed native close left its execution owner permanently retired but still registered. Re-admitting the non-revoked owner preserves custody of its native generation and lease: later operations retry cleanup before replacement work is allowed. The native close waits for the stopped worker before releasing its retained lease, and a failed lease-release attempt still closes its cleanup worker. No failed user operation is replayed.

No overlap with Pash/Sarah changes.

## Evidence

Real execution owner and SQLite workers, with worker exit injected during a marked operation and `disk I/O error` injected at lease release:

- Main `45d46000df1d`: both failure/recovery cases fail with `Agent database execution admission is closed` after the operation and cleanup fail.
- Candidate: all three cases pass. Failed-close recovery performs a real `session.entry.read` successfully after the fault clears.
- Successful-close control passes on both main and the candidate: a worker exit without the lease-release failure does not wedge the agent.
- Persistent fault: two rounds of two concurrent borrowers each share exactly one cleanup attempt. Every borrower receives `disk I/O error`, not `admission is closed`; the tracked live-worker count stays constant. Once the fault clears, the very next native read succeeds. Another agent remains usable.
- The retained logical owner remains registered throughout failed cleanup, so concurrent borrowers cannot install another owner for that path. Replacement native generation creation remains behind successful cleanup.
- The new file is selected by `vitest.infra.config.ts` through `databaseWorkerCoreTestFiles`; the repository test wrapper ran it as `|infra|`.

Command: `node scripts/run-vitest.mjs src/state/openclaw-agent-execution.close-wedge.test.ts --maxWorkers=1`. Measured candidate cost on macOS arm64: 9.00 s Vitest, 28.60 s whole invocation including worker bundle preparation; cases 1.96 s, 1.32 s, and 2.95 s. No sleeps or polling; real worker lifecycle is needed to exercise native retirement and lease cleanup.

Gap: this reproduces the recovery failure with injected native faults, not the original filesystem cause of the production I/O error. No isolated Gateway/provider turn is claimed.

Final focused lifecycle run: 4 files, 46 tests passed (`close-wedge`, `integrity`, `creation-witness`, and `execution-cleanup`), 30.79 s Vitest / 45.67 s command. Scoped Oxlint, formatting, diff whitespace checks, and all consumer type graphs selected for the execution owner passed.

Co-authored-by: Arseniy Palagin <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
cgluttrell pushed a commit to cgluttrell/Aaron that referenced this pull request Oct 3, 2026
…claw#159451)

Closes openclaw#159438
Related: openclaw#157325

Fixes: every turn of an agent fails with `Agent database execution admission is closed` until the Gateway restarts when an agent database operation fails and its native cleanup also fails.

User impact: the affected agent can use its database again on the next request after a transient cleanup failure clears, without a Gateway restart. Explicit resource revocation remains terminal. No configuration, schema, permissions, migration, or public API changes.

A failed native close left its execution owner permanently retired but still registered. Re-admitting the non-revoked owner preserves custody of its native generation and lease: later operations retry cleanup before replacement work is allowed. The native close waits for the stopped worker before releasing its retained lease, and a failed lease-release attempt still closes its cleanup worker. No failed user operation is replayed.

No overlap with Pash/Sarah changes.

Real execution owner and SQLite workers, with worker exit injected during a marked operation and `disk I/O error` injected at lease release:

- Main `aaf0be1026c4`: both failure/recovery cases fail with `Agent database execution admission is closed` after the operation and cleanup fail.
- Candidate: all three cases pass. Failed-close recovery performs a real `session.entry.read` successfully after the fault clears.
- Successful-close control passes on both main and the candidate: a worker exit without the lease-release failure does not wedge the agent.
- Persistent fault: two rounds of two concurrent borrowers each share exactly one cleanup attempt. Every borrower receives `disk I/O error`, not `admission is closed`; the tracked live-worker count stays constant. Once the fault clears, the very next native read succeeds. Another agent remains usable.
- The retained logical owner remains registered throughout failed cleanup, so concurrent borrowers cannot install another owner for that path. Replacement native generation creation remains behind successful cleanup.
- The new file is selected by `vitest.infra.config.ts` through `databaseWorkerCoreTestFiles`; the repository test wrapper ran it as `|infra|`.

Command: `node scripts/run-vitest.mjs src/state/openclaw-agent-execution.close-wedge.test.ts --maxWorkers=1`. Measured candidate cost on macOS arm64: 9.00 s Vitest, 28.60 s whole invocation including worker bundle preparation; cases 1.96 s, 1.32 s, and 2.95 s. No sleeps or polling; real worker lifecycle is needed to exercise native retirement and lease cleanup.

Gap: this reproduces the recovery failure with injected native faults, not the original filesystem cause of the production I/O error. No isolated Gateway/provider turn is claimed.

Final focused lifecycle run: 4 files, 46 tests passed (`close-wedge`, `integrity`, `creation-witness`, and `execution-cleanup`), 30.79 s Vitest / 45.67 s command. Scoped Oxlint, formatting, diff whitespace checks, and all consumer type graphs selected for the execution owner passed.

Co-authored-by: Arseniy Palagin <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit f0423d5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

2 participants