fix(orchestration): keep refusal codes on released chat reads and locate legacy remote transcripts

This commit is contained in:
Jinwoo-H
2026-11-11 23:51:15 -05:00
parent e0cde12e8a
commit 53158d9efa
5 changed files with 31 additions and 10 deletions
@@ -11,20 +11,22 @@ export async function readRemoteAttachmentArchive(args: {
limit?: number
liveness?: 'live' | 'unverifiable' | 'exited'
}) {
const archive = args.runtime
.getOrchestrationDb()
.getWorkerTerminalArchive(args.attachment.dispatch_id)
const db = args.runtime.getOrchestrationDb()
const archive = db.getWorkerTerminalArchive(args.attachment.dispatch_id)
if (!archive || !args.attachment.terminal_handle) {
return null
}
return readArchivedWorkerOutput({
db: args.runtime.getOrchestrationDb(),
db,
dispatchId: args.attachment.dispatch_id,
workerState: args.attachment.state,
resource: {
id: `remote-attachment:${args.attachment.dispatch_id}`,
terminal_handle: args.attachment.terminal_handle,
release_state: args.attachment.stage === 'released' ? 'released' : 'releasing'
release_state: args.attachment.stage === 'released' ? 'released' : 'releasing',
// Rows released before references locate their transcript through the host's resume record.
resume_session:
db.getWorkerTerminalResourceByOwner(args.attachment.dispatch_id)?.resume_session ?? null
},
source: args.source,
cursor: args.cursor,
@@ -33,6 +33,7 @@ const { structuredSessionMailReach } =
await import('../../mailbox/routing/structured-session-mail-address')
const { captureWorkerOutputReference } =
await import('../../workers/archives/worker-output-archive')
const { encodeWorkerOutputCursor } = await import('../../workers/transcripts/worker-output-cursor')
const { stopStructuredWorker, readStructuredWorkerJournal } =
await import('../../../rpc/methods/orchestration/structured-workers/orchestration-structured-worker-lifecycle')
await import('../../../rpc/methods/orchestration/structured-workers/orchestration-structured-worker-session')
@@ -378,6 +379,11 @@ describe.each(['live', 'at-rest'] as const)(
expect(history.indexOf('PRE-CLEAR')).toBeGreaterThan(-1)
expect(history.indexOf('POST-CLEAR')).toBeGreaterThan(history.indexOf('PRE-CLEAR'))
expect(db.getWorkerTerminalArchive(dispatchId)?.content).not.toContain('CLEAR')
// A cursor refusal keeps its own code; it never reads as lost output.
const foreign = encodeWorkerOutputCursor('ctx_other', 'transcript', 'identity', 1)
await expect(
rpcRuntime(db).call('orchestration.workerRead', { dispatch: dispatchId, cursor: foreign })
).rejects.toMatchObject({ code: 'cursor_dispatch_mismatch' })
})
it('stops the worker by closing the successor, and can then release it', async () => {
+2
View File
@@ -148,6 +148,8 @@ const STRUCTURED_RUNTIME_PASSTHROUGH_CODES: ReadonlySet<string> = new Set([
'cursor_dispatch_mismatch',
'source_changed',
'transcript_required',
// A released worker's original transcript or chat is gone, or it never had one.
'archive_unavailable',
...ORCHESTRATION_FEDERATION_ERROR_CODES,
'dispatch_capability_invalid',
'agent_unconfigured',
@@ -400,7 +400,7 @@ describe('orchestration federated worker output', () => {
const unavailable = {
ok: false,
error: { message: expect.stringContaining('is no longer available') }
error: { code: 'archive_unavailable', message: expect.stringContaining('worker_done') }
}
await expect(
homeCall('rpc_remote_read_archive_after_removal', 'orchestration.workerRead', {
@@ -3,6 +3,8 @@ import type {
OrchestrationWorkerReadSource
} from '../../../../../../shared/orchestration/workers/orchestration-worker-output'
import type { PtyLivenessVerdict } from '../../../../../../shared/terminal/pty/lifecycle/pty-liveness-verdict'
import { needsWslHostResolution } from '../../../../../native-chat/host-readable-transcript-path'
import { ORCHESTRATION_SESSION_CALLER_ERROR_CODES as CODES } from '../../../../../../shared/orchestration/orchestration-session-caller-codes'
import { readWorkerResumeSession } from '../../../../orchestration/db/dispatch-context/worker-follow-up-lineage'
import type { OrchestrationDb } from '../../../../orchestration/db/orchestration-db'
import { OrchestrationError } from '../../../../orchestration/orchestration-error'
@@ -78,6 +80,11 @@ async function readReleasedTranscript(
if (!agent || !sessionId) {
throw outputUnavailable(args.dispatchId, 'its transcript was never located')
}
const transcriptPath = reference.transcriptPath ?? resume?.providerSession.transcriptPath
// The resume record keeps no distro; without one a guest path could resolve in another distro.
if (!reference.wslDistro && transcriptPath && needsWslHostResolution(transcriptPath)) {
throw outputUnavailable(args.dispatchId, 'its WSL distro was never recorded')
}
const cursor = decodeWorkerOutputCursor(args.cursor, args.dispatchId)
if (cursor && (cursor.source !== 'transcript' || !cursor.boundaryCheckpoint)) {
throw sourceChanged()
@@ -85,7 +92,7 @@ async function readReleasedTranscript(
const transcript = await readWorkerTranscript({
agent,
sessionId,
transcriptPath: reference.transcriptPath ?? resume?.providerSession.transcriptPath,
transcriptPath,
wslDistro: reference.wslDistro,
offset: cursor?.position,
expectedBoundaryCheckpoint: cursor?.boundaryCheckpoint ?? undefined,
@@ -142,10 +149,14 @@ async function readReleasedChatHistory(
...(args.limit === undefined ? {} : { limit: args.limit })
})
} catch (error) {
if (error instanceof OrchestrationError && error.code === 'source_changed') {
throw error
// Cursor, host-boundary and other refusals keep their own codes, as on a live read.
if (
error instanceof OrchestrationError &&
(error.code === 'transcript_required' || error.code === CODES.notLive)
) {
throw outputUnavailable(args.dispatchId, 'its chat history could not be read')
}
throw outputUnavailable(args.dispatchId, 'its chat history could not be read')
throw error
}
}