Repository navigation
Delphi dproj + PR #166 review fix (status checks ONNX Runtime) - #167
Conversation
…Memory dcc64 F2613 on PR #166: PasClaw.Cmd.Memory.pas(49): Unit 'LocalVector.Models' not found. Same shape as PR #156's miss after PR #155 — the FPC Makefile got the new unit dirs but the Delphi .dproj didn't. PR #165 added the in-tree localvector port under src/pkg/memory/localvector/ + the new PasClaw.Memory.Vector adapter; PR #166 added src/cmd/PasClaw.Cmd.Memory.pas. Neither was wired into PasClaw.dproj, so the Delphi build can't resolve LocalVector.Models / LocalVector.VectorStore / LocalVector.OrtProvision / LocalVector.VecProvision / LocalVector.Downloader / etc. Edits: DCC_UnitSearchPath Added `..\pkg\memory\localvector` (right after `..\pkg\memory` to keep the source-tree shape readable). DCCReference — pkg/memory Added `..\pkg\memory\PasClaw.Memory.Vector.pas` (PR #165 new file). Added all 13 in-tree localvector files under a fresh `pkg/memory/localvector` comment block: LocalVector.Models.pas LocalVector.Runtime.pas LocalVector.Sqlite3.pas LocalVector.Tokenizer.pas LocalVector.Embedder.pas LocalVector.VectorStore.pas LocalVector.VectorStore.Sqlite.pas LocalVector.VectorStore.FireDAC.pas LocalVector.Downloader.pas LocalVector.OrtProvision.pas LocalVector.VecProvision.pas onnxruntime.pas onnxruntime_pas_api.pas DCCReference — cmd Added `..\cmd\PasClaw.Cmd.Memory.pas` (PR #166 new file). Slotted next to PasClaw.Cmd.Membench.pas, matching the .pas filename ordering already present in this block. Stacks on PR #166 (which stacks on PR #165). Lands after both; merge order #165 → #166 → this.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f852059461
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| <DCCReference Include="..\pkg\memory\localvector\LocalVector.Embedder.pas"/> | ||
| <DCCReference Include="..\pkg\memory\localvector\LocalVector.VectorStore.pas"/> | ||
| <DCCReference Include="..\pkg\memory\localvector\LocalVector.VectorStore.Sqlite.pas"/> | ||
| <DCCReference Include="..\pkg\memory\localvector\LocalVector.VectorStore.FireDAC.pas"/> |
There was a problem hiding this comment.
Avoid registering the static FireDAC store for Linux64
On the Linux64 platform enabled by this .dproj, this new reference pulls in LocalVector.VectorStore.FireDAC, whose uses clause imports FireDAC.Phys.SQLiteWrapper.Stat; PasClaw.dpr explicitly excludes that same static wrapper under LINUX because RAD Studio only supports the dynamic SQLite path there. Since LocalVector.VectorStore selects the FireDAC backend for every Delphi target unless LV_PORTABLE_SQLITE is defined, registering this unit makes the newly added Delphi/Linux64 build fail rather than just fixing Win64. Please gate this reference/backend for Linux64 or make the FireDAC unit avoid SQLiteWrapper.Stat on Linux.
Useful? React with 👍 / 👎.
Codex flagged that `pasclaw memory status` was lying when artifacts
were partially provisioned: with vec0 + model + vocab on disk but no
loadable ONNX Runtime (the common Linux/macOS state, since
auto-download is win-x64 only), every checklist row went green even
though TVectorMemoryIndex.Open() would still fail at the
EnsureOnnxRuntime call and memory_search would keep falling back to
FTS-only. The diagnostic said "provision took"; the runtime said
otherwise.
Fix: run the same EnsureOnnxRuntime check the backend gate uses
(AllowDownload=False so status stays read-only), and surface a fourth
checklist row with the result. On failure, when CanAutoProvisionRuntime
is False (Linux/macOS today), also print the system-package install
instructions in dim text so the operator knows the path forward
without having to re-run `pasclaw memory provision` just to see them.
Status output now matches PasClaw.Memory.Vector.Open's actual decision
exactly: green ✓ on every row → hybrid backend will engage on the
next memory_search; any row · → it'll fall back to FTS-only.
Verified by synthesising the exact partial-provision scenario Codex
described (touch the three artifact files so they exist, leave ONNX
unprovisioned):
$ pasclaw memory status
✓ sqlite-vec at .../vec0.so
✓ all-MiniLM-L6-v2 model at .../model.onnx
✓ vocab at .../vocab.txt
· ONNX Runtime not loadable — Could not load onnxruntime. Put
onnxruntime.so next to the executable or on the loader path.
auto-download is win-x64 only on this build; install via:
Debian / Ubuntu: apt install libonnxruntime-dev
macOS (Homebrew): brew install onnxruntime
Other Linux: see https://onnxruntime.ai/docs/install/
Same scenario pre-fix showed all three files as ✓ and zero signal
that the hybrid backend wouldn't engage.
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.
Landed on PR #167 (the dproj fix branch) per maintainer routing —
this commit lives alongside the dproj edits since PR #166 already
went up for review.
Codex noted that registering LocalVector.VectorStore.FireDAC in
PasClaw.dproj would break the Delphi Linux64 build: that unit pulls
FireDAC.Phys.SQLiteWrapper.Stat into its uses clause, and RAD Studio
only ships the static SQLite wrapper for Windows / macOS / mobile —
exactly the same constraint PasClaw.dpr's {$IFNDEF LINUX} guard
addresses (PR #135). The Linux64 hybrid backend needs to use the
dynamic libsqlite3.so path; we have it already in the portable
backend (LocalVector.VectorStore.Sqlite), the factory just wasn't
routing through it on Linux64.
Two-file fix (both modifications scoped to PasClaw — clearly marked
in the file header so a future upstream resync sees them):
LocalVector.VectorStore.pas — force-define LV_PORTABLE_SQLITE on
Delphi Linux64 right after the {$mode} directive. The factory's
existing {$IFDEF LV_PORTABLE_SQLITE} branch already routes
through TSqliteVectorStore (dynamic libsqlite3 + dynamically-
loaded vec0), which works on Linux64. FPC paths untouched.
LocalVector.VectorStore.FireDAC.pas — stub the entire unit body on
Delphi Linux64. The pattern is
{$IF DEFINED(LINUX) AND NOT DEFINED(FPC)}
interface
implementation
end.
{$IFEND}
inserted before the original `interface`. dcc64 hits `end.` on
Linux64 and stops, never reaching the FireDAC.Phys.SQLiteWrapper.Stat
import. Every other Delphi target (and every FPC target) hits the
false branch of the {$IF} and compiles the original implementation
unchanged.
Backend matrix after this fix:
Delphi Windows / macOS / mobile → FireDAC backend
(static SQLiteWrapper.Stat,
unchanged from upstream)
Delphi Linux64 → portable Sqlite backend
(dynamic libsqlite3.so,
same path the Linux64 PasClaw.dpr
build uses since PR #135)
FPC any-OS → portable Sqlite backend
(unchanged)
Per-file modification headers preserved per the in-tree localvector
attribution convention; both new guards are marked as PasClaw
modifications so a future upstream resync can see exactly what we
changed.
Verified: FPC build still clean (the {$IF} on FPC evaluates to false
since NOT DEFINED(FPC) is false, so both files behave as before).
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.
Delphi-side verification (dcc64 on the actual Linux64 target) needs a
real Delphi compiler — not available in CI. The shape mirrors PR #135's
{$IFNDEF LINUX} pattern, which dcc64 accepts.
Two dcc64 errors against the just-merged PR FMXExpress#167: PasClaw.Memory.Index.pas(622): H2443 Inline function 'TFDParam.SetAsInteger' has not been expanded because unit 'FireDAC.Stan.Param' is not specified in USES list LocalVector.VectorStore.FireDAC.pas(31): E2029 'INTERFACE' expected but identifier 'guard' found LocalVector.VectorStore.FireDAC.pas(32): E2052 Unterminated string LocalVector.VectorStore.FireDAC.pas(39): E2038 Illegal character in input file: '}' (#$7D) LocalVector.VectorStore.pas(103): F2063 Could not compile used unit 'LocalVector.VectorStore.FireDAC.pas' The H2443 hint was always present but never surfaced as an error before; the four E20xx errors are a regression my PR FMXExpress#167 stub introduced. Both addressed here. PasClaw.Memory.Index.pas: Added FireDAC.Stan.Param to the {$ELSE} branch of the FireDAC uses list (alongside the existing FireDAC.Comp.Client / Stan.Def / Stan.Async / DApt entries). The TFDParam.SetAsInteger call at line 622 ends up inlined now instead of dispatched through the vtable, and dcc64's H2443 hint goes away. No FPC behaviour change. LocalVector.VectorStore.FireDAC.pas: My PR FMXExpress#167 stub-block comment used curly-brace delimiters and literally spelled out a {$IFNDEF LINUX} directive inside the comment text: { PasClaw modification: stub on Delphi Linux64. ... PasClaw.dpr already routes around this constraint (PR FMXExpress#135 added the {$IFNDEF LINUX} guard there); we extend ... } Curly-brace comments DO NOT NEST in Pascal, so dcc64 parses the inner {$IFNDEF LINUX} as a real compiler directive, then chokes on the closing `}` that was meant for the outer comment. PR FMXExpress#158 hit the exact same trap in PasClaw.Providers.Gemini and switched to (* ... *) delimiters; same fix here. The comment text also no longer spells the directive verbatim — it references the source-level platform guard by its bare name — so a future reader doesn't accidentally re-introduce the trap by reformatting the comment back to curly braces. The actual stub directive {$IF DEFINED(LINUX) AND NOT DEFINED(FPC)} interface implementation end. {$IFEND} is unchanged. Behaviour matrix from PR FMXExpress#167 still holds: Delphi Windows / macOS / mobile → FireDAC backend (unchanged) Delphi Linux64 → portable Sqlite backend (LV_PORTABLE_SQLITE forced on by LocalVector.VectorStore) FPC any-OS → portable Sqlite backend Verified: FPC build still clean. 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. Delphi-side verification needs a real dcc64 compiler — not available here, but the comment-trap fix mirrors PR FMXExpress#158's exactly and the FireDAC.Stan.Param edit is mechanical.
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.
Summary
Two fixes against the PR #165 / PR #166 stack, batched here per maintainer routing.
1. Delphi
.dprojregistration (the original PR #167 scope)Resolves the
dcc64fatal error:Same shape as PR #156 missing after PR #155 — the FPC
Makefilegot the new unit dirs butPasClaw.dprojdidn't. PR #165 added the in-tree localvector port undersrc/pkg/memory/localvector/+ the newPasClaw.Memory.Vectoradapter; PR #166 addedsrc/cmd/PasClaw.Cmd.Memory.pas. None of them were wired intoPasClaw.dproj.Edits to
src/pasclaw/PasClaw.dproj:DCC_UnitSearchPath— added..\pkg\memory\localvectorright after..\pkg\memory.DCCReference— pkg/memory — addedPasClaw.Memory.Vector.pas(PR Memory: hybrid FTS+vector backend, localvector brought in-tree (no vendoring) #165) + all 13 in-tree localvector files (LocalVector.Models/Runtime/Sqlite3/Tokenizer/Embedder/VectorStore[.Sqlite,.FireDAC]/Downloader/OrtProvision/VecProvision+onnxruntime.pas+onnxruntime_pas_api.pas).DCCReference— cmd — addedPasClaw.Cmd.Memory.pas(PR Memory:pasclaw memory provision+ onboarding download hook #166).2. PR #166 Codex P2 — check ONNX Runtime in
memory statusCodex flagged that
pasclaw memory statuswas lying when artifacts were partially provisioned: withvec0+ model + vocab on disk but no loadable ONNX Runtime (the common Linux/macOS state, since auto-download is win-x64 only), every checklist row went green even thoughTVectorMemoryIndex.Open()would still fail at theEnsureOnnxRuntimecall andmemory_searchwould keep falling back to FTS-only. The diagnostic said "provision took"; the runtime said otherwise.Fix. Run the same
EnsureOnnxRuntimecheck the backend gate uses (AllowDownload=Falseso status stays read-only) and surface a fourth checklist row with the result. On failure, whenCanAutoProvisionRuntimeis False (Linux/macOS today), also print the system-package install instructions in dim text so the operator knows the path forward without having to re-runpasclaw memory provisionjust to see them.Verified by synthesising the exact partial-provision scenario Codex described:
Same scenario pre-fix showed all three files as ✓ and zero signal that the hybrid backend wouldn't engage.
Test plan
dcc64build ofPasClaw.dproj(or full Delphi build viabuild-delphi.bat) to confirm the F2613 is resolved and all 14 new units link.Stacks on
PR #166 (
pasclaw memory provision+ onboarding hook), which stacks on PR #165 (in-tree localvector port). Merge order: #165 → #166 → this.