Skip to content

M5: Compaction-checkpoint fast path + budget voter#2

Merged
pdettori merged 12 commits into
mainfrom
feat/m5-compaction-checkpoint
Jun 24, 2026
Merged

M5: Compaction-checkpoint fast path + budget voter#2
pdettori merged 12 commits into
mainfrom
feat/m5-compaction-checkpoint

Conversation

@pdettori

Copy link
Copy Markdown
Member

M5 — Compaction-Checkpoint Fast Path + Budget Voter

Implements the pi-track plan's M4 (repo milestone 5). Spec: docs/specs/2026-06-23-m5-compaction-checkpoint-design.md. Plan: docs/superpowers/plans/2026-06-23-m5-compaction-checkpoint.md.

Makes cold-start session reconstruction O(tail) by riding Pi's native compaction as the checkpoint, and adds a per-turn budget voter that blocks tool calls once a token cap is breached.

Changes

  • @sh/session-backendRedisSessionBackend assigns each entry the Redis stream id "<position>-0", so read(fromPosition) is an O(tail) XRANGE seek instead of a full-stream scan + JS filter. New positionOfId; LogStore interface extended.
  • pi-fork (submodule) — additive SessionManager.openFromCheckpoint() + markerResumePosition helper: reads only the checkpoint marker's resumeFromPosition-forward slice, reuses the existing loadFromEntries/buildSessionContext path, and falls back to openFromBackend when there is no usable marker. openFromBackend is untouched.
  • harness/src/checkpoint-extension.ts — on session_compact, appends a tiny custom/checkpoint marker recording positionOf(firstKeptEntryId).
  • harness/src/budget-voter.ts — pure decideBudget, sessionSpendTotal, and budgetVoterExtension. Gated by env SH_BUDGET_TOKENS (+ optional SH_BUDGET_MARGIN); unset ⇒ inert.
  • harness/src/run-turn.ts — resumes via openFromCheckpoint; always registers the checkpoint extension; registers the budget voter when SH_BUDGET_TOKENS is a finite value > 0.

Submodule

This PR bumps the pi-fork submodule pointer to branch feat/m5-openfromcheckpoint on kagenti/pi (additive openFromCheckpoint loader + a caveat doc comment). No upstream PR.

Verification (no LLM key required)

  • Harness suites 19/19, @sh/session-backend 10/10, all against real Redis.
  • Reconstruction parity gate (the M5 done-criterion): openFromCheckpoint(...).buildSessionContext() deep-equals openFromBackend(...) after a real compaction; slice read is strictly smaller than the full log.
  • pi-fork build (tsgo) passes; targeted session-manager regression tests green.
  • harness/test/run-turn.test.ts is LLM-gated and excluded.

Known caveat (documented + test-locked)

Tail-load drops the session-start thinking_level_change entry (it precedes firstKeptEntryId), so thinkingLevel reconstructs to the settings default on the first post-compaction resume; it self-heals on the next turn and is harmless while thinking level is settings-governed. model is unaffected (re-set by every assistant message, always in the kept tail). A test in checkpoint.test.ts locks this behavior.

Deferred (out of scope)

everyK/forced-checkpoint cadence; cross-turn cumulative budget ledger.

Assisted-By: Claude (Anthropic AI) noreply@anthropic.com

Paolo Dettori added 12 commits June 18, 2026 23:19
Supersedes parent-design §3.3 (gateway forwarding tools). MCP becomes code
the model runs in the sandbox; creds injected + per-call audit at the
AuthBridge egress waypoint. Near-zero Pi surface; lean-both budget.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <paolo.dettori@example.com>
…ssions

Add §5: where secrets live (Keycloak + K8s Secret, broker-sidecar memory
only); per-user scoping for unattended sessions via SPIFFE actor + bound
subject + pre-authorized Keycloak delegation (RFC 8693 §4.1); placeholder
swap; OpenShell env-cred complement; best-fit comparison of AuthBridge /
OpenShell / DAM. New decisions D8-D10, consequences, and gate criterion 5.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <paolo.dettori@example.com>
… HTTP APIs

Generalizes M10's MCP-over-HTTP egress into a unified credentialed-egress
path where MCP is one special case. Same AuthBridge waypoint, selector,
audit producer, and budget machinery; per-destination credential resolver
(RFC 8693 mint vs. per-user stored grant). Adds in-mesh front-door for
external hosts (no baked CA), generic egress helper + committed GitHub
wrapper, and records the per-user external-credential store + linking flow
as an M7-M9 identity-plane dependency.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <paolo.dettori@example.com>
Pivots the non-MCP egress mechanism from an in-mesh front-door + host-based
injection (v1.0) to AuthBridge's own placeholder-swap pattern over a forward
proxy (HTTPS_PROXY + baked CA). The sandbox/tools hold only inert
placeholders; the proxy sees the request at L7 and overwrites with the real
resolved credential. gh/curl/SDKs now work natively and unmodified;
front-door + correctness-wrappers apparatus collapses; full per-call L7
audit preserved; more faithful to AuthBridge. Accepted cost: a baked CA
(trust anchor, not a secret) and a narrow env-inject escape hatch for
request-signing APIs (AWS SigV4). Selector and per-user stored-credential
model unchanged from v1.0.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <paolo.dettori@example.com>
Implements the pi-track plan's Milestone M4 (Tasks 13-14), re-targeted to
the repo's real architecture: ride Pi's native compaction as the checkpoint,
add SessionManager.openFromCheckpoint for O(tail) cold-start reconstruction,
and a per-turn token budget voter. Repo milestone 5 (follows m4-knative).

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <paolo.dettori@example.com>
Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <paolo.dettori@example.com>
Assigns each entry the Redis stream id "<position>-0" so read(fromPosition)
is an XRANGE seek instead of a full-stream scan, and adds positionOfId for the
M5 checkpoint marker.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <paolo.dettori@example.com>
Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <paolo.dettori@example.com>
Pure decideBudget policy plus an extension that meters cumulative assistant
token spend via ctx.sessionManager.getBranch(), blocks the tool call and
appends a single abort entry once the per-turn delta breaches the cap.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <paolo.dettori@example.com>
Appends a resume-pointer custom entry recording positionOf(firstKeptEntryId)
so cold start can seek directly to the kept tail.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <paolo.dettori@example.com>
Resume via the O(tail) openFromCheckpoint loader, always register the
checkpoint-marker extension, and register the budget voter when
SH_BUDGET_TOKENS is set. Adds the reconstruction parity gate.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <paolo.dettori@example.com>
Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <paolo.dettori@example.com>
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