Repository navigation
Description
Problem
One chain per record means one order for every capability. As a default that is fine, and I am not saying the current behaviour is wrong: the lab scan taking the first vision-capable entry, and the document reads preferring a local one, are both deliberate decisions and they stay as they are.
What is missing is the ability to say which chain a capability uses — which provider, on which key, with which model, for a given function. With one global order I cannot express:
- "A one-entry chain for documents, two entries for lab scans, a different one for the coach."
documentAi: [llm1]— my local model only, so no document leaves the house, whether it has a + usable text layer or is a scan;labsOcr: [llm1, llm2]— local first, cloud as the fallback;coach: [llm2]— a cloud model. One entry is a valid chain; more than one is the same thing with a fallback behind it. - "Documents go to this one model, and nowhere else." No fallback out of the house whether that model is up or down — a binding, not a preference. Not expressible today at all.
Whether the model is local or in the cloud is not the point — I happen to care about egress for documents, but the same mechanism should serve someone splitting two cloud models by quality and price.
Checked on v1.47.6, self-hosted (Docker Compose, LAN).
Proposed solution
Provider entries stay as they are; what becomes a first-class object is the chain:
- A record can hold several named chains, each an ordered list of its provider entries — an entry being the provider with its key and model, exactly as the chain editor builds one today — plus one chain marked default.
- Each capability can be attached to a chain. Capabilities with no attachment use the default chain and today's exact rules (no change for anyone who does not configure this).
- A chain holds one entry or several — both are the same object. One entry pins a function to a single provider and refuses rather than falling back to one the person did not choose; two or more give it an order with a fallback behind it.
- Settings: manage chains (create, rename, reorder entries), then one short list — capability → chain, defaulting to "Default" — with the egress of each entry visible (stays on the machine / leaves it).
- Guardrails unchanged: entitlement, consent receipts, capability availability and the operator-key rules apply to a chain exactly as they apply to the single chain today.
Deliberately out of scope: a separate "model" or "key" field per capability. A chain entry already carries both, so attaching a one-entry chain is exactly how one specific model on one specific key gets pinned to one specific function. Reasoning effort and response timeout stay where they are (per provider, per record).
Alternatives considered
- Change the built-in per-capability rules — e.g. make the lab scan rank locals the way the document reads do. I am not asking for that: those rules are deliberate, and changing one still leaves every capability on a single decision.
- A per-capability flag instead of chains — "documents: this one provider, no fallback". Smaller than named chains, and it does cover pinning, but it cannot express an order (three models, tried in this sequence) and every function ends up with its own one-off setting instead of reusing a chain.
- Two accounts, one local and one cloud — records, modules and delegations are per account, so it splits the record I am trying to keep in one place.
Affected surface
Web (PWA), API
Additional context
v1.47.6, self-hosted, no telemetry. The rules above are not guesses: AI_CAPABILITIES[key].providerOrder is hardcoded per capability in the tag (document for documentAi and supplementLabel, chain for the other nine), and src/lib/labs/ocr-capability.ts calls resolveVisionProvider(userId) with no reorder on purpose — "labs passes no reorder → identity".
Why I think the default chain matters as much as the custom one: with it, nothing changes for a person who never touches this screen, and the whole feature is opt-in.
I am not going to send a PR — I do not write TypeScript, and anything I sent would come from the AI assistant mentioned below; I would have no way to vouch for it line by line. If it helps, I can try a release on my instance and just say whether the pinning does what it says — there is a real backlog of scanned documents here to try it on. Nothing more formal than that.
I do not need the whole thing at once. Lab scans and documents attached to a named chain is the part
that changes my setup; the rest can follow whenever.
Full disclosure: I put this write-up together with the help of my own AI agent (a local assistant I run at home). It cloned tag v1.47.6 and read the code paths quoted above; the behaviour itself I checked on my own instance. Happy to walk through any of it.
Pre-flight checks
- I confirmed this is not a duplicate of an existing feature request.
- I'm proposing a feature, not asking a usage question (those go to Discussions or the docs).
Activity
MBombeck commentedon Nov 17, 2026
@ch3funio Thanks, the code references are right, and the way you framed it makes this easy to agree with. One global order works as a default, but it can't say "documents go to this one model and nowhere else", and that is a fair thing to want for documents.
I'll build it the way you describe for 1.48.0. A record can hold several named chains and marks one of them as the default. Each capability can be attached to a chain, and anything not attached keeps today's rules, so nobody who ignores the screen notices a change. A one-entry chain is a binding: if that provider is down, the capability refuses instead of falling back somewhere you didn't pick. The settings show for each entry whether it stays on the machine or leaves it. Consent receipts, egress checks and the operator-key rules apply to every chain the same way they apply to the single chain today. Documents and lab scans come first, as you asked, and the other capabilities follow on the same model.
Trying it on your instance with the scanned backlog is exactly the test I'd want. I'll post here when it's in a release.
MBombeck commentedon Nov 18, 2026
@ch3funio This is in 1.48.0, out today (https://github.com/MBombeck/HealthLog/releases/tag/v1.48.0).
Settings, AI now keeps named chains, and each task can be attached to one: documents to a local model only, the Coach to a cloud model, and so on. A chain with a single entry is a binding, so if that provider is down the task stops with a clear reason instead of falling back somewhere you didn't choose. Each entry shows whether what it reads stays on your machine. Tasks left on Default behave as before.
Could you set it up the way you described, with documents bound to the local model, and tell me whether the binding holds when you take that model offline?
ch3funio commentedon Nov 19, 2026
Tested on 1.48.1, self-hosted, one household record.
What I set up. Two providers, both through a LiteLLM gateway on the LAN: the local slot is a single
local vision model (Ollama on a desktop GPU), the gateway slot is a cloud model. Each provider has its own
virtual key — the local key can reach only the local model, the cloud key only the cloud models — so nothing
can slip out through the wrong entry even if I get a chain wrong.
Two chains:
local-only, one entry, attached to Reading documents, Scanning lab reports, Reading supplement labels and Setting up medications from text.
Cloud, gateway first and the local model behind it, marked default, carrying the rest (Coach and the other background tasks).
The binding holds. With the local model's host stopped:
OllamaException - Cannot connect to host 192.168.2.222:11434 … No fallback was attempted. Retried: 2 times;was an hour earlier, from a different test. It did not quietly leave through the other entry.
The two things that still hurt are both about the moment it fails:
The refusal is silent. When the pinned provider is down, the screen waits, and then nothing happens —
no message, no state on the document, no hint that the task stopped because its chain had nowhere to go.
The reason exists inside (the gateway logged it); it never reaches the person. The same when a model
answers with reasoning and no text: 2 min 24 s, 1305 tokens, empty screen — and the app has an exact error
for that case ("Local AI returned reasoning but no answer") that also stays invisible.
For comparison, in [Bug] Document AI and lab OCR ignore the AI response timeout: hard 60 s cut-off breaks local providers #1090 a local read that hit the 60 s ceiling did show "Couldn't read the document.
Try again." — here, with the provider unreachable, there is no sentence at all. That is the part I would
fix first: it is the difference between "this failed" and "did I click?"
Nothing in the app's own log. Filtering the container log for
ai_chainreturns zero lines — noworking provider, no outcome. The only trace of the failed read was in the gateway. So "which chain
actually served this call" is answerable only because I run the gateway and can read its table.
That second one matters for the promise the card makes. "Bound to this provider, no fallback" is clear in
the UI and true in the behaviour; what is missing is the other half — when it stops, it should say so,
and say it where the person is looking.
Two smaller observations from the same session:
3 of 13 rows, pages 1–2 missed entirely — while the same document through the cloud entry is fine.
Not a bug, and it is why lab scans will get a two-entry chain here while documents stay bound.
uses up the six slots and locks you out for an hour. Worth a sentence in the docs next to the local setup.
One UI bug hit me while configuring this, unrelated to chains — the local provider card wiped my saved
base URL and model when I pressed Save on it while another provider was the saved one. Reported separately
as #1417.
Disclosure: this write-up was put together with my own local AI assistant, which also read the code paths
in the tag. The setup, the measurements and the logs are mine.
MBombeck commentedon Nov 19, 2026
@ch3funio Thanks for testing the binding that thoroughly. Good to hear it never falls back.
MBombeck commentedon Nov 20, 2026
@ch3funio In 1.48.3, out now (https://github.com/MBombeck/HealthLog/releases/tag/v1.48.3): a pinned provider that times out or can't be reached now ends the chat with a message saying which of the two it was, each AI call logs
ai.chain.servedorai.chain.failedwith the chain, capability and provider, and the docs mention that the hourly read and scan limits count failed attempts.fix(coach): name why a provider gave no answer
feat(ai): log which chain and provider served each AI call
docs(ai): note that the hourly read and scan limits count failed atte…
MBombeck commentedon Nov 23, 2026
@ch3funio The last piece from your test is in 1.49.0, out tonight: https://github.com/MBombeck/HealthLog/releases/tag/v1.49.0
Background AI work that stops now says why, which covers the silent document summary you saw. The reason shows on the document itself and on a card in the AI settings: provider not reachable, timeout, a refused key, a chain with nothing set up, a used-up daily allowance, or a model that reasoned without answering. "Try again" sits next to it, and the entry goes away once the work succeeds.
If you take the local model offline again, could you tell me whether the document now names the reason?
ch3funio commentedon Nov 25, 2026
Tested on 1.49.0 (f177e17), self-hosted, with a LiteLLM gateway in front of
a local Ollama on a LAN box. Two named chains; at the time of the failures below
the "Read documents" task was bound to one of them (the log says
chain=pinned:…, capability=documentAi).
What holds
What does not hold
One note, not a request: a successful read writes only the encrypted content index, so "AI read your document" leaves nothing to look at — the button turns into "Read again" and the card gets the provenance pill, and the only other sign is a message that disappears. I am not filing that shape again (#1403); I mention it because it is why, after the retry, I could not tell from the UI that it had worked — only your gateway log said so.
Note: this report was put together with an AI assistant on my side — it read the v1.49.0 code paths and queried the gateway's own logs; the setup, the clicks and the observations are mine.
MBombeck commentedon Nov 26, 2026
@ch3funio Thanks for taking the model offline again and timing all of it. It's good to hear the binding switches without a restart, the slow provider is named as slow, and "Try again" clears the entry. Going through what didn't hold:
main)ai.chain.servedandai.chain.failednow carry the provider call's own time, andai.job.failedcarries the job's. A line that can't know a duration leaves the field out instead of claiming zero. The two codes don't contradict each other: on the chain linecodeis the system error behind the failure, which is empty for HealthLog's own timeout, and on the job line it is the job's own code,provider_timeout. The AI providers guide now explains both. (fix(logging): carry the work's duration on AI log lines #1544)docker logson its own shows one line per event.And your note on the successful read: the message after a read now says the document can be found by its content in search, which is where the result goes (#1554, see #1403).
The duration fix is on
:edgenow. Both fixes ship in v1.49.1 on Saturday 28 November.MBombeck commentedon Nov 26, 2026
The note for a chain with no provider is merged now too (#1545). Everything above ships in v1.49.1 this Saturday, 28 November, and is in the
:edgeimage until then.feat(ai): say why background AI work stopped, on the document and in …
fix(logging): carry the work's duration on AI log lines
fix(settings): say when a task's chain has no provider set up
MBombeck commentedon Nov 28, 2026
@ch3funio and the chain side is out too, in the same release: https://github.com/MBombeck/HealthLog/releases/tag/v1.49.1
A task bound to a chain without a provider now says so in Settings, AI instead of going quiet, and
ai.chain.served/ai.chain.failedreport the time the work actually took. If you get a moment to run your offline test against it once more, I'd love to hear whether it holds. Refs #1404