Files
orca/src/main/runtime/agent-session-conversation-command-record.ts
T
Brennan Benson d1aeba939f Native chat: remove unused journalCheckpoint and setConversationCommand (#30645)
* refactor(native-chat): remove three chat mechanisms nothing drives

- The adapter's optional startAnswered hook lost its only implementer in
  #27925; it was still forwarded through four layers and always read as
  answered. A start that never answered is read from the child's phase, as
  the exit already does.
- The saved lease's journalCheckpoint is only ever written as null and read
  only by validation. Records an older build saved with it still load: it
  joins the retired lease fields dropped at load, so the next write sheds it.
- The record store's setConversationCommand had no production caller. The
  tests that stood in for an older build with it now seed the saved row and
  reopen the store; three that only re-pinned another test are removed.

* test(native-chat): an older build's null journal checkpoint also loads

* Keep startAnswered cleanup in its owning PR

* Keep historical chat fixtures aligned with their readers
2026-10-20 17:12:41 -07:00

49 lines
1.8 KiB
TypeScript

import { agentSessionRefusalError } from '../../shared/agent-session-wire-refusals'
import { createHash } from 'node:crypto'
import { agentSessionOperationKey } from '../../shared/agent-session-operation-ledger'
import type { AgentSessionStoreState } from './agent-session-store-state'
import type { AgentSessionConversationCommandRecord } from '../../shared/agent-session-conversation-command'
export type AgentSessionConversationClear = {
sessionId: string
fence: number
command: AgentSessionConversationCommandRecord & {
command: 'clear'
phase: 'committed'
state: 'completed'
}
now: number
}
export function providerContextBoundaryForClear(clear: AgentSessionConversationClear) {
return {
operationId: createHash('sha256')
.update(agentSessionOperationKey(clear.command.callerKey, clear.command.operationId))
.digest('hex'),
afterFence: clear.fence,
clearedAt: clear.now
}
}
/** The record owns the provider boundary; the journal transaction publishes its divider. */
export function commitConversationClearRecord(
state: AgentSessionStoreState,
clear: AgentSessionConversationClear
): void {
const source = state.records.get(clear.sessionId)
if (!source || source.lease.runtimeFence !== clear.fence) {
throw agentSessionRefusalError('agent_session_checkpoint_stale', { reason: 'leaseMoved' })
}
if (source.lease.ownerProcess !== null || source.lease.claimStatus !== 'released') {
throw agentSessionRefusalError('agent_session_ownership_unknown', { reason: 'leaseMoved' })
}
state.records.set(clear.sessionId, {
...source,
providerHandleChain: [],
lease: { ...source.lease, provenHandleLinkId: null },
conversationCommand: clear.command,
providerContextBoundary: providerContextBoundaryForClear(clear),
updatedAt: clear.now
})
}