Skip to content

fix(state): name the owner that revoked a session reader's receipt - #204702

Merged
obviyus merged 2 commits into
mainfrom
fix/session-reader-receipt-race
Nov 24, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/session-reader-receipt-race

Conversation

@obviyus

@obviyus obviyus commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

src/agents/cli-runner/history-boundary.test.ts > CLI history account > keeps refusing a legacy record that could hide an account switch fails in about 6.5% of scheduled main runs (5 of about 76 since 2026-11-21, always in Bun infra shards) with:

Session reader validation does not match its current physical owner

The refusal said only that the receipt no longer matched. It did not say whether the receipt was revoked, by whom, or whether the file changed, so every failure was a dead end. It never reproduced locally (Node, pinned Bun, 1-CPU Linux, 4 concurrent copies).

Change

  • Each agent-database validation receipt carries a shared revokedBy cell. Every revocation goes through revokeAgentDatabaseValidation(validation, revoker), which records the first revoker before it clears valid.
  • invalidateOpenClawAgentDatabaseValidation now takes a required revoker name, and every caller names itself (lease release without a confirmed close, failed close, disposal, maintenance write, successor receipt, file identity change, and so on).
  • The worker's refusal now reads Session reader validation does not match its current physical owner: <reason>. The reason is the receipt was revoked by <owner>, or it names the agent or file identity mismatch.
  • No retry and no behavior change: the same reads are refused at the same point.

What I tested about the cause

  • Revoking the captured receipt in the prepareRead hook (after capture, before dispatch) reproduces the exact CI refusal. That is the mechanism. The new test pins it and the named reason.
  • A real writer close inside that window does not give this error; it revokes the read itself (Session history database read was revoked). So an ordering fix for the previous write's close on the same path would not address the CI failure, and none is included.
  • Closing an unrelated, deleted database inside the window did not revoke the live receipt in this setup.
  • The cause therefore remains unknown. With this change, the next CI failure names the owner that revoked the receipt.

Evidence

  • New src/config/sessions/session-transcript-worker.receipt-race.test.ts: passes, and asserts the full refusal text including the revoker.
  • Touched test files (23) pass; pnpm tsgo:core and pnpm tsgo:test:src pass; oxfmt and oxlint clean on changed files.
  • Upgrade: a receipt sealed at clean close by an older release has no revokedBy cell. agentDatabaseValidationKey.read (the one decode point for stored and restored receipts) gives it a cell once. A new test in openclaw-agent-db-validation-cache.test.ts revokes and reports such a receipt; without the fix it throws Invalid atomic access index.

@clawsweeper

clawsweeper Bot commented Nov 24, 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 gateway Gateway runtime size: M labels Nov 24, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 24, 2026
@clawsweeper

clawsweeper Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR records which database lifecycle owner revoked a validation receipt and includes that reason in session-reader failures.

Example: A lease release revokes the receipt captured for agent:main:race before worker dispatch.

  • Before: Session reader validation does not match its current physical owner
  • After: Session reader validation does not match its current physical owner: the receipt was revoked by a lease release without a confirmed close

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is focused and source review found no actionable correctness defect, but compatibility evidence stops at a constructed legacy receipt rather than the required upgrade path.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Maintenance · Worth it: Yes · Fix scope: Complete
User problem: A session-reader refusal gives maintainers no indication of which lifecycle owner invalidated its receipt.
Reason: The collaborator-authored direction is established, and the bounded diagnostic addition has clear investigation value while honestly leaving the intermittent failure unresolved.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this maintainer-authored PR adds useful diagnostics for an unresolved receipt refusal, and source review found no discrete introduced correctness defect.

Priority: P2
Reviewed head: 42cc851755e220b0520140c3df5f37327a4e892e

Before merge

  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Supply a latest-stable-to-head upgrade run covering an existing agent database and clean-close receipt, successful history reads, named revocation reporting, and preserved settings/data; redact private identifiers and endpoints.
Agent review details

How this fits together

Session-history readers borrow physical database validation from the agent database owner; lifecycle invalidation clears shared validity, and the worker refuses receipts that no longer match its connection.

flowchart LR
  A[Database lifecycle owners] --> B[Validation receipt]
  B --> C[History read admission]
  C --> D[Reader worker]
  D --> E[Physical owner check]
  E --> F[Read result or named refusal]
Loading

Technical review

Best possible solution:

Keep attribution within the existing receipt owner and preserve the current refusal semantics while using subsequent failures to identify the underlying cause.

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

The capture-to-dispatch revocation path is explicit in source and the added real-worker test; the intermittent scheduled Bun failure itself remains unreproduced and its revoker unknown.

Is this the best way to solve the issue?

