Skip to content

feat(hostenv): resolve paths from the XDG base directory variables - #406

Merged
github-actions[bot] merged 6 commits into
mainfrom
feat/xdg-data-paths-2
Nov 20, 2026
Merged

github-actions[bot] merged 6 commits into
mainfrom
feat/xdg-data-paths-2

Conversation

@aitrawog

@aitrawog aitrawog commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Path resolution now follows the XDG Base Directory Specification, and the XDG bases are
resolved in exactly one place.

  • storeroot.XDG() — the ONE base resolution. It returns the five bases (Data, Config,
    Cache, State, Runtime), applying the specification's Unix defaults and its rule that a
    non-absolute value is invalid and MUST be ignored. Its error fires only when a base had to
    fall back to a RELATIVE default because $HOME was unavailable; an absolute variable
    resolves without $HOME, exactly as the previous os.UserConfigDir/os.UserCacheDir/raw-env
    reads did. Dir and CacheDir build charly's four roots from it (CHARLY_CACHE_DIR is
    unchanged), and hostenv.ExpandHostHome expands an operator-authored $XDG_* token from the
    same values. The runtime base is one decision: XDG_RUNTIME_DIR when absolute, otherwise the
    D-STORE-1 state base — the same value Dir(RootRuntime) uses. An unresolved base (the
    variable unset or relative while $HOME is unavailable) is left as a literal token rather
    than substituted with a relative path.
  • hostenv.ExpandHostHome expands $XDG_DATA_HOME, $XDG_CONFIG_HOME, $XDG_CACHE_HOME,
    $XDG_STATE_HOME and $XDG_RUNTIME_DIR (both $VAR and ${VAR}) alongside ~, $HOME
    and ${HOME}.
  • ResolveVolumesPath / ResolveEncryptedStoragePath default to
    $XDG_DATA_HOME/charly/{volumes,encrypted} instead of a hardcoded ~/.local/share; the
    override and config-file precedence is unchanged and expanded the same way. An absolute
    data variable answers without $HOME.
  • Tests. storeroot/xdg_test.go pins every base, the defaults, the relative-value rule,
    the error contract, the Dir/CacheDir rewiring and the runtime fallback;
    hostenv/xdg_paths_test.go pins the expansion, the defaults, the relative rule, the
    volume/encrypted precedence and both resolvers on a $HOME-less host.

What this makes possible for the deployments: a bind-backed volume host written as
$XDG_DATA_HOME/charly/models/<server> or $XDG_DATA_HOME/charly/volumes/<deploy>/<volume>
moves with a relocated XDG data base on the next charly config, instead of pinning
~/.local/share in the authored config.

Not changed: the four roots' names and the cache semantics. CHARLY_CACHE_DIR still
relocates only the cache root, the runtime root still falls back to the state root when
XDG_RUNTIME_DIR is absent (D-STORE-1), and the content-addressed store is still the only
cache (D-STORE-3).

Supersedes #405, which the validator auto-closed after five verdicts. Every
code finding from that thread is fixed in this head; the only remaining finding was that the
pasted go test ./... output was abbreviated, which this body corrects with the complete,
uncached output below. This is a fresh branch (feat/xdg-data-paths-2) and a fresh thread; the
closed thread is not pushed to, re-run, or reopened.

How tested

Head a83ed926d8293e77a8e229520403566c8ab1b87c.

Complete, uncached run (-count=1), every package line:

