Skip to content

Bound per-tenant runtime lifecycle#316

Merged
oratis merged 2 commits into
mainfrom
codex/tenant-runtime-lifecycle
Jul 25, 2026
Merged

Bound per-tenant runtime lifecycle#316
oratis merged 2 commits into
mainfrom
codex/tenant-runtime-lifecycle

Conversation

@oratis

@oratis oratis commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • replace the unbounded per-UID chat-context and prompt maps with a lifecycle registry
  • create each tenant runtime single-flight under concurrent first requests
  • pin runtimes while session/history/chat/reflection work is active
  • evict idle runtimes by TTL and LRU with a hard tenant-count target
  • keep prompt snapshots inside the same runtime so context and prompt memory are released together
  • expose LISA_TENANT_RUNTIME_TTL_MIN (default 30) and LISA_TENANT_RUNTIME_MAX (default 100)

Why

The cloud process retained every tenant's full loaded history and prompt forever. Memory therefore grew with lifetime tenant cardinality, and concurrent first requests could create duplicate contexts before either populated the old map. This establishes the TenantRuntime lifecycle seam before moving advisor/activity state and context compaction into it.

Safety

Pinned runtimes are never evicted. The registry may temporarily exceed its target when every entry is active, then returns under the limit as leases release. Runtime creation failures clear their single-flight slot and remain retryable. The local/global runtime is unchanged and not subject to tenant eviction.

Validation

  • npm run typecheck — passed
  • npm test — 1393 passed, 1 skipped
  • npm run build — passed
  • tests cover single-flight creation, pinned-entry safety, TTL expiry, LRU order, idempotent release, retry after failed creation, and configuration parsing

Dependency

This is intentionally stacked on #315 because it consumes the unified inference permit lifecycle. Review and merge #315 first; this PR then becomes a focused TenantRuntime change.

@oratis
oratis changed the base branch from codex/inference-admission to main July 25, 2026 19:11
@oratis

oratis commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

Code review: reviewed single-flight creation, pin accounting, TTL/LRU eviction, capacity behavior when every runtime is active, prompt-cache co-lifecycle, and release coverage across session/history/chat/reflect routes. Found an account-deletion race where an in-flight creation could reinsert a deleted runtime; fixed in 4e2ccaa with invalidation and a retry regression test. Integrated with latest billing/admission/body/autonomy main. TypeScript, build, and 30 focused tests pass. No remaining blocking issue.

@oratis
oratis marked this pull request as ready for review July 25, 2026 19:11
@oratis
oratis merged commit 3bf81f7 into main Jul 25, 2026
1 check 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