refactor(session-controller): drop the job roster from the control stream
The control baseline and frames carry queues and projections only; the SessionJob row type, the jobs frame, the registry subscription, and the client jobsBySession mirror are gone, and every client fixture drops the empty mirror. The roster moves to dsh-api-job-controller's job.rows stream in the next change.
This commit is contained in:
1 parent
10d76fbd03
commit
2132b7beeb
44 files changed
+52
-466
No files matched your search
@@ -10,7 +10,6 @@ import type {
|
||||
SessionControlFrame,
|
||||
SessionQueuedItem,
|
||||
SessionSummary,
|
||||
SessionJob as JobView,
|
||||
} from '../../types.ts'
|
||||
import { mergeOrderedBaseline } from '../ordered-baseline.ts'
|
||||
import { isRemoteFailure } from '@deepseek-ai/dsh-api-gateway/client'
|
||||
@@ -56,8 +55,6 @@ export interface SessionListSnapshot {
|
||||
phase: SessionListPhase
|
||||
error: RemoteFailure | null
|
||||
subagentsByParent: Readonly<Record<SessionId, SubagentCatalogSnapshot>>
|
||||
/** Background jobs per session; an absent key is an empty set. */
|
||||
jobsBySession: Readonly<Record<SessionId, readonly JobView[]>>
|
||||
currentAddress: SubagentAddress | undefined
|
||||
}
|
||||
|
||||
@@ -126,12 +123,6 @@ export class SessionManager {
|
||||
private readonly catalogStale = new Set<SessionId>()
|
||||
private readonly openCatalogs = new Set<SessionId>()
|
||||
private readonly catalogDebounce = new Map<SessionId, ReturnType<typeof setTimeout>>()
|
||||
/**
|
||||
* Background jobs per session, last-wins from Session Controller's control
|
||||
* stream. An empty set is stored as an absent key, so absence and `[]` are
|
||||
* one representation.
|
||||
*/
|
||||
private readonly jobsBySession = new Map<SessionId, readonly JobView[]>()
|
||||
|
||||
private selected: SessionId | undefined
|
||||
|
||||
@@ -669,12 +660,6 @@ export class SessionManager {
|
||||
this.notifier.markDirty()
|
||||
return
|
||||
}
|
||||
if (frame.type === 'jobs') {
|
||||
if (frame.jobs.length === 0) this.jobsBySession.delete(frame.sessionId)
|
||||
else this.jobsBySession.set(frame.sessionId, frame.jobs)
|
||||
this.notifier.markDirty()
|
||||
return
|
||||
}
|
||||
this.queues.set(frame.sessionId, frame.items)
|
||||
this.sessions.get(frame.sessionId)?.handleControlFrame(frame)
|
||||
}
|
||||
@@ -685,11 +670,6 @@ export class SessionManager {
|
||||
this.queues.set(sessionId as SessionId, items)
|
||||
}
|
||||
|
||||
this.jobsBySession.clear()
|
||||
for (const [sessionId, jobs] of Object.entries(baseline.jobs)) {
|
||||
if (jobs.length > 0) this.jobsBySession.set(sessionId as SessionId, jobs)
|
||||
}
|
||||
|
||||
for (const [sessionId, block] of Object.entries(baseline.projections)) {
|
||||
const store = this.projectionStore(sessionId as SessionId)
|
||||
const asOfSeq = sessionSeqCursor(block.asOfSeq)
|
||||
@@ -739,7 +719,6 @@ export class SessionManager {
|
||||
if (durableSubagent) this.sessions.get(sessionId)?.handleRunning(false)
|
||||
else this.sessions.get(sessionId)?.handleRemoved()
|
||||
this.queues.delete(sessionId)
|
||||
this.jobsBySession.delete(sessionId)
|
||||
if (!durableSubagent) this.projectionStores.delete(sessionId)
|
||||
const inflightCatalog = this.catalogInflight.get(sessionId)
|
||||
if (inflightCatalog !== undefined) {
|
||||
@@ -951,7 +930,6 @@ export class SessionManager {
|
||||
phase: this.listPhase,
|
||||
error: this.listError,
|
||||
subagentsByParent: Object.fromEntries(this.catalogs),
|
||||
jobsBySession: Object.fromEntries(this.jobsBySession),
|
||||
currentAddress: current === undefined ? undefined : this.addresses.get(current),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import { SessionSeq, type SessionId } from '@deepseek-ai/dsh-session/types'
|
||||
import { workspaceTitleOf } from '@deepseek-ai/dsh-util-workspace-path'
|
||||
import type { WorkspaceId } from '@deepseek-ai/dsh-workspace/types'
|
||||
import { SESSION_SEARCH_RESULT_LIMIT } from '../../types.ts'
|
||||
import type { SessionJob as JobView } from '../../types.ts'
|
||||
import type { SessionProjectionMap } from '@deepseek-ai/dsh-session-projection/types'
|
||||
import {
|
||||
createSnapshotStore, type SnapshotStore,
|
||||
@@ -76,12 +75,6 @@ export interface SessionListState {
|
||||
phase: SessionListPhase
|
||||
/** Direct durable catalogs keyed by their selected parent address. */
|
||||
subagentsByParent: Readonly<Record<SessionId, SubagentCatalogSnapshot>>
|
||||
/**
|
||||
* Background jobs each session can see, mirrored last-wins from Session
|
||||
* Controller's control baseline and `jobs` frames. A missing key is an empty
|
||||
* set, so consumers read absence rather than a sentinel.
|
||||
*/
|
||||
jobsBySession: Readonly<Record<SessionId, readonly JobView[]>>
|
||||
/** Current session's catalog-derived address, absent on ordinary navigation. */
|
||||
currentAddress: SubagentAddress | undefined
|
||||
}
|
||||
@@ -233,7 +226,7 @@ export class ClientSessions implements ISessions {
|
||||
)
|
||||
this.list = createSnapshotStore<SessionListState>({
|
||||
ids: [], byId: {}, current: undefined, phase: 'pending',
|
||||
subagentsByParent: {}, jobsBySession: {}, currentAddress: undefined,
|
||||
subagentsByParent: {}, currentAddress: undefined,
|
||||
})
|
||||
// The manager owns wire truth; the store is its projection. Manager
|
||||
// notifications are already microtask-batched.
|
||||
@@ -576,7 +569,7 @@ export class ClientSessions implements ISessions {
|
||||
/** Project the manager's list snapshot into the store (title derivation is display-only). */
|
||||
private projectList(): void {
|
||||
const {
|
||||
items, current, phase, subagentsByParent, jobsBySession, currentAddress,
|
||||
items, current, phase, subagentsByParent, currentAddress,
|
||||
} = this.manager.getListSnapshot()
|
||||
const ids: SessionId[] = []
|
||||
const byId: Record<SessionId, SessionSummary> = {}
|
||||
@@ -642,7 +635,7 @@ export class ClientSessions implements ISessions {
|
||||
...(currentAddress === undefined ? {} : { subagentAddress: currentAddress }),
|
||||
})
|
||||
}
|
||||
this.list.set({ ids, byId, current, phase, subagentsByParent, jobsBySession, currentAddress })
|
||||
this.list.set({ ids, byId, current, phase, subagentsByParent, currentAddress })
|
||||
this.pruneScopes()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/** Live Session queue, jobs, and projection state with reconnect baselines. */
|
||||
/** Live Session queue and projection state with reconnect baselines. */
|
||||
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import type { Agent } from '@deepseek-ai/dsh-agent'
|
||||
import { Deque } from '@deepseek-ai/dsh-deque'
|
||||
import type { JobSnapshot } from '@deepseek-ai/dsh-jobs'
|
||||
import type {
|
||||
Session, SessionEvent, SessionEventMap, SessionId, UserMessage,
|
||||
} from '@deepseek-ai/dsh-session'
|
||||
@@ -11,7 +10,6 @@ import type { JsonValue } from '@deepseek-ai/dsh-util-values'
|
||||
import type {
|
||||
SessionControlBaseline,
|
||||
SessionControlFrame,
|
||||
SessionJob,
|
||||
SessionProjectionBaseline,
|
||||
SessionProjectionValues,
|
||||
SessionQueuedItem,
|
||||
@@ -21,7 +19,7 @@ import type {
|
||||
export class SessionControlController {
|
||||
private readonly streams = new Set<ControlQueue>()
|
||||
|
||||
/** @param ctx - Host context carrying live Agent, projection, and jobs services. */
|
||||
/** @param ctx - Host context carrying live Agent and projection services. */
|
||||
constructor(private readonly ctx: Context) {
|
||||
ctx.on('session/event', (session, event) => { this.onSessionEvent(session, event) })
|
||||
ctx.sessionProjections.onChanged((session, key, value, seq) => {
|
||||
@@ -33,13 +31,6 @@ export class SessionControlController {
|
||||
seq,
|
||||
})
|
||||
})
|
||||
ctx.inject(['jobs'], (jobsCtx) => {
|
||||
jobsCtx.jobs.onJobsChanged((owner) => { this.onJobsChanged(owner) })
|
||||
})
|
||||
ctx.on('session/created', (session) => {
|
||||
const jobs = this.jobsFor(this.ctx.agents.get(session.id))
|
||||
if (jobs.length > 0) this.broadcast({ type: 'jobs', sessionId: session.id, jobs })
|
||||
})
|
||||
ctx.effect(() => () => {
|
||||
for (const stream of this.streams) stream.end()
|
||||
this.streams.clear()
|
||||
@@ -67,15 +58,12 @@ export class SessionControlController {
|
||||
private baseline(): SessionControlBaseline {
|
||||
const sessions = this.ctx.sessions.list()
|
||||
const queues = Object.create(null) as Record<SessionId, readonly SessionQueuedItem[]>
|
||||
const jobs = Object.create(null) as Record<SessionId, readonly SessionJob[]>
|
||||
for (const session of sessions) {
|
||||
const agent = this.ctx.agents.get(session.id)
|
||||
queues[session.id] = agent?.session === session ? queueItems(agent) : []
|
||||
jobs[session.id] = this.jobsFor(agent)
|
||||
}
|
||||
return {
|
||||
queues,
|
||||
jobs,
|
||||
projections: this.projectionBaseline(sessions),
|
||||
}
|
||||
}
|
||||
@@ -106,25 +94,6 @@ export class SessionControlController {
|
||||
})
|
||||
}
|
||||
|
||||
private onJobsChanged(owner: Agent | undefined): void {
|
||||
if (owner !== undefined) {
|
||||
this.broadcast({ type: 'jobs', sessionId: owner.id, jobs: this.jobsFor(owner) })
|
||||
return
|
||||
}
|
||||
for (const session of this.ctx.sessions.list()) {
|
||||
this.broadcast({
|
||||
type: 'jobs',
|
||||
sessionId: session.id,
|
||||
jobs: this.jobsFor(this.ctx.agents.get(session.id)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private jobsFor(agent: Agent | undefined): SessionJob[] {
|
||||
const jobs = this.ctx.get('jobs')
|
||||
return jobs === undefined ? [] : jobs.list(agent).map(jobView)
|
||||
}
|
||||
|
||||
private broadcast(frame: SessionControlFrame): void {
|
||||
for (const stream of this.streams) stream.push(frame)
|
||||
}
|
||||
@@ -202,16 +171,3 @@ function promptRpcId(message: UserMessage): Pick<SessionQueuedItem, 'rpcId'> {
|
||||
const source = message.source
|
||||
return source.kind === 'user' && 'rpcId' in source ? { rpcId: source.rpcId } : {}
|
||||
}
|
||||
|
||||
function jobView(job: JobSnapshot): SessionJob {
|
||||
return {
|
||||
id: job.id,
|
||||
kind: job.kind,
|
||||
label: job.label,
|
||||
status: job.status,
|
||||
...(job.detail === undefined ? {} : { detail: job.detail }),
|
||||
startedAt: job.startedAt,
|
||||
...(job.finishedAt === undefined ? {} : { finishedAt: job.finishedAt }),
|
||||
...(job.outputTotal === undefined ? {} : { record: true as const }),
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import type { ContentBlock } from '@deepseek-ai/dsh-llm/types'
|
||||
import type { ChunkRow } from '@deepseek-ai/dsh-session/chunk-rows'
|
||||
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
||||
import type { SessionProjectionMap } from '@deepseek-ai/dsh-session-projection/types'
|
||||
import type { JobId } from '@deepseek-ai/dsh-jobs/brand'
|
||||
import type { JsonValue } from '@deepseek-ai/dsh-util-values'
|
||||
import type { WorkspaceId } from '@deepseek-ai/dsh-workspace/types'
|
||||
|
||||
@@ -479,28 +478,9 @@ export interface SessionQueuedItem {
|
||||
}
|
||||
}
|
||||
|
||||
/** Browser-safe background-job row. */
|
||||
export interface SessionJob {
|
||||
readonly id: JobId
|
||||
readonly kind: string
|
||||
readonly label: string
|
||||
readonly status: 'running' | 'stopping' | 'completed' | 'killed' | 'failed'
|
||||
readonly detail?: string
|
||||
readonly startedAt: number
|
||||
readonly finishedAt?: number
|
||||
/**
|
||||
* Present exactly when the job declared an observation record: the row is
|
||||
* observable through the job controller's `job.observe` stream, whose
|
||||
* `opened` anchor carries the live byte offsets. The roster refreshes on
|
||||
* lifecycle commits only, so it mirrors no byte count.
|
||||
*/
|
||||
readonly record?: true
|
||||
}
|
||||
|
||||
/** Complete live control baseline emitted once per control stream generation. */
|
||||
export interface SessionControlBaseline {
|
||||
readonly queues: Readonly<Record<SessionId, readonly SessionQueuedItem[]>>
|
||||
readonly jobs: Readonly<Record<SessionId, readonly SessionJob[]>>
|
||||
readonly projections: Readonly<Record<SessionId, SessionProjectionBaseline>>
|
||||
}
|
||||
|
||||
@@ -516,7 +496,6 @@ export interface SessionProjectionUpdate {
|
||||
export type SessionControlFrame =
|
||||
| { readonly type: 'baseline'; readonly value: SessionControlBaseline }
|
||||
| { readonly type: 'queue'; readonly sessionId: SessionId; readonly items: readonly SessionQueuedItem[] }
|
||||
| { readonly type: 'jobs'; readonly sessionId: SessionId; readonly jobs: readonly SessionJob[] }
|
||||
| ({ readonly type: 'projection' } & SessionProjectionUpdate)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user