MCPcopy
hub / github.com/coder/mux / materializeForkedPartialSnapshot

Function materializeForkedPartialSnapshot

src/node/services/workspaceService.ts:805–843  ·  view source on GitHub ↗
(params: {
  historyService: HistoryService;
  partialSnapshot: MuxMessage | null;
  sourceWorkspaceId: string;
  targetWorkspaceId: string;
})

Source from the content-addressed store, hash-verified

803}
804
805async function materializeForkedPartialSnapshot(params: {
806 historyService: HistoryService;
807 partialSnapshot: MuxMessage | null;
808 sourceWorkspaceId: string;
809 targetWorkspaceId: string;
810}): Promise<void> {
811 if (!params.partialSnapshot) {
812 return;
813 }
814
815 // Forking must be read-only with respect to the source workspace. During tool calls
816 // such as task_await, deleting or committing the source partial can make the live
817 // parent turn look interrupted. Instead, copy the partial into the fork and finalize
818 // only that snapshot so the child has no inherited live-stream state. The snapshot
819 // is captured before fork checkout/copy I/O so a parent stream that finishes mid-fork
820 // cannot make the child miss the latest visible assistant state.
821 const writeResult = await params.historyService.writePartial(
822 params.targetWorkspaceId,
823 params.partialSnapshot
824 );
825 if (!writeResult.success) {
826 log.warn("Failed to snapshot source partial into fork", {
827 sourceWorkspaceId: params.sourceWorkspaceId,
828 targetWorkspaceId: params.targetWorkspaceId,
829 error: writeResult.error,
830 });
831 return;
832 }
833
834 const commitResult = await params.historyService.commitPartial(params.targetWorkspaceId);
835 if (!commitResult.success) {
836 log.warn("Failed to finalize forked partial snapshot", {
837 sourceWorkspaceId: params.sourceWorkspaceId,
838 targetWorkspaceId: params.targetWorkspaceId,
839 error: commitResult.error,
840 });
841 await params.historyService.deletePartial(params.targetWorkspaceId);
842 }
843}
844
845function getOldestSequencedMessage(
846 messages: readonly MuxMessage[]

Callers 1

forkMethod · 0.85

Calls 3

writePartialMethod · 0.80
commitPartialMethod · 0.80
deletePartialMethod · 0.80

Tested by

no test coverage detected