Skip to content

profiles bind: place candidates in their Chrome profile directories, bind by directory where names collide (#21 step 2) - #45

Merged
SSFSKIM merged 4 commits into
mainfrom
feat/bind-directory-map
Oct 6, 2026
Merged

SSFSKIM merged 4 commits into
mainfrom
feat/bind-directory-map

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

Issue #21, step 2. Step 1 (vendor labels beside candidates, automatic bind on a unique name) is #27.

What

cua profiles bind <key> now shows, beside each live Google Chrome backend, the Chrome profile directory it belongs to and that directory's display name, computed by cua in the CLI process. It no longer depends only on the vendor's label. Interactive listing and --json (chromeProfile: {directory, name, thisProfile}, null when no store places the candidate; directoryMap: {status, reason?, readError?, unreadableStores?}).

  • Mapping (src/profiles/directory-map.mjs, the vendor's method from spike Spike: does Full Disk Access let the vendor's profile enrichment label backends (profileName)? #8). The profile list comes from Local State profile.info_cache. For each profile with a Local Extension Settings/<id> store, cua copies the store with fs/promises cp into a private mkdtemp under $CUA_HOME/staging and removes the copy's LOCK. It opens the copy with the installed release's own classic-level, loaded by absolute path from runtime.paths.moduleDir, and reads extensionInstanceId. It checks every id the pin's nativeHost.extensionIds allows. Copies are removed in finally. Copies older than 10 minutes that a killed run left behind are swept on the next run. Chrome's directory is only read.
  • Degradation. If Local State can't be read (chrome_data_unreadable with its code), every candidate shows as profile directory unknown, bind prints a note with the Full Disk Access fix, and the step 1 rule applies. An unreadable or corrupt store makes the mapping partial. A missing classic-level or staging failure makes it unavailable. None of these fails the command.
  • Automatic bind, extended rather than weakened (src/profiles/bind.mjs):
    • If the registered directory's own store records exactly one live candidate, bind it (by: "directory"). This holds even when display names collide and even when the vendor label disagrees.
    • If that store records instances and none of them is live, nothing is bound (directory_backend_not_live).
    • If it records several live candidates, or an id another directory's store also records, the user picks (several_directory_backends, instance_in_several_directories).
    • Only when the registered directory has no readable store does the step 1 name rule run (by: "name"). Even then it never binds a backend that the mapping places in another directory (labelled_backend_other_directory).
    • An explicit pick that the mapping places in another directory is refused (other_profile_directory). A pick placed in the registered directory is accepted even if its label conflicts.
    • The explicit pick stays mandatory in every ambiguous case.
  • --dry-run (new): makes and prints the same decision ("would bind ...", dryRun: true) without recording anything. I added it so the live check could run against the real CUA_HOME without touching profiles.json.
  • Spec: Decision Log entry (newest first), plus a Surprises entry for the cpSync abort below. README's profiles bind section is rewritten.

Why

Display names collide on the mini ("직장" and "l1ngual.com" each appear twice). The registry binds directories, so the directory is the identifier that settles it.

Left unchanged (flagged, not changed)

profiles_list and readiness are unchanged. The mapping could split binding_stale into two cases: the bound id is still this directory's (its host is asleep, so wake it), or this directory's store now records another id (so rebind). Readiness also runs inside cua serve, though, and that process may not have Full Disk Access. I'd take that up as a separate ticket.

Surprise

fs.cpSync(..., {recursive: true}) on a mode-000 source directory aborts the whole Node process (Node 22.23.2: libc++abi: terminating due to uncaught exception of type std::__1::__fs::filesystem::filesystem_error ... Permission denied). It does not throw. The mapping therefore uses fs/promises cp, which rejects with EACCES. The chmod-000 test caught it.

How verified

  • npm test: 501 tests, 501 pass, 0 fail, 0 skipped (488 before this change).
  • New tests use real LevelDB fixtures. The test writes each store with classic-level and keeps it open while the mapping runs, the way Chrome holds its live store.
    • test/profiles-directory-map.test.mjs:
      • Colliding names are mapped by directory, with Chrome's directory byte-identical afterwards (live LOCK included).
      • A chmod-000 store gives partial with EACCES.
      • A chmod-000 Local State gives unavailable / chrome_data_unreadable.
      • A malformed Local State and a missing classic-level are each unavailable.
      • A non-LevelDB store and a failing reader each give partial, with the copies removed.
      • Stale copies are swept.
    • test/profiles.test.mjs: the rule cases (directory beats name, not live, other directory, instance in several directories, explicit refusal and acceptance).
    • test/profiles-commands.test.mjs: bind end to end with a name collision, --dry-run recording nothing, an unreadable Local State, and a mapper that throws.
    • test/serve-cli.test.mjs: the CLI against a fake installed release with a real classic-level linked in. Covers the human rows, --json, --dry-run, and the Full Disk Access note.
    • These tests take classic-level from the installed runtime in the default CUA_HOME, or else from /Applications/ChatGPT.app. They skip (with that reason) on a machine with neither.

Live read-only check (first Mac, real CUA_HOME, real Chrome running, terminal with Full Disk Access)

node bin/cua.mjs profiles bind <key> --dry-run [--json], with instance ids truncated to 8 characters. Display names are redacted here because this repo is public; in the real output the vendor label and cua's directory name agreed for both backends.

$ node bin/cua.mjs profiles bind personal --dry-run
would bind personal to extension instance 94c9fc71… (this profile directory's extension store records exactly this live backend); dry run, nothing was recorded
live backends:
  1) extension instance 41f3ec26…  0 tab(s)  Chrome profile "Profile 11" "<name-2>" (another profile's directory)  labelled "<name-2>" (another profile's name)
  2) extension instance 94c9fc71…  12 tab(s)  Chrome profile "Default" "<name-1>" (this profile's directory)  labelled "<name-1>" (this profile's name)  <- likely match

--json summaries:

  • personal (Default): ok: true, dryRun: true, how: automatic, by: directory, extensionInstanceId: 94c9fc71, directoryMap.status: complete; candidates 41f3ec26 → Profile 11 (thisProfile: false) and 94c9fc71 → Default (thisProfile: true, likelyMatch).
  • school (Profile 6): pick_required, reason: directory_backend_not_live, staleBinding: af96e8b8, directoryMap.status: complete. Profile 6's store records an instance that is not live now, so nothing would be bound and the label rule is not consulted.
  • work (Profile 8): refused before any listing, profile_not_ready (the extension is not installed in Profile 8).
  • shasum profiles.json was identical before and after all runs, and $CUA_HOME/staging was empty afterwards. Nothing was bound, created or changed, and Chrome was not touched.

Not verified: the mini, where names actually collide. The collision case is covered by fixtures only.

… directory where names collide

cua profiles bind now maps each live Chrome backend's extension instance id to its
profile directory itself: copies of each profile's OpenAI extension store under
$CUA_HOME/staging, read with the installed runtime's classic-level, removed
afterwards. The registered directory's own store decides the automatic bind
before the step 1 name rule; an unreadable Local State degrades to unplaced
candidates with the Full Disk Access note. Adds --dry-run.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

…dable Local State one note

Review fixes for PR #45: fs/promises cp copied a store directory that is itself a symlink as a link, so the LOCK
removal and the open acted on the live store through it; it now dereferences. A refused Local State read printed two
notes (labels, directories); it is now one, ending with the Full Disk Access fix. Two minor mapping gaps are logged
in tech-debt-tracker.md.
@SSFSKIM

SSFSKIM commented Oct 6, 2026

Copy link
Copy Markdown
Owner Author

Independent review (Opus; the medium-rung reviewer could not run because its gateway returned 503 twice).

One blocking finding, now fixed in 7932d72. A store directory that was itself a symlink got opened and rewritten in place: cp copied the link rather than the files behind it, and the code then deleted LOCK through the link. cp now dereferences the link. A new test makes the store a symlink to a live store held open by another handle, and asserts the target is unchanged file for file, LOCK included.

A cosmetic finding is also fixed: an unreadable Local State now gives one note instead of two.

Two minor gaps are logged in tech-debt-tracker.md:

  • With some stores unreadable, an instance id that one of those stores also records cannot be seen as duplicated. The bound id is still one this directory's own store records.
  • Profiles in info_cache without a name are not scanned.

The reviewer found the automatic rule stricter than step 1's in every ambiguous case, cleanup sound on every path, degradation never failing bind, and --dry-run sound. npm test: 501/501.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant