Skip to content

fix: prevent chat send retries during identity lock contention - #158259

Merged
fuller-stack-dev merged 1 commit into
mainfrom
openclaw/chat-identity-cache-20260925
Sep 25, 2026
Merged

fuller-stack-dev merged 1 commit into
mainfrom
openclaw/chat-identity-cache-20260925

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes chat sends failing with a five-second device-identity lock timeout when another operation is using the state database, even though the gateway already has its identity cached.

User Impact

Warm chat sends no longer need a retry solely because request fingerprinting waits for that unnecessary lock. This is a backend fix; no UI, configuration, schema, migration, or identity-rotation behavior changes. It does not address separate cold-start or other database-contention failures.

Why This Change Was Made

The synchronous process-identity loader acquired the lifecycle and migration coordinators before checking its process cache. Return a cached identity first, matching the existing async loader. Cache misses still use the original coordinated creation and validation owner.

Evidence

  • Observed initial chat.send failures after 5014 ms and 5007 ms with DeviceIdentityCoordinatorError caused by state-lifecycle contention.
  • Added a regression through the actual chat request fingerprint function, holding a real lifecycle coordinator against private test state. No storage or identity mocks.
  • Before the fix: same error after 5375 ms. After the fix: regression passes in 143 ms; request fingerprint remains stable and distinguishes changed content.
  • Regression plus identity creation, migration, corruption, cache-key, async, and coordinator siblings: 41 tests passed across five files, 35.81 seconds total wall time across two routed shards.
  • Entire new test file audited: private state/locks, release in finally, database/environment/temp cleanup; no skipped or removed coverage.
  • Independent API-key review: scoped-clean, no actionable findings. ClawSweeper completed exact-head review with no findings or pre-merge blockers. Formatting, whitespace, and all changed-scope checks passed (node scripts/check-changed.mjs --base 573ff8e07088d0404cbc25b6891707326203686d --head 1ffcd5488beb29c29423dfcddbb63c56c117b8a6, exit 0); hosted checks remain required before landing.
  • No live gateway was modified or restarted for this proof.

@clawsweeper

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

@fuller-stack-dev
fuller-stack-dev marked this pull request as ready for review September 25, 2026 18:45
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Sep 25, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 25, 2026, 2:51 PM ET / 18:51 UTC.

ClawSweeper review

What this changes

The branch returns cached process device identities before acquiring SQLite coordinators and adds a lock-contention regression test for chat goal request fingerprinting.

Merge readiness

✅ Ready for maintainer review

The fix remains useful: current main still waits for the device-identity coordinator before checking a warm cache, and the proposed change follows the existing async loader’s cache-first contract. No actionable patch defect was found. The PR is also member-authored, so this cleanup review should not close it.

Priority: P1
Reviewed head: 1ffcd5488beb29c29423dfcddbb63c56c117b8a6

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level fix has a relevant lock-contention regression and no identified correctness or security defect.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The ordinary contributor proof gate does not apply to this member-authored PR. Its reported before-and-after check exercises production fingerprinting with a real SQLite lifecycle lock, but no full Gateway chat send is shown; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor proof gate does not apply to this member-authored PR. Its reported before-and-after check exercises production fingerprinting with a real SQLite lifecycle lock, but no full Gateway chat send is shown; no stored-data contract changes.
Evidence reviewed 7 items Introduced repair: The introduced hunk checks the process cache before entering the coordinated cold-load path.
Boundary regression: The new test fingerprints through the production request function while holding a real state-database lifecycle lock, then checks fingerprint stability and changed-content distinction. The PR body reports a pre-fix timeout and an after-fix pass; this review did not execute the test.
Current main still needs the fix: At the fetched main revision, the synchronous loader acquires the coordinator before reading its process cache.
Findings None None.
Security None None.

How this fits together

The Gateway fingerprints goal-intent chat requests using its process device identity before admitting the goal. That identity comes from a process cache when warm and from coordinated SQLite storage when cold.

flowchart LR
A[Goal intent chat send] --> B[Gateway request handler]
B --> C[Process identity cache]
C -->|Warm| D[Keyed request fingerprint]
C -->|Cold| E[Coordinated SQLite identity load]
E --> D
D --> F[Goal admission]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0, Tests +43. Total +43 across 2 files.

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

Review metrics

None.

Technical review

Best possible solution:

Keep warm synchronous identity reads on the existing process cache while preserving coordinated validation and creation for cache misses.

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

Yes. Current main takes the coordinator before a warm cache read, and the PR supplies a lock-contention test plus reported pre-fix timeouts; this reviewer did not execute the test.

Is this the best way to solve the issue?

Yes. Moving the warm cache read ahead of coordination matches the established async contract while leaving cold identity creation with its existing owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5caf34625c01.

Labels

Label changes:

  • add P1: Observed five-second lock timeouts can fail goal-intent chat sends during state-database contention.
  • 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. Not applicable: The ordinary contributor proof gate does not apply to this member-authored PR. Its reported before-and-after check exercises production fingerprinting with a real SQLite lifecycle lock, but no full Gateway chat send is shown; no stored-data contract changes.

Label justifications:

  • P1: Observed five-second lock timeouts can fail goal-intent chat sends during state-database contention.
  • 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. Not applicable: The ordinary contributor proof gate does not apply to this member-authored PR. Its reported before-and-after check exercises production fingerprinting with a real SQLite lifecycle lock, but no full Gateway chat send is shown; no stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 0474704 adds src/gateway/server-methods/session-goal-request.ts:8 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 047470456ff2; files: src/gateway/server-methods/session-goal-request.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.

@fuller-stack-dev
fuller-stack-dev enabled auto-merge (squash) September 25, 2026 19:00
@fuller-stack-dev
fuller-stack-dev merged commit 847863a into main Sep 25, 2026
274 checks passed
@fuller-stack-dev
fuller-stack-dev deleted the openclaw/chat-identity-cache-20260925 branch September 25, 2026 19:02
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

roboclaw-bot added a commit that referenced this pull request Sep 26, 2026
Backport #157571: 0484d7a
Adapted backport #150702: 6b5fb4b
Backport #157958: 3802abe
Backport #158259: 847863a
Backport #156858: a5f1d09

Keep completion carriers within current-turn traversal and stop terminal
transcript assertion retries. Preserve delegated restart provenance and
owed completion custody; unknown provenance cannot inherit human evidence.
Never let a queued, unstarted timeout end a different active turn. Reuse
warm device identity and reacquire complete admission after observed rotation.

Move the unchanged synchronous abort event into its existing lifecycle
owner to satisfy the frozen line budget without weakening tests or guards.
Source proof, recovery correction and owner-extraction checks are retained
at their exact trees. Independent findings are resolved and composition
preserves all 32 postimages; frozen ratchets and Madge pass.

The two embedded-fallback attempt-count E2E cases remain unexecuted because
canonical runtime preparation refused ownership; no guard was bypassed.

Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: Jason (Json) <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vyctorbrzezowski <[email protected]>
Co-authored-by: steipete <[email protected]>
Co-authored-by: jalehman <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. 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