Skip to content

[Bug]: Browser pairing fails while another process initializes the relay key #130784

Closed

Description

@steipete

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

Browser extension pairing and relay-token initialization can reject an empty key file that another process has exclusively created but is still writing, instead of adopting that first writer's completed key.

Steps to reproduce

  1. Create an isolated temporary state/credentials directory; do not use an operator's credentials or Gateway.
  2. In one process, exclusively open browser-extension-relay.secret with mode 0600, leaving the file empty and the descriptor open.
  3. While that writer is paused, call the real ensureExtensionRelayToken owner from another process using the isolated state directory. Repeat separately through the real buildBrowserExtensionPairing path.
  4. Finish writing a synthetic valid relay key through the original descriptor after the second process starts.

Expected behavior

The initialization/pairing call adopts the first writer's completed key within the existing bounded handoff. It must retain the writer's file identity and must not overwrite malformed persistent credentials. This is the first-writer-wins contract already implemented for competing exclusive creates and the documented automatic/manual pairing flow: https://docs.openclaw.ai/tools/chrome-extension.

Actual behavior

Both isolated reproductions reject in approximately 1 ms with FsSafeError code invalid-path and a message that the relay-secret file is empty. The writer then completes successfully without changing the inode. The owner fails before entering its bounded exclusive-create handoff; pairing additionally reads the key during config resolution before it reaches the owner.

OpenClaw version

Source build 19762af88e31f1502b6fe969514035142dd25087 (manifest 2026.8.1), installed @openclaw/fs-safe 0.5.6. The affected owner and test blobs are identical at base 8dac217ce94e14a67ad2fc65837e518a2fbe0669. Stable-release exposure has not been established.

Operating system

macOS 27.0; Node.js 24.19.0.

Install method

Source checkout with repository-pinned pnpm dependencies.

Model

Not applicable: this is filesystem and browser-pairing initialization, with no model invocation.

Provider / routing chain

Not applicable: isolated local credential writer and browser plugin owner/pairing calls; no external provider or live Gateway.

Logs

scenario: writer-created-before-ensure
adopted: false
elapsedMs: 1
sameInode: true
finalTokenUnchanged: true
failure.code: invalid-path
failure.message: browser extension relay secret file at <synthetic-state>/credentials/browser-extension-relay.secret is empty.

Screenshots, recordings, and evidence

The installed dependency's dist/secret-file.js:114-160 rejects existing empty files; dist/pinned-write.js:117-145 publishes the exclusive-created final name before its asynchronous write. OpenClaw's default filesystem mode uses that fallback. Real owner and pairing regressions both failed before the local repair, without mocking the SDK or touching live credentials.

Impact and severity

Concurrent first-use pairing/relay initialization can fail instead of returning the shared key. The ordering reproduces deterministically with an already-open empty file; its frequency in production is not measured. No credential replacement or data loss was observed.

Additional information

Related: #128379 — the larger standalone-relay feature separately repaired the read inside its EEXIST loop. This report covers the pre-existing first read and earlier config/lifecycle reads, not a regression introduced by that feature. A focused repair is being prepared independently so the feature can reuse the canonical fix.

Activity

  1. self-assigned this
    on Aug 27, 2026
  2. added
    bug
    on Aug 27, 2026
  3. added
    maintainer
    on Aug 27, 2026
  4. added
    clawsweeper:source-repro
    impact:auth-provider
    issue-rating: 🦞 diamond lobster
    P2
    on Aug 27, 2026
  5. clawsweeper commented on Aug 27, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed August 27, 2026, 3:31 AM ET / 07:31 UTC.

    Summary
    This remains necessary: current main can reject an initializing relay secret before its existing bounded first-writer handoff, and the protected maintainer label requires explicit maintainer handling rather than automated closure or repair dispatch.

    Reproducibility: yes. from source: create and hold an empty relay-secret file, then invoke the real pairing or relay owner; the synchronous safe read occurs before the bounded handoff. This review did not execute it because dependencies are absent in the read-only checkout.

    Root-cause cluster
    Relationship: canonical
    Canonical: #130784
    Summary: This issue is the canonical remaining pre-read/configuration race; the linked relay-daemon PR repairs only an overlapping later EEXIST handoff.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Next step
    The protected maintainer label keeps this verified bug out of automated repair dispatch; it needs the owner-level dependency-contract check before implementation.

    Review details

    Best possible solution:

    Keep strict rejection for persistent malformed credentials, but centralize first-writer initialization-state handling in the Browser relay-secret owner so configuration, pairing, and relay lifecycle cannot bypass the bounded adoption path.

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

    Yes, from source: create and hold an empty relay-secret file, then invoke the real pairing or relay owner; the synchronous safe read occurs before the bounded handoff. This review did not execute it because dependencies are absent in the read-only checkout.

    Is this the best way to solve the issue?

    Yes, provided the repair preserves strict rejection of persistent malformed credentials and fixes the state classification at the relay-secret owner rather than adding caller-specific retries.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The checkout has no installed @openclaw/fs-safe source and network resolution failed, so the repair must inspect that package’s exact error/state contract before distinguishing an initializing empty file from a persistently malformed credential.

    Codex review notes: model internal, reasoning high; reviewed against 0c5fb0f7ac94.

    Label changes

    Label changes:

    • add P2: A deterministic concurrent first-use failure blocks Browser pairing or relay startup, but reported production frequency is unmeasured and no loss of credentials was observed.
    • add impact:auth-provider: The broken state is the host-local secret that authenticates the Browser extension relay and is consumed by pairing.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.

    Label justifications:

    • P2: A deterministic concurrent first-use failure blocks Browser pairing or relay startup, but reported production frequency is unmeasured and no loss of credentials was observed.
    • impact:auth-provider: The broken state is the host-local secret that authenticates the Browser extension relay and is consumed by pairing.
    Evidence reviewed

    What I checked:

    Likely related people:

    • steipete: Current blame and feature history attribute the relay-secret owner, configuration read, and Browser relay work to this contributor. (role: recent Browser relay contributor; confidence: high; commits: d77e2a5876b9, 5350b92dc83d, 83900e468333; files: extensions/browser/src/browser/extension-relay/relay-auth.ts, extensions/browser/src/browser/config.ts, extensions/browser/src/browser/extension-pairing.ts)
    How this review workflow works
    • 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.
  6. steipete commented on Aug 27, 2026

    @steipete
    ContributorAuthor

    Fixed by PR #130832 — concurrent first-use extension pairing, merged as dd005e53866f.

    Failed reads now stay in the bounded, validated adoption path, including an in-progress key reached through an existing credentials-directory alias. Creating a missing key through a symlinked directory still rejects, and malformed persistent credentials are not replaced. The earlier config/lifecycle reads that could fail before reaching the owner were removed.

    Verified with failed-before/passed-after real-file regressions, 184 passing focused/sibling tests (one Windows-only skip), type/lint checks, a canonical runtime-artifact build, and successful exact-head CI. The built public CLI paired in 11.093 seconds within the unchanged 30-second bound, preserving the synthetic key, inode, and mode. All 12 landed files match the reviewed candidate. The separate developer source-launcher timeout remains a named tooling follow-up; it is not claimed fixed by this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2bugclawsweeper:source-reproimpact:auth-providerissue-rating: 🦞 diamond lobstermaintainer

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions