Skip to content

fix(hooks): retry native relay lookup after SQLite contention - #161822

Merged
steipete merged 1 commit into
mainfrom
steipete/locator-lock-wait
Sep 30, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/locator-lock-wait

Conversation

@steipete

@steipete steipete commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Related: #161583

What Problem This Solves

Fixes native hook relay lookup falling back unnecessarily when its SQLite locator briefly returns SQLITE_BUSY or SQLITE_LOCKED.

User Impact

Transient locator contention now retries within the existing hook deadline. Node hook subprocesses also avoid starting a second cold worker for this read-only lookup. No configuration, schema, or data migration is required.

Why This Change Was Made

The client treated lock contention as a terminal lookup failure. Its Node one-shot process can safely read the locator itself with no SQLite lock wait, yielding between retries so the CLI deadline remains responsive. One shared reader retains schema admission, Kysely lookup, row validation, and database cleanup. Gateway reads retain their existing shared-state worker owner.

Bun keeps the dedicated worker and joins its cleanup before returning because its native SQLite handles can outlive close(). This preserves the existing runtime-specific resource boundary.

Update behavior: existing locator rows remain readable without conversion; installed updater behavior is unchanged.

Data-model compatibility proof

No persisted data model changes. The shared reader executes the same existing schema-admission function, locator-row query, and row decoder moved from the worker; it introduces no DDL, schema-version change, migration, write, or new row format. The CLI fixture seeds a locator through the unchanged production writer, reads it through the candidate, verifies the authenticated response, and checks the database bytes remain unchanged. A newer-schema fixture is refused and its database bytes also remain unchanged. Existing operator state and installed updater behavior remain unchanged; a migration or upgrade conversion is not applicable to this read-only change.

Evidence

The real CLI regression failed before the fix: after one transient lock, it returned empty fallback output instead of the authenticated loopback bridge response (39.09 s wall, including runtime preparation). The repaired flow passes; a real exclusive SQLite lock exhausts a fake-clock deadline with a deny response and no transport, and a newer schema is refused without rewriting the database.

Focused validation and constrained-host observations

All focused tests use node scripts/run-vitest.mjs <file> --maxWorkers=1:

File Result Wall
src/cli/native-hook-relay-cli.locator-worker.test.ts 4 passed; 2.55 s test bodies 15.02 s
src/cli/native-hook-relay-cli.test.ts 22 passed 4.89 s
src/agents/harness/native-hook-relay.lifecycle.test.ts 18 passed 72.62 s, including 29.66 s worker preparation
src/cli/native-hook-relay-cli.import-boundary.test.ts 4 passed 4.30 s

The locator file also passed under OPENCLAW_VITEST_RUNTIME=bun: 3 passed, 1 Node-only no-wait case skipped, 38.25 s wall. The ordinary Bun cases retain their worker-isolation assertions.

Validation also passed: full pnpm build (782.05 s), core types (10.61 s), root-test types (58.97 s), targeted core/script lint (11.50/13.90 s), Kysely guard (58.79 s), docs sanity, formatting, and whitespace checks. Fresh standalone validation on base 7db6ea365a62: gateway-profile setup/build passed (42.6 s build phases); locator CLI 4 passed (30.95 s wall, including 22.07 s worker preparation), deadline CLI 22 passed (3.46 s), core types (10.99 s), root-test types (39.97 s), and formatting passed. Fresh Codex review is clean through P2.

Three original native-hook pressure-file runs in a Linux cgroup restricted to 2 CPUs and 8 GiB passed all 20 matched calls (214.33/315.68/288.78 s file walls). Peak sampled relay RSS was 1.73/1.96/2.10 GB versus 2.14/2.33 GB in nearby baseline observations. Latency ranges overlapped. These observations support bounded resource behavior but do not establish that this change fixes the separately investigated pressure-test failure.

CI follow-up

The first PR CI attempt hit an inherited fixture failure. PR job 109852648826 and main job 109838457268 both failed the relocated-store case in src/gateway/session-activity-summaries.test.ts:981 with expected 2 to be 3. The unchanged fixture injects model preparation/completion and never invokes the native-hook locator path.

Bounded local reproduction on macOS/Node 26.10.0: the captured 13-file CI cohort passed 286 tests in 437.09 s, then the isolated file reproduced the same failure in 213.97 s (22 passed, 1 failed). Commands were node --import ./scripts/tsx.mjs scripts/ci-run-node-test-shard.mts with the captured agentic-gateway-server-isolated-hosted-13 group, followed by node scripts/run-vitest.mjs src/gateway/session-activity-summaries.test.ts --maxWorkers=1.

The owning fix subsequently landed on main as #161824 (5bfb545bfc34): the fixture awaits its authoritative publication callback instead of polling, retaining the covered-message assertion. The branch now includes that fixed main input after a conflict-free, patch-identical rebase; no failed-jobs rerun or admin merge was requested for the old attempt. The locator patch itself remains unchanged.

Rebased head 0dc5def38ae0 validation: repaired recap file 23 passed (208.99 s wall), locator CLI 4 passed (31.89 s; 3.24 s test bodies), deadline CLI 22 passed (4.82 s), core types 14.97 s, root-test types 61.46 s, targeted lint 13.25 s. git range-diff confirms the locator commit is unchanged; its existing clean Codex review and unaffected proof remain valid. Fresh current-head CI and ClawSweeper review are required before landing.

