Skip to content

Memory cache path: fix mixed slashes that broke Windows provisioning - #169

Merged
FMXExpress merged 1 commit into
mainfrom
claude/cache-path-separator
Jun 7, 2026
Merged

FMXExpress merged 1 commit into
mainfrom
claude/cache-path-separator

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Summary

Live trace from a Windows operator running pasclaw memory provision:

Provisioning hybrid memory_search runtime
All artifacts land under C:\Users\anony\.pasclaw\cache/localvector
                                                  ^
                                                  here

[localvector] sqlite-vec not found - downloading v0.1.9 ...
  ✗ sqlite-vec: Cannot create file
    "C:\Users\anony\.pasclaw\cache\localvector\sqlite-vec-...tar.gz".
    The system cannot find the path specified

[localvector] onnxruntime not found - downloading ...
  runtime download failed: Cannot create file
    "C:\Users\anony\.pasclaw\cache\localvector\onnxruntime-...zip".
    The system cannot find the path specified

[localvector] downloading vocab.txt ...
  ✗ embedding model: Cannot create file
    "C:\Users\anony\.pasclaw\cache\localvector\models\...\vocab.txt".
    The system cannot find the path specified

! provisioning incomplete

All three downloads fail because the cache directory was never actually created. The user-visible header line (All artifacts land under ...) shows the smoking gun: cache/localvector — a forward slash on Windows.

Cause

JoinPath only inserts a PathDelim between the two args; embedded separators inside either arg survive verbatim. The literal CACHE_SUBDIR = 'cache/localvector' embedded a POSIX / directly into the path. On Windows the mixed-separator result (C:\...\.pasclaw\cache/localvector) takes one shape going into ForceDirectories and a different normalised shape going into the downstream CreateFile calls inside the localvector downloaders — ForceDirectories either creates the dir at the mixed-separator path or fails silently; the subsequent file writes look for the dir at the all-backslashes path and report system cannot find the path specified.

Linux/macOS happened to work because POSIX PathDelim is /, so the old form was accidentally consistent there.

Fix

Drop the CACHE_SUBDIR const in both the cmd handler and the backend adapter; build the cache path with nested JoinPath calls so each segment gets the host's PathDelim:

// PasClaw.Cmd.Memory.CacheDir
// PasClaw.Memory.Vector.TVectorMemoryIndex.CacheDir
Result := JoinPath(JoinPath(GetHome, 'cache'), 'localvector');

Each call site carries a comment naming the trap so a future reader doesn't fold the two JoinPaths back into a single literal.

Test plan

  • make clean on Linux/FPC.
  • pasclaw memory status reports cache dir: /root/.pasclaw/cache/localvector — all-/ segments on POSIX, as expected.
  • Full test suite green: smoke + hashline + toolview + anthropic-server-tools + openai-server-tools + println-helper + utf8-codepage-tag + gemini-schema-strip + markdown-render + json-utf8-roundtrip.
  • Live re-run of pasclaw memory provision on Windows to confirm the three downloads now succeed (operator can verify; the cache dir should now create cleanly and the three artifacts should land alongside it).

Generated by Claude Code

Live trace from a Windows operator running `pasclaw memory provision`:

  Provisioning hybrid memory_search runtime
  All artifacts land under C:\Users\anony\.pasclaw\cache/localvector
                                                    ^
                                                    here

  [localvector] sqlite-vec not found - downloading v0.1.9 ...
    ✗ sqlite-vec: Cannot create file
      "C:\Users\anony\.pasclaw\cache\localvector\sqlite-vec-...tar.gz".
      The system cannot find the path specified

  [localvector] onnxruntime not found - downloading ...
    runtime download failed: Cannot create file
      "C:\Users\anony\.pasclaw\cache\localvector\onnxruntime-...zip".
      The system cannot find the path specified

  [localvector] downloading vocab.txt ...
    ✗ embedding model: Cannot create file
      "C:\Users\anony\.pasclaw\cache\localvector\models\...\vocab.txt".
      The system cannot find the path specified

  ! provisioning incomplete

All three downloads fail because the cache directory was never
actually created — the mixed-separator path that
  CACHE_SUBDIR = 'cache/localvector'
+ JoinPath(GetHome, CACHE_SUBDIR)
produces on Windows (`C:\...\.pasclaw\cache/localvector`) takes one
shape going into ForceDirectories and a different normalised shape
going into the downstream CreateFile calls inside the localvector
downloaders. ForceDirectories either creates the dir at the
mixed-separator path or fails silently; the subsequent file writes
look for the dir at the all-backslashes path, don't find it, and
report "system cannot find the path specified". User-visible header
line ("All artifacts land under ...") shows the smoking gun.

Cause is mechanical: JoinPath only inserts a PathDelim BETWEEN the
two args; embedded separators inside either arg survive verbatim.
The 'cache/localvector' literal embedded a POSIX `/` directly into
the path, which Windows path APIs disagree about.

Fix: drop the CACHE_SUBDIR const in both the cmd handler and the
backend adapter, build the cache path with nested JoinPath calls so
each segment gets the host's PathDelim:

  PasClaw.Cmd.Memory.CacheDir
  PasClaw.Memory.Vector.TVectorMemoryIndex.CacheDir
    Result := JoinPath(JoinPath(GetHome, 'cache'), 'localvector');

Each site carries a comment naming the trap so a future reader
doesn't fold the two JoinPaths back into a single literal.

