diff --git a/packages/session-query/session-query/src/observation.ts b/packages/session-query/session-query/src/observation.ts index 8c08108775..69ddf1f19c 100644 --- a/packages/session-query/session-query/src/observation.ts +++ b/packages/session-query/session-query/src/observation.ts @@ -54,8 +54,8 @@ export interface SessionObservationOptions { * instance still reports the same revision. */ interface PreparedEntry { - /** The persistence instance whose `stat` produced {@link revision}; revisions from another instance are incomparable. */ - readonly persistence: SessionPersistence + /** Stable service identity whose `stat` produced this revision; proxy references are not instance identities. */ + readonly persistenceIdentity: symbol /** Durable revision observed by `stat` immediately before the log read. */ readonly revision: SessionPersistenceRevision /** Unpublished Session restored from the balanced log; never entered into the store. */ @@ -109,7 +109,7 @@ export class SessionObservationReader { const snapshot = await this.statSource(persistence, sessionId, signal) const attachedDuringStat = this.ctx.sessions.get(sessionId) if (attachedDuringStat !== undefined) return this.live(attachedDuringStat, projectionMode) - let entry = this.cachedEntry(persistence, sessionId, snapshot.revision) + let entry = this.cachedEntry(persistence.identity, sessionId, snapshot.revision) if (entry === undefined) { const loaded = await this.loadSource(persistence, sessionId, signal) throwIfObservationAborted(signal) @@ -138,7 +138,7 @@ export class SessionObservationReader { ) } entry = { - persistence, + persistenceIdentity: persistence.identity, revision: snapshot.revision, session, events: Object.freeze(seed), @@ -201,12 +201,12 @@ export class SessionObservationReader { /** Return a still-valid cached entry and mark it most recently used. */ private cachedEntry( - persistence: SessionPersistence, + persistenceIdentity: symbol, sessionId: SessionId, revision: SessionPersistenceRevision, ): PreparedEntry | undefined { const cached = this.cache.get(sessionId) - if (cached === undefined || cached.persistence !== persistence || cached.revision !== revision) { + if (cached === undefined || cached.persistenceIdentity !== persistenceIdentity || cached.revision !== revision) { return undefined } this.cache.delete(sessionId) diff --git a/packages/session/session-persistence/src/index.ts b/packages/session/session-persistence/src/index.ts index f17ec2e777..2894aa5f3d 100644 --- a/packages/session/session-persistence/src/index.ts +++ b/packages/session/session-persistence/src/index.ts @@ -133,6 +133,9 @@ declare module '@deepseek-ai/cordis' { * on this backend instance observe at least that prefix. */ export abstract class SessionPersistence extends Service { + /** Process-local instance identity, stable through Context proxies and distinct after service replacement. */ + readonly identity = Symbol('sessionPersistence') + constructor(ctx: Context) { super(ctx, 'sessionPersistence') }