Repository navigation
feat(kernel): add history-backed session lifecycle - #2687
Conversation
Add isolated session batching, run-owned inputs, immutable snapshots and pinned reconstruction. Separate soft write admission from hard persistence bounds while preserving explicit cleanup and uncertain-acceptance recovery. Co-authored-by: Mecatl <[email protected]>
Completed lifecycle checkpoint — full plan archive
Full publishable plan, with no substantive omissions. The 2026-11-05 delivery amendment supersedes historical no-push/no-PR and pending-status prose. This archives the completed lifecycle slice, not the new context/content plan or obsolete Phase B tasks. Planned verification below is distinguished from actual delivery results in the PR body. Future implementation remains separately authorized; humans merge. Isolated session: run-owned inputs and immutable snapshotsSlug: kernel-session Scope and authorityJoe authorized and completed the run-owned-input/immutable-snapshot revision on Delivery amendment, 2026-11-05: Joe authorized publishing this existing slice The next-slice design interview is complete. Agreed direction and the three future This plan supersedes the old idle-input/consumption model and detached-copy Scope remains four lifecycle record kinds only. No model/tool/accounting vocabulary Limits amendment: soft admission, hard bounds and error timingAgreed behavior
Approved policy/API contract (2026-11-04)Joe authorized implementation and approved this layout: existing MaxRetainedRecords, Dependency-ordered pending tasksL1. Completed: policy contract approved. Existing Max fields are hard; explicit Planning critique: no blocking inconsistency. An Important error-cause-collision Grounding
Paths abbreviated above are under Implemented baseline contractsThe following records the completed run-owned snapshot revision. Pending limits Identity and lifecycle
Batch and error boundariesKeep New I/O-free, History/policy bound and operations caller-serialized. Snapshot Public builder sketch (request/type names may follow existing conventions): batch, err := s.BeginCommit()
// handle err; batch.Discard() remains available before submission
err = batch.Create() // only for a new session
runID, err := batch.StartRun()
inputID, err := batch.AddInput(AddInputRequest{RunID: runID, Content: content})
ref, err := s.SubmitCommit(ctx, batch)
// later batch: batch.Interrupt()No empty CreateRequest, StartRunRequest or InterruptRequest. AddInputRequest is
Immutable snapshot/read surfaceSnapshot is an accepted-state handle, not a mutable detached export or restore token. Required public-contract sketch (review coherently before implementation consumers): Method/type names and routine Go collection edge behavior are contract-sketch
Append-only storage and publicationUse private immutable accepted-record backing plus geometric arrays of locators: Never replace or mutate a published array element or DTO. Append only beyond old Validate admission, canonical envelope identity, decode/own new records, all ordered Cost contract: O(1) snapshot capture and run/input/record positional access; GC owns lifetimes; snapshots/individual handles can retain extra backing capacity Load, closeout and compatibilityLoad pins Head once, reads bounded verified pages from genesis and uses common Every active accepted candidate reserves its actual one-record interruption, API compatibility: isolated unpublished Go and session payload schemas change: Completed baseline implementation tasksTasks 1–5 below are completed; they are retained to explain the existing candidate,
Observable verification
Focused gates from root: engine kernel/history adapter/architecture race tests; This revision changes engine state, format and root checks/docs: integrating agent Completed-code panel review starts at the recorded implementation start OID above, Review and deliveryFresh-context plan critique found no correctness/security/requirement gaps: Material baseline and limits-amendment choices are settled; L1's approved contract PR delivery and plan-comment synchronization for this existing slice were authorized Stop after publishing this completed checkpoint, the separately requested next-slice |
Summary
Deliver the lifecycle inspection checkpoint for #2663: an isolated, passive history-backed session aggregate. This is not completion of #2663 or parent #2659, and production sessions do not use this package.
Deliberate boundary
Only creation, run start, authored input, and interruption are implemented. No model/tool execution or lifecycle facts, normal completion, request constructor, usage accounting, pending-input service, distributed writer fencing, or production integration.
Inputs belong to active runs; loading leaves active runs active and never synthesizes an interruption. Intentional early-kernel Go/payload contracts are isolated from the legacy aggregate.
Verification
Fresh delivery gates on commit
6a7b064edaa3130b8fdb6d5c20d8b6614c6d17a4:task lint— passed across configured modules.task test:race— passed complete offline suite, modules, and standalone proofs.go run ./cmd/mecademo— passed; actual Read call/result and Write permission ask, approval, and result observed.git diff --check— passed.Earlier implementation evidence also includes generation/API/codecs freshness, docs, full offline tests, engine standalone, focused kernel/history/architecture race, session 386/fuzz, and independent Spec/Standards/Test/Domain review. Targeted test-gap fixes and the soft/hard amendment were incrementally rechecked; remaining findings and reviewer failures were zero. This does not claim a newly repeated whole-branch panel.
API compatibility
No remote-observable API/behavior change: no production callers, protobuf/server/client changes, major bump, feature identifier, or client upgrade requirement. Experimental kernel Go APIs and session payloads are new isolated contracts with snapshots tracked; no legacy session migration or mixed-version read promise. Existing History envelopes/codec contracts remain unchanged. Early-kernel changelog bookkeeping is waived by scoped guidance.
Tracking and next work
Related to #2663; do not close it from this checkpoint. The approved design interview splits continuation into reusable context/content facts, passive model/tool lifecycle, then a separate versioned request-construction library. Concrete accounting remains a later explicit checkpoint. No future implementation is included here.
The full completed-slice plan is archived and readback-verified in one identifiable conversation comment. Humans own merge; no automatic merge is configured.