Skip to content

[P1][LM-1] Define local-model contracts and prove the native Codex integration seam #377

Closed

Description

@BunsDev

Outcome and dependencies

Accept the smallest connection/model contract and prove the installed Codex app-server can use it before building the complete interface.

Parent: #376. Completion dependencies: none. Delivery group: Local models v1 / Gate A. Priority: P1. Consume the architecture, privacy invariants and shared execution contract in #376. This is the first implementation issue; parent closure is not a prerequisite.

Context and source entry points

Publication baseline: ec7be578765f9ce54976882853e57ca190252361; refresh current main and open PRs before work. Reuse #273's accepted conversation contracts and the already-landed #373 iPhone broker integration; do not recreate them.

Existing: AGENTS.md, apps/desktop/src/shared/types.ts, apps/desktop/src/main/engine/backends/{types,codex}.ts.
Proposed: apps/desktop/src/shared/local-models.ts, docs/local-models.md, apps/desktop/test/local-model-contract.test.ts. Proposed paths are additions, not claims of existing modules.

Produces: reviewed connection/model/run-provenance types, migration semantics, compatibility-evidence contract, exact native configuration/source map and a reproducible native feasibility receipt. Downstream issues consume those accepted artifacts, not invented parallel contracts.

Implementation steps

  • Read current main, scoped instructions, open PRs, [Tracker] Native conversation fidelity: execution → transcript → recovery → Notes #273 and the native backend schemas. Record the exact source map, CLI version and supported configuration mechanism. Reconcile changed source rather than treating the historical audit SHA as the required base.
  • Separate harness (codex/claude), connection, opaque exact model identifier, credential reference and run provenance. Preserve BackendId as the execution harness. Specify versioned connection/model references and additive thread migration; do not turn every inference server into a tool executor.
  • Define independent connection-health and compatibility states. Capabilities use supported/unsupported/unknown plus evidence and tested configuration. Record effective context separately from advertised maximum. Tool use, images, structured outputs, reasoning, resume and cancellation are distinct capabilities. Changing relevant model/runtime/template/configuration invalidates prior qualification.
  • Perform an explicitly authorized native app-server probe against an already installed local model: initialize, select model, run a harmless read/tool round trip in a disposable fixture, interrupt, and continue safely. Test arbitrary model IDs and actual catalogue requirements. A terminal --oss demonstration or synthetic greeting alone is insufficient.
  • Inspect version-specific provider wire and native tool requirements using the official references in [Tracker][LM] Integrate local models through native harnesses with verified compatibility #376. Capture actual request/response shapes, not assumed Chat Completions compatibility. Record unsupported controls and the safe unavailable behavior.
  • Document the narrow policy boundary: bounded metadata discovery HTTP belongs in main; coding inference stays inside native CLIs. Preserve the no-direct-coding-inference rule. Record local app/account admission behavior without bypassing existing account or managed-safety policy.

Acceptance criteria

  • AC1: the accepted contract identifies connection and revision independently of model name/cloud account; legacy thread fixtures retain their original meaning.
  • AC2: a real app-server probe records exact version/configuration, observed tool result, interruption and safe continuation evidence, or Gate A remains explicitly blocked with a reproducible reason.
  • AC3: no model-brand allowlist, direct coding-inference client, second agent loop or tool executor is introduced.
  • AC4: capabilities distinguish metadata assertions from observed tests; greeting success is not coding qualification.
  • AC5: the source/interface map is sufficient for discovery, execution, UI and policy consumers without duplicate identity models. Existing account/safety constraints remain intact.

Verification and handoff

Use failing-first contract/migration tests and fresh repository-required checks (pnpm build && pnpm test; UI changes also pnpm test:e2e). Native probes use explicit authorization and disposable data, never unapproved downloads or production edits. Record mock versus native evidence separately with full SHA, CLI/runtime/model/configuration versions, exact commands/results and remaining gates. Update docs/status.md and a dated docs/reviews/ receipt. No merge/release.

Long-running goal prompt