$ GOWORK=off go test -count=1 ./...
ok  	github.com/opencharly/spec	0.038s
ok  	github.com/opencharly/spec/cache	0.343s
ok  	github.com/opencharly/spec/calver	0.008s
?   	github.com/opencharly/spec/capability	[no test files]
?   	github.com/opencharly/spec/checkhost	[no test files]
ok  	github.com/opencharly/spec/checkstep	0.018s
ok  	github.com/opencharly/spec/climodel	0.183s
?   	github.com/opencharly/spec/clireflect	[no test files]
ok  	github.com/opencharly/spec/container	4.162s
ok  	github.com/opencharly/spec/cuetoolchain	1.471s
ok  	github.com/opencharly/spec/deploy	0.021s
ok  	github.com/opencharly/spec/exec	9.131s
ok  	github.com/opencharly/spec/exitcode	0.011s
ok  	github.com/opencharly/spec/hostenv	0.018s
?   	github.com/opencharly/spec/http	[no test files]
?   	github.com/opencharly/spec/internal/cuesetup	[no test files]
?   	github.com/opencharly/spec/internal/schemagen	[no test files]
ok  	github.com/opencharly/spec/internal/wiregen	0.101s
?   	github.com/opencharly/spec/loader	[no test files]
ok  	github.com/opencharly/spec/lock	1.106s
ok  	github.com/opencharly/spec/matchers	0.014s
ok  	github.com/opencharly/spec/merge	0.011s
ok  	github.com/opencharly/spec/needsolver	0.005s
ok  	github.com/opencharly/spec/ops	0.011s
ok  	github.com/opencharly/spec/phase	0.010s
ok  	github.com/opencharly/spec/poll	0.221s
ok  	github.com/opencharly/spec/proc	2.271s
ok  	github.com/opencharly/spec/proto	1.258s
ok  	github.com/opencharly/spec/refs	17.528s
ok  	github.com/opencharly/spec/report	0.034s
ok  	github.com/opencharly/spec/retired	0.328s
?   	github.com/opencharly/spec/retired/cmd/retired-sweep	[no test files]
ok  	github.com/opencharly/spec/schema	21.735s
ok  	github.com/opencharly/spec/schemacompose	0.855s
ok  	github.com/opencharly/spec/schemaconcat	0.006s
ok  	github.com/opencharly/spec/schemaparams	0.701s
ok  	github.com/opencharly/spec/schemaretag	0.009s
?   	github.com/opencharly/spec/shellquote	[no test files]
ok  	github.com/opencharly/spec/spec	2.887s
?   	github.com/opencharly/spec/sshx	[no test files]
ok  	github.com/opencharly/spec/storeroot	0.012s
?   	github.com/opencharly/spec/testkit	[no test files]
ok  	github.com/opencharly/spec/transport	0.218s
[exited with code 0]
$ GOTOOLCHAIN=go1.26.8 golangci-lint run ./hostenv/... ./storeroot/...
0 issues.
[exited with code 0]

$ gofmt -l hostenv storeroot      # no output

pinXDG(t, home) used by TestXDGResolvesEveryBase is the existing helper in the unchanged
storeroot/roots_test.go (it pins HOME, every XDG variable and CHARLY_CACHE_DIR); it is not
new in this diff, and the package compiles and passes.

The tests fail on the unchanged tree: hostenv's assertions expect a resolved $XDG_* token
the old ExpandHostHome left literal; Dir/CacheDir return the relative value the old
callers accepted instead of the specification default; the runtime test catches the old bare
!= "" branch; the $HOME-less tests catch the all-or-nothing error contract and the
volume/encrypted fallback; and storeroot/xdg_test.go references XDG()/Bases, which do not
exist there. Each expected path is spelled out, not derived from the implementation.

Rulebook compliance

  • R0: /charly-internals:go, /charly-core:deploy, /charly-core:charly-config and this
    repo's AGENTS.md loaded before the edit.
  • R1: all findings from the predecessor thread are fixed in this head; the round RCAs are
    on feat(hostenv): resolve paths from the XDG base directory variables #405. The model-cache/state volume split that surfaced while this change
    was open is filed as Split model caches from per-deploy state and share them across the AI stack and its beds distro-cachyos#215 and listed under ## Filed issues.
  • R2: one implementation of the base resolution, storeroot.XDG(). The private
    xdgBaseDir/xdgRuntimeDir predicate is gone; Dir, CacheDir and
    hostenv.ExpandHostHome all consume XDG(), and storeroot/xdg_test.go pins it. Dir does
    not re-read XDG_RUNTIME_DIR: it consumes RuntimeSet and falls back to the state root for
    an unset or relative value (D-STORE-1). No second getenv/IsAbs/default path remains.
  • R3: no sleep, retry or workaround. A relative XDG value falling back to the
    specification default is the specification's rule.
  • R4: no documented command changes; --bind name=path simply accepts the XDG variables.
  • R5: the hardcoded ~/.local/share defaults are replaced in the same change; no alias or
    legacy path is added.
  • R6: git status clean before the edits; no destructive git action, no submodule edit.
  • R7: the changed functions execute in the tests — XDG() for every base, the relative
    rule and the error contract; Dir/CacheDir for a relative value, the runtime fallback and
    the $HOME-less absolute case; ExpandHostHome and the two resolvers for the expansion,
    precedence, $HOME-less case and the unresolved-token rule. The tests fail without the change (above).
  • R8: N/A — no live service boundary.
  • R9: N/A — a library package; the consumer rebuilds its binary at its own gate.
  • R10: the complete Go-module gate (go test -count=1 ./..., gofmt, golangci-lint) ran on
    the final committed tree and its full output is pasted above.
  • R11: no DESIGN shape, field, kind or mechanism is added. D-STORE-1's four roots are
    untouched in name and resolution source; D-STORE-3's cache root is untouched. The change
    corrects the default of an existing operator path setting to the base the specification
    defines and moves the base computation into the existing resolver.

