Skip to content

[Feature] Named provider chains, attachable per capability — one default for everyone, custom where it matters #1404

Open

Description

@ch3funio

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:

  1. 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.
  2. 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).
  3. 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.
  4. 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).
  5. 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

  1. added
    enhancement
    on Nov 17, 2026
  2. MBombeck commented on Nov 17, 2026

    @MBombeck
    Owner

    @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.

  3. added
    roadmap
    on Nov 17, 2026
  4. MBombeck commented on Nov 18, 2026

    @MBombeck
    Owner

    @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?

  5. added
    waiting-on-reporter
    on Nov 18, 2026
  6. ch3funio commented on Nov 19, 2026

    @ch3funio
    Author

    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:

    • a document summary never came back;
    • a document read never came back;
    • the gateway log for those calls says:
      OllamaException - Cannot connect to host 192.168.2.222:11434 … No fallback was attempted. Retried: 2 times;
    • and in the gateway's spend table the cloud key has no calls at all in that window — its previous call
      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:

    1. 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?"

    2. Nothing in the app's own log. Filtering the container log for ai_chain returns zero lines — no
      working 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:

    • Quality is the price of pinning. The local model read a scanned 2021 morphology report badly —
      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.
    • The hourly scan limit counts attempts that reach the provider, so diagnosing a broken local model
      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.

  7. MBombeck commented on Nov 19, 2026

    @MBombeck
    Owner

    @ch3funio Thanks for testing the binding that thoroughly. Good to hear it never falls back.

    1. An empty screen after more than two minutes is not acceptable. When the pinned provider is down or answers with reasoning and no text, the chat should say so. That goes into the next patch.
    2. I'll log which chain and provider served a call, so you can grep for it.
    3. The scan limit counting failed attempts goes into the docs.
  8. MBombeck commented on Nov 20, 2026

    @MBombeck
    Owner

    @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.served or ai.chain.failed with the chain, capability and provider, and the docs mention that the hourly read and scan limits count failed attempts.

  9. MBombeck commented on Nov 23, 2026

    @MBombeck
    Owner

    @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?

  10. ch3funio commented on Nov 25, 2026

    @ch3funio
    Author

    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

    • The binding takes effect with no restart. With "Read documents" bound to my cloud chain I made one read: four calls on deepseek-flash through the cloud key between 18:02:48 and 18:03:41, none on the local model, and the line under the picker said the task is bound to that provider and to nothing else.
    • A slow provider is named as slow. Limit 10 s against a provider that answered in 90 s: I clicked at 17:17:45, the entry appeared at 17:18 saying the provider did not answer in time, and the gateway finished the same call at 17:19:15 with a normal reply. Correct sentence, and correctly distinct from "could not connect".
    • "Try again" works. With the local model back, the pending read finished in 256 s (the model was cold) and the entry in Settings disappeared by itself.

    What does not hold

    • With a gateway in the chain, "could not connect" can never appear. I took the local model offline and started a read at 18:57. The call reached the gateway, the gateway held it for 812 s and only then gave up (19:10:37); my own 600 s limit fired first, at 19:07, and the read was reported as a timeout. The model was in fact gone. When the provider entry is an HTTP endpoint that answers but the model behind it is dead, HealthLog cannot tell the two apart — and "unreachable" stays unreachable as a reason.
    • A chain with no usable provider removes the action instead of explaining it. I bound "Read documents" (and Coach) to a chain with no provider: no read button in the document at all, no line, no reason. The release note says the work now says why; here it does not start and says nothing. Is that intended?
    • The line that carries the reason does not say how long anything took. ai.chain.failed: failure=timeout, code=null, duration_ms=0. ai.job.failed: code=provider_timeout, duration_ms=0 — on a job that had been running ten minutes. Whatever duration_ms measures there, it is not the work. The two events also disagree about the same failure: code=null on the chain line, provider_timeout on the job line.
    • In the copy of the log I got, every field of those lines is repeated hundreds of times under one timestamp ("WRN WRN … request_id=… meta=…" over and over). That may be my log viewer rather than the logger — mentioning it in case it is the logger, because it makes docker logs unreadable.

    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.

  11. MBombeck commented on Nov 26, 2026

    @MBombeck
    Owner

    @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:

    1. "Could not connect" never appears behind a gateway. That's a limit of where HealthLog sits rather than something I can fix here. HealthLog only talks to the gateway, and the gateway was up, accepted the call and held it for 812 seconds. From HealthLog's side that is a slow answer, so your 600-second limit fired and it was reported as a timeout. If the gateway's own timeout and retries end before HealthLog's limit, its error comes back instead, and the document shows that the provider answered with an error rather than a timeout.
    2. A chain with no provider removes the action without a word. The button staying away is intended, because an AI task that can't run isn't offered. But nothing told you why, and that was a gap. The task's row under Settings, AI, "Chains per task" now says that nothing in its chain is set up and that the action comes back once a provider is set up or another chain is picked. It no longer calls such a chain a binding. (fix(settings): say when a task's chain has no provider set up #1545, on its way to main)
    3. duration_ms=0 and the two codes. A real bug. Those lines only timed the writing of the line itself. ai.chain.served and ai.chain.failed now carry the provider call's own time, and ai.job.failed carries 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 line code is 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)
    4. The repeated lines. That isn't HealthLog. It writes each event as one JSON line to stdout, and there's no "WRN" or "meta=" in what it prints. The repeats come from your log viewer turning the JSON into text, and docker logs on 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 :edge now. Both fixes ship in v1.49.1 on Saturday 28 November.

  12. MBombeck commented on Nov 26, 2026

    @MBombeck
    Owner

    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 :edge image until then.

  13. MBombeck commented on Nov 28, 2026

    @MBombeck
    Owner

    @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.failed report 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementroadmapwaiting-on-reporter

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions