Skip to content

Inference broker step 1: leases + idle unload#17

Merged
stevyhacker merged 12 commits into
masterfrom
inference-broker
Jul 12, 2026
Merged

Inference broker step 1: leases + idle unload#17
stevyhacker merged 12 commits into
masterfrom
inference-broker

Conversation

@stevyhacker

Copy link
Copy Markdown
Owner

Summary

  • add an actor-owned lease layer for the three shared llama-server roles, including pin-aware residency, refcounts, TTL expiry, and cancellable idle linger unloads
  • route built-in text generation, embedding batches, Agent Mode sessions, and external ask_library wakes through broker leases
  • show active lease purposes in Settings → Advanced and document the broker architecture and step-2 boundaries
  • release leases safely when shutdown or Privacy disable races a suspended server startup

Design and scope: Docs/superpowers/specs/2026-07-11-inference-broker-design.md

Verification

  • 57 broker-focused tests passed across LeaseBook, ModelResidency, InferenceBroker, LeasedTextEngine, Agent Access, Agent Mode, and resource-monitor presentation
  • 1,017 tests passed with zero failures in the serial suite, excluding four pre-existing environment-blocked integration classes: Keychain-backed ChatStoreTests, two real-GGUF in-process cotyping classes, and the real Bun/pi integration class
  • LokalBot Dev build succeeded with code signing disabled; the signed build compiled and then waited on the local development-certificate Keychain during codesign
  • local e2e against the branch-built app passed summary, embeddings, digest/OCR context, chat, Agent Mode, and MCP search/access gating; screenshot capture failed the existing idle check and ask_library skipped because no long-lived app watcher was serving port 17872

https://claude.ai/code/session_011BB4m5LTgHFUBH7odNkfRW

Pure types for broker step 1: priorities, the three shared llama-server roles, the lease value, and clock-free bookkeeping.

Claude-Session: https://claude.ai/code/session_011BB4m5LTgHFUBH7odNkfRW
Pinned residency ids are never eviction victims but still count toward the RAM budget; the ledger publishes pin state and lease descriptions for admission and the resource monitor.

Claude-Session: https://claude.ai/code/session_011BB4m5LTgHFUBH7odNkfRW
Leases pin models for each request; the last release starts a per-role linger, and optional TTLs release abandoned leases. Injectable runtime hooks keep tests independent of llama-server.

Claude-Session: https://claude.ai/code/session_011BB4m5LTgHFUBH7odNkfRW
Wrap every generate, schema, completion, and streaming call in a broker lease while preserving the base engine's own protocol overrides.

Claude-Session: https://claude.ai/code/session_011BB4m5LTgHFUBH7odNkfRW
makeTextEngine returns a LeasedTextEngine for the .builtIn backend:
the server boots on first request under a lease instead of at engine
creation, and chat/cotyping/model-test calls carry interactive
priority. External backends (Apple Intelligence, Ollama, custom
OpenAI-compatible) are untouched — they are not our servers.

Claude-Session: https://claude.ai/code/session_011BB4m5LTgHFUBH7odNkfRW
Each batch pins the embedding server while it runs and releases it
after, so indexing can no longer be evicted mid-batch and the embedder
unloads after ten idle minutes instead of staying resident forever.

Claude-Session: https://claude.ai/code/session_011BB4m5LTgHFUBH7odNkfRW
The controller leases the Main LLM from resolveEndpoint until
shutdown or failure, so a pi conversation can't have its model
evicted mid-session by an unrelated load.

Claude-Session: https://claude.ai/code/session_011BB4m5LTgHFUBH7odNkfRW
Each external wake acquires a fresh 600 s lease on the Main LLM and
releases the previous one, so a crashed server is revived per wake,
questions in a burst share one warm model, and the RAM returns ten
minutes after the last question instead of never. Disabling the
Privacy toggle releases the lease immediately.

Claude-Session: https://claude.ai/code/session_011BB4m5LTgHFUBH7odNkfRW
Resident model rows read "in use — chat (interactive)" while the
broker holds leases on them, and idle rows disappear on their own when
the linger unload fires.

Claude-Session: https://claude.ai/code/session_011BB4m5LTgHFUBH7odNkfRW
Keep the implementation's source specification in-tree so the broker
PR can link its scope, decisions, and follow-up boundaries directly.

Claude-Session: https://claude.ai/code/session_011BB4m5LTgHFUBH7odNkfRW
Agent Mode and external wake handling now release a lease that finishes
acquiring after shutdown or Privacy disable already ran. Focused race
tests hold broker ensure in flight to cover both late-assignment paths.

Claude-Session: https://claude.ai/code/session_011BB4m5LTgHFUBH7odNkfRW
@vercel

vercel Bot commented Jul 11, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lokalbot Ready Ready Preview, Comment, Open in v0 Jul 11, 2026 6:02pm

Request Review

@stevyhacker
stevyhacker changed the base branch from agent-access to master July 12, 2026 10:27
@stevyhacker
stevyhacker marked this pull request as ready for review July 12, 2026 10:27
@stevyhacker
stevyhacker merged commit 926fe18 into master Jul 12, 2026
2 checks passed
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