Linux/macOS behaviour unchanged — POSIX PathDelim is '/' so the
old form already happened to work there. Only Windows builds were
broken.

Verified on Linux/FPC:
  $ pasclaw memory status
    cache dir:      /root/.pasclaw/cache/localvector   ← all '/' (POSIX)
On Windows the same code path now produces all '\' segments via
PathDelim, which is what the downloaders / ForceDirectories agree on.

Full test suite green: smoke + hashline + toolview +
anthropic-server-tools + openai-server-tools + println-helper +
utf8-codepage-tag + gemini-schema-strip + markdown-render +
json-utf8-roundtrip.
@FMXExpress
FMXExpress merged commit a033e49 into main Jun 7, 2026
khongten001 pushed a commit to khongten001/PasClaw that referenced this pull request Jul 13, 2026
Lifts the "use the provider's /models endpoint" idea from
UltraCode-Shim's Auto Router (and the carry-over from PR FMXExpress#163's
followup question) into a complete loop: discover, cache, surface
in onboarding.

New unit: src/pkg/providers/PasClaw.Providers.Models.pas

  Three family parsers driven off TProviderSpec.Family:

    pfOpenAI     GET <base>/v1/models, Bearer auth (or asNone for
                 Ollama / vLLM / LM Studio). Parses `data[].id` +
                 `data[].created`. Used by 14 catalog rows that share
                 the OpenAI-compatible /v1/models shape — openrouter,
                 groq, deepseek, mistral, xai, qwen, zhipu, cerebras,
                 moonshot, ollama, vllm, lmstudio, litellm, openai.

    pfAnthropic  GET <base>/v1/models, x-api-key + anthropic-version
                 headers. Parses `data[].id` + `display_name` + ISO
                 `created_at`.

    pfGemini     GET <base>/v1beta/models, x-goog-api-key header.
                 Strips the "models/" namespace prefix from each
                 `name`, filters out rows that don't list
                 "generateContent" in supportedGenerationMethods
                 (embedders and counters live there too and would
                 404 the chat path).

  Cache at $PASCLAW_HOME/cache/models/<provider>.json with a
  fetched_at unix timestamp. JoinPath built up segment-by-segment
  so PathDelim insertion stays consistent on Windows (PR FMXExpress#169 trap).

  Discovery never raises; failure modes return Ok=False with a
  human-readable ErrMsg the caller surfaces verbatim. Empty result
  is Ok=True with Length=0 (the operator's call whether to retry).

New subcommands: src/cmd/PasClaw.Cmd.Model.pas

    pasclaw model refresh <provider>     hit /v1/models, save cache
    pasclaw model refresh --all          refresh every configured row
    pasclaw model list <provider>        show cached roster + age

  `pasclaw model show` now adds a cache-freshness annotation for the
  default provider — "models cached: 47 (refreshed 3 days ago)" or
  the gentle nudge "(none — run `pasclaw model refresh anthropic`
  to populate)" when no cache exists yet.

Onboarding picker: src/cmd/PasClaw.Cmd.Onboard.pas

  Flipped the order: now prompts for the API key BEFORE the model,
  so the key is available for the /v1/models fetch. Live fetch is
  bounded at 8s — onboarding is interactive, a slow provider status
  page shouldn't make the user wait 30s. On success: numbered
  picker over the top 12 newest models (sorted by created_at desc),
  with the option to type a free-form id or hit Enter for the
  catalog default. On failure: falls back to the existing text
  prompt verbatim so a broken /v1/models never blocks first-time
  setup.

  Both the full result AND a sort-truncated view get cached, so
  `pasclaw model list <provider>` later shows the whole roster
  even though the onboarding picker only displayed the top 12.

New test: src/tests/model_discovery_tests.pas

  Covers the cache schema contract (Save → Load round-trip preserves
  every field), missing-cache fallback (LoadCachedModels returns
  False, NOT True-with-empty-array), HumanAge bucket boundaries
  (minutes / hours / days / over-a-year cap), and case-insensitive
  ModelCachePath canonicalisation. Wired into `make test` as
  test-model-discovery.

Updated:
  - src/pasclaw/PasClaw.dproj: registers PasClaw.Providers.Models
    so the Delphi build resolves it too (PR FMXExpress#156 / FMXExpress#167 pattern).
  - README.md: maintenance section adds `model refresh` / `model list`
    examples + explains the onboarding picker behaviour.
  - Makefile: adds test-model-discovery target and rolls it into the
    composite `test:` target.

Verified end-to-end on Linux/FPC:

  $ pasclaw model show
    default provider: anthropic
    default model:    claude-opus-4-7
    models cached:    (none — run `pasclaw model refresh anthropic` to populate)

  $ pasclaw model refresh anthropic        # without a real key
      · fetching /models from Anthropic ...
      ✗ anthropic: API key required for Anthropic /models endpoint

  $ # synthesised cache file → list works:
  $ pasclaw model list openai
    openai (3 cached, refreshed over a year ago)
      · gpt-4o   (GPT-4o)
      · gpt-4o-mini   (GPT-4o Mini)
      · gpt-5   (GPT-5)

  $ make test
    ... all 11 test suites green including model_discovery_tests: OK

Live-HTTP verification against real Anthropic / OpenAI / Gemini /
xAI keys hasn't run in this environment (no real keys), but the
parser tests cover the JSON shapes documented in each provider's
current API reference.
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.

2 participants