Repository navigation
fix(setup): refresh registrations of another installed REA package - #15029
Conversation
Ownership of an absolute launcher now carries whether it selects this installation, and launcher equivalence requires that fact instead of inferring it from ownership alone. Co-Authored-By: gensokyo-dev <[email protected]>
A registration saved by an earlier npx run, a different global prefix or another runtime points at REA's own CLI script under a different path. Exact path comparison classified it as foreign, so setup refused to refresh it and asked for manual edits in every client. An absolute launcher whose script resolves to the CLI script named by an installed node_modules/rea-agents/package.json is now owned but selects another installation. Doctor reports it stale with a refresh remediation, and setup replaces it with the current launcher after backing it up. Source checkouts, other package names, other bin scripts and removed installations stay foreign or unknown. Fixes #15022 Co-Authored-By: gensokyo-dev <[email protected]>
Co-Authored-By: gensokyo-dev <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The reviewed changes appear safe to merge; no blocking findings remain. SummaryThis PR lets setup refresh registrations that point to another installed REA package or runtime.
The previous manifest-read finding is fixed. No new actionable issues were found. Review checks were source-only; tests were not rerun. Whether another PR supersedes this one could not be checked because GitHub access was unavailable. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Read saved launcher] --> B{Selects current script and runtime?}
B -->|Yes| C[Owned: current installation]
B -->|No| D{Proves another REA installation or runtime?}
D -->|Yes| E[Owned: other installation]
D -->|Unresolved| F[Unknown: leave untouched]
D -->|No| G[Foreign: leave untouched]
E --> H[Doctor reports stale]
H --> I[Setup backs up and refreshes after approval]
Reviews (6) · Last reviewed commit: "fix(setup): compare the script before re..." · Reviewed by Greptile |
| } catch { | ||
| return false; |
There was a problem hiding this comment.
Unreadable manifests look foreign
When another installation's script exists but its manifest cannot be read or parsed, this catch returns false. entrypointOwnership then reports foreign, even though package ownership could not be checked. Doctor tells the user to rename or remove the registration instead of reporting an unresolved identity.
The repository requires unresolved identity to remain unknown. Return a distinct unknown result for failed manifest reads and preserve it through the caller. This requirement must be satisfied before merging.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/application/InstalledReaPackage.ts
Line: 42-43
Comment:
**Unreadable manifests look foreign**
When another installation's script exists but its manifest cannot be read or parsed, this catch returns `false`. `entrypointOwnership` then reports `foreign`, even though package ownership could not be checked. Doctor tells the user to rename or remove the registration instead of reporting an unresolved identity.
The repository requires unresolved identity to remain `unknown`. Return a distinct unknown result for failed manifest reads and preserve it through the caller. This requirement must be satisfied before merging.
**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Valid. Package evidence is now tri-state (verified / absent / unknown) in InstalledReaPackage.ts (b67c9aa). A script in the node_modules/rea-agents/scripts/rea.mjs layout whose manifest cannot be read or parsed is unknown, and entrypointOwnership / aubeShimOwnership carry that through as identity: "unknown", so doctor gives the unresolved-identity remediation instead of rename/remove. A missing package.json (ENOENT) stays absent, because then no installed package claims the script; the existing Aube store fixtures depend on that. An oversized or non-regular manifest is also absent (fixed 1 MiB ceiling; REA publishes about 30 KB). Regression: setup keeps a launcher of an unparseable REA manifest unknown, which fails on the previous commit.
There was a problem hiding this comment.
Thanks — the Aube change addresses the runtime-switch case: it retains the parsed target and only claims a different-runtime shim when that target is verified as an installed REA package; the unverified managed/direct cases keep their prior handling.
The original finding still applies to ordinary [runtime, script, "mcp"] registrations, though. installedReaPackageEntrypoint returns false both when a path is definitively not an REA installation and when stat, reading, or parsing the manifest fails. In the latter case, entrypointOwnership preserves the initial foreign result rather than reporting unknown. This needs a distinct unresolved result so an unreadable or malformed manifest does not become a foreign-ownership claim.
There was a problem hiding this comment.
This follow-up predates b67c9aa. Package evidence is now verified / absent / unknown. A layout-matching manifest that cannot be read or parsed is unknown, and so is a script that does not resolve (latest commit). Both are carried through as identity: "unknown". Covered by setup keeps a launcher of an unparseable REA manifest unknown.
Node removes `..` before following links, while native traversal follows links first. A spelling such as `<dir>/link/../scripts/rea.mjs` could realpath into an installed REA package while another runtime runs an unrelated script, so it no longer proves another REA installation. Co-Authored-By: gensokyo-dev <[email protected]>
Shim inspection discarded the parsed target when the shim's runtime was not this process's, so a saved Aube wrapper stayed unknown after a Node change even when its target was an installed REA package. Inspection now reports which runtime the shim uses, and ownership claims another installation only for a verified REA package target; other targets keep their earlier classification. Co-Authored-By: gensokyo-dev <[email protected]>
A launcher in REA's package layout whose manifest cannot be read or parsed, or whose spelling Node and native traversal resolve to different files with either one in an REA package, no longer reads as foreign. Package evidence is now verified, absent or unknown, and unknown evidence leaves ownership unknown. A missing manifest still means no installed package claims the script. Co-Authored-By: gensokyo-dev <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b67c9aa606
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } catch { | ||
| return undefined; |
There was a problem hiding this comment.
Preserve unknown identity when script resolution fails
When a saved registration uses another still-existing runtime but its cached script has been removed or cannot be resolved, the runtime is classified as foreign and this helper converts both realpathSync failures to undefined; installedReaPackageEvidence then treats that as absent, leaving the whole command definitively foreign. This contradicts the documented removed-cache behavior and directs users to treat an unresolved registration as foreign rather than restore the installation or fix access. Preserve failed script resolution as unknown evidence instead.
AGENTS.md reference: AGENTS.md:L19-L21
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid. A different runtime no longer proves a registration foreign under this PR, so a script that fails to resolve under another existing runtime (for example an nvm switch combined with a pruned _npx entry) has to stay unresolved. Fix (latest commit): installedReaPackageEvidence maps a selection whose realpath fails to unknown instead of absent, and entrypointOwnership carries that as identity: "unknown". That matches the documented removed-cache behavior. Same-runtime branches already returned unknown before reaching this check. Regression: setup leaves a removed installation's launcher under another runtime unknown (acceptance), which fails on b67c9aa and passes now. 18 related files: 454 passed.
A different runtime no longer proves a registration foreign, so a saved launcher under another runtime whose REA script was removed, such as a pruned npx cache entry, is now unknown rather than foreign. Doctor then asks the user to restore or verify the installation instead of renaming or removing the registration. Co-Authored-By: gensokyo-dev <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db832d1f33
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (interpreterIdentity !== "owned") | ||
| return { | ||
| identity: currentPathAvailable ? interpreterIdentity : "unknown", | ||
| ...(currentPathAvailable | ||
| ? entrypointOwnership(interpreterIdentity, entrypoint) | ||
| : { identity: "unknown" }), |
There was a problem hiding this comment.
Compare the script before rejecting a changed runtime
When setup is run from the documented source-checkout entrypoint after switching to another still-installed Node runtime, the saved command can be [oldNode, currentCheckoutScript, "mcp"]; this branch passes the interpreter's foreign identity into entrypointOwnership instead of first comparing the script with currentCommandPath. Because a checkout is intentionally not under node_modules/rea-agents, package evidence is absent and setup misclassifies its own exact script as foreign, refusing to refresh the registration. The runtime and script identities need to be evaluated separately; aubeShimOwnership has the same runtime-first behavior for a linked checkout.
AGENTS.md reference: AGENTS.md:L19-L21
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid. The runtime-first decision meant [oldNode, <checkout>/scripts/rea.mjs, "mcp"] never compared its script with currentCommandPath. Fix (latest commit): a new helper, otherRuntimeScriptOwnership, evaluates runtime and script separately. When the runtime is a proven different one, the script is checked under both spellings, raw/native and resolve()/lexical, since the other runtime may use either:
- both select the current entrypoint →
ownedwithinstallation: "other"(stale, refreshable); - only one does →
unknown; - neither does → the existing installed-package evidence decides.
aubeShimOwnership uses the same helper for a shim whose runtime differs. Existing Aube assertions that read "not owned" are restated as installation !== "current", the invariant they protect: such a shim is never aligned or kept as equivalent. Regressions: setup refreshes this installation's script under another runtime (acceptance, the CLI fixture runs this checkout's script) and classifies a saved Aube launcher of another runtime whose target is this installation's script. Both fail on db832d1. 18 related files: 456 passed.
A registration that starts this installation's own script under another still-installed runtime, such as a source checkout after a Node switch, was foreign because the runtime mismatch was decided first. Runtime and script identity are now evaluated separately: when both Node's lexical and native traversal select the current script, the registration is owned but selects another installation, and setup refreshes it. A spelling only one traversal maps to the current script is unknown. Aube launchers of another runtime use the same rule. Co-Authored-By: gensokyo-dev <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a009ca4472
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } catch (cause) { | ||
| // No manifest means no installed package claims the script; one that | ||
| // cannot be read or parsed leaves the package unresolved. | ||
| return isEnoentError(cause) ? "absent" : "unknown"; |
There was a problem hiding this comment.
Keep a missing package manifest unresolved
When a partially pruned installation still contains node_modules/rea-agents/scripts/rea.mjs but its package.json has disappeared, this maps the manifest's ENOENT to absent, so entrypointOwnership reports the registration as foreign. The package-shaped installation is unresolved just like an unreadable or malformed manifest, and classifying it as foreign gives users the manual removal remediation instead of allowing them to restore the installation; return unknown for this case.
AGENTS.md reference: AGENTS.md:L19-L21
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining this one, deliberately. A missing package.json is an observed fact: no installed package claims the script. That differs from a manifest that exists but cannot be read or parsed, which stays unknown. npm and npx prune whole package directories, so a pruned cache entry fails script resolution and is already unknown (db832d1). A script that survives while only its manifest disappears is not a layout package managers produce. For that case the result stays foreign, the same as before this PR, so it is not a regression. Changing it would also reclassify the existing mise/Aube store fixtures, which ship scripts without manifests. The maintainer agreed to leave this as is.
gensokyo-dev
left a comment
There was a problem hiding this comment.
Reviewed the final diff, review-thread fixes and validation; approving.
Summary
Fixes #15022.
When an earlier
npx rea-agents setupsaved REA's launcher from one npx cache folder (npm-cache/_npx/af752b…/node_modules/rea-agents/scripts/rea.mjs), and a later npx run landed in a different cache folder, doctor reported every client registration asconfig_driftwithcommand_identity: foreign. Setup then refused to refresh them and told the user to hand-edit six client configs. The same thing happens after a global install moves to another prefix, or when nvm/fnm switches the Node.js runtime.With this PR, doctor reports such a registration as owned but stale, and
rea setupreplaces it with the current launcher after backing it up.Problem and expected behavior
Trigger: a client config contains
[node, <other install>/node_modules/rea-agents/scripts/rea.mjs, "mcp"], and REA runs from a different path.Violated invariant: REA's own registration must stay identifiable so that setup can refresh it. Before this change, ownership required the saved entrypoint to realpath-match the running entrypoint, and any other existing path was
foreign.Expected: a launcher that provably starts another installed
rea-agentspackage is owned and refreshable. A genuinely foreign command stays foreign.Change and scope
New owner
src/application/InstalledReaPackage.ts(installedReaPackageEvidence). It returns one of three results:verifiedwhen all of these hold:realpath(resolve(path))) are the same file;<root>/scripts/rea.mjs, where<root>isnode_modules/rea-agents;<root>/package.jsonparses withname: "rea-agents", and itsbin.rearesolves to that file.This is the layout npm, npx, pnpm and Bun create, and the "package resolves as rea-agents" check the issue asks for.
unknownwhen the script does not resolve (for example a pruned_npxentry under another runtime), when the layout matches but the manifest cannot be read or parsed (for example a partly extracted npx install), or when the two traversal semantics select different files and either one lands in an REA package.absentotherwise: other locations, a missing manifest, or another name or bin.The manifest read is limited to regular files of at most 1 MiB. That ceiling is fixed: REA's manifest is about 30 KB, and the limit only bounds a single parse during identity checks; it is not a caller-facing analysis limit.
ClientRegistrationIdentityadds the parsed factinstallation: "current" | "other"to owned absolute launchers. This covers runtime/script launchers, a foreign runtime paired with an REA package script (the nvm case), managed Aube shims, and absolute direct launchers.unknownpackage evidence keeps ownershipunknown. With a proven different runtime, the script is compared first (otherRuntimeScriptOwnership). If Node's lexical spelling and the native spelling both select the current entrypoint, as with a source checkout after a Node switch, the registration is owned/other. If only one does, it isunknown. Otherwise the package evidence decides.inspectAubeShimnow returns its parsed target together with whether the shim uses the current runtime, rather than nothing when the runtime differs. An Aube wrapper whose runtime changed is then owned/other when its target is verified, and keeps its earlier classification otherwise. The managed-shim branch moved intoinspectManagedShimCommand, which bringsinspectDirectRegistrationCommandcomplexity below main. The "different installation" decision is made in one place, and consumers read that fact:registrationAlignedmarksotheras stale, alongside legacy package-runner registrations.equivalentClientRegistrationCommandskeeps a prior launcher only when it selects the current installation. Without this, setup would write the stale path back.owned, so they now treat these registrations as REA's. Uninstall removes them, as it already does fornpx -y rea-agents@<any version> mcpregistrations.The foreign/unknown remediation no longer claims that a different installation path can never prove ownership.
Intentionally not changed: what setup writes while it runs from an npx cache. The issue suggests writing
npx -y rea-agents@<version> mcpor a globalreapath instead. #7757 / c77735f deliberately removed package-runner registrations, because npx resolves the package again from the client's working directory, where a project tree can supply a same-name package. A globalreawould also be a different installation from the one the user chose to run. Setup therefore still binds the installation that runs it. A durable global install remains the documented recommendation.Also not changed: a registration whose installation has since been removed (for example a pruned
_npxfolder). REA cannot read that manifest, so ownership staysunknownand the existing manual-repair remediation applies. This keeps the rule that unresolved identity is not treated as owned.Scope decision: not applicable; this is a fix within existing setup and registration boundaries.
Contract and boundary impact
installedReaPackageEvidencedecides whether a launcher path selects an installed REA package.inspectClientRegistrationCommandturns that intoidentityandinstallationfacts. Consumers (registrationAligned,equivalentClientRegistrationCommands, doctor remediation, setup/update/uninstall viaowned) read those facts and do not re-derive them from paths. The case that separates old from new behavior:node <other>/node_modules/rea-agents/scripts/rea.mjs mcpwasforeignand is nowowned+stale. A source checkout with the same manifest staysforeign.command_identityenum is unchanged. Some registrations move fromforeigntoowned, withstate: "stale"and a new remediation sentence. Setup can now plan a refresh for them.node:pathon the native realpath, so it applies to Windows npx caches and POSIX installs. On Windows, area.cmdshim still is not a link to the script, so it stays foreign as before..rea.backupbehavior.Expected effects:
These are the existing client-config writes by setup, after approval. The new read is the installed package manifest.
Evidence and regression coverage
tests/acceptance/setup/registrationOwnershipSetup.test.tsruns real CLIdoctorandsetupworkflows:owned/stale/ remediation, the setup rewrite to the current launcher, preservedenvand peer servers, and the backup.bin.reanames a different script.link/../scripts/rea.mjsspelling that native traversal resolves into an REA package while Node selects an unrelated script.tests/boundary/filesystem/aubeBinShimRegistration.test.ts: a saved Aube wrapper whose runtime changed is owned and stale when its target is this installation's script or has REA's manifest, and stays unknown/foreign for an unverified package. Earlier "not owned" assertions for shims of another runtime are restated asinstallation !== "current".git stash -- src), both refresh tests fail (2 failed | 12 passed) and the three foreign controls pass. Each review regression (traversal divergence, Aube runtime change, unparseable manifest, unresolved script under another runtime, current script under another runtime) fails on the commit before its fix and passes now.unknown(/missing/old-rea/scripts/rea.mjs) still passes.realpathSync.nativeplusnode:pathon win32, which these tests do not exercise.Validation performed
npm run test:focused -- tests/acceptance/setup/registrationOwnershipSetup.test.tsplus 17 sibling suites: client registration status, launcher alias, Aube shim, configuration dialects, package-runner bound installation and registration, CLI setup, ClientRegistration, Setup planning/recovery/configuration, SetupPlan, Doctor, doctor registration environment, cleanup ownership, project uninstall, duplicate JSON member setup. Result: 18 files, 456 passed, 1 skipped.npm run check:fast: passed (typecheck, lint, architecture guards).ClientRegistrationIdentity.tsnow has 4 lint warnings, all existing on main (main has 5;inspectDirectRegistrationCommandcomplexity drops from 32 to 28). TheAubeBinShim.tscomplexity warning is unchanged from main.npm run knip: clean.npm run docs:check: passed.npx oxfmt --checkon touched files: clean.Compatibility, safety, and release
reaentry is reclassified as REA-owned only if it points at REA's own installed CLI script, verified through the package manifest, and both traversal semantics select that same script. Setup still requires approval and backs up the config. Uninstall's removal set now includes these entries.Author readiness
Human owner: exempt maintainer account (CONTRIBUTING.md readiness exemption); readiness boxes intentionally left unchecked.
Author checklist (completed by the PR author before requesting review)
type(scope): outcome.REA_runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.