Repository navigation
Conversation
Determine workspace trust before reading its settings so excluded malformed files cannot block setup or invalidate doctor registration checks. Preserve trusted policy failures and cover the public CLI with isolated configuration fixtures.
Check for known absence before evaluating workspace trust. Retain trust-first content admission for present or unresolved settings paths, and cover malformed trust files with public setup and doctor regressions.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Treat only ENOENT as absence. Preserve unreadable metadata errors and ignore untrusted workspace content before parsing it. Refs: #3206, #3319 Co-authored-by: haoran20100322 <[email protected]>
|
Thanks for incorporating the Gemini workspace-trust fix in The original CI failure was an unrelated JavaScript regression, addressed in Since the fix is included upstream, I'll leave the PR disposition to the maintainers. No further changes to this branch are needed from my side. |
rahul05ranjan
left a comment
There was a problem hiding this comment.
The ordering fix here is the right one: readClientPolicyBlock used to parse <workspace>/.gemini/settings.json before consulting trust, so a cloned repo shipping malformed (or unreadable) workspace settings could hard-fail rea setup/rea doctor with needs_human even in workspaces Gemini itself wouldn't trust. Moving the trust decision ahead of the read means untrusted workspace settings are never parsed at all.
Verified against the PR head:
- Unlisted workspace (valid, empty
trustedFolders.json) with{ not jsonin<project>/.gemini/settings.json: setup exits 0, statusready, gemini registrationaligned. The three acceptance scenarios (unlisted,GEMINI_CLI_TRUST_WORKSPACE=false, restricted mode with opt-in) all pass, including the assertions that no.rea.backupis created and the workspace file is left untouched. GEMINI_CLI_TRUST_WORKSPACE=truewith the same malformed file: setup exits 1,needs_human, remediation carries theInvalid JSON/JSONCdiagnostic — trusted workspaces still surface real errors rather than silently ignoring the file.- Missing workspace settings + malformed trust file: setup exits 0. The trust file isn't consulted until something actually needs admitting.
- Workspace settings present + malformed trust file: setup exits 1 and the remediation names the trust file ("...trust.json are malformed: ..."), not the workspace file. With both files malformed, the old order surfaced the workspace file's parse error first; pointing remediation at the trust file instead is the better attribution, since that's the one the user actually has to fix.
The "only ENOENT proves absence" comment is the right call: stat failures other than ENOENT (EACCES, EISDIR, ...) fall through to a trust decision instead of being read as absence, which fails closed. I also checked whether other clients need the same gating: the array-form configPath segments for cursor/windsurf/antigravity resolve via join(context.home, ...), so Gemini is the only client where rea reads a workspace-resident (cwd) settings source. The trust boundary scope looks right.
Two nits:
- The
cause instanceof Error && "code" in cause && cause.code === "ENOENT"predicate is now the third copy of this check in this area (ClientConfigPath.tshas a privateisMissing,ClientConfigurationFiles.tsinlines the same shape). A sharedisEnoenthelper would keep them from drifting. - Each of these acceptance tests spawns ~10 CLI invocations, and two of the five exceeded vitest's 30s default
testTimeouton a slow ARM host I test on (behavior verified correct via direct CLI runs). An explicit timeout argument on thosecliTestcalls would avoid false failures on slower machines.
|
Heads up: main already has this change in aade9bb. The code is in 🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
Superseded by the delivered change on main: aade9bbcb. Gemini workspace trust and file absence are checked before workspace settings are parsed, so an untrusted workspace cannot override the registration lookup. Closing this earlier proposal. Current main qualification passed: https://github.com/morluto/rea/actions/runs/38690953281. |
|
Thanks @CmsChase for catching the Gemini workspace-trust check occurring too late. Main checks trust before parsing the configuration. |
Summary
Fixes #3206. Ignore malformed settings in untrusted Gemini workspaces while preserving setup and doctor success when no workspace settings exist.
Problem and expected behavior
REA parsed workspace settings before checking trust, so malformed excluded settings blocked setup and marked a valid user registration invalid. Trust controls workspace-policy admission; an absent workspace settings file should not trigger an unrelated trustedFolders.json error. Present settings with unresolved or malformed trust must still be rejected.
Change and scope
Probe workspace settings metadata and omit that source only when ENOENT establishes absence. Otherwise retain the existing trust decision before reading or parsing content. Setup and registration diagnostics share this owner. Trust overrides, restricted-mode precedence, settings merge order, and the home-directory exclusion remain unchanged.
Contract and boundary impact
GeminiClientSettings.readClientPolicyBlock, workspace policy admission.Expected effects of the existing setup workflow:
The configuration effect is existing approved user registration/skill installation. This fix adds no target interaction.
Evidence and regression coverage
Five compiled CLI acceptance tests cover absent settings with valid/malformed trust, materializing settings with malformed trust, implicit/explicit distrust, restricted mode, and trusted malformed/excluded controls.
Original [Bug] Malformed settings in an untrusted Gemini workspace make setup and doctor fail #3206 regressions: 3 failed / 1 passed on unchanged production code, then 4 passed with trust-first admission.
Added compatibility regression: 1 failed / 4 passed before the absence correction, then all 5 passed.
Three-version replay made 75 real CLI calls. No-settings/malformed-trust setup and doctor changed from baseline exit 0 to exit 1 with unconditional trust evaluation, then returned to exit 0. Present-settings/malformed-trust calls retain exit 1; trusted exclusions and conflicting overrides remain rejected.
User, trust and workspace bytes were preserved. Unknown metadata errors are not treated as absence; that non-ENOENT branch was reviewed in source, not independently fault-injected.
Observed, derived, and inferred claims remain distinguishable.
Artifact identity, source provenance, and failed attempts remain preserved.
Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.
Validation performed
Windows x64, Node 24.18.0/npm 11.16.0, locked dependencies:
npm run test:focused -- tests/acceptance/setup/geminiWorkspaceTrust.test.ts— 5 passed.npm exec --no -- vitest run --project cli-boundary tests/boundary/cli/clientProfiles.test.ts -t Gemini— 10 passed; four unrelated OpenCode cases excluded by selection.npm run check— passed: typecheck, format, lint (0 errors; one additional function-length warning at 101 lines versus 100), knip, metadata, module boundaries and architecture guards.npm run verify:test-discovery— all 1253 test files discovered exactly once.Previously observed packaging results, not rerun for the compatibility correction:
npm pack --dry-runpassed; the generic package verifier failed on both original and trust-first source at Windowsspawn npm ENOENT; the Windows verifier required the absent source-checkout native manifest. Complete package verification remains unavailable in this environment. Previously recorded unrelated Windows symlink, launcher and OpenCode test failures remain outside this fix.Compatibility, safety, and release
Author readiness
Human owner: @CmsChase
Before merge