Skip to content

fix(harness): charly_worktree_remove must not report a removal it never performed (#410) - #426

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/harness-bindings
Oct 7, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/harness-bindings

Conversation

@aitrawog

@aitrawog aitrawog commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Cluster C8's opencharly/opencharly#410. scripts/check-pi-gates.mjs asserted the pi gate
extension by matching its text, so the surface was "asserted by nothing" that could see
behaviour. This change fixes the defect the text could not see and gives the surface the gate
that can.

The defect (root cause, proven from the shipped pi runtime, not inferred). charly-gates.ts
wrapped its git worktree remove in try { … } catch { … --force … }. pi.exec never rejects:
pi 1.0.4's exec delegates to execCommand, whose promise resolves {stdout, stderr, code, killed} in every branch, its own internal catch included. So the --force retry was unreachable
dead code and a removal git had refused printed success.

The fix. Every recovery step is driven by the observed result (code/stderr), never a
rejection; a refused removal returns isError: true instead of a success string; the report
carries the observed effect (removed). The branch arm replaces the retired ancestry test
git branch --merged origin/main — blind to the org's squash landing, so every landed feat/
branch leaked — with a squash-true patch-id proof (git cherry -> - <sha>) and -D, and an
unlanded branch is kept and named as kept. The legacy ancestry path is deleted, not left
beside the new one.

The gate. scripts/check-pi-gates.mjs now also loads the shipped module (Node's native
type-stripping, a stand-in for its only runtime bare import typebox, and an ExtensionAPI
stub whose exec mirrors the proven real contract) and fires the gate and the tool against
real git repositories. No assertion was weakened: the aggregated static reading is unchanged and
all 12 pre-existing mutations still go red.

How tested

The change-class gate is scripts/check-pi-gates.mjs — the file this diff edits. The umbrella
carries no per-repo workflow beyond tag-on-merge.yml (discovered, not assumed:
gh api repos/opencharly/opencharly/contents/.github/workflows --jq '.[].name' ->
tag-on-merge.yml), so the gate that owns this change class IS the scripts/check-*.mjs family.
Every command below was executed on head
f128afda5d4881ec9c7d6d1cb95a72b91b47182f; the gate is charly-free, so its transcript is
warning-free — zero WARNING lines.

$ node scripts/check-pi-gates.mjs
  PASS  .pi/extensions/charly-gates.ts: fails closed, rule-2 paths, gate wiring + SOUL injection present, and the worktree materializes a scoped module set from the shared object cache
  PASS  .pi/extensions/charly-gates.ts FIRED: the tool_call gate BLOCKS a hook-bypassing commit (real pre-commit-gate.sh) and ALLOWS a benign command
  PASS  .pi/extensions/charly-gates.ts FIRED: before_agent_start re-injects the project-root SOUL.md identity every turn
  PASS  charly_worktree_remove FIRED: the --force escalation is reachable — a dirty worktree is really gone
  PASS  charly_worktree_remove FIRED: a refused removal FAILS and reports removed=false, never success
  PASS  charly_worktree_remove FIRED: a SQUASH-merged branch is deleted (patch-id containment, not ancestry)
  PASS  charly_worktree_remove FIRED: an UNMERGED branch survives and the report says KEPT, not deleted
  PASS  charly_worktree_remove FIRED: reports the OBSERVED effect (a surviving directory is removed=false)
check-pi-gates: OK
gate exit=0

The self-test output is pasted in full — all 18 mutation lines, then the unmutated-copy check
and the terminal line. The earlier revision of this body pasted only the last 7 lines while
claiming 18; that mismatch was mine and it is corrected here rather than re-counted:

$ node scripts/check-pi-gates.mjs --self-test
  PASS  mutation 'fail-open' is caught (gate red)
  PASS  mutation 'fail-open on absent gate' is caught (gate red)
  PASS  mutation 'worktree path' is caught (gate red)
  PASS  mutation 'unparseable' is caught (gate red)
  PASS  mutation 'no gate wiring' is caught (gate red)
  PASS  mutation 'no tool_call' is caught (gate red)
  PASS  mutation 'no SOUL injection' is caught (gate red)
  PASS  mutation 'graph-wide submodule init' is caught (gate red)
  PASS  mutation 'no object cache' is caught (gate red)
  PASS  mutation 'required module set emptied' is caught (gate red)
  PASS  mutation 'modules can DROP the required set' is caught (gate red)
  PASS  mutation 'no modules argument' is caught (gate red)
  PASS  mutation 'dead --force escalation (#410)' is caught (gate red)
  PASS  mutation 'a refused removal reported as success (#410)' is caught (gate red)
  PASS  mutation 'ancestry test for the branch — blind to a squash (#410)' is caught (gate red)
  PASS  mutation 'a surviving directory reported as removed (#410)' is caught (gate red)
  PASS  mutation 'gate exit 2 treated as ALLOW (static checks stay green)' is caught (gate red)
  PASS  mutation 'SOUL read but not injected (static checks stay green)' is caught (gate red)
  PASS  the unmutated copy is GREEN
check-pi-gates --self-test: OK (every assertion is live)
self-test exit=0

That is 12 pre-existing mutations plus the 6 added here, i.e. the 18 the count refers to.

R7 — the new coverage FAILS without the change. The same gate, run with --root against a
copy of the merge-base extension (sha 91e61db7228ef42f813d39a08d4d51e61efefbbb), keeps the
static reading green — the old gate was blind — and turns 5 of the 7 fired assertions RED:

$ git show $(git merge-base origin/main HEAD):.pi/extensions/charly-gates.ts > /tmp/hb-old/.pi/extensions/charly-gates.ts
$ node scripts/check-pi-gates.mjs --root /tmp/hb-old
  PASS  .pi/extensions/charly-gates.ts: fails closed, rule-2 paths, gate wiring + SOUL injection present, and the worktree materializes a scoped module set from the shared object cache
  PASS  .pi/extensions/charly-gates.ts FIRED: the tool_call gate BLOCKS a hook-bypassing commit (real pre-commit-gate.sh) and ALLOWS a benign command
  PASS  .pi/extensions/charly-gates.ts FIRED: before_agent_start re-injects the project-root SOUL.md identity every turn
  FAIL  charly_worktree_remove FIRED: the --force escalation is reachable — a dirty worktree is really gone
  FAIL  charly_worktree_remove FIRED: a refused removal FAILS and reports removed=false, never success
  FAIL  charly_worktree_remove FIRED: a SQUASH-merged branch is deleted (patch-id containment, not ancestry)
  FAIL  charly_worktree_remove FIRED: an UNMERGED branch survives and the report says KEPT, not deleted
  FAIL  charly_worktree_remove FIRED: reports the OBSERVED effect (a surviving directory is removed=false)
check-pi-gates: 5 finding(s)
oldcode exit=1

The two fired assertions that stay green there (the gate's BLOCK decision and the SOUL
re-injection) are correct: that wiring was already sound; they are pinned so a future
weakening is caught, and the two --self-test mutations that keep every static assertion green
while breaking them show they are not decorative.

The sibling harness surfaces are unchanged and still green on this head:

$ node scripts/check-harness-config.mjs | tail -2
  PASS  no two families share a marketplace skill directory name (collisions: none)
  PASS  every marketplace/<family>/skills/<name>/SKILL.md is bound by a .dsh/skills/<name> entry (351 corpus skills, missing: none)
check-harness-config: OK
exit 0

$ node scripts/check-opencode-plugin.mjs | tail -2
  PASS  real pre-commit-gate.sh ALLOWS `git commit -m ok` (exit 0)
  SKIP  live opencode layer (set LIVE_OPENCODE=1 to run the real binary end to end)
check-opencode-plugin: OK
exit 0

The R5 sweep, with its command and output pasted:

$ git grep -n 'branch --merged' -- . ':!CHANGELOG'
.pi/extensions/charly-gates.ts:594:      // (`git branch --merged origin/main`) proved ANCESTRY, which the org's squash landing
scripts/check-pi-gates.mjs:273:    //      origin/main, so the retired `git branch --merged` never fired and every landed
grep exit=0

Exactly two hits, both explanatory comments written by this change; the executed mechanism is
gone from the extension. The third hit is the --self-test mutation that restores the retired
command verbatim, which is why the mutation proves the assertion is live.

Host-condition notice in the supplementary hook transcript — RCA, not a dismissal. The
clone-level pre-commit hook (hooks/pre-commit, installed via core.hooksPath=hooks) was run on
this head and exited 0, printing pre-commit: OK; it runs task policy-b, task self-test, this
file and the four sibling check-*.mjs gates. Its two charly-driven steps emit the dev-build
notice, which a previous revision of this body disposed of with a parking phrase. That is
corrected here with the RCA the org already settled, read from the emitting code rather than
asserted:

  • Emitting code. charly/charly/plugin_loader.go: warnSkippedFHSPlugins() (:452-465) prints
    it once per process; it is called from bakedPluginDirs() at :490 under if !packagedInstall().
  • Condition, measured on this host. It is a HOST fact, not a property of the diff: it fires
    when the running binary is not at /usr/bin or /usr/local/bin AND /usr/lib/charly/plugins
    holds *.providers — both true here (command -v charly -> /usr/bin/charly, but the
    worktree binary is not FHS-installed; ls /usr/lib/charly/plugins/*.providers | wc -l -> 10).
  • Independence from this diff, measured. A command that reads no project file at all emits it:
    ./charly/bin/charly version prints 2026.280.1725 on stdout and the notice on stderr,
    exit 0. No file this PR touches is read.
  • Why it cannot be eliminated here (the operator's named warning-free route, measured
    UNAVAILABLE).
    opencharly/.github#172 records the achievable route as "a host without the
    FHS charly package, or a run from an installed charly binary". On this host the installed
    binary is too old for this tree's schema, so it cannot run the gate at all:
    /usr/bin/charly version -> 2026.268.1917, and /usr/bin/charly task policy-b ->
    charly: error: command "task": load project: …/charly/charly.yml:doc0: node check-kubevirt-vm-vmi: cue decode: cpu: cannot use value {cores:2} (type struct) as int,
    exit 1. The worktree-local build is therefore REQUIRED here (R9), and a charly-driven
    transcript cannot be warning-free on this host.
  • Named homes that carry it. opencharly/charly#801 (CLOSED, NOT_PLANNED — operator
    disposition: "leave it, disclose, don't land … every worktree-produced gate transcript carries
    the notice with a one-line disclosure") and opencharly/.github#172 (CLOSED, refuted: "No
    rulebook or org-variable change is made or sought"; the residual B5-wording question is
    operator-owned). No new issue is filed because both homes are already adjudicated, and filing
    a third would be a duplicate of a settled matter.
  • Not used, deliberately. CHARLY_PLUGIN_ONLY=1 silences it, and BOTH adjudications rule that
    out: .github#172 calls it "a resolution switch / masking, not a fix", and charly#801 states
    it "is not to be used as a log filter to silence it". Using it would be the R4 workaround
    this evidence contract exists to catch, so the notice is disclosed instead of hidden.

RDD spike (the cluster's named unknown, run FIRST). The ledger asks: load each harness
config and FIRE its gate, not merely parse it. Spike (/tmp/hb-spike/spike.mjs, thrown away):
mkdtemp a scratch root, copy the REAL .claude/hooks/ gates + the REAL extension + SOUL.md,
write a 6-line typebox stand-in, import under Node 26 type-stripping, drive the handlers with a
stub ExtensionAPI. It LOADS and FIRES, and it confirmed this defect before the fix — the tool
printed Worktree …/.worktrees/spike-dirty and branch feat/spike-dirty removed. while the
directory survived and the exec log held exactly ONE worktree remove call, no escalation. Its
own narrow copy of .claude/hooks/ (two .sh files, no sibling gitcmd.py) is what produced a
ModuleNotFoundError that made the gate fail closed; the shipped gate copies the directory
whole. That mechanism is what this change ships.

Rulebook compliance

  • R0 — skills first: git-workflow, strict-policy and agents loaded before the first
    action, and git-workflow's pre-validator self-audit reference re-read at the push step.
  • R1 — RCA every anomaly: four anomalies, each root-caused and fixed or routed with a named
    home: (a) the first commit was blocked by pre-commit: charly binary missing — the session
    worktree had no charly/ materialized; fixed by materializing with --reference and building
    the worktree-local binary (R9), no bypass; (b) the spike's ModuleNotFoundError was its own
    narrow copy set, fixed by copying .claude/hooks/ whole; (c) my first commit message carried
    unmeasured counts (it said six original mutations and "20/20"), measured and corrected to 18/12
    while still unpushed; (d) the host-condition notice, above, with its emitting code, its
    measured condition, its measured independence, its unavailable named alternative, and the two
    closed adjudications that carry it. The owning gate's transcript is warning-free.
  • R2 — finish the cutover: the retired ancestry mechanism is deleted in the same commit; both
    polarities (squash-merged and unmerged) and both removal outcomes (removed and refused) are
    fixed and asserted here; no follow-up PR and no unowned deferral. The host-condition notice is
    routed to its named, already-adjudicated homes rather than parked.
  • R3 — no duplication: the fired assertions sit beside the static readings rather than
    replacing them, because they prove a DIFFERENT claim (the static ones still catch a renamed
    path or a dropped hook; firing catches a wrong contract). One load-and-fire helper serves all
    seven fired assertions and one shared mutation list serves all 18. No third issue is filed for
    a matter two closed issues already own.
  • R4 — no workarounds: no sleep, no retry, no fallback that hides the failure; the recovery
    step is driven by the observed exit code and a refusal fails loudly. CHARLY_PLUGIN_ONLY=1 is
    NOT used to silence the notice, per both adjudications. Where the RDD probe could not reach a
    state with real git, the guard was not shipped as an unreachable branch — the effect became
    asserted data with a reachable fixture on both polarities.
  • R4a — fix the product first: the tool is fixed before its gate, and the tool's own
    description: is corrected in the same commit so the prose cannot advertise a removal
    capability it does not have.
  • R5 — delete legacy completely: pasted above — the retired git branch --merged origin/main
    is gone from the shipped extension, with the claim-keyed grep and its output.
  • R6 — git safety: git status --short clean after the commit; no force-push, no history
    rewrite, no hook bypass. The one blocked commit attempt was resolved with the remedy the gate
    itself names (git commit -F <file>), never --no-verify; the branch was amended only while
    still unpushed.
  • R7 — prove behaviour, not compilation: pasted above; the changed path ran live and the
    coverage fails without the change (5 RED on the merge-base extension).
  • R7a — live or skip: the fired assertions run the REAL .claude/hooks/ gate scripts and real
    git in real repositories; no mock of git and no mock of the gates. The only stand-ins are the
    harness API itself, and ExtensionAPI.exec deliberately mirrors the contract read out of the
    shipped pi binary and its upstream source rather than a convenient one.
  • R8 — preserve emitted artifacts: the tool's returned details and text are the artifact
    under test; the assertions read details.removed, details.branchState and the text.
  • R9 — binary equals source: the gate ran on this head through the worktree-local build
    charly/scripts/bootstrap-charly.sh produced (2026.280.1725), never a shared install — and
    the installed /usr/bin/charly is measurably incompatible with this tree, above.
  • R10 — fresh disposable proof: no disposable target is affected (a harness-config extension
    and its umbrella gate script; no runtime, image, pin or gitlink change), so the owning gate is
    the scripts/check-*.mjs family plus the changed path executed live — both pasted above.
    charly task verify is not the gate here.

Change classification

Non-.md, code/config change class: git diff --stat $(git merge-base origin/main HEAD)..HEAD
lists .pi/extensions/charly-gates.ts and scripts/check-pi-gates.mjs only (2 files, 348
insertions, 24 deletions). documentation reviewed is therefore forbidden. R10 gate: the
scripts/check-*.mjs family owning this change class, on the final committed tree, plus the
changed path executed live. Attribution tier: fully tested and validated — the change-class
gate passed on the final tree with zero findings, the changed path was executed live, and the
gate's own transcript carries zero warnings.

Closes #410.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

…er performed (#410)

`pi.exec` RESOLVES on a non-zero exit: pi 1.0.4's `exec` delegates to `execCommand`, whose
promise resolves `{stdout, stderr, code, killed}` in EVERY branch, its own internal catch
included. The `catch`-gated `--force` retry was therefore unreachable dead code, and a
removal git had refused printed success — measured: ONE `worktree remove` call in the exec
log while the worktree was still registered in `git worktree list`.

- drive every recovery step from the observed RESULT (`code`/`stderr`), never a rejection;
- a refused removal FAILS (`isError: true`) instead of printing success;
- report the OBSERVED effect (`removed`), so what it says happened is what happened;
- replace the ancestry test `git branch --merged origin/main` — blind to the org's squash
  landing, so every landed `feat/` branch leaked — with a squash-true patch-id proof
  (`git cherry`, `- <sha>`), and KEEP an unlanded branch, saying so instead of claiming it
  was removed.

The gate that owns this surface read the extension's TEXT and stayed green through all of
it: `scripts/check-pi-gates.mjs` now also LOADS the shipped module (Node type-stripping,
stand-ins for its only runtime bare import and for `ExtensionAPI`, whose `exec` mirrors the
proven real contract) and FIRES the gate and the tool against real git repositories. The
gate now prints 8 PASS lines — 1 aggregated static reading (properties 1-5) plus 7 FIRED
assertions; all 18 self-test mutations are caught. Against origin/main's extension the
static reading still PASSES and 5 of the 7 fired assertions go RED (the other two, the
gate's BLOCK decision and the SOUL re-injection, pass there too — that wiring was sound).

No assertion was weakened: the static reading is unchanged and all 12 original mutations
still go red.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Review — BLOCK

Head SHA: f128afda5d4881ec9c7d6d1cb95a72b91b47182f (branch: feat/harness-bindings)

Change class: code/config (.pi/extensions/charly-gates.ts + scripts/check-pi-gates.mjs) — not docs-only, so a runtime/behavioural gate is required (supplied).

Comment thread: 0 comments — nothing to disposition.

Blocks

  1. A1 / B12 / rule 4 — the pasted self-test evidence contradicts the body's own count. The body states grep -c "is caught (gate red)" over the self-test run is 18 — the 12 original mutations plus the 6 added here, yet the pasted --self-test output shows exactly 6 is caught (gate red) lines followed immediately by the terminal lines (PASS the unmutated copy is GREEN, check-pi-gates --self-test: OK, exit 0). A run whose full output carries 18 such lines cannot also terminate right after the 6th. The claim (18) and the pasted run (6) cannot both be true, and I cannot reconcile the count from the diff (the diff only shows the 6 appended entries; the pre-existing 12 are not visible). Fix: paste the complete self-test output (all 18 lines) or explicitly mark the elision in the pasted block — an unreconciled result is a BLOCK.

  2. R1 / B5 — two surviving WARNING lines in the gate output are dismissed, not fixed or routed. The body itself reports that the umbrella pre-commit gate output contains two informational WARNING: charly is a dev/worktree build … lines, and disposes of them as "independent of this diff". R1 requires every surfaced warning to carry an RCA and a real fix, and "independent of this diff" is the forbidden pre-existing/out-of-scope dismissal (R2) — a parking phrase is a finding unless it names an exit this PR advances, and no thematic batch is named here. Fix: eliminate the warning or route it to its NAMED batch cutover in the body; do not land with a dismissed warning in the gate output.

Note (non-blocking)

  • The R5 sweep claim ("grep -rn "branch --merged" … returns only this change's own explanatory comments and the mutation") is verifiable from the diff (the only hits are the explanatory comment in charly-gates.ts and the restoring mutation in check-pi-gates.mjs), but B14(d) requires the executed command and its output to be pasted, which the body does not do. Reconcile by pasting the command output.

Verdict: BLOCK


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Review — PASS

Head SHA: f128afda5d4881ec9c7d6d1cb95a72b91b47182f (branch: feat/harness-bindings)

Security screen: PASS — no injected instructions, secrets, exfiltration, dependency/pin changes, or guardrail weakening; the diff strengthens both the extension gate and its check script.
Checklist: All applicable rules PASS or NA (code/config class; harness-config gate is the scripts/check-*.mjs family, clean and warning-free; placement CORRECT — harness extension + its gate, no core/sdk/candy movement; single atomic commit; fired coverage fails without the change).
Comments: @github-actions[bot] #6047227852 — both findings stale-superseded: the current body pastes all 18 --self-test mutation lines (re-derived: 18 counted, matching 12 pre-existing + 6 added in the diff), and the dev-build notice now carries a measured RCA (emitting code, host condition, measured independence, unavailable alternative) routed to named adjudicated homes with the masking switch refused — the earlier parking-phrase disposition it flagged no longer exists.

Verdict: PASS


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) October 7, 2026 21:34
@github-actions
github-actions Bot merged commit ce1f1d3 into main Oct 7, 2026
1 of 2 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Oct 7, 2026
@aitrawog
aitrawog deleted the feat/harness-bindings branch November 1, 2026 19:09
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.

charly_worktree_remove reports success for a removal it never performed (the --force retry is dead code)

1 participant