Repository navigation
fix(browser): handle concurrent first-use extension pairing - #130832
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 5:25 AM ET / 09:25 UTC. ClawSweeper reviewWhat this changesThe branch makes browser-extension pairing and relay startup adopt a concurrently written first-use relay key, and stops browser configuration resolution from reading that persistent credential. Merge readinessThis focused race repair remains necessary: current main still performs the unprotected initial relay-key read, while this branch moves first-writer adoption into the single lifecycle owner. The patch has no actionable correctness finding, but the protected maintainer PR needs ordinary human merge review after exact-head CI completes. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: FAIL (failed) — execution before step 1 Assertions:
How this fits togetherBrowser extension pairing creates a host-local URL and key for Chrome to reach the local relay. Configuration selects profiles, while the relay lifecycle owns creation and adoption of the persisted relay key before the relay accepts connections. flowchart LR
A[Pairing command] --> B[Browser configuration]
B --> C[Relay lifecycle]
A --> D[Relay key owner]
C --> D
E[Shared credentials file] --> D
D --> F[Pairing URL and local relay]
Decision needed
Why: The latest follow-up changes credential adoption semantics on a maintainer-labeled PR, so the final landing choice should remain with a human reviewer. Before merge
Agent review detailsSecurityNone. PR surfaceSource -13, Tests +112. Total +99 across 12 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk options
Maintainer options:
Technical reviewBest possible solution: Keep one relay-lifecycle-owned create-or-adopt flow, retain the existing key-validation and live-key checks, and land this focused repair once exact-head checks and protected maintainer review are complete. Do we have a high-confidence way to reproduce the issue? Yes, at source level: the owner and pairing tests construct an exclusively opened empty secret file, then verify adoption of the original writer's key and inode. This read-only review did not execute the regression suite. Is this the best way to solve the issue? Yes. Centralizing creation and adoption in the relay-key owner removes both the pre-owner configuration read and the duplicate retry path while preserving atomic creation and live-key validation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 111c3c633ded. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Merged via squash.
|
…#130832) * fix(browser): handle concurrent first-use extension pairing * fix(browser): keep failed key reads in adoption handoff
Current proof status: Maintainer inspection is complete for
b37b80f52190195cc48ee7a5fb28f9448f09d742; the focused repair is approved for landing through the required native gates. Updated-head CI and the built public-bin pairing smoke pass. The failed developer-launcher smoke remains separately recorded below.Closes #130784 — browser pairing fails while another process initializes the relay key.
Related: #128379 — standalone extension-relay feature; this independently fixes the pre-existing race on main and does not add or modify that feature.
Runtime proof update: The new candidate's built public CLI entrypoint passes pairing in 11,093 ms within the unchanged 30-second budget. The failed developer source-launcher smoke remains recorded below as a separate tooling follow-up; it is not relabeled as passing.
Additional instructions
This is a same-repository branch, so maintainers can take over and update it.
What Problem This Solves
Fixes an issue where users pairing the browser extension or starting its relay could receive an empty-secret-file error when another local process had created the shared key file but was still writing it. Pairing could also fail during browser config resolution before reaching the token-creation owner.
Why This Change Was Made
The token owner now puts the first read and all subsequent reads inside one bounded first-writer handoff, retaining exclusive creation and the same canonical credential reader. Browser config normalization no longer reads persistent credentials; the relay lifecycle owns the adopted key and carries that fact across config refreshes.
A valid initial read still returns without invoking creation, preserving existing credential-directory permissions and layouts. Simply removing that fast read would unnecessarily chmod existing directories or reject previously accepted symlinked credential directories. The alternate reread path, private forwarding alias, redundant config reload, and now-unneeded attached-runtime cleanup are removed.
User Impact
Concurrent first-use initialization and pairing can adopt the first writer's completed key instead of failing immediately. Existing valid keys remain stable, and persistent empty, whitespace, or malformed credentials still fail without being replaced. No configuration option, dependency, database schema, authentication policy, or wire protocol is added or changed.
This is only the race repair. It does not publish the standalone daemon or native wake-up work in #128379.
Evidence
Original failing and passing reproductions
On source base
19762af88e31f1502b6fe969514035142dd25087with installed@openclaw/fs-safe0.5.6, a separate synthetic writer exclusively opened the final key filename, signaled that it was still empty, and completed its write after the reader started. Before the repair, both direct initialization and real pairing rejected in approximately 1 ms. The new owner regression failed at the unprotected read; the pairing regression failed at the earlier config read.The unchanged subprocess reproductions pass after the repair and retain the writer's inode and final key. Tests use real descriptors and the actual SDK, not a mocked secret-file reader or a new production test seam. No operator credentials, configuration, or Gateway services were accessed or changed.
Directory-alias handoff completion
Current head:
b37b80f52190195cc48ee7a5fb28f9448f09d742, retaining basefa16a4f80ea3bb1bdd68b3c0a13a6ca24b366190without another rebase. The original commit remains intact; this is a two-file follow-up, so old-head CI cannot substitute for new-head CI.An existing credential-directory alias exposed one incomplete case: when the initial read threw while the writer's real file was empty, attempt zero still tried creation. The creation guard correctly refused the symlinked root, preventing adoption even after the writer finished. Creation is now enabled only after the first canonical read completes successfully with no valid token. A thrown read stays in validated adoption; the existing create guard remains unchanged.
The existing real-descriptor concurrency table now includes a writer in progress through a directory alias. On prior source
5e999c7, this case failed with the expected symlink-root error (one failed, twelve passed). After the fix all thirteen owner tests pass. A new negative test confirms a missing key is not created through the alias; persistent-invalid tests also verify a retained error cause. No mocks or production test seam were added.On the exact source committed as this head:
adopted=falsetoadopted=true, preserving inode, final key, and alias. Original independent owner/pairing probes also pass in 36 ms / 37 ms, preserving inode and final key.git diff --checkpassed.pnpm build:ci-artifactspassed in 2m32s. This canonical profile builds runtime/CLI artifacts, scoped SDK declarations and exports, assets/UI, native control-plane loads, and startup metadata.dist/build-info.jsonmatches this full head. Full global declaration emission was not repeated for this private control-flow change with unchanged signatures.{ "proof": "built application public bin; not the pnpm source launcher", "command": "node openclaw.mjs browser extension pair --json", "nodeVersion": "v26.7.0", "head": "b37b80f52190195cc48ee7a5fb28f9448f09d742", "buildCommit": "b37b80f52190195cc48ee7a5fb28f9448f09d742", "timeoutSeconds": 30, "timedOut": false, "exitCode": 0, "elapsedMs": 11093, "returnedPairing": true, "paired": true, "sameInode": true, "finalTokenUnchanged": true, "fileModeUnchanged": true }The full 25-check local gate and five doctor guard tests below belong to the original head only. For this bounded follow-up, the canonical changed-file classifier was inspected; production/test types, targeted lint, formatting, regressions, and runtime build were rerun locally. Updated-head hosted CI supplied the global gates. No assertion, timeout, or gate was weakened.
The ClawSweeper review requested built pairing proof and direct fs-safe confirmation. Built-bin evidence is above; installed
@openclaw/fs-safe0.5.6 was directly inspected:dist/secret-file.jsrejects empty contents, treats only absence as missing, and forbids a symlink creation root;dist/pinned-write.js:117-145exclusively opens the final name before writing. Both requests are addressed without weakening that dependency contract. The maintainer independently inspected the alias refinement and reran its reproduction before approving native landing.Exact-head CI run 33058047739 passed on attempt 1 at
b37b80f52190195cc48ee7a5fb28f9448f09d742: 30 successful jobs and 21 intentional skips. Requiredopenclaw/ci-gatejob 98471251243 passed.node scripts/watch-pr-ci.mjs 130832 b37b80f52190195cc48ee7a5fb28f9448f09d742exited 0 withGREEN; early failure-state rollups were cancelled label/dispatch automation, not failures in this CI run. No retry or gate bypass was used.The latest ClawSweeper review, reviewed at 09:25 UTC on this exact
b37b80f5head, reports no correctness or security findings and accepts the recorded built-application proof. Its only rank-up move is completion of exact-head checks; CI run 33058047739 and required gate 98471251243 are now successful. The maintainer independently inspected this head and approved native landing. The bot's separate help probe used an unbuilt source tree missingdist/entry; it does not supersede the observed exact-build pairing result. No redundant re-review was requested.Original candidate verification (superseded head)
Original candidate:
5e999c77c0d76711bfeaac6b1d9595a0134d7b38on refreshed basefa16a4f80ea3bb1bdd68b3c0a13a6ca24b366190.The rebase was conflict-free and patch-identical:
git range-diffreports equality, with stable patch ID2af913b5aa5e85b9d2b72a21171147c0c61d8762before and after. The browser source and secret-file owner did not change in the base refresh. All build/test/check results below were rerun on this exact candidate; the pre-commit review applies to the unchanged patch.pnpm build: passed, 18m 13s. Includes all nine unified bundle invocations, native loading of 48 plugin control-plane modules, CLI bootstrap import guard, SDK exports, UI size budgets, and startup metadata. NoINEFFECTIVE_DYNAMIC_IMPORTwarning.git diff --check origin/main...HEAD: passed.All 25 candidate check results
All passed: conflict markers; max-lines ratchet; assertion-safety ratchet; changelog attributions; doctor deprecation registry; guarded plugin wildcard re-exports; plugin-SDK wildcard re-exports; duplicate-scan coverage; coercion-helper declarations; dependency pins; changed-file formatting; doctor declaration/closure tests; deprecated API usage; plugin boundaries; package patches; dead exports; warning-only test-temp report; plugin production types; plugin test types; both changed-file lint batches; database-first legacy stores; media-download helpers; runtime-sidecar loaders; runtime import cycles (zero cycles).
The warning-only temp report flags an existing
mkdtempfixture now wrapped inrealpath. This is not a new directory lifetime; its existingfinallycleanup remains.Original candidate built application proof and developer-launcher follow-up
The results in this section belong to
5e999c77c0d76711bfeaac6b1d9595a0134d7b38; they are preserved as historical evidence, not new-head proof.The initial smoke used
pnpm openclaw browser extension pair --json, which starts the TypeScript developer source runner before the built application. With isolated home, state, config, and credentials directories and a synthetic preexisting key, its fixed 30-second budget expired without pairing JSON. Only the owned process group was terminated. That original result remains a failure; no timeout increase or warmed retry was used.{ "command": "pnpm openclaw browser extension pair --json", "head": "5e999c77c0d76711bfeaac6b1d9595a0134d7b38", "timeoutSeconds": 30, "timedOut": true, "exitCode": 143, "elapsedMs": 30302, "returnedPairing": false, "paired": false, "sameInode": true, "finalTokenUnchanged": true }One separate instrumented diagnostic of that same command and unchanged budget expired before the built CLI launched. It observed 17.70 seconds of sampled wall time in tsx transform-cache directory enumeration and 3.58 seconds in source-runner artifact checks. No plugin command registration or relay code ran. Those measurements attribute the diagnostic only, not the uninstrumented run's exact time distribution.
The package's public
binisopenclaw.mjs;scripts/run-node.mts:1234-1235invokes that same file after developer-runner preparation. I inspected both entrypoints and verified thatdist/build-info.jsonnames this exact candidate. A fresh isolated smoke then exercised the real built application through its public bin, with a new random synthetic key, no profiling/cache/security overrides, and the same 30-second bound:{ "command": "node openclaw.mjs browser extension pair --json", "nodeVersion": "v26.7.0", "head": "5e999c77c0d76711bfeaac6b1d9595a0134d7b38", "buildCommit": "5e999c77c0d76711bfeaac6b1d9595a0134d7b38", "timeoutSeconds": 30, "timedOut": false, "exitCode": 0, "elapsedMs": 26109, "returnedPairing": true, "paired": true, "sameInode": true, "finalTokenUnchanged": true, "fileModeUnchanged": true }This supplied the original candidate's built-application proof rather than substituting source tests or green CI for it. It is not an npm-install or live-Chrome-profile claim. The application entrypoint and all credential validation remain unchanged; no application path or security check was bypassed.
Named follow-up: developer CLI pre-launch cache-index latency. The failed
pnpmsource-launcher smoke remains open tooling work, separately recorded for investigation. No shared caches were deleted, dependencies changed, or timeouts raised. The inspected launcher/dependency paths are outside this PR's unchanged 12-file browser-plugin scope.Exact-head hosted CI run 33054205774 passed on its first non-draft attempt; required
openclaw/ci-gatejob 98458292604 passed. The earlier draft-triggered run was skipped.Scope and contracts
Current full PR: production +38/-51 (net -13); tests +212/-100 (net +112) across the same 12 files. The two-file follow-up is production +9/-6 (net +3) and tests +26/-6 (net +20). The iteration-local creation decision records the successful first read inside the existing owner loop; it adds no helper or alternate credential path. The loop remains bounded to 50 attempts with a 10 ms delay. Only a successful first read with no valid token may enable exclusive creation; thrown reads only retry adoption, and other write failures propagate. Terminal failures retain the underlying read/create error. All adoption attempts use
readExtensionRelayToken, so validation stays at its existing owner rather than being bypassed by a separate read path.The broader standalone-relay feature and its active worktree remain separate. The regressions cover actual isolated source pairing and loopback protocol flows. No real Chrome UI or live operator Gateway proof is claimed. AI-assisted implementation and review; no agent transcripts or credential-bearing logs are included.