Skip to content

fix: resolve the deferred {{.Home}} token on machine venues - #188

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/machine-venue-home-token
Aug 29, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/machine-venue-home-token

Conversation

@atrawog

@atrawog atrawog commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes opencharly/charly#460: a candy's copy: step silently fails to deliver on a
target: vm / target: local deploy.

Root cause. A home-relative copy: to: ${HOME}/... is tokenized at compile into
{{.Home}}/... so each emit target resolves it against the destination home — the
deliberate design recorded in install_build.go ("Tokenize a home-relative to: so each
EmitTarget resolves it against the real destination home at emit"). The OCI target does
that, in OCITarget.emitPlan:

if t.Home != "" {
    ResolveHome(plan, t.Home)   // spec.ResolveHome: `case *OpStep: s.To = sub(s.To)`
}

The machine-venue walk had no equivalent. walkOp passed step.To straight to
PutFile, so the literal token reached the venue.

Observed on a live Arch guest — the file is delivered, just to a directory literally
named {{.Home}}:

$ ls -la ~/copyprobe
-rw-r--r--  written.txt          # write: applied
                                 # copy:  absent

$ sudo find / -xdev -name copied.txt
/home/arch/{{.Home}}/copyprobe/copied.txt

$ ls -la ~
drwxr-xr-x  copyprobe
drwxr-xr-x  {{.Home}}            # created by the unresolved token

No error is raised, which is why it went unnoticed: mkdir:, write: and command: from
the same candy in the same deploy all apply normally, because those legs render shell that
expands $HOME at runtime. Only the PutFile-staged verbs are affected.

Why it matters beyond one candy: pod-sway delivers both its sway-wrapper and its
config via copy:, so a target: vm deploy of the sway stack lands a compositor whose
launcher is in a junk directory.

The fix

WalkPlans resolves the token before any step runs, across the same field set
spec.ResolveHome covers, so the machine venue and the OCI target resolve the same places
rather than drifting (R3). Three details worth reviewing:

  • Lazy probe. Only a plan that actually carries the token pays the extra RunCapture,
    so the common case costs nothing.
  • One probe implementation. ensureVenueManagedBlock carried its own inline
    printf %s "$HOME"; both now call probeVenueHome.
  • Empty home is a no-op, not an empty substitution — a failed probe must not silently
    rewrite ${HOME}/x into /x.

The field list lives in one function (homeBearingFields) that both the predicate and the
resolver read, so a future view field cannot be added to one and forgotten in the other.

How tested

The regression test fails without the fix. Neutralising only the resolution call, with
the helpers left in place, reproduces the live symptom exactly:

--- FAIL: TestWalkPlans_ResolvesHomeTokenForCopy
    copy did not land at the resolved home path "/home/u/probe/copied.txt";
    PutFile saw [{{.Home}}/probe/copied.txt]
    PutFile destination still carries the unresolved token: "{{.Home}}/probe/copied.txt"
--- FAIL: TestWalkPlans_ExplicitHomeOptWins
    explicit WalkOpts.Home not honoured; PutFile saw [{{.Home}}/m]

With the fix restored:

--- PASS: TestWalkPlans_ResolvesHomeTokenForCopy
--- PASS: TestWalkPlans_ExplicitHomeOptWins
--- PASS: TestStepCarriesHomeToken
--- PASS: TestResolveStepHomeNoopOnEmptyHome
ok  github.com/opencharly/sdk/kit

TestStepCarriesHomeToken walks every field family (To, Dest, ExtractDest,
UnitPath, UnitText, Snippet, Destination, EnvVars, PathAdd, PathAppend),
asserting each is both detected and resolved, and that a token-free step does not
trigger a probe.

Full module, no regressions:

$ GOWORK=off go test ./...     TEST_EXIT=0   (10 packages ok, 0 failures)
$ GOWORK=off go vet ./...      (clean)
$ gofmt -l kit/walk.go kit/walk_home_token_test.go   (clean)

gofmt -l kit/ also reports kit/install_ledger_test.go; that is pre-existing —
verified identical on pristine HEAD before this branch — and untouched here.

Live acceptance is not in this PR, and why

The end-to-end proof needs plugin-deploy-vm rebuilt against this sdk, which means this
tag first, then that plugin's pin. The minimal reproducer is committed in the issue and
reproduces in ~2 minutes on a disposable Arch cloud-image VM bed:

- run: mkdir: "${HOME}/copyprobe"
- run: copy: marker.txt   to: "${HOME}/copyprobe/copied.txt"
- run: write: "${HOME}/copyprobe/written.txt"

Before: only written.txt in ~/copyprobe, copied.txt under ~/{{.Home}}/. The unit
test above encodes exactly that assertion at the seam where the defect lives, which is why
it fails without the change.

Rulebook compliance

  • R1 — root-caused to the specific missing call by tracing the OCI target's
    ResolveHome and confirming the token on a live guest; the fix addresses the cause, not
    the symptom.
  • R3 — reuses spec.HomeToken and mirrors spec.ResolveHome's field set instead of
    inventing a second notion of "home-bearing"; the duplicated inline $HOME probe is
    collapsed into one helper.
  • R4 — no defensive || true, no path-guessing fallback: an unresolvable home is an
    explicit no-op.
  • Scope — one function plus its helpers and a test file; no behaviour change for plans
    that carry no token.

Change classification

  • Change class: bug fix in the deploy walk (sdk/kit), plus a regression test.
  • Verification gate: go test ./... on the module, go vet, gofmt, and a negative
    control proving the test fails without the fix.
  • Attribution tier: analysed on a live system — the defect was measured on a live
    guest and the fix is unit-proven at the seam, but the end-to-end rerun needs the
    downstream repin described above, so the stronger tier would overstate it.

Assisted-by: Claude Code claude-opus-5[1m] (analysed on a live system)

A home-relative `copy: to: ${HOME}/...` is TOKENIZED at compile into
"{{.Home}}/..." so each emit target resolves it against the DESTINATION home. The
OCI target does that (OCITarget.emitPlan -> spec.ResolveHome). The machine-venue
walk had no equivalent, so the literal token reached PutFile and the file landed in
a directory named "{{.Home}}" inside the venue home - silently, with no error, while
the sibling mkdir/write/command verbs in the same candy applied normally.

Measured on a live Arch guest: /home/arch/{{.Home}}/copyprobe/copied.txt.

WalkPlans now resolves the token across the same field set spec.ResolveHome covers,
before any step runs, so the machine venue and the OCI target resolve the same
places. The venue home is probed LAZILY - only a plan that actually carries the
token pays the extra RunCapture - and that probe is now one helper shared with the
env.d managed-block finalizer, which carried its own inline copy.

An unresolvable home is a no-op rather than substituting empty, so a failed probe
cannot silently rewrite ${HOME}/x into /x.

Closes opencharly/charly#460.

Claude-Session: https://claude.ai/code/session_016fnPmYiC6ZkqXSi6D8PAP6
@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: 1195d59d3ace (branch: fix-home-token-machine-venues)

Security screen: PASS — no scope mismatch (diff matches the described fix exactly), no secrets/exfiltration, no network calls, no weakened guardrails, no supply-chain changes, no embedded directives.

Checklist: All applicable rules PASS or NA.

  • A1/A2/A3 — Body is complete: real summary accounting for both changed files, root cause, how-tested with pasted output, rulebook compliance, and an honest, non-inflated attribution tier (analysed on a live system — the end-to-end bed run genuinely requires the downstream plugin repin, which is a self-gating cross-repo dependency; the unit test encodes the assertion at the seam and the negative control proves it fails without the fix). Footer ends with the *Assisted-by:* line.
  • R1 — Defect root-caused to the missing ResolveHome equivalent in the machine-venue walk, confirmed on a live guest; zero warnings in the PR's own gate output.
  • R2 — No out-of-scope split. The disclosed install_ledger_test.go gofmt issue is in a file this PR does not touch, verified pre-existing on pristine HEAD, and the PR's own files are gofmt-clean — transparent disclosure, not a parked defect of this change.
  • R3 — Duplication reduced: the two inline $HOME probes collapse into one probeVenueHome; homeBearingFields is the single source of truth for both predicate and resolver, mirroring spec.ResolveHome's field set.
  • R4 — No ad-hoc workarounds; empty home is an explicit no-op, not a path-guessing fallback.
  • R10 — Regression test fails without the fix (negative control pasted) and passes with it; full module go test ./... (10 pkgs, 0 failures), go vet clean, gofmt clean on touched files.
  • B16 placement — CORRECT: the fix lives in the existing sdk kit walk mechanism; no new core import, no alias file, no capability pulled into core.
  • B15 — Single atomic commit; no partial/split work.
  • B18 — Code is gofmt/vet-clean; no dead code, no shadowing, no lint-visible issues in the diff.

Verdict: PASS


ollama/deepseek-v4-flash — pi-review-action.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) August 29, 2026 21:17
@github-actions
github-actions Bot merged commit 446ef72 into main Aug 29, 2026
1 check passed
charly-auto-merge Bot added a commit that referenced this pull request Aug 29, 2026
github-actions Bot pushed a commit to opencharly/plugin-deploy-vm that referenced this pull request Aug 29, 2026
…#3)

