Repository navigation
feat(tooling): close three agent pre-flight and landing gaps - #115333
Merged
Merged
Conversation
Matching only the top-level tree let a docs file under src/ carrying `export` in a code sample set the flag. That mattered because the flag also short- circuited changedCheckRequiresRemote above its docsOnly guard, so a docs-only change could be dragged onto the heavy remote route and made to run knip. Scope detection to the source extensions knip actually reads, and drop the routing branch entirely: any file that can now trigger detection already enables a non-docs lane, which the existing final clause routes remotely. The branch was dead for every real source change and wrong for the docs case.
Preserving byte-exact formatting required a hand-rolled JSON scanner: string escape handling, container nesting, and span splicing, for a file that lives in gitignored .local/ and is only ever read back through JSON.parse. repin already parses the artifact to validate it, so assign the two identity fields and re-serialize. JSON.parse/stringify keeps insertion order, which is the only formatting property worth holding. Drops four helpers.
steipete
marked this pull request as ready for review
July 28, 2026 17:35
Inspecting changed lines for an `export` token has two false negatives that
defeat the purpose. Barrels export through multiline `export { ... }` lists, so
removing a symbol changes a line carrying no `export` token. Worse, the failure
that motivated this scan was an import-only edit: it orphaned a re-export in a
barrel the diff never touched, which no changed-line rule can see.
Select by path instead: any changed production source file under src/,
extensions/, ui/, or packages/. This also removes the merge-base dependency, so
a shallow checkout or unrelated history can no longer silently skip the scan.
Those paths already enable a non-docs lane, so the run already routes remotely
and knip's cost lands on the box already doing the heavy work.
OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 still opts out.
The repin subcommand defeats the property the identity pin exists to enforce. It rewrites the pinned PR number and head SHA while keeping every recommendation, finding, and Markdown conclusion, so a completed "READY FOR /prepare-pr" verdict authored against one revision can be relabelled as covering another and then pass validation. The test added alongside it restamped PR #7 as PR #42 and asserted validation succeeded, which is exactly the substitution the fail-closed gate was built to stop. Re-authoring a review after the head moves is friction on purpose: the code the verdict describes may no longer be the code being landed. A safe version has to prove the reviewed content is equivalent across the move, which is a design decision about what equivalence means, not a convenience wrapper. Reverts 5d89a70 and its follow-up c6304eb.
Two reviewers independently read the new component comparison as inspecting committed state while the refusal was triggered by working-tree files. The uncommitted-wrapper guard above already exits for any staged or unstaged edit to these three paths, so HEAD matches the working tree by the time this runs. State the invariant at the site instead of letting a third reader re-derive it.
The hand-written extension alternation matched .tsx but not .jsx, so a JSX source change would skip a scan that knip does apply to it. Use the `[cm]?[jt]sx?` selector the lint lanes in check-changed.mjs already use, which covers both and is shorter, and pin the extension coverage in tests.
Contributor
Author
|
Merged via squash.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Jul 29, 2026
…w#115333) * fix(tooling): check changed exports for dead code * fix(tooling): name mismatched PR wrapper components * feat(tooling): repin PR review artifacts * fix(tooling): scope dead-export detection to source files Matching only the top-level tree let a docs file under src/ carrying `export` in a code sample set the flag. That mattered because the flag also short- circuited changedCheckRequiresRemote above its docsOnly guard, so a docs-only change could be dragged onto the heavy remote route and made to run knip. Scope detection to the source extensions knip actually reads, and drop the routing branch entirely: any file that can now trigger detection already enables a non-docs lane, which the existing final clause routes remotely. The branch was dead for every real source change and wrong for the docs case. * refactor(tooling): round-trip the repinned review JSON Preserving byte-exact formatting required a hand-rolled JSON scanner: string escape handling, container nesting, and span splicing, for a file that lives in gitignored .local/ and is only ever read back through JSON.parse. repin already parses the artifact to validate it, so assign the two identity fields and re-serialize. JSON.parse/stringify keeps insertion order, which is the only formatting property worth holding. Drops four helpers. * fix(tooling): select the dead-export scan by path, not changed lines Inspecting changed lines for an `export` token has two false negatives that defeat the purpose. Barrels export through multiline `export { ... }` lists, so removing a symbol changes a line carrying no `export` token. Worse, the failure that motivated this scan was an import-only edit: it orphaned a re-export in a barrel the diff never touched, which no changed-line rule can see. Select by path instead: any changed production source file under src/, extensions/, ui/, or packages/. This also removes the merge-base dependency, so a shallow checkout or unrelated history can no longer silently skip the scan. Those paths already enable a non-docs lane, so the run already routes remotely and knip's cost lands on the box already doing the heavy work. OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 still opts out. * Revert "feat(tooling): repin PR review artifacts" The repin subcommand defeats the property the identity pin exists to enforce. It rewrites the pinned PR number and head SHA while keeping every recommendation, finding, and Markdown conclusion, so a completed "READY FOR /prepare-pr" verdict authored against one revision can be relabelled as covering another and then pass validation. The test added alongside it restamped PR openclaw#7 as PR openclaw#42 and asserted validation succeeded, which is exactly the substitution the fail-closed gate was built to stop. Re-authoring a review after the head moves is friction on purpose: the code the verdict describes may no longer be the code being landed. A safe version has to prove the reviewed content is equivalent across the move, which is a design decision about what equivalence means, not a convenience wrapper. Reverts 5d89a70 and its follow-up c6304eb. * docs(tooling): note why the wrapper diagnostic reads HEAD blobs Two reviewers independently read the new component comparison as inspecting committed state while the refusal was triggered by working-tree files. The uncommitted-wrapper guard above already exits for any staged or unstaged edit to these three paths, so HEAD matches the working tree by the time this runs. State the invariant at the site instead of letting a third reader re-derive it. * fix(tooling): cover jsx in the dead-export source selector The hand-written extension alternation matched .tsx but not .jsx, so a JSX source change would skip a scan that knip does apply to it. Use the `[cm]?[jt]sx?` selector the lint lanes in check-changed.mjs already use, which covers both and is shorter, and pin the extension coverage in tests.
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 Problem This Solves
Two gaps in the tooling agents use to pre-flight and land PRs, both hit for real
while landing #115189 and #115212.
1.
pnpm check:changedcould not predict the CI dead-code failure.scripts/changed-lanes.mjshad no dead-code lane andcheck-changed.mjsneverinvoked knip, so
deadcode:exportsin thecheck-dependenciesjob was invisibleto pre-flight. Concretely: a PR moved two imports off barrels onto their defining
modules, orphaning those barrels' re-exports.
check:changedpassed (remotely, onTestbox, exit 0); CI then failed on four
Unused exports.2. The
scripts/prwrapper gate named no files. It comparesscripts/pr,scripts/pr-lib, andscripts/lib/plain-gh.shas one combined rev-parse and onmismatch says only "does not match origin/main". In practice
scripts/pritselfwas byte-identical and only
scripts/pr-lib/worktree.shhad drifted after mainadvanced; finding that meant diffing
scripts/by hand.Why This Change Was Made
1. The scan is selected by path: any changed production source file under
src/,extensions/,ui/, orpackages/.The first cut instead inspected changed lines for an
exporttoken, to keep thetrigger narrow. That was wrong in a way worth recording. Barrels export through
multiline
export { ... }lists, so removing a symbol changes a line carrying noexporttoken. And the failure that motivated the scan was an import-onlyedit — it orphaned a re-export in a barrel the diff never touched, which no
changed-line rule can see by construction. The heuristic would not have caught its
own motivating bug. Path selection also drops the merge-base lookup, so a shallow
checkout or unrelated history can no longer silently skip the scan.
Cost, stated plainly: this fires for most PRs touching
src/, including colocatedtests (the full-tree knip scan reads tests, so a deleted last consumer can orphan
an export there too). Those paths already enable a non-docs lane, which already
routes the whole check remotely, so knip's ~60-90s lands on a box already doing
heavy work rather than on a laptop.
OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1optsout, and the step name says so.
2. Diagnostics only. Each component is compared individually against the same
anchor and the differing ones are named. The refusal, its exit code, the
classification table, and the dev-wrapper opt-in are untouched. The explicit
refs/remotes/origin/main:form is preserved per component, so the documentedanti-spoofing property (a local ref shadowing the DWIM name
origin/main) stillholds.
User Impact
For agents and maintainers landing PRs:
check:changednow catches the dead-exportclass before CI, and a wrapper-mismatch refusal says which component drifted.
No CI behavior changes.
check:changedgains one conditional step.Evidence
node scripts/run-vitest.mjs test/scripts/changed-lanes.test.ts test/scripts/pr-review-artifact-validation.test.ts test/scripts/pr-wrappers.test.ts— 3 files, 179 tests passednode scripts/check-script-declarations.mjs— 244 declaration contracts matchbash -n scripts/pr— cleanNew coverage: scan selection across core/extension/ui/package source and an
import-only edit, with negative cases for the docs and scripts trees plus
non-source files (
.md,.sql) inside scanned trees; plan membership on both thepositive path and the skip env var.
The wrapper diagnostic was verified live: run from this branch it prints
differing wrapper components vs origin/main: scripts/pr, which is exactly thedrift this PR introduces.
Dropped from this PR
A third change added
scripts/pr review-artifacts-repinto re-pin reviewartifacts after a push, replacing manual SHA edits in two files. It is reverted in
216deb5daecand is not proposed here.Review caught that it defeats the property the identity pin enforces: it rewrote
the pinned PR number and head SHA while keeping every recommendation, finding, and
Markdown conclusion, so a completed
READY FOR /prepare-prverdict authoredagainst one revision could be relabelled as covering another and still pass
validation. The test written alongside it restamped PR #7 as PR #42 and asserted
success — the exact substitution the fail-closed gate was built to stop.
Re-authoring after the head moves is friction on purpose: the code the verdict
describes may not be the code being landed. A safe version must prove the reviewed
content is equivalent across the move, which is a design decision about what
equivalence means rather than a convenience wrapper, so it needs its own
discussion.
Note for reviewers
Because this PR edits
scripts/pr, the wrapper trust gate correctly refuseslanding subcommands from its own branch. The landing flow is driven from a
detached worktree pinned at
origin/main. That is inherent to the trust boundary,but it is undocumented; a line in
scripts/CLAUDE.mddescribing the anchor-worktreepattern would save the next agent the discovery.