Repository navigation
fix: git branch read-only classification and the cache-invalidation diagnostic - #381
Merged
github-actions[bot] merged 2 commits intoAug 17, 2026
Merged
Conversation
branch_is_readonly screened only the delete/rename/force family, so any other dash-leading option classified as a read. --set-upstream-to=, --unset-upstream, --edit-description and the attached -u<upstream> form all mutate repository state and all passed. This was never exploitable: the rewrite targets the dedicated git tool, which is SideEffectClass::Write, so authorize still HITL-gates it. Note the git tool's own argument policy explicitly permits -u and --set-upstream-to, so it is not what stops them — the side-effect class is. Labelling a mutation as a read one layer above a security boundary is still wrong, and a denylist is the wrong shape for the job. Inverted to an allowlist of known read-only options, so an option this module has never heard of is no longer assumed to be a read. Only the = spelling of valued options needs matching; the space spelling puts the value in a bare operand, which is already rejected.
record_prompt_snapshot parsed the previous prompt with from_slice to
diff it against the current one. But last_prompt_wire holds the
append-only encoding -- tools\nsystem\nmsg0\nmsg1\n... -- which is one
JSON document per part, not a single document. That parse always failed
once there was more than one part, fell back to json!({}), and left
first_json_pointer comparing an empty object against the whole prompt.
The first_difference field in CACHE PREFIX INVALIDATED has therefore
never named a real mutation site.
Fixed without retaining the previous prompt: common_prefix_len already
reports where the two encodings diverge, so part_pointer_at counts the
completed parts before that offset and names the part it lands in. An
offset on a boundary names the part it opens, which is what a divergence
point means.
This also drops the strip_cache_control deep copy that fed the old diff,
so the DEBUG path no longer copies the prompt at all.
This was referenced Aug 17, 2026
Merged
github-actions Bot
pushed a commit
that referenced
this pull request
Aug 17, 2026
…#383) The comments added in #381 claimed the git branch misclassification was never exploitable because GitTool is SideEffectClass::Write and authorize still gates it. That is wrong, and it is wrong in the direction that matters. Approval is gated on tool identity, not side-effect class. hitl_tools holds the shell-equivalent tools (bash, background_run, exec_command, mcp:*) and apply_mode clears hitl_classes in every shipped mode, so authorize returns Allow for any tool outside that set before pattern rules are consulted. git is outside it, and GitTool's own argument policy permits -u/--set-upstream-to. Nothing downstream catches a misclassification. So readonly.rs is the boundary, not a layer above one, and #381 closed an approval bypass rather than fixing a cosmetic label: a mutating git command classified as a read became an unprompted mutation. Corrects the module header, the branch_is_readonly doc and the test comment, and pins the mechanism with two tests so it cannot be misread again: bash prompts while the rewritten git call is allowed outright, and both shipped modes leave hitl_classes empty.
mohitranka
added a commit
that referenced
this pull request
Aug 21, 2026
…iagnostic (#381) * fix(governance): allowlist read-only git branch options branch_is_readonly screened only the delete/rename/force family, so any other dash-leading option classified as a read. --set-upstream-to=, --unset-upstream, --edit-description and the attached -u<upstream> form all mutate repository state and all passed. This was never exploitable: the rewrite targets the dedicated git tool, which is SideEffectClass::Write, so authorize still HITL-gates it. Note the git tool's own argument policy explicitly permits -u and --set-upstream-to, so it is not what stops them — the side-effect class is. Labelling a mutation as a read one layer above a security boundary is still wrong, and a denylist is the wrong shape for the job. Inverted to an allowlist of known read-only options, so an option this module has never heard of is no longer assumed to be a read. Only the = spelling of valued options needs matching; the space spelling puts the value in a bare operand, which is already rejected. * fix(core): make the cache-invalidation diagnostic name a real site record_prompt_snapshot parsed the previous prompt with from_slice to diff it against the current one. But last_prompt_wire holds the append-only encoding -- tools\nsystem\nmsg0\nmsg1\n... -- which is one JSON document per part, not a single document. That parse always failed once there was more than one part, fell back to json!({}), and left first_json_pointer comparing an empty object against the whole prompt. The first_difference field in CACHE PREFIX INVALIDATED has therefore never named a real mutation site. Fixed without retaining the previous prompt: common_prefix_len already reports where the two encodings diverge, so part_pointer_at counts the completed parts before that offset and names the part it lands in. An offset on a boundary names the part it opens, which is what a divergence point means. This also drops the strip_cache_control deep copy that fed the old diff, so the DEBUG path no longer copies the prompt at all.
mohitranka
added a commit
that referenced
this pull request
Aug 21, 2026
…#383) The comments added in #381 claimed the git branch misclassification was never exploitable because GitTool is SideEffectClass::Write and authorize still gates it. That is wrong, and it is wrong in the direction that matters. Approval is gated on tool identity, not side-effect class. hitl_tools holds the shell-equivalent tools (bash, background_run, exec_command, mcp:*) and apply_mode clears hitl_classes in every shipped mode, so authorize returns Allow for any tool outside that set before pattern rules are consulted. git is outside it, and GitTool's own argument policy permits -u/--set-upstream-to. Nothing downstream catches a misclassification. So readonly.rs is the boundary, not a layer above one, and #381 closed an approval bypass rather than fixing a cosmetic label: a mutating git command classified as a read became an unprompted mutation. Corrects the module header, the branch_is_readonly doc and the test comment, and pins the mechanism with two tests so it cannot be misread again: bash prompts while the rewritten git call is allowed outright, and both shipped modes leave hitl_classes empty.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
…iagnostic (#381) * fix(governance): allowlist read-only git branch options branch_is_readonly screened only the delete/rename/force family, so any other dash-leading option classified as a read. --set-upstream-to=, --unset-upstream, --edit-description and the attached -u<upstream> form all mutate repository state and all passed. This was never exploitable: the rewrite targets the dedicated git tool, which is SideEffectClass::Write, so authorize still HITL-gates it. Note the git tool's own argument policy explicitly permits -u and --set-upstream-to, so it is not what stops them — the side-effect class is. Labelling a mutation as a read one layer above a security boundary is still wrong, and a denylist is the wrong shape for the job. Inverted to an allowlist of known read-only options, so an option this module has never heard of is no longer assumed to be a read. Only the = spelling of valued options needs matching; the space spelling puts the value in a bare operand, which is already rejected. * fix(core): make the cache-invalidation diagnostic name a real site record_prompt_snapshot parsed the previous prompt with from_slice to diff it against the current one. But last_prompt_wire holds the append-only encoding -- tools\nsystem\nmsg0\nmsg1\n... -- which is one JSON document per part, not a single document. That parse always failed once there was more than one part, fell back to json!({}), and left first_json_pointer comparing an empty object against the whole prompt. The first_difference field in CACHE PREFIX INVALIDATED has therefore never named a real mutation site. Fixed without retaining the previous prompt: common_prefix_len already reports where the two encodings diverge, so part_pointer_at counts the completed parts before that offset and names the part it lands in. An offset on a boundary names the part it opens, which is what a divergence point means. This also drops the strip_cache_control deep copy that fed the old diff, so the DEBUG path no longer copies the prompt at all.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
…#383) The comments added in #381 claimed the git branch misclassification was never exploitable because GitTool is SideEffectClass::Write and authorize still gates it. That is wrong, and it is wrong in the direction that matters. Approval is gated on tool identity, not side-effect class. hitl_tools holds the shell-equivalent tools (bash, background_run, exec_command, mcp:*) and apply_mode clears hitl_classes in every shipped mode, so authorize returns Allow for any tool outside that set before pattern rules are consulted. git is outside it, and GitTool's own argument policy permits -u/--set-upstream-to. Nothing downstream catches a misclassification. So readonly.rs is the boundary, not a layer above one, and #381 closed an approval bypass rather than fixing a cosmetic label: a mutating git command classified as a read became an unprompted mutation. Corrects the module header, the branch_is_readonly doc and the test comment, and pins the mechanism with two tests so it cannot be misread again: bash prompts while the rewritten git call is allowed outright, and both shipped modes leave hitl_classes empty.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
…iagnostic (#381) * fix(governance): allowlist read-only git branch options branch_is_readonly screened only the delete/rename/force family, so any other dash-leading option classified as a read. --set-upstream-to=, --unset-upstream, --edit-description and the attached -u<upstream> form all mutate repository state and all passed. This was never exploitable: the rewrite targets the dedicated git tool, which is SideEffectClass::Write, so authorize still HITL-gates it. Note the git tool's own argument policy explicitly permits -u and --set-upstream-to, so it is not what stops them — the side-effect class is. Labelling a mutation as a read one layer above a security boundary is still wrong, and a denylist is the wrong shape for the job. Inverted to an allowlist of known read-only options, so an option this module has never heard of is no longer assumed to be a read. Only the = spelling of valued options needs matching; the space spelling puts the value in a bare operand, which is already rejected. * fix(core): make the cache-invalidation diagnostic name a real site record_prompt_snapshot parsed the previous prompt with from_slice to diff it against the current one. But last_prompt_wire holds the append-only encoding -- tools\nsystem\nmsg0\nmsg1\n... -- which is one JSON document per part, not a single document. That parse always failed once there was more than one part, fell back to json!({}), and left first_json_pointer comparing an empty object against the whole prompt. The first_difference field in CACHE PREFIX INVALIDATED has therefore never named a real mutation site. Fixed without retaining the previous prompt: common_prefix_len already reports where the two encodings diverge, so part_pointer_at counts the completed parts before that offset and names the part it lands in. An offset on a boundary names the part it opens, which is what a divergence point means. This also drops the strip_cache_control deep copy that fed the old diff, so the DEBUG path no longer copies the prompt at all.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
…#383) The comments added in #381 claimed the git branch misclassification was never exploitable because GitTool is SideEffectClass::Write and authorize still gates it. That is wrong, and it is wrong in the direction that matters. Approval is gated on tool identity, not side-effect class. hitl_tools holds the shell-equivalent tools (bash, background_run, exec_command, mcp:*) and apply_mode clears hitl_classes in every shipped mode, so authorize returns Allow for any tool outside that set before pattern rules are consulted. git is outside it, and GitTool's own argument policy permits -u/--set-upstream-to. Nothing downstream catches a misclassification. So readonly.rs is the boundary, not a layer above one, and #381 closed an approval bypass rather than fixing a cosmetic label: a mutating git command classified as a read became an unprompted mutation. Corrects the module header, the branch_is_readonly doc and the test comment, and pins the mechanism with two tests so it cannot be misread again: bash prompts while the rewritten git call is allowed outright, and both shipped modes leave hitl_classes empty.
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.
Two bugs raised as findings by earlier work on #379 and #380, investigated and fixed. Both were flagged as "not fixed, raising instead"; neither changes model-visible behavior.
1.
git branchmutations classified as read-onlybranch_is_readonlyscreened only the delete/rename/force family, so any other dash-leading option counted as a read. These all mutate repository state and all passed:--set-upstream-to=origin/main--unset-upstream--edit-description--set-upstream-uorigin/main(attached short form — one word, so the bare-operand check cannot see it)This was never exploitable, but the originally reported reason was wrong. The finding said the dedicated
gittool "re-validates every option against its own allowlist". It does re-validate — but that allowlist explicitly permits-uand--set-upstream-to(builtins.rs:757-758), so it is not what stops these. What actually holds the line is thatGitToolisSideEffectClass::Write, soauthorize()HITL-gates the rewritten call by class. The backstop is real; the mechanism reported for it was not.Labelling a mutation as a read one layer above a security boundary is still a bug, and a denylist is the wrong shape for the job. Inverted to an allowlist of known read-only options, so an option this module has never heard of is no longer assumed to be a read. Only the
=spelling of valued options needs matching — the space spelling puts the value in a bare operand, which was already rejected.Four tests replace the one that pinned the old behavior: the mutating flags above, unknown/future flags, the genuine reads still rewriting (including
--sort=/--format=/--contains=), and a regression guard that the delete/rename/force family stays rejected.2.
CACHE PREFIX INVALIDATEDnever named a real mutation siterecord_prompt_snapshotparsed the previous prompt withserde_json::from_sliceto diff it against the current one. Butlast_prompt_wireholds the append-only encoding —tools\nsystem\nmsg0\nmsg1\n…— which is one JSON document per part, not a single document. That parse always failed once there was more than one part, fell back tojson!({}), and leftfirst_json_pointercomparing an empty object against the whole prompt. Sofirst_differenceonly ever reported whichever key sorted first in the current wire.There is a second layer to it: even had the parse succeeded,
previousis the concatenated encoding while the current side is the wire object — different shapes, not comparable.The obvious fix — retain the previous wire object to diff against — would undo the deep-copy removal from #380. Instead:
common_prefix_lenalready reports where the two encodings diverge in bytes, sopart_pointer_atcounts the completed parts before that offset and names the part it lands in. No allocation, nothing retained, and it names the specific message rather than a top-level key. An offset sitting on a boundary names the part it opens, which is what a divergence point means.This also removes the
strip_cache_controldeep copy that fed the old diff, so the DEBUG path no longer copies the prompt at all.Six tests, including one that pins the root cause directly (
the_snapshot_encoding_is_not_a_single_json_document), one that drives a real mutation end-to-end throughcommon_prefix_lenand asserts/messages/1, Codex-shapedinstructions/inputwires, boundary semantics, and totality on out-of-range offsets since this runs inside a diagnostic.Verification
cargo fmt --all -- --check,cargo clippy --workspace --all-targets --locked -- -D warnings, andcargo test --workspace --locked --no-fail-fastall green on19efceb.forge-governance84 → 87,forge-model66 → 71.