@clawsweeper

clawsweeper Bot commented Sep 30, 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 cli CLI command changes scripts Repository scripts agents Agent runtime and tooling extensions: codex size: M labels Sep 30, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 30, 2026, 7:34 AM ET / 11:34 UTC (Revision 5).

ClawSweeper review

What this changes

The branch makes the native hook CLI retry temporary SQLite locator locks within its deadline, reads the locator directly in one-shot Node processes while retaining Bun worker cleanup, and updates focused tests and documentation.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open. Current main and v2026.9.7 lack the SQLite lock retry, and the merged recap-test repair addresses a separate CI failure. This branch remains useful; the review found no blocking patch defect.

Priority: P2
Reviewed head: 0dc5def38ae0754291f5dcb08504c8739c97224c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused patch with relevant production-boundary proof and no identified correctness or security defect.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The changed locator reader feeds the production relay CLI. The PR reports before-fix fallback and after-fix authenticated recovery through a real loopback HTTP bridge after an injected lookup lock, plus deadline refusal under an exclusive lock. No stored-data contract changes, so migration compatibility is not applicable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed locator reader feeds the production relay CLI. The PR reports before-fix fallback and after-fix authenticated recovery through a real loopback HTTP bridge after an injected lookup lock, plus deadline refusal under an exclusive lock. No stored-data contract changes, so migration compatibility is not applicable.
Evidence reviewed 9 items Current-main gap: The current-main retry classifier handles missing locators and selected connection errors, but does not classify SQLite lock errors.
Introduced retry: The pinned PR adds the existing SQLite lock classifier to the relay's deadline-bounded retry loop.
Runtime-specific read boundary: Node uses a read-only, no-wait locator read in the one-shot CLI; Bun retains the worker and joins its cleanup.
Findings None None.
Security None None.

How this fits together

A native hook starts OpenClaw's relay CLI with an event and relay ID. The CLI reads a SQLite locator, contacts an authenticated local bridge, and returns a hook response or an unavailable response.

flowchart LR
A[Native hook event] --> B[Relay CLI]
B --> C[SQLite locator read]
C --> D{Lookup result}
D -->|Temporary lock| C
D -->|Valid locator| E[Authenticated local bridge]
E --> F[Hook response]
D -->|Deadline reached| G[Unavailable response]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +20, Tests +87, Docs +2, Other 0. Total +109 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 52 32 +20
Tests 1 190 103 +87
Docs 1 6 4 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 7 249 140 +109

Review metrics

Metric Value Why it matters
Code and test growth production +20 lines, tests +87 lines The shared reader accounts for the bounded production growth; the added test code exercises the CLI, lock retry, and schema boundary.

Stored data model

Persistent data-model change detected: database schema: src/agents/harness/native-hook-relay-client-read.ts, database schema: src/agents/harness/native-hook-relay-client.worker.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Use the existing deadline loop to absorb transient locator contention while preserving locator storage and the bridge's current-registration checks.

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

Yes. Current-main source and the PR's CLI fixture give a high-confidence lock-then-recovery path; this read-only review did not rerun it against current main.

Is this the best way to solve the issue?

Yes. The patch extends the existing retry owner, retains schema admission, and preserves Bun's separate cleanup boundary.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 872c9ba2bbd5.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Temporary locator contention can disrupt native hooks, with impact limited to this relay path.
  • 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 changed locator reader feeds the production relay CLI. The PR reports before-fix fallback and after-fix authenticated recovery through a real loopback HTTP bridge after an injected lookup lock, plus deadline refusal under an exclusive lock. No stored-data contract changes, so migration compatibility is not applicable.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed locator reader feeds the production relay CLI. The PR reports before-fix fallback and after-fix authenticated recovery through a real loopback HTTP bridge after an injected lookup lock, plus deadline refusal under an exclusive lock. No stored-data contract changes, so migration compatibility is not applicable.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • sightingsstellar-beep: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • jalehman: 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 (4 earlier review cycles)
  • reviewed 2026-09-30T10:54:09.437Z sha 6dd15ae001e6e3ce7c691415d26ee7a181006257 :: blocked before merge. :: none
  • reviewed 2026-09-30T10:58:47.609Z sha 6dd15ae001e6e3ce7c691415d26ee7a181006257 :: blocked before merge. :: none
  • reviewed 2026-09-30T11:07:07.026Z sha 6dd15ae001e6e3ce7c691415d26ee7a181006257 :: blocked before merge. :: none
  • reviewed 2026-09-30T11:28:59.118Z sha 6dd15ae001e6e3ce7c691415d26ee7a181006257 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 30, 2026
@steipete
steipete force-pushed the steipete/locator-lock-wait branch from 6dd15ae to 0dc5def Compare September 30, 2026 11:30
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit 71156a0 into main Sep 30, 2026
203 of 206 checks passed
@steipete
steipete deleted the steipete/locator-lock-wait branch September 30, 2026 12:01
@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

agents Agent runtime and tooling cli CLI command changes docs Improvements or additions to documentation extensions: codex P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: M 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