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

Method writePartial

src/node/services/historyService.ts:1178–1202  ·  view source on GitHub ↗

* Write a partial message to disk.

(workspaceId: string, message: MuxMessage)

Source from the content-addressed store, hash-verified

1176 * Write a partial message to disk.
1177 */
1178 async writePartial(workspaceId: string, message: MuxMessage): Promise<Result<void>> {
1179 return this.fileLocks.withLock(workspaceId, async () => {
1180 try {
1181 const workspaceDir = this.config.getSessionDir(workspaceId);
1182 await ensurePrivateDir(workspaceDir);
1183 const partialPath = this.getPartialPath(workspaceId);
1184
1185 const partialMessage: MuxMessage = {
1186 ...message,
1187 metadata: {
1188 ...message.metadata,
1189 partial: true,
1190 },
1191 };
1192
1193 // Atomic write: writes to temp file then renames, preventing corruption
1194 // if app crashes mid-write (prevents "Unexpected end of JSON input" on read)
1195 await writeFileAtomic(partialPath, JSON.stringify(partialMessage, null, 2));
1196 return Ok(undefined);
1197 } catch (error) {
1198 const errorMessage = getErrorMessage(error);
1199 return Err(`Failed to write partial: ${errorMessage}`);
1200 }
1201 });
1202 }
1203
1204 /**
1205 * Delete the partial message file for a workspace.

Calls 7

getPartialPathMethod · 0.95
ensurePrivateDirFunction · 0.90
OkFunction · 0.90
getErrorMessageFunction · 0.90
ErrFunction · 0.90
withLockMethod · 0.80
getSessionDirMethod · 0.65

Tested by 3

finalizeChildReportFunction · 0.64