@ricsam/r5d-worker 0.0.55 → 0.0.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mjs/main.mjs CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  import { terminateProcessTree } from "./process-tree.mjs";
15
15
  import { openWorkerPortForwardRelay } from "./port-forward-client.mjs";
16
16
  import { applyWorkspaceIncidentUpdate, releasePendingWorkspaceHead } from "./workspace-incident-state.mjs";
17
+ import { acquireWorkspaceCommandMutation, runWorkspaceCommand } from "./workspace-command-sync-policy.mjs";
17
18
  import {
18
19
  isRetryableWorkerServerStatus,
19
20
  superviseWorkerRuntime,
@@ -2257,7 +2258,7 @@ async function openPty(input) {
2257
2258
  });
2258
2259
  },
2259
2260
  onExit: (event) => {
2260
- input.releaseWorkspaceMutation();
2261
+ input.releaseWorkspaceMutation?.();
2261
2262
  activePtys.delete(input.message.ptyId);
2262
2263
  sendWorkerMessage(input.ws, {
2263
2264
  type: "pty_exit",
@@ -2267,7 +2268,7 @@ async function openPty(input) {
2267
2268
  });
2268
2269
  },
2269
2270
  onError: (error) => {
2270
- input.releaseWorkspaceMutation();
2271
+ input.releaseWorkspaceMutation?.();
2271
2272
  activePtys.delete(input.message.ptyId);
2272
2273
  sendWorkerMessage(input.ws, {
2273
2274
  type: "pty_error",
@@ -2280,7 +2281,7 @@ async function openPty(input) {
2280
2281
  activePtys.set(input.message.ptyId, {
2281
2282
  ...ptyProcess,
2282
2283
  target: input.resolvedTarget.target,
2283
- releaseWorkspaceMutation: input.releaseWorkspaceMutation
2284
+ ...input.releaseWorkspaceMutation ? { releaseWorkspaceMutation: input.releaseWorkspaceMutation } : {}
2284
2285
  });
2285
2286
  }
2286
2287
  function writePty(ws, message) {
@@ -2826,14 +2827,20 @@ async function startWorker(options) {
2826
2827
  });
2827
2828
  return;
2828
2829
  }
2829
- const releaseWorkspaceMutation = await workspaceSyncSingleFlight.acquireMutation();
2830
+ const releaseWorkspaceMutation = await acquireWorkspaceCommandMutation(message.target, workspaceSyncSingleFlight);
2830
2831
  let leaseTransferred = false;
2831
2832
  try {
2832
2833
  const resolvedTarget = resolveMessageTarget(message.target);
2833
2834
  process.stdout.write(`[r5d-worker] pty ${message.ptyId}: ${describeWorkerSessionTarget(message.target)}
2834
2835
  `);
2835
- await openPty({ ws, message, resolvedTarget, planRoot, releaseWorkspaceMutation });
2836
- leaseTransferred = true;
2836
+ await openPty({
2837
+ ws,
2838
+ message,
2839
+ resolvedTarget,
2840
+ planRoot,
2841
+ ...releaseWorkspaceMutation ? { releaseWorkspaceMutation } : {}
2842
+ });
2843
+ leaseTransferred = releaseWorkspaceMutation !== void 0;
2837
2844
  } catch (error) {
2838
2845
  sendWorkerMessage(ws, {
2839
2846
  type: "pty_error",
@@ -2842,7 +2849,7 @@ async function startWorker(options) {
2842
2849
  error: error instanceof Error ? error.message : String(error)
2843
2850
  });
2844
2851
  } finally {
2845
- if (!leaseTransferred) releaseWorkspaceMutation();
2852
+ if (!leaseTransferred) releaseWorkspaceMutation?.();
2846
2853
  }
2847
2854
  return;
2848
2855
  }
@@ -2871,12 +2878,13 @@ async function startWorker(options) {
2871
2878
  }
2872
2879
  let result;
2873
2880
  try {
2874
- result = await workspaceSyncSingleFlight.runMutation(async () => {
2881
+ const runCommand = async () => {
2875
2882
  const resolvedTarget = resolveMessageTarget(message.target);
2876
2883
  process.stdout.write(`[r5d-worker] exec ${message.runId}: ${message.argv.join(" ")}
2877
2884
  `);
2878
2885
  return await executeCommand({ message, resolvedTarget, baseUrl, token, artifactRoot, planRoot });
2879
- });
2886
+ };
2887
+ result = await runWorkspaceCommand(message.target, workspaceSyncSingleFlight, runCommand);
2880
2888
  } catch (error) {
2881
2889
  result = {
2882
2890
  type: "exec_result",
@@ -2905,7 +2913,7 @@ async function startWorker(options) {
2905
2913
  requestId: message.requestId,
2906
2914
  runId: message.runId
2907
2915
  });
2908
- void workspaceSyncSingleFlight.runMutation(async () => {
2916
+ const runCommand = async () => {
2909
2917
  const resolvedTarget = resolveMessageTarget(message.target);
2910
2918
  process.stdout.write(`[r5d-worker] exec_start ${message.runId}: ${message.argv.join(" ")}
2911
2919
  `);
@@ -2918,7 +2926,9 @@ async function startWorker(options) {
2918
2926
  artifactRoot,
2919
2927
  planRoot
2920
2928
  });
2921
- }).catch((error) => {
2929
+ };
2930
+ const execution = runWorkspaceCommand(message.target, workspaceSyncSingleFlight, runCommand);
2931
+ void execution.catch((error) => {
2922
2932
  sendWorkerMessage(ws, {
2923
2933
  type: "exec_start_error",
2924
2934
  requestId: message.requestId,
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.55",
3
+ "version": "0.0.56",
4
4
  "type": "module"
5
5
  }
@@ -0,0 +1,14 @@
1
+ function shouldSerializeWorkspaceCommand(target) {
2
+ return target.type === "workspace" && target.rootProfile === "canonical_sync";
3
+ }
4
+ function runWorkspaceCommand(target, coordinator, operation) {
5
+ return shouldSerializeWorkspaceCommand(target) ? coordinator.runMutation(operation) : Promise.resolve().then(operation);
6
+ }
7
+ function acquireWorkspaceCommandMutation(target, coordinator) {
8
+ return shouldSerializeWorkspaceCommand(target) ? coordinator.acquireMutation() : Promise.resolve(void 0);
9
+ }
10
+ export {
11
+ acquireWorkspaceCommandMutation,
12
+ runWorkspaceCommand,
13
+ shouldSerializeWorkspaceCommand
14
+ };