Skip to content

Destructive-command check closes the command-parsing gaps found after the last release (GST-3190) - #4521

Closed
garrytan wants to merge 3 commits into
mainfrom
careful-parser-gaps
Closed

garrytan wants to merge 3 commits into
mainfrom
careful-parser-gaps

Conversation

@garrytan

@garrytan garrytan commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

The destructive-command check now blocks force-pushes to main written with --repo=, after a cd, or with --all, and asks again for the other shapes that slipped past it after #4513.
It also stops over-blocking dry runs, wipefs on image files, and greps for SQL text, and GSTACK_SESSION_KIND=interactive keeps the ask under CI=1.
Nothing to do: the check runs in every session already.

What changed, by shape

Steps back from main, fixed first:

  • git push --repo=origin +refs/heads/main and git push --repo=origin --force main are denied. With --repo, every operand is read as a possible refspec (git itself reads the first one as the repository, so this is the cautious reading).
  • A cd inside a pipeline (cd /tmp | true && rm -rf dir) no longer counts as moving into scratch: bash runs each pipeline part in a subshell. A subshell now gives back the exact outer state, so cd /tmp && (pwd) && rm -rf dir no longer asks.
  • git reset --hard "$REV" asks again.
  • printf x >> f && git reset --hard on a clean tree stays allowed: the only work it can lose is what the same command wrote. git stash pop earlier in the same command does make a later discard ask, because pop drops the stash, the same loss stash drop always asks about.

Gaps in the catches #4513 added:

  • git clean -q / --quiet no longer hides the dry-run listing.
  • --work-tree, --git-dir, GIT_DIR= and GIT_WORK_TREE= forms of checkout -f, switch -f and clean -f ask.
  • find -L <dir> -delete (leading find options) is read correctly.
  • rm dir -rf with flags at the end asks when rm is the command; docker rm web -f and aws s3 rm stay those tools' subcommands.
  • A mktemp variable assigned again in the same command is no longer scratch.
  • .. beats the /proc and /dev exemptions, a cd through .. is never scratch, and rm -rf ../build no longer rides the build-output allow.
  • A cloud delete's dry run counts only from the delete itself to the end of its statement, so a dry run on the line before (or before ; with no space) never excuses it, and plan counts only as a whole word.
  • GSTACK_SESSION_KIND=interactive outranks CI=1 in the every-session guard hook (claude -p stays headless).

Over-catches removed:

  • git push -nf is a dry run (letters after o in a short-option group are a push-option value, not flags).
  • wipefs -a stays blocked unless every target has a disk-image suffix (.img, .iso, .raw, .qcow2, .vhd, .vhdx, .vmdk, .dmg) outside /dev/; the values of -t, -o and -O are not targets.
  • The bare SQL shape (TRUNCATE x;) is ignored inside grep, rg, ag, ack and git grep, and in echo/printf text when nothing after it pipes or redirects (|| is not a pipe); ./psql/ in a path is a folder, not a client.

Force-pushes that only asked:

  • cd . && git push -f origin on main is denied: git now reads the folder a cd chain leads to for the force-push lookups (discard checks still ask after any cd).
  • git push --force --all, --branches and --mirror are denied when main, master or the default branch exists locally.

Speed: the statement loop no longer indexes a bash array, which is linear per read on bash 3.2. A 200 KB command takes 1.3 s instead of 4.3 s on bash 3.2.57 and 0.9 s instead of 1.1 s on bash 5.2. Everyday commands are unchanged: p50 73.4 ms vs 73.2 ms at 55aaa6c on bash 5.2 (n=400 each, same machine, interleaved), with 9 ms of drift between repeat passes.

Tests

test/careful-replay.test.ts gains 48 rows (PARSER_CASES), one or more per shape above; 26 fail at 55aaa6c, 10 more (from review) fail at e20997b, 5 fail at e74219a, and the rest are controls or the pinned printf decision. Non-main test trees now also hold a local main branch, as a feature checkout does. test/destructive-guard-hook.test.ts gains the CI=1 case, which fails at 55aaa6c. The 102-row GEVA-560 replay stays green on bash 5.2.21 and 3.2.57.

Not in this PR (outside its scope, none a step back from main): a quoted scratch path with a space, denying a literal home path, a failure while reading input before the safety trap, and a backtick revision in reset --hard.

Open notes found in review, left for a follow-up: the SQL-text exemption still allows grep 'truncate users;' a.sql | sh and echo "$(dbtool exec 'TRUNCATE TABLE users')"; quoted parentheses can restore an earlier cd into scratch; echo cd /tmp still counts as a cd; LC_ALL=C cd /tmp && rm -rf dir and printed SQL text followed by a pipe in a later statement ask; and grep 'a; truncate demo;' still asks.

Agent notes
{"head":"e74219a82144c18753450f36c6fc697d207cf76c","run":"ship-4521-e74219a","mark":"stop","tree":"549c381c3b257cf96c2c5e14128d4f95bd6f91a4"}
{"head":"f7dd58d837dfca81122e7db83215521861060959","run":"ship-4521-f7dd58d","mark":"stop","tree":"3b2e64b797cc9adaa1fb6713f0b330794a1557c7"}

Open in Capy

… the last release (GST-3190)

Force-pushes to main written with --repo=, after a cd or with --all are blocked again; pipeline cds, $ reset revisions, quiet git clean, alternate git trees, find -L, trailing rm flags, reassigned mktemp variables, .. paths and same-line dry runs ask again; dry-run pushes, wipefs on files and SQL text in greps no longer trip it; GSTACK_SESSION_KIND=interactive outranks CI=1.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 19, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

garrytan and others added 2 commits November 19, 2026 11:44
…atement, and six review fixes (GST-3190)

A dry run on the line before no longer excuses a real aws delete. SQL text that is printed into a pipe or file still asks, push-option values are not read as flags, wipefs stays blocked unless every target is a disk image, cd counts only as a command, and || is not a pipe.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
… and wipefs reads /dev and option values correctly (GST-3190)

Puts back the earlier cd handling, so a discard after if cd, while cd or time cd asks again. wipefs stays blocked for any /dev/ target, and the values of -t, -o and -O are not read as targets.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai

capy-ai Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Closing this in favor of #4525, which carried all three commits from this branch unchanged plus the wipefs fixes, and landed on main as 1730386. The open notes listed here (the SQL-text loosenings, LC_ALL=C cd, and the later-pipe ask) are listed in #4525's description and go to a follow-up.

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.

1 participant