Repository navigation
fix(config): a user config that cannot be inspected is an error, an absent one is announced where it may be a wrong directory (#864) - #869
Merged
Conversation
…bsent one is announced where it may be a wrong directory (#864) try_exists in both user-config loaders so an I/O error no longer reads as no file. One stderr notice for an absent user config when CODECORA_HOME is set, the data directory cannot be resolved, a session started the process or the face is unattended; the default path and cron tick stay silent.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
…its path on one line, check the other readers (#864) The error names --no-config and CODECORA_HOME. The path in the error and in the notice is single-line and capped (newline and escape cannot forge a stderr line). serve hook routes, doctor, [curator] and cron.tz_source use the same try_exists check instead of exists().
| Ok(false) => Ok(None), | ||
| Err(e) => Err(format!( | ||
| "cannot inspect the user config {} ({e})", | ||
| path.display() |
…es the ways out (#864)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Options A and B of #864 (chosen by the owner). A: a user config path that cannot be inspected is a startup error naming the path and the ways out, instead of silently meaning "no user config". B: an absent user config is announced once on stderr, but only where it may be a wrong directory rather than a choice. The other readers of the user config get the same check. Closes #864.
Why
The user config is the only source of
[sandbox],[sandbox.consumers],[secrets],[delegation], hook routes, profiles and the approval allow and trust lists.load_user_configusedpath.filter(|p| p.exists()), andPath::existsreads every I/O error (permission denied, a parent that is a file) as "not there", soCODECORA_HOMEat an unreadable directory or a file silently ran with defaults, with nothing on stderr. Item 2 of the not-fixed list of #858.Changes
config/mod.rs:user_config_present(path)(try_exists:Ok(true),Ok(false), orErr(message)) andone_line_path(path). The error readscannot inspect the user config <path> (<io error>); not running with the default sandbox, approval and secret settings instead. Fix the path or its permissions, fix or unset CODECORA_HOME, or pass --no-config to ignore the file for this one run (owner at a terminal only). It stays fail-closed (tole doctoris not on the skip list, so it fails with the same message before it runs; making doctor report a finding instead would need to run with defaults, which this issue is about).one_line_path: the path comes from the environment, so a newline or escape sequence in it must not forge a second stderr line: control characters are shown as\n,\r,\t,\u{..}and the path is cut at 200 characters with an ellipsis. Used in the error, the notice, and the existingusing user configline.config/apply.rs:load_user_configusesuser_config_present;AbsentCtxand the pureabsent_user_config_notice(path, ctx).main.rs: after the user config load, a missing file (None) is announced through that function with the real context (CODECORA_HOMEset and non-blank,under_session,sandbox_flag_class(..).0= serve, acp, mcp). Shown when: the data directory cannot be resolved (HOMEunset or relativeCODECORA_HOME: always), the root comes fromCODECORA_HOME, a session started the process, or the face is unattended. Otherwise silent: an owner on the default path with no config chose the defaults, andtole cron tickthere prints nothing (an OS cron mails stderr; fix(cron): tole cron run and tick apply the owner's user config (#863) #868 drops theusing user configline without a terminal, and a normal valid config stays silent).Path::existsnow use the same check (mechanical swap):serve.rshook routes (the server does not start, like a route that does not parse),skill/curator.rs(curator_config_at: reported and defaults apply, like a parse error; unit test),delegation/ledger_file.rszones()(cron.tz_source: one warning, the default source applies, as for a file that does not parse),doctor.rsrouter lines (an ERROR finding like a file that does not parse). Neither[curator]nortz_sourceis a security setting. No known silentexists()reader of the user config is left.cron/setup.rs::user_config(): same rule.CODECORA_HOMEelsewhere; the boundary against that is the command sandbox that masks the data directory.config_apply.rsthat asserted an empty stderr with aCODECORA_HOMEhome and no user config now expect the notice (and one status check uses--no-config, which prints nothing).Callers and impact (grep, each checked):
load_user_confighas one production caller (main.rs); the four swapped readers areserve.rs:123,skill/curator.rs:409,delegation/ledger_file.rs:86,doctor.rs:842, each with its single call site;user_config_pathreaders that never test existence (sandbox_cmd.rs,hook_cli.rs,config/mod.rs) are unchanged. Visible behaviour change: withCODECORA_HOME(or no resolvable data dir, a session, serve/acp/mcp) and no user config, one stderr line now appears; a harness that setsCODECORA_HOMEto an empty directory and asserts an empty stderr sees it. Tests to rerun:config_apply,config_check,config_sensitive,main_gate_tests,cron_*,sandbox_cli,sandbox_flags_cli,no_config_guard_e2e,owner_only_e2e,curatorunit tests,layering.Testing
tole sessionsandtole cron tick, scrubbed environment: an uninspectable path is a startup error naming the path, the--no-configandCODECORA_HOMEways out (and--no-configreally runs), the notice for aCODECORA_HOMEoverride, a session marker and an unresolvable directory, silence for the default root includingcron tick.a_newline_in_codecora_home_cannot_forge_a_stderr_line(the error path and the notice path) fails withone_line_pathneutered by hand (stderr carried the forgedtole: FORGED lineline) and passes with it. Unit:a_path_in_a_user_config_message_is_one_short_line(newline, CR, ESC, over-long path, ordinary path untouched) andthe_messages_carry_a_single_line_path_and_the_error_names_the_way_out.apply_tests.rs): a missing file andNoneareNone; a parent that is a file (whereexists()said false) is an error and announces nothing; the notice for each unusual case alone and silence for the default path. Curator:curator_config_reports_an_uninspectable_user_config. (A mode-000 directory is not used: tests run as root locally.)cargo fmt --all --check;cargo clippy --workspace --all-targets --all-features -- -D warnings;cargo clippy -p tole-core -p tole-cli -p tole-tui --no-default-features --all-targets -- -D warnings;cargo testof tole-core and tole-cli (default) and of tole-core, tole-cli, tole-tui with--no-default-features, withTOLE_REQUIRE_BWRAP=1and--no-fail-fast: green (the two tests that needcronare gated onshell-tools). The attribution grep overorigin/develop..HEADis empty.scripts/review-local.shcannot run (cora is not installed here: exit 1, not a pass), so I self-reviewedgit diff origin/develop...HEADas an adversarial reviewer: only an absent file returnsOk(None), every othertry_existserror is fatal (or reported, for the two non-security readers) before any config is applied; the notice is only printed whenloadedisNoneand the load was attempted (--no-configand skip-list commands never reach it) and once per process; the default-path owner and the cron tick are silent; paths in the new messages are single-line and capped; no change to the sandbox, approval or secret paths themselves. The independent review of the first head found no blocker; this body covers the follow-up commit (ways out in the error, one-line paths, the four readers).