This plugin walks deploy plans via kit.WalkPlans, which until sdk
v0.2026241.2117 never resolved the deferred {{.Home}} token on a machine venue. A
candy's home-relative `copy: to: ${HOME}/...` therefore reached PutFile carrying the
literal token and landed in a directory named "{{.Home}}" inside the guest home -
silently, while the sibling mkdir/write/command verbs applied normally.

The fix is in the sdk (opencharly/sdk#188); this repin is what delivers it to
target: vm deploys.

Verified end to end on a disposable Arch cloud-image VM bed: the reproducer's copy
assertion fails on the old pin and passes on this one.

Refs opencharly/charly#460.

Claude-Session: https://claude.ai/code/session_016fnPmYiC6ZkqXSi6D8PAP6
github-actions Bot pushed a commit to opencharly/plugin-installstep that referenced this pull request Aug 29, 2026
…#2)

This plugin walks deploy plans through kit.WalkPlans, which until sdk
v0.2026241.2117 never resolved the deferred {{.Home}} token on a machine venue. A
candy's home-relative copy: to: ${HOME}/... therefore reached PutFile carrying the
literal token and landed in a directory named "{{.Home}}" in the venue home -
silently, while the sibling mkdir/write/command verbs applied normally.

The fix is in the sdk (opencharly/sdk#188); this repin delivers it to install-step execution on machine venues.

Refs opencharly/charly#460.

Claude-Session: https://claude.ai/code/session_016fnPmYiC6ZkqXSi6D8PAP6
github-actions Bot pushed a commit to opencharly/plugin-deploy-local that referenced this pull request Aug 29, 2026
…#3)

This plugin walks deploy plans through kit.WalkPlans, which until sdk
v0.2026241.2117 never resolved the deferred {{.Home}} token on a machine venue. A
candy's home-relative copy: to: ${HOME}/... therefore reached PutFile carrying the
literal token and landed in a directory named "{{.Home}}" in the venue home -
silently, while the sibling mkdir/write/command verbs applied normally.

The fix is in the sdk (opencharly/sdk#188); this repin delivers it to target: local host deploys.

Refs opencharly/charly#460.

Claude-Session: https://claude.ai/code/session_016fnPmYiC6ZkqXSi6D8PAP6
github-actions Bot pushed a commit to opencharly/plugin-deploy-pod that referenced this pull request Aug 29, 2026
…#5)

This plugin walks deploy plans through kit.WalkPlans, which until sdk
v0.2026241.2117 never resolved the deferred {{.Home}} token on a machine venue. A
candy's home-relative copy: to: ${HOME}/... therefore reached PutFile carrying the
literal token and landed in a directory named "{{.Home}}" in the venue home -
silently, while the sibling mkdir/write/command verbs applied normally.

The fix is in the sdk (opencharly/sdk#188); this repin delivers it to pod deploys (overlay candies applied onto a running pod).

Refs opencharly/charly#460.

Claude-Session: https://claude.ai/code/session_016fnPmYiC6ZkqXSi6D8PAP6
@aitrawog
aitrawog deleted the fix/machine-venue-home-token branch September 25, 2026 19:08
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.

copy: step is not applied on a target: vm deploy (mkdir/write/command from the same candy are)

1 participant