Skip to content

feat(tooling): close three agent pre-flight and landing gaps - #115333

Merged
steipete merged 9 commits into
mainfrom
steipete/agent-preflight-landing-tooling
Jul 28, 2026
Merged

steipete merged 9 commits into
mainfrom
steipete/agent-preflight-landing-tooling

Conversation

@steipete

@steipete steipete commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

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:changed could not predict the CI dead-code failure.
scripts/changed-lanes.mjs had no dead-code lane and check-changed.mjs never
invoked knip, so deadcode:exports in the check-dependencies job was invisible
to pre-flight. Concretely: a PR moved two imports off barrels onto their defining
modules, orphaning those barrels' re-exports. check:changed passed (remotely, on
Testbox, exit 0); CI then failed on four Unused exports.

2. The scripts/pr wrapper gate named no files. It compares scripts/pr,
scripts/pr-lib, and scripts/lib/plain-gh.sh as one combined rev-parse and on
mismatch says only "does not match origin/main". In practice scripts/pr itself
was byte-identical and only scripts/pr-lib/worktree.sh had drifted after main
advanced; 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/, or packages/.

The first cut instead inspected changed lines for an export token, to keep the
trigger narrow. That was wrong in a way worth recording. Barrels export through
multiline export { ... } lists, so removing a symbol changes a line carrying no
export token. And the failure that motivated the 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 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 colocated
tests (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=1 opts
out, 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 documented
anti-spoofing property (a local ref shadowing the DWIM name origin/main) still
holds.

User Impact

For agents and maintainers landing PRs: check:changed now catches the dead-export
class before CI, and a wrapper-mismatch refusal says which component drifted.

No CI behavior changes. check:changed gains 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 passed
  • node scripts/check-script-declarations.mjs — 244 declaration contracts match
  • bash -n scripts/pr — clean
  • Codex autoreview on the branch diff

New 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 the
positive 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 the
drift this PR introduces.

Dropped from this PR

A third change added scripts/pr review-artifacts-repin to re-pin review
artifacts after a push, replacing manual SHA edits in two files. It is reverted in
216deb5daec and 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-pr verdict authored
against 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 refuses
landing 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.md describing the anchor-worktree
pattern would save the next agent the discovery.

steipete added 5 commits July 28, 2026 09:48
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.
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: M maintainer Maintainer-authored PR labels Jul 28, 2026
@steipete
steipete marked this pull request as ready for review July 28, 2026 17:35
steipete added 2 commits July 28, 2026 10:43
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.
steipete added 2 commits July 28, 2026 10:54
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.
@steipete
steipete merged commit 68ac905 into main Jul 28, 2026
100 checks passed
@steipete
steipete deleted the steipete/agent-preflight-landing-tooling branch July 28, 2026 18:15
@steipete

Copy link
Copy Markdown
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR scripts Repository scripts size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant