Skip to content

LM-2: main-owned local connections and bounded model discovery (#378) - #403

Merged
BunsDev merged 32 commits into
mainfrom
lm2-adopt
Oct 24, 2026
Merged

BunsDev merged 32 commits into
mainfrom
lm2-adopt

Conversation

@BunsDev

@BunsDev BunsDev commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

LM-2 for #378 under #376. This PR lands the whole LM-2 change on main in one squash.

It now targets main (it was stacked on #402, then #398). It carries #398's six commits and their two review fixes, #402's hardening, and the adoption of LM-1's accepted contract. That supersedes #386, #398 and #402, which will not merge separately. Gate A was accepted on #377 for main at bb0e1a4, and this branch's LM-1 files are identical to main's. Against main, the diff is 17 LM-2 files.

What lands

  • Endpoint policy (main/engine/local-models/endpoint-policy.ts):
    • Only same-machine HTTP(S) origins: localhost, 127.0.0.0/8, ::1 and their alternate spellings. Every address localhost resolves to is re-checked when the socket connects.
    • Redirects, credentials in the URL, queries, fragments and unexpected paths are refused.
    • Each request has a deadline, a byte cap and cancellation, and uses its own agent, so an environment proxy never sees it. Failure text is fixed.
  • Profiles (connections.ts):
    • Profiles live in app/local-connections.json and contain no secrets. Each saved token gets its own versioned entry in the existing encrypted SecretStore.
    • The revision moves when the runtime, address or token changes. A token never follows a changed address, and stale edits are refused. Deletion leaves a tombstone that never resolves.
    • A failed write never changes what an old revision resolves.
    • An unreadable or newer profiles file is refused, never overwritten, and entries this build can't read are kept.
    • The token can't be saved into a name or model ID, and token entries no profile names are swept.
  • Discovery (discovery.ts):
    • Reads only: Ollama /api/tags, /api/ps and /api/show (capped at 32 models); LM Studio /api/v0/models, falling back to /v1/models; and /v1/models for Responses-compatible servers.
    • Exact model IDs, as schema-1 LocalModelRefs.
    • Installed, loaded and kind come only from what the runtime reports; otherwise they are unknown. Advertised metadata is keyed by [P1][LM-1] Define local-model contracts and prove the native Codex integration seam #377's Capability and is never qualification.
    • Embedding-only, non-text and Ollama cloud models can't be selected. Manual IDs survive a failed listing.
    • Late answers after an edit, delete, cancel or newer read are stale.
    • A listing that repeats the token is dropped.
    • An unreadable token means no request at all.
    • A whole discovery ends within three per-request deadlines.
  • IPC (service.ts, shared/local-connections.ts): one strictly validated local-models:command channel, registered localOnly, which the Store desktop demo refuses.

There is no UI, no execution binding and no inference.

Evidence

All evidence is fixtures plus real Electron IPC; no real runtime was contacted. Every defect fix began with a regression that failed first. The criterion-level receipt is docs/reviews/2026-10-22-lm2-connections-discovery.md.

Local, on c592eee (main at 21e50ba merged in). The head since then also merges main at e5252ea (#405), docs only. macOS 27.0.1 arm64, Node v24.22.0, pnpm 10.34.5, Electron 44.4.5, Playwright 1.63.0.

  • Focused local-model-* tests (including LM-1's contract tests): 42/42.
  • pnpm build && pnpm test: exit 0. Worktree 117/117, core 16/16, desktop 1955 tests (1938 passed, 17 skipped, 0 failed), native/package 26 (21 passed, 5 skipped), site 10/10, Store 16/16.
  • pnpm typecheck: exit 0.
  • e2e/local-models-ipc.spec.ts: 1/1. There is no renderer change, so CI's unit + e2e (macOS) covers the full suite.
  • Hosted CI passed every job on the earlier heads 5652180, c7107c3 and 2956c1a.

Still open after landing

Every commit is SSH-signed.

🤖 Generated with Claude Code

BunsDev and others added 25 commits October 23, 2026 18:48
Same-machine HTTP(S) origins only; localhost resolutions re-checked at
connect; redirects, credentials-in-URL, queries and unexpected paths
refused; deadline, byte cap and cancellation; fixed error text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Profiles live in app/local-connections.json without secrets; optional
tokens use the existing SecretStore under local_connection:<id>. The
renderer view carries presence only. Revisions move when runtime,
address or token change; a token never follows a changed address;
stale edits are refused; deletion leaves a non-resolving tombstone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ollama (tags/ps/capped show), LM Studio (/api/v0/models, /v1 fallback)
and Responses-compatible (/v1/models) metadata reads only. Exact IDs,
installed/loaded/kind/advertised states or unknown, cloud-routed and
embedding models unselectable, manual IDs kept on failure. Size, count
and time bounds; superseded, edited or deleted reads return stale.
The resolver test seam is always wrapped by the loopback check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
local-models:command validates request shape strictly and is registered
localOnly; edits and deletes invalidate in-flight discovery. Store
desktop's offline demo refuses it. Adds a production-IPC Electron spec,
the dated review receipt and the status entry; completion stays blocked
on #377.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…al (#378)

Each saved token now gets its own versioned secret entry, and the profile
names the entry it uses. Edits write any new token first, then the profile,
and remove the superseded entry only after the profile is durable; a failed
write drops the new entry instead. Failure-injection tests cover rotation,
clear, endpoint moves, create and delete.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A local server that echoes its bearer token into a model ID no longer gets
it into IPC: the listing is rejected whole as `reflected-credential`, never
redacted into a different model identity, and manual IDs holding the token
are left out. Exact and embedded fixtures cover Responses, LM Studio and
Ollama listings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The installed CLI moved from 0.163.0 to 0.164.0, which invalidates the
earlier receipt. Same Strata build (all ten runtime hashes match), same
probes: schema selection and real read -> Stop -> continuation passed again.
Records the schema delta and keeps every earlier boundary.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… of plain text (#378)

Failing-first regressions, each confirmed against 954cd5b before the fix:

- An unreadable, wrongly shaped or newer-version local-connections.json
  read as empty and the next save replaced it, losing every profile and
  tombstone (AC6 history). Only a missing file reads as empty now; list
  and every edit throw a fixed message and leave the file byte-for-byte,
  and resolve/provenance return null. Entries this build can't validate
  are written back exactly as found and are never listed or resolved.
- A saved token pasted into the label or a manual model ID was written to
  the plain-text profiles file and returned in views (AC3). Create and
  update refuse it, including when a new token is already inside a saved
  name or ID. An address change still drops the token, so nothing saved
  can repeat it.
- Token entries left by a crash between saving a token and its profile,
  or by a failed clear on delete, stayed in secrets.json. After every
  successful save, local_connection entries no profile (live or foreign)
  names are removed; other secrets are never touched. SecretStore gains
  names(), which lists entry names only.
- resolve() reports credentialUnavailable when a saved token can't be
  decrypted, for discovery to act on in the next commit.

The token-reflection fixture no longer saves a manual ID holding the
token, since that is now refused at save time.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…adline per discovery (#378)

Failing-first regressions, each confirmed against 954cd5b before the fix:

- When a profile's saved token couldn't be decrypted (keychain locked or
  unavailable), discovery sent the metadata reads without it and could
  report "ready" from an unauthenticated answer. It now returns
  "unavailable" with the new fixed reason credential-unavailable, keeps
  manual IDs, and makes zero requests (AC3, AC1).
- Each read had a deadline but a whole discovery did not: 32 Ollama
  /api/show reads just under the per-request deadline, four at a time,
  held the answer for ~7.2 s at a 1 s deadline (~40 s at the default).
  A discovery now ends within three per-request deadlines: listings use
  at most two, and per-model reads share what remains. Detail still
  unread at the deadline stays "unknown", not a failure; a real cancel or
  supersede still returns stale.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ngs (#378)

Regression coverage only; both passed on first run against 954cd5b, so
neither found a defect.

- Through LocalModelsService (the path local-models:command takes), a
  slow read is stale after a label-only, manual-IDs-only, address or
  token edit, and after deletion; an untouched profile still reads. The
  existing stale test drove the store and invalidate() directly.
- Endpoint policy: octal and trailing-dot IPv4 and fullwidth "localhost"
  normalize to loopback origins; IPv4-compatible, NAT64 and other
  embeddings of 127.0.0.1, "localhost." and port 65536 are refused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Receipt section "Hardening, 2026-10-24": each defect, the failing
assertion it began with on 954cd5b, the regression-only coverage that
found nothing, request counts, and exact command results on b12483c.
Status names the hardening on lm2-integrate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Applies the LM-1 session's consumer patch
(docs/reviews/2026-10-24-lm1/lm2-identity.patch, written against
954cd5b) on top of the hardening commits; it applied without conflicts.

- shared/local-connections.ts no longer declares its own ConnectionRef.
  It imports and re-exports ConnectionRef and schema-1 LocalModelRef from
  shared/local-models.ts, and LocalRuntime is an alias for
  LocalMetadataRuntime.
- Discovered and manual descriptors build their model with
  localModelRef(connection, exactId), so each carries schema: 1 and a
  copied revision. IDs are not normalized.

Failing first: the Ollama fixture's model assertion, updated by the
patch to expect schema: 1, failed against the merged tree before the
source half was applied. No other behaviour changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The network-boundary wording LM-1 proposes for AGENTS.md says discovery
refuses proxy routing. Node 24 can route http.request through
HTTP_PROXY when NODE_USE_ENV_PROXY or --use-env-proxy is set, and the
bearer token would reach that proxy before the loopback check on the
response. A child process with each setting and a recording proxy shows
the read and its token go straight to the loopback target; the proxy
sees nothing.

Regression only: it passed first on Node v24.22.0, because each request
uses its own agent (agent: false). Removing that from the compiled
policy makes the test fail, so it would catch a change that reached the
global agent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Descriptors reported advertised tools/vision/reasoning, a second
capability vocabulary beside #377's Capability (tools, images,
structuredOutputs, reasoning, resume, cancellation). advertised is now
Record<Capability, Advertised>:

- vision becomes images, from the same runtime facts (Ollama "vision",
  LM Studio type "vlm"/"llm").
- structuredOutputs, resume and cancellation are always "unknown",
  because none of these listings advertise them.

The values are still runtime metadata, never qualification. Failing
first: the Ollama, LM Studio and Responses fixtures, updated to the
six-key shape, failed against the old three-key descriptors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#378)

Receipt section "LM-1 adoption, 2026-10-24": the merge of LM-1's
reconciliation (91deb28, not yet on #397), the identity patch, the
capability keying, the proxy regression, what was deliberately not
adopted, and exact results on 1211708. docs/local-models.md now says the
consumer patch is applied on lm2-adopt instead of "not yet adopted";
status names lm2-adopt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reconciliation this branch merged as local 91deb28 is published in
#400 (lm1-handoff at cb7ca6c, same contract files), and #397 merged to
main as ffb9e1d. The receipt records the #400 merge and the results on
its merged head 1cf5ca2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vercel

vercel Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
modex Ready Ready Preview Oct 24, 2026 5:09pm UTC

Request Review

@github-code-quality

github-code-quality Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: TypeScript

TypeScript / code-coverage-agent

main 21e50ba lm2-adopt 002f65b +/-
65% 65% 0%
View coverage of the 8 most impacted files.
File main 21e50ba lm2-adopt 002f65b +/-
apps/store-desk...rc/main/demo.ts 95% 95% 0%
apps/desktop/sr...gine/secrets.ts 100% 100% 0%
apps/desktop/sr...shared/types.ts 100% 100% 0%
apps/desktop/sr...dels/service.ts 0% 95% +95%
apps/desktop/sr.../connections.ts 0% 100% +100%
apps/desktop/sr...ls/discovery.ts 0% 100% +100%
apps/desktop/sr...point-policy.ts 0% 100% +100%
apps/desktop/sr...-connections.ts 0% 100% +100%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 24, 2026 17:41 UTC

…378)

Val accepted Gate A narrowly on 2026-10-24 for main at bb0e1a4: the
LM-1 contract (#397, #400) and the recorded Strata combination only (see
the acceptance comment on #377). local-models.md, both status bullets
and the LM-2 receipt now say so instead of "not accepted", and list
what remains open: native Ollama/LM Studio metadata reads, the AGENTS.md
network wording, the #386/#398 choice and the landing order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
BunsDev and others added 2 commits October 24, 2026 10:26
Resolves docs/status.md: keeps main's new In-flight entries and this
branch's LM-1 entry (Gate A accepted), now saying LM-2 consumes the
contract through #403. The LM-2 entry moves from In flight to "On main,
unreleased", because #403 lands it, and keeps its open gates (native
Ollama/LM Studio reads, the AGENTS.md metadata wording).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@BunsDev BunsDev changed the title LM-2: adopt LM-1's shared identity and capability names (#378) LM-2: main-owned local connections and bounded model discovery (#378) Oct 24, 2026
@BunsDev
BunsDev changed the base branch from lm2-integrate to main October 24, 2026 15:31
@BunsDev
BunsDev enabled auto-merge October 24, 2026 15:35
BunsDev and others added 2 commits October 24, 2026 12:08
#405 recorded Val's Gate A acceptance and approval of the AGENTS.md
metadata boundary, plus a CLI inventory with no local generative model.

Resolutions:
- docs/local-models.md keeps main's status line. The adoption paragraph
  now says #403 adopted the contract and that #386 and #398 are
  superseded.
- docs/status.md keeps main's LM-1 entry, which now says LM-2 consumes
  it through #403. The LM-2 entry records the approved boundary and
  says LM-2's discovery has not yet run against a real runtime.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — 002f65b0 Deployed Oct 24, 2026 by vercel[bot]
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