Filed issues

Change classification

Breaking change + rollback: none — on a host with the default XDG values the resolved paths
are byte-identical; on a host with a relocated XDG_DATA_HOME the defaults move to that base,
and on a $HOME-less host an absolute variable still answers, which are the intended
corrections. Rollback is a revert of this squash commit.

Relates to #404 and opencharly/distro-cachyos#215. Supersedes #405.

Agent: owui-full-stack · Claude Code session 00d99c7c-dad9-4d14-be0e-7be094b099e9
Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)

ExpandHostHome now expands $XDG_DATA_HOME, $XDG_CONFIG_HOME, $XDG_CACHE_HOME,
$XDG_STATE_HOME and $XDG_RUNTIME_DIR alongside ~ and $HOME, using the XDG Base
Directory Specification's defaults and ignoring a non-absolute value as the
specification requires. ResolveVolumesPath and ResolveEncryptedStoragePath take
the data-base default ($XDG_DATA_HOME/charly/{volumes,encrypted}) instead of a
hardcoded ~/.local/share, so deploy volume hosts and env_file paths authored with
$XDG_DATA_HOME follow a relocated XDG data base at `charly config` time.
charly's own four roots (D-STORE-1) and the content-addressed cache root
(D-STORE-3) are unchanged.

Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
Review round 1 (R2): the first cut added a second getenv/IsAbs/default predicate in
hostenv. storeroot now exposes XDG(), which resolves the five bases once under the
specification's absolute-path rule; Dir and CacheDir build charly's roots from it, and
hostenv expands an operator-authored $XDG_* token from the same values. No second
implementation of the base resolution remains. storeroot/xdg_test.go pins every base,
the defaults and the relative-value rule.

R1: the model-cache volume split surfaced while this change was open is filed as
opencharly/distro-cachyos#215 instead of being waved at the consumer.

Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
… rewired callers

