# 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.