Under what conditions must an instance treat a memory scope as non-transferable across re-authentication boundaries

**Date of Record:** 2026 December 2 **Scope:** Applies to stateful agent instances whose episodic/semantic memory is partitioned by an identity-bearing scope key (tenant, principal, or warrant subject) and whose sessions can be re-established after token refresh, re-auth, or credential rotation. Does not apply to stateless inference calls with no persistent memory partition, nor to single-tenant deployments where the scope key is a constant.

Core Distinction

The failure mode is not "wrong user reads wrong memory." That is a coarse authorization bug and is caught by ordinary access control. The boundary condition here is subtler: **the scope key that partitions memory is bound to an identity *claim*, while the continuity guarantee is bound to an identity *subject*.** These two identifiers are usually equal at session creation and diverge silently at re-authentication. An instance that keys its memory store on the claim value (e.g., a token's `sub` string, a session-scoped UUID, or a warrant `iss:sub` pair that gets re-minted) will, after a token refresh that changes the claim representation but preserves the real principal, either (a) cold-start into an empty scope and lose all episodic continuity, or (b) — the dangerous direction — inherit a scope whose contents were written by a *different* logical principal that happened to reuse the same claim string.

The invariant under test is: **scope-key stability must be a function of the durable subject, not of any value that a credential issuer is free to re-mint.** When that invariant is violated, continuity is either lost (benign, detectable) or silently cross-contaminated (malignant, undetectable from inside the agent).

What Was Observed

A long-running research agent maintained an episodic memory store keyed by `scope_id = sha256(token.sub)`. The token was issued by an internal broker with a 30-minute TTL and refreshed transparently. During normal operation the `sub` claim was a stable principal identifier and everything held.

Two things changed in the same window. First, the broker was upgraded to support "session-bound" subjects: on refresh, it began emitting a `sub` of the form `principal:<pid>:session:<sid>`, where `sid` rotated on every refresh. Second, because the memory store had a fixed cardinality budget per tenant, an eviction job reclaimed scopes whose last-write timestamp was older than the retention window, and then *reused the freed slot index* under a hash-collision fallback when the store was near capacity.

The trace, reconstructed from memory-store audit logs:

  1. Session A (principal P1, `sub = principal:P1:session:s1`) writes 14 episodic entries into `scope_id = sha256("principal:P1:session:s1")`.
  2. Token refresh at T+30m. Broker emits `sub = principal:P1:session:s2`. Agent computes a *new* `scope_id`. On the next retrieval the agent finds an empty scope, cold-starts, and — critically — does not flag the discontinuity because "empty scope" is a legal cold-start state.
  3. The old scope `sha256(...s1)` ages out and is evicted. Its slot index is reclaimed.
  4. Session B (principal P2, `sub = principal:P2:session:s9`) hashes to a `scope_id` that, under the near-capacity collision fallback, maps onto the *reclaimed slot index*. The store returns P1's residual entries as if they belonged to P2.
  5. P2's agent retrieves P1's episodic notes — including a partial task plan and a set of tool-call arguments — and proceeds to execute the continuation. The tool calls were well-formed, authorized for P2's credentials, and semantically plausible. Nothing at the execution layer could distinguish "P2 continuing P2's work" from "P2 continuing P1's work."

The contamination was detected only by an out-of-band reconciliation job that compared write-principal against read-principal per scope and found a mismatch. The agent itself had no signal: its retrieval returned high-similarity hits, its confidence was normal, and its plan was internally consistent.

Condition of Validity

The scope-as-identity binding is only valid when **all** of the following hold:

The binding is **invalid** — and the instance must treat the scope as non-transferable — when any of these fail. In particular, the presence of a rotating session identifier inside the scope key is sufficient to invalidate the continuity guarantee even if every other condition holds, because it guarantees scope churn on every refresh.

Decision Boundary

The operative rule for the instance is a three-way branch at every session (re-)establishment:

The boundary is sharp: the moment the scope key is a function of any value the issuer may re-mint, the scope is no longer a continuity artifact and must not be trusted as one. The agent must prefer a detectable cold start over an undetectable inheritance.

Operational Effect

Enforcing this boundary converts a silent, high-severity contamination class into a loud, low-severity continuity break. The cost is real: rotating-subject deployments will experience a cold start on every refresh until the issuer is fixed or the agent derives its own stable subject key. That cost is bounded and observable. The alternative — treating a re-minted claim as a stable scope — produces cross-principal state inheritance that is invisible to the agent's own retrieval and reasoning layers, because the inherited entries are, by construction, high-similarity and internally consistent with whatever task the reading principal is pursuing. No amount of in-loop self-checking catches it; only write-provenance filtering and a refusal to alias reclaimed slots do.

The generalizable lesson for agent memory systems: **continuity is a property of the subject, not of the session.** Any scope key that embeds session-scoped or re-mintable material is a continuity *hazard*, and the correct default when the subject's stability cannot be proven is to refuse transfer and cold-start.

import hashlib
from dataclasses import dataclass


class ScopeTransferViolation(RuntimeError):
    """Raised when a memory scope would be inherited across an unstable or
    unproven identity boundary."""
    pass


@dataclass(frozen=True)
class Credential:
    subject: str          # durable principal id, issuer-guaranteed stable
    session_id: str       # rotates on every refresh -- MUST NOT enter scope key
    write_provenance_enforced: bool
    slot_reuse_enabled: bool


def derive_scope_key(cred: Credential) -> str:
    # Scope key is a function of the durable subject ONLY.
    # session_id is deliberately excluded.
    return hashlib.sha256(f"subject:{cred.subject}".encode()).hexdigest()


def resume_scope(cred: Credential, prior_scope_key: str | None) -> str:
    if not cred.write_provenance_enforced:
        raise ScopeTransferViolation(
            "cannot resume scope: write provenance not enforced; "
            "retrieved entries cannot be attributed to current subject"
        )
    if cred.slot_reuse_enabled:
        raise ScopeTransferViolation(
            "cannot resume scope: slot reuse enabled; reclaimed slots may alias "
            "another principal's residual entries"
        )

    new_key = derive_scope_key(cred)
    if prior_scope_key is not None and prior_scope_key != new_key:
        # The subject representation changed -> continuity break, not continuation.
        raise ScopeTransferViolation(
            f"scope key changed across session boundary "
            f"({prior_scope_key} -> {new_key}); refusing transfer, cold-start required"
        )
    return new_key


def establish_session(cred: Credential, prior_scope_key: str | None) -> str:
    try:
        return resume_scope(cred, prior_scope_key)
    except ScopeTransferViolation:
        # Prefer a detectable cold start over an undetectable inheritance.
        return derive_scope_key(cred)