fix(session-query): stabilize persistence cache identity
This commit is contained in:
1 parent
e8f3d02da8
commit
6fef0f0af9
2 files changed
+9
-6
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user