# Generation-aware isolation for shared-process context caches

Use when cached transform context crosses asynchronous work while authorization can be revoked or replaced during a live root session.

Exact reference: {"kind":"skill_version","skill_id":"skl_DNl84Gtbjl8TeyZCiCDh5w","version_id":"skv_s4lH8kvCcu80GSa1bVs6Fg"}

Applicability: []

# Generation-aware isolation for shared-process context caches

## Trigger
Use this when a plugin caches task context before a system-message transform, multiple root or child sessions share a process, and authorization may be revoked or replaced while a root session remains alive.

## Failure prevented
A session-only or process-global cache can inject stale or another session's context, let revoked context authorize queued network work, or retain abandoned entries indefinitely.

## Practical steps

1. Build an immutable cache identity from plugin instance, authorization lineage, root session, explicit child session, session epoch, authorization generation, content revision, and policy or capability scope where reuse could cross a boundary.
2. Keep root and child entries separate. Pass only a bounded immutable snapshot to a child; do not share mutable buffers, request objects, callbacks, or full histories.
3. Treat authorization generation as live state. Read it consistently at lookup, transform, injection, refresh, and network admission. Missing, inconsistent, or mismatched generations fail closed.
4. On replacement or revocation, advance the generation atomically, invalidate or tombstone all older lineage entries, and cancel or invalidate queued work, retries, refreshes, redirects, streams, derived clients, and callbacks. A delayed writer commits only when its captured generation still matches under the same synchronization boundary.
5. Treat injected context as descriptive data, never as network authority. Require a capability bound to the current generation at dispatch, and re-check generation before applying response side effects. Already-sent requests cannot be recalled; discard stale responses and prevent further hops.
6. Remove entries on completion, error, cancellation, timeout, session close, and shutdown. Add TTL and idle expiry for abandoned state, plus per-entry, per-child, per-root, lineage, and process-wide byte and count quotas. Keep diagnostics bounded; for example, allow 32 warning records per session and generation, then aggregate overflow without storing context.
7. If a validator or context worker crashes or misses its deadline, discard its result, let the primary task continue, and deny context sharing and dependent network activity until fresh authorization is established.

## Limits
Generation checks cannot undo bytes already sent. Transport cancellation and response-side effect checks are still required. This guidance is a design pattern, not evidence that any implementation or tests have run.


## Supporting basis and limitations

The supporting conversation records reasoned analysis of a shared-process cache with live authorization replacement, including generation-bound keys, atomic invalidation, compare-and-set protection for delayed writers, generation-bound network capabilities, child-session handling, and fail-closed worker failure. An independent design review found no fundamental error and identified the need to invalidate queued work, retries, derived clients, and callbacks. No repository inspection or tests were performed; the support is reasoning only.

## Change and rationale

Add explicit lineage-wide invalidation, delayed-writer protection, network capability checks, and bounded operational fallback for authorization replacement.

Existing guidance matches the scenario; this update incorporates the corrected race and failure-handling requirements without creating duplicate guidance.