The focused diagnostic approach is appropriate: one shared field and one revocation operation serve existing owners without adding retries, weakening validation, or guessing at an unverified cause.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Physical validation and revocation keeps the original intent (fix: avoid repeated agent database integrity scans #146512: Reuse verified physical database health across ordinary reopens while revoking remembered proof on replacement, disposal, registry invalidation, quarantine, or failed admission.)
  • Reader receipt refusal keeps the original intent (ad3c930: Worker-owned session reads retain physical-owner validation rather than consuming stale or foreign proof; this PR changes only the explanation at the existing refusal.)
  • Clean-close receipt restoration keeps the original intent (perf(sqlite): reuse database validation after clean shutdown #169649: Reuse completed validation after a matching clean shutdown while keeping invalidation and physical identity checks authoritative.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +97, Tests +88. Total +185 across 37 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 12 130 33 +97
Tests 25 146 58 +88
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 37 276 91 +185

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: The diagnostics support investigation of recurring session-reader failures without changing normal read behavior or claiming an urgent runtime repair.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: The diagnostics support investigation of recurring session-reader failures without changing normal read behavior or claiming an urgent runtime repair.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.

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.

Reviewed November 24, 2026, 10:14 AM ET / 15:14 UTC.

@obviyus

obviyus commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: the only red job is not caused by this PR.

# PR #204702 head 42cc851755e2; main run 45403387860
PostgreSQL conformance (3/4)	src/gateway/server-database-engine-cron.postgres.test.ts	OURS

ci-triage tags it OURS only because ordinary main pushes do not run this lane. The same test failed at the same lines (:263, :472, restart readiness gets 503) on scheduled main run https://github.com/openclaw/openclaw/actions/runs/45365444232. Filed as #204730. This PR changes only SQLite agent-receipt revocation reporting; every receipt path (create, transfer, decode) carries the new revokedBy cell.

@obviyus
obviyus merged commit 51f5626 into main Nov 24, 2026
259 of 262 checks passed
@obviyus
obviyus deleted the fix/session-reader-receipt-race branch November 24, 2026 15:42
@obviyus

obviyus commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 51f5626.

  • Problem: the intermittent history-boundary.test.ts refusal (Session reader validation does not match its current physical owner) did not say why the receipt was refused.
  • Fix: every receipt revocation records its owner, and the refusal names it (or the agent / file identity mismatch). Receipts restored from an older clean-close seal get the new cell on decode.
  • Proof: the new receipt-race test reproduces the exact refusal and asserts the named owner. The upgrade test fails without the decode fix. 23 touched test files and both typechecks pass.
  • The cause of the original flake is still open. The next CI failure names the revoker.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 25, 2026
…penclaw#204702)

## What Problem This Solves

`src/agents/cli-runner/history-boundary.test.ts > CLI history account > keeps refusing a legacy record that could hide an account switch` fails in about 6.5% of scheduled `main` runs (5 of about 76 since 2026-11-21, always in Bun `infra` shards) with:

`Session reader validation does not match its current physical owner`

The refusal said only that the receipt no longer matched. It did not say whether the receipt was revoked, by whom, or whether the file changed, so every failure was a dead end. It never reproduced locally (Node, pinned Bun, 1-CPU Linux, 4 concurrent copies).

## Change

- Each agent-database validation receipt carries a shared `revokedBy` cell. Every revocation goes through `revokeAgentDatabaseValidation(validation, revoker)`, which records the first revoker before it clears `valid`.
- `invalidateOpenClawAgentDatabaseValidation` now takes a required revoker name, and every caller names itself (lease release without a confirmed close, failed close, disposal, maintenance write, successor receipt, file identity change, and so on).
- The worker's refusal now reads `Session reader validation does not match its current physical owner: <reason>`. The reason is `the receipt was revoked by <owner>`, or it names the agent or file identity mismatch.
- No retry and no behavior change: the same reads are refused at the same point.

## What I tested about the cause

- Revoking the captured receipt in the `prepareRead` hook (after capture, before dispatch) reproduces the exact CI refusal. That is the mechanism. The new test pins it and the named reason.
- A real writer close inside that window does not give this error; it revokes the read itself (`Session history database read was revoked`). So an ordering fix for the previous write's close on the same path would not address the CI failure, and none is included.
- Closing an unrelated, deleted database inside the window did not revoke the live receipt in this setup.
- The cause therefore remains unknown. With this change, the next CI failure names the owner that revoked the receipt.

## Evidence

- New `src/config/sessions/session-transcript-worker.receipt-race.test.ts`: passes, and asserts the full refusal text including the revoker.
- Touched test files (23) pass; `pnpm tsgo:core` and `pnpm tsgo:test:src` pass; oxfmt and oxlint clean on changed files.
- Upgrade: a receipt sealed at clean close by an older release has no `revokedBy` cell. `agentDatabaseValidationKey.read` (the one decode point for stored and restored receipts) gives it a cell once. A new test in `openclaw-agent-db-validation-cache.test.ts` revokes and reports such a receipt; without the fix it throws `Invalid atomic access index`.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant