Merge origin/master into fix/lazy-subagent-migration
This commit is contained in:
commit
6f3140d7cf
109 files changed
+3961
-1147
No files matched your search
@@ -7,12 +7,14 @@ import type { WorkspaceId } from '@deepseek-ai/dsh-workspace/types'
|
||||
import type {
|
||||
SessionControlBaseline,
|
||||
SessionControlFrame,
|
||||
SessionProjectionHints,
|
||||
SessionRenameValue,
|
||||
SessionSummary,
|
||||
SessionJob as JobView,
|
||||
} from '../../types.ts'
|
||||
import { mergeOrderedBaseline } from '../ordered-baseline.ts'
|
||||
import { isRemoteFailure } from '@deepseek-ai/dsh-api-gateway/client'
|
||||
import { assertNever } from '@deepseek-ai/dsh-util-values'
|
||||
import type { RemoteFailure, RemoteResult } from '@deepseek-ai/dsh-typert-protocol'
|
||||
import type { SessionListEntry, TitledSessionSummary } from './lineage.ts'
|
||||
import { flattenLineage } from './lineage.ts'
|
||||
@@ -376,18 +378,12 @@ export class SessionManager {
|
||||
session.handleBlank(s.blank)
|
||||
session.handleRunning(s.running)
|
||||
}
|
||||
// Seed each row's projection baseline into the per-session value
|
||||
// store (cold titles surface without opening the session). Per-key
|
||||
// apply, not seed(): the list block is a partial baseline — the
|
||||
// cold cache serves only version-matching keys — so an absent key
|
||||
// must not clear; higher-seq-wins still keeps a stale list block
|
||||
// from overwriting a newer push frame or tail baseline.
|
||||
// Land each row's projection block in the per-session value store
|
||||
// (cold titles surface without opening the session). A list block is
|
||||
// partial — only the keys its source holds — so an absent key never
|
||||
// clears; how the present keys merge depends on the block's kind.
|
||||
for (const s of result.value.items) {
|
||||
const block = s.projections
|
||||
if (block === undefined) continue
|
||||
const store = this.projectionStore(s.sessionId)
|
||||
const values = block.values as Record<string, unknown>
|
||||
for (const key of Object.keys(values)) store.apply(key, values[key], sessionSeqCursor(block.asOfSeq))
|
||||
if (s.projections !== undefined) this.applyListBlock(s.sessionId, s.projections)
|
||||
}
|
||||
} else {
|
||||
this.listState = 'error'
|
||||
@@ -604,12 +600,30 @@ export class SessionManager {
|
||||
handleSessionAdded(summary: SessionSummary): void {
|
||||
this.mergeSummary(summary)
|
||||
this.sessions.get(summary.sessionId)?.handleBlank(summary.blank)
|
||||
const projections = summary.projections
|
||||
if (projections !== undefined) {
|
||||
const store = this.projectionStore(summary.sessionId)
|
||||
for (const [key, value] of Object.entries(projections.values)) {
|
||||
store.apply(key, value, sessionSeqCursor(projections.asOfSeq))
|
||||
if (summary.projections !== undefined) this.applyListBlock(summary.sessionId, summary.projections)
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge one list-surface projection block by the sequence space it declares.
|
||||
* A `sequenced` block came from the Host's live registry for an attached
|
||||
* Session, so each key lands under higher-seq-wins against that Session's
|
||||
* baselines and frames. A `cached` block was viewed from the persisted
|
||||
* checkpoint by a header-only listing: its watermark is not comparable with
|
||||
* this connection's seqs, so it only fills keys no sequenced row holds.
|
||||
*/
|
||||
private applyListBlock(sessionId: SessionId, block: SessionProjectionHints): void {
|
||||
const store = this.projectionStore(sessionId)
|
||||
switch (block.kind) {
|
||||
case 'sequenced': {
|
||||
const seq = sessionSeqCursor(block.asOfSeq)
|
||||
for (const [key, value] of Object.entries(block.values)) store.apply(key, value, seq)
|
||||
return
|
||||
}
|
||||
case 'cached':
|
||||
store.applyCached(block.values)
|
||||
return
|
||||
default:
|
||||
assertNever(block.kind, 'session list projection block kind')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
/**
|
||||
* Generic per-session projection value store (push model; see the
|
||||
* session-projection subsystem page, docs/subsystems/session-projection.md):
|
||||
* the host is the only computation site; the client holds finished
|
||||
* whole values per key — `key → { value, seq }` — seeded by a follow opening
|
||||
* baseline and updated by Session Controller `projection` frames,
|
||||
* under the single rule **higher seq wins**. No client-side domain folding
|
||||
* the host is the only computation site; the client holds finished whole
|
||||
* values per key in one of two row kinds. A `sequenced` row
|
||||
* (`{ value, seq }`) comes from the connected Host — a follow opening
|
||||
* baseline, a Session Controller `projection` frame, a list block the Host
|
||||
* computed for an attached Session — and merges under **higher seq wins**
|
||||
* against other sequenced rows. A `cached` row (`{ value }`) comes from the
|
||||
* session list's view of the persisted checkpoint, carries no comparable
|
||||
* seq, and yields to every sequenced write. No client-side domain folding
|
||||
* exists: a domain ships projection support with zero client code. Per-key
|
||||
* bare observable faces feed `useProjection` (ui-renderer binds them).
|
||||
*/
|
||||
@@ -52,11 +56,18 @@ export interface ProjectionsBaseline {
|
||||
values: Readonly<Record<string, unknown>>
|
||||
}
|
||||
|
||||
/** One key's row: the latest finished value and the seq it is consistent with. */
|
||||
interface Row {
|
||||
value: unknown
|
||||
seq: SessionSeqCursor
|
||||
}
|
||||
/**
|
||||
* One key's row. A `sequenced` row was computed by the Host for this Session
|
||||
* within the current connection generation and carries the seq it is
|
||||
* consistent with; seqs of sequenced rows are comparable with each other. A
|
||||
* `cached` row was viewed from the persisted projection checkpoint by a
|
||||
* header-only listing without a Session: its origin cannot vouch that its
|
||||
* stored seq is comparable with the log the client later opens, so it carries
|
||||
* none and yields to every sequenced write.
|
||||
*/
|
||||
type Row =
|
||||
| { kind: 'cached'; value: unknown }
|
||||
| { kind: 'sequenced'; value: unknown; seq: SessionSeqCursor }
|
||||
|
||||
/** Per-key notification channel: the bare face plus its batching notifier. */
|
||||
interface Channel {
|
||||
@@ -66,10 +77,14 @@ interface Channel {
|
||||
|
||||
/**
|
||||
* One session's projection values. Framework semantics, uniform across every
|
||||
* key: a baseline seeds rows at its cut, a push frame updates one row, and in
|
||||
* both paths a lower-or-equal seq within the Host generation loses. A replayed
|
||||
* frame cannot regress a value; a stale baseline cannot overwrite a newer
|
||||
* frame. A key the store has never seen reads `undefined` (capability absent). Faces are identity-stable
|
||||
* key. Sequenced writes (a baseline seeds rows at its cut, a push frame
|
||||
* updates one row) compare seqs among themselves: a lower-or-equal seq within
|
||||
* the Host generation loses, so a replayed frame cannot regress a value and a
|
||||
* stale baseline cannot overwrite a newer frame. Cached writes (the session
|
||||
* list's zero-I/O block) only fill keys no sequenced row holds, and a baseline
|
||||
* discards every cached row before it seeds, regardless of seq: the connected
|
||||
* Session is the truth and a cached value never outranks it. A key the store
|
||||
* has never seen reads `undefined` (capability absent). Faces are identity-stable
|
||||
* per key (create-on-demand, cached) so the React side binds each exactly
|
||||
* once; the store-level channel (`subscribeAny`) serves coarse consumers (the
|
||||
* manager's list projection reads the `title` key).
|
||||
@@ -133,27 +148,54 @@ export class ProjectionValueStore {
|
||||
*/
|
||||
apply(key: string, value: unknown, seq: SessionSeqCursor): void {
|
||||
const row = this.rows.get(key)
|
||||
if (row !== undefined && seq <= row.seq) return // higher seq wins; replays and stale frames drop
|
||||
this.rows.set(key, { value, seq })
|
||||
// higher seq wins among sequenced rows; replays and stale frames drop. A
|
||||
// cached row has no comparable seq and always yields.
|
||||
if (row?.kind === 'sequenced' && seq <= row.seq) return
|
||||
this.rows.set(key, { kind: 'sequenced', value, seq })
|
||||
this.changed(key)
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed from a history tail page's projections block: every carried key
|
||||
* lands under the same seq rule as frames; a key the block omits is
|
||||
* capability-absent as of the cut — its row clears unless a newer frame
|
||||
* already superseded the cut (a stale baseline can neither overwrite nor
|
||||
* clear newer values).
|
||||
* Fill keys from a session-list block the Host labeled `cached`: a zero-I/O
|
||||
* view of the persisted checkpoint. A cached value lands only where no
|
||||
* sequenced row exists: a connected Session has already answered for such
|
||||
* a key, and the list's view of the persisted checkpoint cannot be newer
|
||||
* than it.
|
||||
* @param values - whole values by key viewed from the persisted checkpoint.
|
||||
*/
|
||||
applyCached(values: Readonly<Record<string, unknown>>): void {
|
||||
for (const key of Object.keys(values)) {
|
||||
if (this.rows.get(key)?.kind === 'sequenced') continue
|
||||
this.rows.set(key, { kind: 'cached', value: values[key] })
|
||||
this.changed(key)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed from a history tail page's projections block. Every cached row is
|
||||
* discarded first, regardless of seq: the block comes from the connected
|
||||
* Session, and a value viewed from the persisted checkpoint never outranks
|
||||
* it. Then every carried key lands under the same seq rule as frames, and a
|
||||
* key the block omits is capability-absent as of the cut — its row clears
|
||||
* unless a newer frame already superseded the cut (a stale baseline can
|
||||
* neither overwrite nor clear newer sequenced values).
|
||||
* @param baseline - the response's projections block.
|
||||
*/
|
||||
seed(baseline: ProjectionsBaseline): void {
|
||||
for (const [key, row] of this.rows) {
|
||||
if (row.kind !== 'cached') continue
|
||||
this.rows.delete(key)
|
||||
this.changed(key)
|
||||
}
|
||||
// Erased walk: the framework crosses the open key space; per-key typing
|
||||
// is re-established at the consumer (useProjection's map lookup).
|
||||
const values = baseline.values as Record<string, unknown>
|
||||
for (const key of Object.keys(values)) this.apply(key, values[key], baseline.asOfSeq)
|
||||
for (const [key, row] of this.rows) {
|
||||
if (Object.hasOwn(values, key)) continue
|
||||
if (row.seq > baseline.asOfSeq) continue
|
||||
// Every cached row was deleted above; the kind test only narrows the
|
||||
// type so `row.seq` is readable.
|
||||
if (row.kind === 'sequenced' && row.seq > baseline.asOfSeq) continue
|
||||
this.rows.delete(key)
|
||||
this.changed(key)
|
||||
}
|
||||
|
||||
@@ -137,8 +137,9 @@ export class Session implements SessionFace {
|
||||
* Per-session projection value store (push model; see the session-projection
|
||||
* subsystem page, docs/subsystems/session-projection.md): finished whole
|
||||
* values computed on the Host, seeded by the tail page's
|
||||
* projections block and updated by Session Controller control frames under the
|
||||
* one higher-seq-wins rule. Keys are read via `projections.faceOf(key)`
|
||||
* projections block and updated by Session Controller control frames;
|
||||
* Host-sequenced writes merge under higher-seq-wins and cached list blocks
|
||||
* yield to them (projection-store.ts). Keys are read via `projections.faceOf(key)`
|
||||
* (the useProjection resolution face); the conversation snapshot never
|
||||
* carries projection values, and no client-side domain folding exists.
|
||||
* Manager-owned when constructed through SessionManager (frames route and
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import type {} from '@deepseek-ai/dsh-agent-presets'
|
||||
import type { ImageAttachmentLimits } from '@deepseek-ai/dsh-attachment'
|
||||
import { SessionLogOffset } from '@deepseek-ai/dsh-session'
|
||||
import type { Session, SessionEvent, SessionHeader, SessionId } from '@deepseek-ai/dsh-session'
|
||||
import type {} from '@deepseek-ai/dsh-session-projection'
|
||||
import type { ProjectionSnapshot } from '@deepseek-ai/dsh-session-projection'
|
||||
import type {} from '@deepseek-ai/dsh-session-projection-cache'
|
||||
import { SessionQueryError, type SessionSearchCursor } from '@deepseek-ai/dsh-session-query'
|
||||
import { RemoteError } from '@deepseek-ai/dsh-typert-protocol'
|
||||
@@ -272,21 +271,16 @@ export class ApiSessionList {
|
||||
session: Session | undefined,
|
||||
): SessionProjectionHints | undefined {
|
||||
try {
|
||||
if (session !== undefined) {
|
||||
// The live registry computed the block for this Session: its watermark
|
||||
// shares the sequence space of the Session's baselines and frames.
|
||||
return hintsOf('sequenced', this.ctx.sessionProjections.cachedSnapshot(session))
|
||||
}
|
||||
// A cold row reads the persisted cache by header alone; the cache serves
|
||||
// seeded and unseeded lifecycles alike because a listing never seeds a
|
||||
// fold. The watermark is the stored record's own.
|
||||
const cache = this.ctx.get('sessionProjectionCache')
|
||||
const block = session === undefined
|
||||
? header.isSeeded
|
||||
? undefined
|
||||
: cache?.cachedSnapshot(header, SessionLogOffset(0))
|
||||
?? cache?.cachedPredecessorTitle(header, SessionLogOffset(0))
|
||||
: this.ctx.sessionProjections.cachedSnapshot(session)
|
||||
return block !== undefined && Object.keys(block.values).length > 0
|
||||
? {
|
||||
asOfSeq: block.asOfSeq,
|
||||
// Listing hints contain every currently cached wire value but remain
|
||||
// partial: missing cells and cache rows are never materialized here.
|
||||
values: block.values as SessionProjectionValues,
|
||||
}
|
||||
: undefined
|
||||
return hintsOf('cached', cache?.cachedSnapshot(header) ?? cache?.cachedPredecessorTitle(header))
|
||||
} catch (error) {
|
||||
this.ctx.logger.warn(
|
||||
`api-session.list: projection column for "${header.id}" failed; serving the row without it: ${String(error)}`,
|
||||
@@ -296,6 +290,22 @@ export class ApiSessionList {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap one projection block as Session-list hints of the named sequence space.
|
||||
* @param kind - which sequence space the block's watermark belongs to.
|
||||
* @param block - the block, or `undefined` when no source served one.
|
||||
* @returns the hints, or `undefined` when the block is absent or carries no value.
|
||||
*/
|
||||
function hintsOf(
|
||||
kind: SessionProjectionHints['kind'],
|
||||
block: ProjectionSnapshot | undefined,
|
||||
): SessionProjectionHints | undefined {
|
||||
if (block === undefined || Object.keys(block.values).length === 0) return undefined
|
||||
// Listing hints contain every wire value the source currently holds but
|
||||
// remain partial: missing cells and cache rows are never materialized here.
|
||||
return { kind, asOfSeq: block.asOfSeq, values: block.values as SessionProjectionValues }
|
||||
}
|
||||
|
||||
function normalizeSearchQuery(query: string): string {
|
||||
const normalized = query.trim()
|
||||
if (normalized.length === 0) {
|
||||
|
||||
@@ -49,10 +49,24 @@ export interface SessionListMetadata {
|
||||
readonly lastPromptAt: number | null
|
||||
}
|
||||
|
||||
/** Every available cached wire value used as partial, possibly stale Session-list hints. */
|
||||
/**
|
||||
* Every available wire value a Session-list row carries as partial, possibly
|
||||
* stale hints. `kind` and `asOfSeq` are independent facts: `kind` says which
|
||||
* sequence space `asOfSeq` belongs to, and therefore how a client may merge
|
||||
* the block; `asOfSeq` is the producer's watermark in that space.
|
||||
*/
|
||||
export interface SessionProjectionHints {
|
||||
/**
|
||||
* `sequenced`: the Host's live registry produced the block for an attached
|
||||
* Session, so `asOfSeq` is comparable with baselines and frames of the same
|
||||
* connection. `cached`: a header-only listing viewed the block from the
|
||||
* persisted projection cache, so `asOfSeq` is the stored record's own
|
||||
* watermark and must not be compared with the connected Session's values.
|
||||
*/
|
||||
readonly kind: 'cached' | 'sequenced'
|
||||
/** Watermark of the block in the sequence space named by `kind`. */
|
||||
readonly asOfSeq: number
|
||||
/** Provider-validated values present in the cache; omitted keys remain unknown. */
|
||||
/** Provider-validated values present in the block; omitted keys remain unknown. */
|
||||
readonly values: SessionProjectionValues
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user