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

Method normalizeWorkspaceTurnRecord

src/node/services/taskService.ts:5690–5731  ·  view source on GitHub ↗
(
    record: WorkspaceTurnTaskHandleRecord
  )

Source from the content-addressed store, hash-verified

5688 }
5689
5690 private async normalizeWorkspaceTurnRecord(
5691 record: WorkspaceTurnTaskHandleRecord
5692 ): Promise<WorkspaceTurnTaskHandleRecord | null> {
5693 assert(record.ownerWorkspaceId.length > 0, "normalizeWorkspaceTurnRecord requires owner id");
5694 assert(record.handleId.length > 0, "normalizeWorkspaceTurnRecord requires handle id");
5695
5696 // Older recovery skipped deferred stream-end history and could mark a completed workspace turn
5697 // interrupted. Re-check the durable child history anywhere handles are observed so task_list and
5698 // task_await agree on the self-healed terminal status.
5699 if (
5700 record.status === "interrupted" &&
5701 record.error === "Workspace turn interrupted after restart" &&
5702 (record.deferredMessageIds?.length ?? 0) > 0
5703 ) {
5704 const recovered = await this.recoverTerminalWorkspaceTurnFromHistory(record);
5705 if (recovered != null) {
5706 await this.taskHandleStore.upsertWorkspaceTurn(recovered);
5707 await this.cleanupDisposableWorkspaceTurn(recovered);
5708 const active = this.activeWorkspaceTurnHandleByWorkspaceId.get(record.workspaceId);
5709 if (
5710 active?.handleId === record.handleId &&
5711 active.ownerWorkspaceId === record.ownerWorkspaceId
5712 ) {
5713 this.activeWorkspaceTurnHandleByWorkspaceId.delete(record.workspaceId);
5714 }
5715 return await this.taskHandleStore.getWorkspaceTurn(
5716 record.ownerWorkspaceId,
5717 record.handleId
5718 );
5719 }
5720 }
5721
5722 if (
5723 (record.status === "queued" || record.status === "starting" || record.status === "running") &&
5724 !(await this.isLiveWorkspaceTurn(record))
5725 ) {
5726 await this.settleStaleWorkspaceTurn(record);
5727 return await this.taskHandleStore.getWorkspaceTurn(record.ownerWorkspaceId, record.handleId);
5728 }
5729
5730 return record;
5731 }
5732
5733 async getWorkspaceTurnSnapshot(
5734 ownerWorkspaceId: string,

Callers 2

Calls 9

isLiveWorkspaceTurnMethod · 0.95
upsertWorkspaceTurnMethod · 0.80
getWorkspaceTurnMethod · 0.80
getMethod · 0.65
assertFunction · 0.50
deleteMethod · 0.45

Tested by

no test coverage detected