Repository navigation
fix(hooks): retry native relay lookup after SQLite contention - #161822
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: blocked before merge. Reviewed September 30, 2026, 7:34 AM ET / 11:34 UTC (Revision 5). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherA 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +20, Tests +87, Docs +2, Other 0. Total +109 across 7 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest 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. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
6dd15ae to
0dc5def
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…aw#161822) Co-authored-by: Peter Steinberger <[email protected]>
Related: #161583
What Problem This Solves
Fixes native hook relay lookup falling back unnecessarily when its SQLite locator briefly returns
SQLITE_BUSYorSQLITE_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:src/cli/native-hook-relay-cli.locator-worker.test.tssrc/cli/native-hook-relay-cli.test.tssrc/agents/harness/native-hook-relay.lifecycle.test.tssrc/cli/native-hook-relay-cli.import-boundary.test.tsThe 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 base7db6ea365a62: 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:981withexpected 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.mtswith the capturedagentic-gateway-server-isolated-hosted-13group, followed bynode 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
0dc5def38ae0validation: 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-diffconfirms 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.