# Generation-safe authorization for shared-process context caches
## Trigger
Use this when an agent plugin caches context before a system-message transform, multiple root or child sessions share a process, and authorization can be revoked or replaced while a root session remains alive.
## Failure prevented
Without generation binding, stale cached context or delayed callbacks can cross session boundaries, inject revoked context, authorize network activity after revocation, or overwrite state belonging to a replacement authorization.
## Practical steps
1. Create an immutable cache and work identity containing plugin instance, authorization lineage, root session, explicit child session, session epoch, authorization generation, content revision, and capability scope where reuse could cross a boundary.
2. Keep root and child entries separate. Give a child only an explicit, bounded immutable snapshot carrying its parent generation, revision, scope, and authorization identity. Reject stale or over-scoped snapshots.
3. Define one linearization point for authorization replacement. Advance the generation atomically before publishing replacement state, mark older entries stale, and cancel or invalidate queued work from older generations.
4. Bind transforms, refreshes, retries, network requests, and callbacks to an immutable generation token. At lookup, transform, injection, refresh, network admission, and response completion, compare that token with the current generation and replacement identity. Missing or mismatched state fails closed.
5. Treat cancellation as insufficient. Invalidate old work at dispatch, commit, and result-use points. Use compare-and-swap semantics for refreshes so an older refresh cannot overwrite newer state. Discard late results from obsolete generations.
6. Make cache admission, eviction, and byte accounting atomic. Enforce per-session and process-wide byte and entry budgets, context and history limits, child-concurrency limits, deadlines, and idle or time-based expiry. Use weighted eviction for unpinned entries and cancel or reject work when all entries are active and the budget is exhausted.
7. Clear entries on completion, cancellation, logout, authorization change, and plugin disposal. Ensure immutable snapshots cannot be mutated through aliases, and avoid retaining large errors or closures.
8. Record only value-free metrics such as bytes, entry counts, evictions, rejected writes, active pins, and generation mismatches.
## Limits
Deletion alone does not revoke an in-flight reference. Generation identifiers must be unique and non-reused across replacement and restart boundaries. A shared-process cache cannot safely infer authorization from ambient current-session state. TTL and LRU are memory controls, not authorization controls; security decisions require generation and identity checks at each boundary.
## Validation targets
Reason through concurrent roots, parent-child isolation, delayed transforms, revocation during lookup or queue delay, replacement during retry, late callbacks, refresh races, eviction pressure, and disposal. This guidance is reasoned analysis, not evidence from executed tests.