Implement LM-1 in TypeSafeAI/modex under #376. Read this issue, the tracker architecture/shared execution contract, current AGENTS.md, source and open PRs. Verify current main and an owned worktree. Establish the minimal connection/model/run-provenance and qualification contracts. Inspect the installed app-server schema and existing launch seam, then prove a harmless local tool round trip, Stop and safe continuation before downstream work assumes support. Keep legacy threads, account policy and native-only execution intact. Work one acceptance slice at a time with failing-first tests. Run targeted and required checks, update status/evidence and prepare signed reviewable commits. Checkpoint full SHAs, exact results, native/runtime/model versions, unresolved gates and one next step. No merge, release, global configuration changes or unapproved downloads.

Follow-up / resume prompt

Resume LM-1 from the live issue/PR and checkpoint. Verify worktree ownership and inspect the actual diff. Recheck whether the installed CLI schema, native probe or connection contract changed. Reproduce the smallest native feasibility test and resolve only the remaining contract ambiguity. Do not substitute terminal documentation, mocks or a greeting for app-server/tool evidence. Rerun relevant smoke and required checks, separate native evidence from fixtures and update each acceptance receipt. Leave unverified gates open with an exact next action. Do not merge, publish or widen scope.

Activity

  1. self-assigned this
    on Oct 22, 2026
  2. BunsDev commented on Oct 23, 2026

    @BunsDev
    ContributorAuthor

    Refreshed goal prompts — 2026-10-23 (main at 203a350)

    On main already:

    • nothing from LM-1. apps/desktop/src/shared/local-models.ts and docs/local-models.md do not exist on main, and docs/status.md has no local-model entry;
    • Codex Plan mode now runs in Codex's native plan collaboration mode (Run Plan mode on Codex in Codex's native plan collaboration mode (CF-3) #385). Its nested collaborationMode.settings model takes precedence over the turn-level model, so LM-3 must pin both.

    Still open:

    • Review and landing. The LM-1 work is a single signed commit, 048d1e8, on the local lm1-contract branch. It has not been pushed and has no PR. It adds shared/local-models.ts, seven contract tests, docs/local-models.md, a dated receipt (docs/reviews/2026-10-22-lm1-feasibility.md plus probe scripts and filtered JSON) and a status entry. It is based on ec7be57, so it needs a rebase onto current main.
    • Gate A acceptance. The receipt records a real codex app-server (codex-cli 0.163.0) run against the user's installed Strata 0.1.47 runtime with qwen3.8-flash-next-iq3_s. It covered selecting an unlisted model ID with fallback off, a sentinel read, an interrupted sleep, explicit background-terminal cleanup and continuation on the same thread. Nobody has accepted it on this issue. An unpublished review in the lm-foundation worktree recommends accepting it for narrow consumption and asks for a sanitized runtime launch config in the handoff.
    • Not covered by the probe: Ollama or LM Studio, fresh-process thread/resume, native Plan mode, edit/test, images, structured output, offline/network-denied runs, Electron or companion UI.
    • Contract reconciliation with LM-2. Draft PR LM-2: secure local connections and bounded model discovery (#378) #386 keeps its own shared/local-connections.ts types. Its model refs lack schema: 1. Its runtimes (ollama, lmstudio, responses) do not map one-to-one to LM-1's profiles (ollama, lmstudio, llamacpp, vllm, custom). The accepted contract has to settle one shared identity.
    • Policy note. AGENTS.md lists every network call the app makes outside the CLIs. Loopback metadata discovery from main is not on that list yet.

    Leftover local worktrees: lm1-contract (unpushed 048d1e8), lm2-discovery (PR #386), lm3-isolation (unpushed docs checkpoint 665c095), lm-foundation (untracked review and design docs only) and lm6-runtimes (clean at main). Raw LM-1 probe artifacts are outside the repo under ~/Documents/Codex/artifacts/modex-lm1/2026-10-22/.

    Long-running goal prompt

    Finish LM-1 (#377) in TypeSafeAI/modex under tracker #376. Read AGENTS.md, #376's architecture, privacy invariants and shared execution contract, this issue, docs/status.md and draft PR #386. Then verify main's SHA. Never edit the primary checkout. The LM-1 work is commit 048d1e8 on the local lm1-contract branch. If you are not its owner, claim it with scripts/worktree.sh claim lm1-contract --owner <session> and run check; otherwise use scripts/worktree.sh new. Slice 1: rebase onto current main and re-run the seven contract tests. Reconcile with #385, which merged native Plan collaboration mode: record in docs/local-models.md that the collaboration-mode model overrides the turn model and that a local run must pin both. Slice 2: settle one shared identity with LM-2. Add schema: 1 to model refs, map #386's ollama/lmstudio/responses metadata runtimes to LM-1's connection kinds, and say which module owns ConnectionRef. Write failing tests first. Slice 3: add a sanitized runtime launch config to the receipt so another person can repeat the Strata probe. Keep real-model execution inside codex app-server, with no direct inference client, model allowlist or tool executor. Add the loopback metadata-discovery boundary to AGENTS.md's network list as a proposal for Val to approve. Slice 4: only with Val's explicit authorization, run the same app-server probe against an already-installed Ollama or LM Studio model. Never download models or edit ~/.codex/config.toml. Run pnpm build && pnpm test and pnpm typecheck; there is no UI change, so no e2e. Update docs/local-models.md, docs/status.md and the dated docs/reviews/ receipt. Push signed commits, open a PR that links #377, and ask Val to accept Gate A. Wait for Val's go-ahead to merge.
    

    Follow-up / resume prompt

    Resume LM-1 (#377). Confirm you own the lm1-contract worktree, fetch main and read the latest comments here, on #376 and on #386. Check whether the installed codex-cli version changed since 0.163.0. If it did, regenerate the app-server schema and compare its hashes to the receipt before trusting the earlier probe. Re-run the contract tests. If Val has accepted Gate A, post the accepted SHA so LM-2 and LM-3 can consume it. If not, fix only what the review asked for. Do not swap a mock, a greeting or a terminal --oss run in for app-server tool evidence. Post a checkpoint: SHA, CLI/runtime/model versions, results, what's left for a human, and one next action.
    
  3. BunsDev commented on Oct 24, 2026

    @BunsDev
    ContributorAuthor

    LM-1 checkpoint: the original producer landed through #397 as ffb9e1dba5d8f214d91a2514fccb0e26b8153372. PR #400 now targets main at signed head cb7ca6c30a3aa68012187aaf508cc552c84445d3, incorporating main 6c40547ab05eff9fd6095da8e570affcd331cf51 and resolving the parent squash conflicts. Owned branch/worktree: lm1-handoff. Its eight-file diff contains the canonical identity/runtime mapping, schema-1 model factory, tested LM-2 consumer patch, sanitized Strata launch configuration and explicitly unapproved network-policy proposal.

    Fresh local pnpm build && pnpm test and pnpm typecheck passed: 2,038 passed, 16 skipped, zero failures; focused LM-1 tests passed 9/9. Hosted CI/E2E, iPhone and Windows/Linux checks passed on prior head 8b3b35ed16c76c39b70c56fb2128417576ae8445; the current head has separate new checks. The recorded native receipt remains Codex 0.164.0, Strata 0.1.47, qwen3.8-flash-next-iq3_s, context 32768, ordinary tool read/Stop/terminal cleanup/same-thread continuation. This finish work ran no new inference and changed no global configuration or models.

    Val: please accept or reject narrow Gate A and record the exact accepted producer SHA here, and decide the AGENTS metadata proposal in #400. LM-2 adoption remains gated on that acceptance. Ollama/LM Studio probing still requires your separate explicit authorization. Plan, fresh-process resume, offline and broader runtime qualification remain open. No merge of #400 is authorized or performed; the next action is the acceptance decision.

  4. BunsDev commented on Oct 24, 2026

    @BunsDev
    ContributorAuthor

    Gate A: accepted (narrow), 2026-10-24

    Val approved Gate A in an LM-2 Claude Code session on 2026-10-24 ("i approve"). This comment records that decision.

    Accepted producer: main at bb0e1a42ac7bb3e11ccfee05a40d8a02f1dc10c4, specifically the LM-1 contract in apps/desktop/src/shared/local-models.ts from #397 (ffb9e1dba5d8f214d91a2514fccb0e26b8153372) plus #400's identity reconciliation (ConnectionRef, schema-1 LocalModelRef, localModelRef, and the LocalConnectionProfile ↔ LocalMetadataRuntime mapping).

    Accepted native evidence, for this combination only: codex app-server (codex-cli 0.163.0, refreshed on 0.164.0) with Strata engine 0.1.47, qwen3.8-flash-next-iq3_s, effective context 32768, loopback, fallback disabled. It covers an unlisted exact model ID, a native tool read of a sentinel, an interrupted command with explicit background-terminal cleanup, and continuation on the same thread. See docs/reviews/2026-10-22-lm1-feasibility.md.

    Not covered by this acceptance:

    • Qualification beyond that combination: Plan mode, fresh-process resume, account/profile isolation, edit/test, Ollama, LM Studio, other runtimes, images, structured output, offline/network-denied operation and UI.
    • The AGENTS.md loopback-metadata network proposal from Finish LM-1 identity reconciliation and reproducible probe handoff (#377) #400, which is a separate decision.
    • Any Ollama or LM Studio probing, which still needs explicit authorization.
    • Merge authority for downstream PRs.

    Downstream: LM-2's adoption of this contract is draft #403. Its LM-1 files are identical to bb0e1a4, and it is stacked on #402, which is stacked on #398. LM-3 (#379) may now consume the accepted contract within the scope above.

  5. BunsDev commented on Oct 24, 2026

    @BunsDev
    ContributorAuthor

    Val separately approved the #400 AGENTS.md loopback-metadata boundary in this LM-1 task on 2026-10-24. The approved scope is the existing proposed wording: bounded main-owned loopback metadata reads using only the configured connection's credential, with no prompts/files/cloud credentials, proxy/redirect routing, inference, model lifecycle operations or tool execution. The narrow Gate A acceptance at bb0e1a42ac7bb3e11ccfee05a40d8a02f1dc10c4 remains as already recorded; #378/#379 can consume that accepted producer and the approved metadata boundary within their own gates.

    Val also authorized an installed-model probe, then explicitly selected “Defer until a local coding model exists” after inventory: Ollama 0.40.10 has no models; LM Studio has only an embedding model on this Mac, while its LLM entries belong to a linked device. No inference was attempted, and no weights were downloaded/imported. Ollama/LM Studio coding qualification remains deferred. This records approval and deferral decisions, not downstream merge authority; the documentation follow-up is being verified in owned lm1-native-approval.

  6. BunsDev commented on Oct 26, 2026

    @BunsDev
    ContributorAuthor

    Completion audit against main d717bb0861378718783513ae34895bfd50ae09c8: closing LM-1 for the narrow Gate A scope Val already accepted. The accepted producer bb0e1a42ac7bb3e11ccfee05a40d8a02f1dc10c4 and approval-documentation merge e5252ea6a66a3d38ca76975211adaf8e0b55af96 are ancestors of current main. The shared contract and its tests are byte-identical to the accepted producer.

    • AC1: canonical connection/revision/model identity and additive legacy migration semantics are delivered in shared/local-models.ts; LM-2 consumes that identity.
    • AC2: the accepted, preserved real app-server receipts cover Codex 0.163.0 and its 0.164.0 refresh with Strata 0.1.47, the exact recorded model/configuration, native sentinel reads, interruption, explicit background-terminal cleanup and same-thread continuation. This audit inspected the existing receipts; it did not run new inference.
    • AC3: the LM-1 artifact is a shared contract and native feasibility handoff, with no model-brand allowlist, direct coding-inference client or second tool executor.
    • AC4: metadata assertions and configuration-bound native capability observations remain distinct; unknown or changed configuration does not inherit qualification.
    • AC5: docs/local-models.md supplies the consumer/source map, native configuration precedence and account/safety boundaries. The approved metadata exception and exact acceptance/deferral decisions are preserved in docs/reviews/2026-10-24-lm1-acceptance.md.

    The optional Ollama/LM Studio coding probe was explicitly deferred by Val until an eligible local coding model exists. Closing this producer does not qualify Plan, fresh-process resume, edit/test, account/profile isolation, UI, other runtimes or network-denied operation. Those gates remain with #378–#383 and tracker #376; #417's outstanding review findings are unaffected. Source worktrees remain protected by their owners and the pruning guards.

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

Metadata

Metadata

Assignees

Labels

area:local-modelsenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions