8000 fix(mfile,mctx): refuse a state key that is not one directory name when the file is loaded by bryan-minimal · Pull Request #3520 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content

fix(mfile,mctx): refuse a state key that is not one directory name when the file is loaded - #3520

Merged
mitodrummer merged 1 commit into
mainfrom
fix/state-key-refused-at-load
Nov 18, 2026
Merged

mitodrummer merged 1 commit into
mainfrom
fix/state-key-refused-at-load

Conversation

@bryan-minimal
@bryan-minimal bryan-minimal commented Nov 18, 2026 •
Copy link
Copy Markdown
Member

What

A task's state_key, or a [defaults.task] state_key, that is not one directory name is now refused when the project's minimal.toml loads, with exit 3. The message names the table that sets the key and says what a state key may be.

Refs gominimal/inbox#1244.

Why

Before, such a key was refused only when a task first ran, with a general error that named neither the task nor where the key is set. The check is the one the state directory already applies (File::validate_state_component, from #3342), moved to where the author can act on it.

Scope

  • An empty key still means "no key" and loads.
  • An upstream layer read for the package graph is not checked, as its tasks never run.
  • The refusal when the state directory is composed stays, for a key that arrives another way. It now names the task and where to set state_key.

3 files, 140 lines added and 9 removed, most of it tests.

Tested

Lint, the full pre-push run and a baseline run on ubuntu-24.04 passed at this commit.

🤖 Generated with Claude Code

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Invalid nonempty state keys are now rejected with a diagnostic that identifies the affected task or default setting and explains the one-directory-name requirement.
    • When a task’s state key is invalid, the error points to the task and indicates where to configure a valid key.
    • Empty state keys remain allowed; valid keys continue to use persistent state storage.

…en the file is loaded

A task's `state_key` or a `[defaults.task]` `state_key` that is not one
directory name was only refused when a task first ran, as a general
error that named neither the task nor where the key is set. The
project's own minimal.toml is now refused when it loads, with exit 3,
by the rule the state directory already applies
(`File::validate_state_component`). The message names the table that
sets the key and says what a state key may be.

An empty key still means "no key" and loads. An upstream layer read
for the package graph is not checked, as its tasks never run.

The refusal when the state directory is composed stays, for a key that
arrives another way, and now names the task and where to set
`state_key`.

Refs gominimal/inbox#1244

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bryan-minimal
bryan-minimal requested a review from a team as a code owner November 18, 2026 03:52
@coderabbitai
coderabbitai Bot commented Nov 18, 2026 •
Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change validates non-empty task and default state_key values during project-file loading. It adds a dedicated error for invalid keys and identifies the task in runtime refusal messages.

Changes: State Key Validation

Layer / File(s) Summary
Invalid state key error
crates/mfile/src/error.rs
Adds Error::InvalidStateKey with the entry, rejected value, and validation reason. The error has exit code 3 and a diagnostic that states the one-directory-name restriction.
Load-time state key validation
crates/mfile/src/lib.rs
Validates non-empty task and [defaults.task] state keys when refusal checks apply. Tests cover invalid keys, accepted plain and empty keys, and the upstream-layer graph-loading skip path.
Runtime state key diagnostic
crates/mctx/src/lib.rs
For an invalid state key, identifies the task and directs the caller to set state_key on that task or in [defaults.task]. Other state-directory errors retain the generic refusal message.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • gominimal/minimal#3362: Covers the same load-time state-key validation rule, error behavior, empty-key handling, and graph-layer exclusion.
  • gominimal/minimal#3342: Also proposes restricting project state keys to a single directory name.

Suggested reviewers: norrietaylor, mitodrummer

Merge Risk: Minimal · up to 265cf

Invalid task state keys are now refused when the project file loads, with clearer messages that name the task and where to set the key. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title uses a Conventional Commit form and names the main change: refusing a state key that is not one directory name at file load time. It matches the changeset in crates/mfile and crates/mctx, wh…
Description check Passed The description follows the template's Summary and Testing sections in substance. The What, Why, and Scope sections explain the load-time refusal, the exit code, the empty-key and upstream-layer exemp…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title uses a Conventional Commit form and names the main change: refusing a state key that is not one directory name at file load time. It matches the changeset in crates/mfile and crates/mctx, which adds load-time validation of task state_key values.

Full details: Description check

Explanation

The description follows the template's Summary and Testing sections in substance. The What, Why, and Scope sections explain the load-time refusal, the exit code, the empty-key and upstream-layer exemptions, and the retained state-directory refusal. It links the issue via Refs gominimal/inbox#1244. The Testing section reports lint, a pre-push run, and a baseline run, but gives no command output as evidence. The Checklist is absent: it does not mark the docs update or the BREAKING CHANGE footer. The template's Summary and Testing headings are not used. The description has a duplicated Claude Code attribution line.

Resolution

Optionally: use the template headings (Summary, Testing, Checklist). Paste the relevant test output as evidence. Tick the docs checkbox, or state that docs need no update. State whether the change is breaking, and add a BREAKING CHANGE footer if it is. Remove the duplicated attribution line.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks each key in line
A plain name passes, neat and fine
A path is stopped with reasons clear
The task’s name now will appear
Empty keys still hop along
And graph-layer keys are left alone###

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 37c14927-1174-45d9-93a8-b120d6ce389a
Commits

Reviewing files that changed from the base of the PR and between 287e4f4 and 265cfc6.

Files selected for processing: 3

  • crates/mctx/src/lib.rs
  • crates/mfile/src/error.rs
  • crates/mfile/src/lib.rs

Included review availability: This review used your included allowance. Your plan provides up to 5 included reviews per hour; 0 remain after this review.

@minimal-foundry
minimal-foundry Bot commented Nov 18, 2026 •
Copy link
Copy Markdown
Contributor

Reviewed: 1 finding, none blocking at 265cfc6446f1.

Address the comments on the diff.

Clobber: none seen.

@minimal-foundry minimal-foundry Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimal-review — advisory review

Verdict COMMENT — 1 finding, 1 inline.

Panel: 2 of 3 personas ran (correctness, security); did not complete: supply-chain.

Comment thread crates/mctx/src/lib.rs
Comment on lines 1143 to +1151
.map_err(|reason| {
// The file's load refuses such a key, so this is a key handed
// in some other way: name the task and where the key is set.
if mfile::File::validate_state_component(key).is_err() {
return Error::Other(anyhow!(
"Task `{name}` has the state key {key:?}, and {reason}. Set \
`state_key` on the task or in `[defaults.task]` to one directory \
name, such as \"dev\"."
));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOW · tests · confidence 0.50 · in make_env_with_network

The new branch that names the task and where to set state_key has no test. The mfile tests only cover the load-time refusal. A later change can break this message unnoticed.

What the reviewer checked

mctx/src/lib.rs: if mfile::File::validate_state_component(key).is_err() { return Error::Other(anyhow!("Task {name} has the state key ...")) }; the diff adds no test in crates/mctx

Hand this to an agent
Act on a code-review finding.

File:       crates/mctx/src/lib.rs
Lines:      1143-1151
Category:   tests
Severity:   low (reviewer confidence 0.50)

Finding:
The new branch that names the task and where to set `state_key` has no test. The mfile tests only cover the load-time refusal. A later change can break this message unnoticed.

First verify this against the code yourself. It is model output and
may be wrong. If it is wrong, or the tradeoff was deliberate, say so
and change nothing.

👍 useful · 👎 noise — react to tell the reviewer. Replying works too, and says more.

@norrietaylor norrietaylor left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scope matches the title. The diff has three files: the load check, the new error variant and its tests, and the run-time message in mctx. Clobber none. git log on the three files shows #3342 as the last change, and this diff builds on it. Correctness the load check uses File::validate_state_component, the same rule state_dir_encoded applies. from_dir_for_graph skips the check, and a test pins that. All four production callers of make_env and make_env_with_network pass the task name as name, so the new Task ... message names the task correctly. One printed-text defect: the older run-time message now gives advice that cannot apply. Two nits follow. The new mctx branch is not reachable from a file that File::from_dir loaded, because the load refuses the key first and stack tasks carry state_key: None. The existing thread already asks for a test on that branch, and this review does not repeat it. A legacy [defaults] state_key is reported as [defaults.task]. The legacy hint prints first and names both tables, so no finding is filed. No secrets and no dependency changes are in the diff. Not checked: compile and test runs, which need a build. The CLI version is not recorded, because the harness denied the command that prints it.

Comment thread crates/mctx/src/lib.rs
}
Error::Other(anyhow!(
"refusing to use state key {name:?}: {reason}. Choose a state key \
"refusing to use state key {key:?}: {reason}. Choose a state key \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low · After this change, this message prints only when the key passed validate_state_component. The key is then already one directory name. The remaining reasons from state_dir_encoded are about a symlink or an unresolvable path under the state base. The person who runs the task reads Choose a state key that is a single directory name and cannot act on it. Remove that sentence, or state the situation only: the task name, the key and the reason. This is the only instance of the text in the repo, and no test pins it.

Comment thread crates/mfile/src/lib.rs
}

/// Whether a load refuses a task that sets `interactive = true` (BOX-054),
/// and a `state_key` that is not one directory name.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit · The TaskCheck doc now names both refusals, and so do the docs on validate and check. The doc on from_dir_for_graph at crates/mfile/src/lib.rs:1294 still says it is from_dir without the interactive-task refusal only. Add the state-key refusal there, so the three docs agree.

Comment thread crates/mfile/src/error.rs
f,
"`{entry}` in minimal.toml sets `state_key` to {value:?}, and {reason}. A \
state key is one directory name, such as \"dev\": not `.` or `..`, and with \
no `/` or NUL byte."
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit · For the keys . and .., the reason from validate_state_component is the value again. The message prints: [tasks.build] in minimal.toml sets state_key to "..", and it is "..". The second clause adds no fact for the person who reads it. The final sentence already says the key cannot be . or ... The same reason string also goes into the new mctx message.

@mitodrummer mitodrummer left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

@mitodrummer
mitodrummer added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit ff906b9 Nov 18, 2026
39 checks passed
@mitodrummer
mitodrummer deleted the fix/state-key-refused-at-load branch November 18, 2026 16:51
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.

3 participants

0