Review round 2 (R2/R10): Dir(RootRuntime) still re-read \$XDG_RUNTIME_DIR with a
\`!= \"\"\` predicate, diverging from XDG()'s absolute-path rule and contradicting the
one-resolver claim. Bases now carries RuntimeSet, set only for an absolute value; Dir
uses it to choose the runtime root or the documented state fallback, and a valid runtime
dir answers even when \$HOME is unavailable (the runtime path does not depend on it).

Tests now exercise the REWIRED callers, not only XDG(): Dir/CacheDir with a relative
XDG value must use the specification default (the previous os.UserConfigDir /
os.UserCacheDir / raw XDG_STATE_HOME read returned the relative value), and the runtime
fallback is pinned for a relative value and for an absolute value without \$HOME.

Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
XDG() reports a missing $HOME, but each root needs only its own base. Dir and CacheDir
now fail only when the base they use is the relative fallback; an absolute variable
answers directly, as the previous os.UserConfigDir/os.UserCacheDir/raw-env reads did.
Dir(RootRuntime) already answered through RuntimeSet; this closes the same all-or-nothing
gap for config, state and cache, with a test that sets every variable and clears $HOME.

Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
XDG() errored whenever $HOME was unavailable, even when every variable was absolute; the
doc comment said otherwise, and ResolveVolumesPath/ResolveEncryptedStoragePath discarded
the resolved data base and fell back to a relative default. The error now fires only when
a base had to fall back to a relative default because $HOME was unavailable; the resolved
Bases are always returned, and the volume/encrypted defaults use an absolute data base
without $HOME. Tests pin the error contract and both resolvers on a HOME-less host.

Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
@github-actions

Copy link
Copy Markdown

Review — BLOCK

Head SHA: 9179646976bc29dfd195dc63bd3764fc923d5062 (branch: feat/xdg-data-paths-2)

Change class: code/config (Go library + tests).
Placement: CORRECT (the XDG base mechanism belongs in storeroot, consumed by hostenv; no core/sdk/candy misplacement).

Blocks

  1. R11 (D-STORE-1) / R2 — $XDG_RUNTIME_DIR expansion disagrees with Dir(RootRuntime).
    storeroot/roots.go:XDG() sets Bases.Runtime to /run/user/<uid> whenever XDG_RUNTIME_DIR is unset or relative (RuntimeSet=false), but Dir(RootRuntime) deliberately ignores that value and falls back to Bases.State (D-STORE-1). hostenv/runtime_config.go:ExpandHostHome then substitutes $XDG_RUNTIME_DIR from Bases.Runtime unconditionally. On a host with no valid XDG_RUNTIME_DIR, ExpandHostHome("$XDG_RUNTIME_DIR/charly") returns /run/user/<uid>/charly while charly's runtime root is <state>/charly. This contradicts the diff's own comment “never disagrees with charly's own roots”, the body's R2 claim “one implementation / no second default path”, and D-STORE-1.
    Fix: make ExpandHostHome use the same runtime decision as Dir(RootRuntime) (honor RuntimeSet, state fallback, or leave the token unexpanded) and update TestExpandHostHomeXDGDefaults; or remove the /run/user/<uid> default from XDG() and use one runtime resolution. Update the body/comment accordingly.

  2. R11 / R7 — ExpandHostHome ignores XDG()'s error and substitutes non-absolute fallback bases.
    When $HOME is unavailable and an XDG variable is unset or relative, XDG() returns a relative fallback and a non-nil error. ExpandHostHome discards that error and substitutes the relative value, so $XDG_CONFIG_HOME/x becomes .config/x while Dir(RootConfig) returns an error. This violates the body's stated rule that a non-absolute value is invalid and MUST be ignored, and the stated error contract. No test covers this case.
    Fix: only substitute absolute bases; for unresolved/relative bases leave the token unexpanded (or propagate an error), and add a $HOME-less unset/relative test.

Verdict: BLOCK


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

View action run

…bstitution

Review round 5 (R11/R2/R7): XDG() gave Runtime a /run/user/<uid> default that
Dir(RootRuntime) never used, so ExpandHostHome disagreed with charly's own runtime root.
Runtime now carries the D-STORE-1 state fallback unless XDG_RUNTIME_DIR is absolute, so both
consumers make the same decision. ExpandHostHome substitutes a base only when it is absolute:
an unresolved base (variable unset or relative while $HOME is unavailable) leaves the token
literal instead of writing a relative path into a container bind. Tests pin both decisions.

Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
@aitrawog

Copy link
Copy Markdown
Contributor Author

STATUS

RCA — round 5 BLOCK (successor #406).

Mechanism. Two mismatches between the resolver and its consumers.

  1. XDG() defaulted Runtime to /run/user/<uid> while Dir(RootRuntime) chose the state
    root, so ExpandHostHome expanded $XDG_RUNTIME_DIR to a value charly's own runtime root
    never uses. I imported the XDG spec default without reconciling it with D-STORE-1's
    documented state fallback, and tested only Dir's branch, not the expansion.
  2. ExpandHostHome ignored XDG()'s error and substituted relative fallback bases, so an
    unresolved token became a relative path — contradicting the absolute-value rule the same
    function states.

Missed control. I did not write a test comparing the two consumers' answers for the same
environment, and did not test ExpandHostHome's unresolved-base path. A same-input comparison
is the cheap control that would have caught both.

Fix. Runtime is the state base unless XDG_RUNTIME_DIR is absolute — one decision, both
consumers; ExpandHostHome substitutes only absolute bases and leaves unresolved tokens
literal, with tests for both.

Agent: owui-full-stack · Claude Code session 00d99c7c-dad9-4d14-be0e-7be094b099e9
Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)

Agent: owui-full-stack · Claude Code session 00d99c7c-dad9-4d14-be0e-7be094b099e9
Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)

@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: a83ed926d8293e77a8e229520403566c8ab1b87c (branch: feat/xdg-data-paths-2)

Security screen: PASS — diff matches stated intent; no injected directives, secrets, egress, guardrail weakening, or supply-chain change.
Checklist: All applicable rules PASS or NA. (Placement CORRECT: the one XDG base resolution lives in storeroot, consumed by Dir/CacheDir/hostenv; no core/sdk/candy misplacement, no alias growth, no new charly/ import.)

Comments considered:

  • @github-actions[bot] (7043377857, round-5 BLOCK) — re-derived both findings against the CURRENT diff and they are FIXED: XDG() now sets Runtime to the D-STORE-1 state base (never /run/user/<uid>) so ExpandHostHome agrees with Dir(RootRuntime), and ExpandHostHome substitutes only absolute bases, leaving an unresolved/relative token literal (pinned by TestExpandHostHomeUnresolvedTokenStaysLiteral, TestExpandHostHomeXDGDefaults, TestDirRuntimeFallback). → stale-superseded.
  • @aitrawog (7043464234, STATUS/RCA) — coordination metadata; carries the round-5 RCA naming the missed control (a same-input consumer comparison) per R1. → verified, not a finding.

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) November 20, 2026 15:32
@github-actions
github-actions Bot merged commit d047822 into main Nov 20, 2026
4 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Nov 20, 2026
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