Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 66 additions & 3 deletions src/snapshot/stage0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ import { egressPlaneGateOn } from "../knobs.js";
import { EGRESS_SYSTEM_MSGID } from "../storage/egress-state.js";
import { checkR3Identity, FoundationRejectError, r3FaultTracker } from "./plane.js";

// #7981: the kernel's content-hash mint shape (deriveMessageId: "h_" + 16
// lowercase hex, optional within-pass cluster suffix "_k" — the ledger row
// for a reminted cluster; fastpath.ts carries the same pattern). Used ONLY
// for the namespace-jump fingerprint in tryIncrementalPin below: a drifted
// overlap row whose LEDGER side is server-minted content is a namespace
// jump, not a shared-namespace drift.
const MINTED_ROW_RE = /^h_[0-9a-f]{16}(?:_\d+)?$/;
// #7981: bounded once-per-session warn guard for the namespace-jump notice
// (a session on hit-turn-only flow can fire the jump branch every turn —
// the warn stays once, the debug line lands per turn). Cleared whole when
// the cap is exceeded: the set only gates log noise, never pin semantics.
const jumpWarnedSids = new Set<string>();

export interface Stage0Input {
sessionId: string;
/** Lane name for log prefixes only ("openai" | "responses"). */
Expand Down Expand Up @@ -374,7 +387,12 @@ export function runStage0(opts: Stage0Input): Stage0Result {
// body list on carrier-off turns: the overlap then spans hundreds–2047
// rows and the pin PROVES MORE, not less — so a degraded "full" turn can
// still pin and re-upgrade the client; the full list is never a
// requirement any client must be able to produce. Exported: the anthropic
// requirement any client must be able to produce. The ONE tolerated
// exception is the #7981 namespace jump (host-uuid wire space over an
// all-content-hash ledger — see the drift loop below): there the
// row-by-row match deadlocks forever, and the egress ledger already
// answers the identical situation with REANCHOR_NOW (never null).
// Exported: the anthropic
// lane's inline pin reuses it (two-form rule).
export function tryIncrementalPin(
sessionId: string,
Expand Down Expand Up @@ -440,12 +458,57 @@ export function tryIncrementalPin(
// >2048 sessions can only ever send their retained tail) carries up to
// the client's window of overlap rows and proves MORE. ANY drift row
// degrades to the full signal — D1: never a reject.
//
// #7981 exception — the NAMESPACE JUMP. When the wire id space moves
// from content hashes to host ids (the dsh 0.1.217 client upgrade:
// every message gets a stable host uuid), the ledger — write-once per
// position (INSERT OR IGNORE) — keeps its h_ rows while EVERY
// client-declared id is a fresh uuid: every overlap row drifts
// (uuid vs h_) and the row-by-row match deadlocks the pin forever. Each
// null turn re-mints the whole prefix as h_, and fold blocks recorded
// under the churn re-anchor onto "churned bytes" every turn → the
// double cache cold per fold the issue reports. The egress ledger hits
// the identical jump and answers it with REANCHOR_NOW (never null);
// the legacy positional pin gets the same answer under a conservative
// fingerprint: EVERY drifted row must be a content-hash LEDGER row
// carrying a VALID client id that is FOREIGN to the whole ledger. A
// drift row whose ledger side already holds a host id (or whose client
// id appears somewhere in the ledger) = shared namespace = ordinary
// drift = the legacy null degrade (I2/I3). A "?" client slot proves no
// namespace and degrades. Why the tolerant branch is safe: a ledger
// whose rows are all content mints has NEVER held the client's ids, so
// no position is being rewritten IN ITS OWN namespace — stamping the
// declared ids converges in one round (miss turns ingest RAW: the
// sweep retires the un-presented h_ rows and appends the host ids,
// #3285/#4390) instead of oscillating forever. The stamped view
// ({h_ prefix restamped from the ledger, host-uuid tail}) is stable
// across turns, so fold coverage stops churning after it.
const overlapEnd = L - n; // first slot that is a NEW core (>= C)
const ledgerRows = new Set(liveIds);
let jump = false;
for (let j = 0; j < overlapEnd; j++) {
if (tailIds[j] !== ledgerEl[T - L + j]) {
log("info", `[${sessionId}] [2x2:${lane}] incremental tail drift at overlap row ${T - L + j} (got=${tailIds[j]}, ledger=${ledgerEl[T - L + j]}) — full signal (reanchor next turn)`);
if (tailIds[j] === ledgerEl[T - L + j]) continue;
const ledgerRow = ledgerEl[T - L + j]!;
const declared = tailIds[j]!;
const jumpRow =
declared !== "?" &&
MINTED_ROW_RE.test(ledgerRow) &&
!ledgerRows.has(declared);
if (!jumpRow) {
log("info", `[${sessionId}] [2x2:${lane}] incremental tail drift at overlap row ${T - L + j} (got=${declared}, ledger=${ledgerRow}) — full signal (reanchor next turn)`);
return null;
}
if (!jump) {
jump = true;
if (!jumpWarnedSids.has(sessionId)) {
if (jumpWarnedSids.size > 4096) jumpWarnedSids.clear();
jumpWarnedSids.add(sessionId);
log("warn", `[${sessionId}] [2x2:${lane}] namespace jump: every drifted overlap row is a content-hash ledger row carrying a client id the ledger has never recorded (host-uuid wire space over an h_ ledger) — pinning onto the declared ids, one round (#7981)`);
}
}
}
if (jump) {
log("debug", `[${sessionId}] [2x2:${lane}] namespace-jump pin applied (overlap rows=${overlapEnd}, new cores=${n}, view=${T}, ledger=${C}) — prefix restamps from the ledger, new cores take the declared ids`);
}
// Entry screening on the NEW cores (same rules as msgid-pin
// validateMsgIds — a bad id must never reach the ledger's unique index).
Expand Down
Loading
Loading