@relayfx/sdk 0.3.4 → 0.3.5

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.
@@ -16,7 +16,7 @@ import {
16
16
  exports_tool_executor,
17
17
  exports_tool_output,
18
18
  exports_turn_policy
19
- } from "./index-25gwk9tj.js";
19
+ } from "./index-8fpd6kvj.js";
20
20
  import {
21
21
  ClientError,
22
22
  CommandReplyInvalid,
@@ -51,7 +51,7 @@ import {
51
51
  followExecutionFrom,
52
52
  inputSchemaRef,
53
53
  outputSchemaRef
54
- } from "./index-cphmds30.js";
54
+ } from "./index-cyfx5y3r.js";
55
55
  import {
56
56
  __export
57
57
  } from "./index-nb39b5ae.js";
@@ -7679,9 +7679,10 @@ var MaxAttemptRow = Schema35.Struct({
7679
7679
  });
7680
7680
  var ExpiredCallRow = Schema35.Struct({
7681
7681
  id: Schema35.String,
7682
+ execution_id: Schema35.String,
7682
7683
  active_attempt_id: Schema35.NullishOr(Schema35.String)
7683
7684
  });
7684
- var IdRow = Schema35.Struct({ id: Schema35.String });
7685
+ var IdRow = Schema35.Struct({ id: Schema35.String, execution_id: Schema35.String });
7685
7686
  var metadata8 = (input) => input ?? {};
7686
7687
  var normalizeCall = (call) => ({ ...call, metadata: metadata8(call.metadata) });
7687
7688
  var sameCallIdentity = (left, right) => exports_shared_schema.canonicalEquals(normalizeCall(left), normalizeCall(right));
@@ -7776,15 +7777,15 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
7776
7777
  "completed_at"
7777
7778
  ].join(", "));
7778
7779
  const resultColumns = sql.literal(["tool_call_id", "output_json", "error", "metadata_json", "created_at"].join(", "));
7779
- const selectCallByKey = (tenantId, id) => sql`
7780
+ const selectCallByKey = (tenantId, executionId, id) => sql`
7780
7781
  SELECT ${callColumns}
7781
7782
  FROM relay_tool_calls
7782
- WHERE tenant_id = ${tenantId} AND id = ${id}
7783
+ WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND id = ${id}
7783
7784
  `;
7784
- const selectResultByKey = (tenantId, callId) => sql`
7785
+ const selectResultByKey = (tenantId, executionId, callId) => sql`
7785
7786
  SELECT ${resultColumns}
7786
7787
  FROM relay_tool_results
7787
- WHERE tenant_id = ${tenantId} AND tool_call_id = ${callId}
7788
+ WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND tool_call_id = ${callId}
7788
7789
  `;
7789
7790
  const insertCallBody = (tenantId, input, definition, placement = { kind: "local" }) => sql`
7790
7791
  (
@@ -7823,13 +7824,13 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
7823
7824
  `,
7824
7825
  orElse: () => (tenantId, input, definition, placement) => sql`
7825
7826
  INSERT INTO relay_tool_calls ${insertCallBody(tenantId, input, definition, placement)}
7826
- ON CONFLICT (tenant_id, id) DO NOTHING
7827
+ ON CONFLICT (tenant_id, execution_id, id) DO NOTHING
7827
7828
  `
7828
7829
  });
7829
7830
  const insertCall = sql.onDialectOrElse({
7830
7831
  mysql: () => (tenantId, input, definition, placement) => sql.withTransaction(Effect37.gen(function* () {
7831
7832
  yield* insertCallStatement(tenantId, input, definition, placement);
7832
- return yield* selectCallByKey(tenantId, input.call.id);
7833
+ return yield* selectCallByKey(tenantId, input.executionId, input.call.id);
7833
7834
  })),
7834
7835
  orElse: () => (tenantId, input, definition, placement) => sql`
7835
7836
  ${insertCallStatement(tenantId, input, definition, placement)}
@@ -7838,10 +7839,11 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
7838
7839
  });
7839
7840
  const insertResultStatement = (tenantId, input) => sql`
7840
7841
  INSERT INTO relay_tool_results (
7841
- tenant_id, ${resultColumns}
7842
+ tenant_id, execution_id, ${resultColumns}
7842
7843
  )
7843
7844
  VALUES (
7844
7845
  ${tenantId},
7846
+ ${input.executionId},
7845
7847
  ${input.result.call_id},
7846
7848
  ${encodeJson(input.result.output)},
7847
7849
  ${input.result.error ?? null},
@@ -7849,19 +7851,19 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
7849
7851
  ${timestampParam(sql, input.createdAt)}
7850
7852
  )
7851
7853
  `;
7852
- const selectAttempts = (tenantId, callId) => sql`
7854
+ const selectAttempts = (tenantId, executionId, callId) => sql`
7853
7855
  SELECT ${attemptColumns}
7854
7856
  FROM relay_tool_attempts
7855
- WHERE tenant_id = ${tenantId} AND tool_call_id = ${callId}
7857
+ WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND tool_call_id = ${callId}
7856
7858
  ORDER BY attempt_number ASC
7857
7859
  `;
7858
7860
  const lockedCallRows = sql.onDialectOrElse({
7859
- pg: () => (tenantId, callId) => sql`
7860
- ${selectCallByKey(tenantId, callId)}
7861
+ pg: () => (tenantId, executionId, callId) => sql`
7862
+ ${selectCallByKey(tenantId, executionId, callId)}
7861
7863
  FOR UPDATE
7862
7864
  `,
7863
- mysql: () => (tenantId, callId) => sql`
7864
- ${selectCallByKey(tenantId, callId)}
7865
+ mysql: () => (tenantId, executionId, callId) => sql`
7866
+ ${selectCallByKey(tenantId, executionId, callId)}
7865
7867
  FOR UPDATE
7866
7868
  `,
7867
7869
  orElse: () => selectCallByKey
@@ -7874,35 +7876,35 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
7874
7876
  const decoded = yield* decodeAttemptRow(row);
7875
7877
  return yield* Effect37.try({ try: () => toAttemptRecord(decoded), catch: toRepositoryError17 });
7876
7878
  });
7877
- const readLockedCall = Effect37.fn("ToolCallRepository.readLockedCall")(function* (tenantId, callId) {
7878
- const rows = yield* lockedCallRows(tenantId, callId).pipe(Effect37.mapError(toRepositoryError17));
7879
+ const readLockedCall = Effect37.fn("ToolCallRepository.readLockedCall")(function* (tenantId, executionId, callId) {
7880
+ const rows = yield* lockedCallRows(tenantId, executionId, callId).pipe(Effect37.mapError(toRepositoryError17));
7879
7881
  if (rows[0] === undefined)
7880
7882
  return yield* ToolCallNotFound.make({ id: callId });
7881
7883
  return yield* decodeCall(rows[0]);
7882
7884
  });
7883
- const readAttempts = Effect37.fn("ToolCallRepository.readAttempts")(function* (tenantId, callId) {
7884
- const rows = yield* selectAttempts(tenantId, callId).pipe(Effect37.mapError(toRepositoryError17));
7885
+ const readAttempts = Effect37.fn("ToolCallRepository.readAttempts")(function* (tenantId, executionId, callId) {
7886
+ const rows = yield* selectAttempts(tenantId, executionId, callId).pipe(Effect37.mapError(toRepositoryError17));
7885
7887
  return yield* Effect37.forEach(rows, decodeAttempt);
7886
7888
  });
7887
- const nextAttemptNumber = Effect37.fn("ToolCallRepository.nextAttemptNumber")(function* (tenantId, callId) {
7889
+ const nextAttemptNumber = Effect37.fn("ToolCallRepository.nextAttemptNumber")(function* (tenantId, executionId, callId) {
7888
7890
  const rows = yield* sql`
7889
7891
  SELECT COALESCE(MAX(attempt_number), 0) AS max_attempt
7890
7892
  FROM relay_tool_attempts
7891
- WHERE tenant_id = ${tenantId} AND tool_call_id = ${callId}
7893
+ WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND tool_call_id = ${callId}
7892
7894
  `.pipe(Effect37.mapError(toRepositoryError17));
7893
7895
  const row = yield* decodeMaxAttemptRow(rows[0]);
7894
7896
  const max = Number(row?.max_attempt ?? 0);
7895
7897
  return max + 1;
7896
7898
  });
7897
- const insertAttemptNumber = Effect37.fn("ToolCallRepository.insertAttemptNumber")(function* (tenantId, callId, attemptNumber, createdAt, workerId, claimExpiresAt) {
7899
+ const insertAttemptNumber = Effect37.fn("ToolCallRepository.insertAttemptNumber")(function* (tenantId, executionId, callId, attemptNumber, createdAt, workerId, claimExpiresAt) {
7898
7900
  const attemptId = toolAttemptId(attemptNumber);
7899
7901
  yield* sql`
7900
7902
  INSERT INTO relay_tool_attempts (
7901
- tenant_id, id, tool_call_id, attempt_number, state, worker_id, claim_expires_at,
7903
+ tenant_id, execution_id, id, tool_call_id, attempt_number, state, worker_id, claim_expires_at,
7902
7904
  error, created_at, completed_at
7903
7905
  )
7904
7906
  VALUES (
7905
- ${tenantId}, ${attemptId}, ${callId}, ${attemptNumber}, 'running', ${workerId ?? null},
7907
+ ${tenantId}, ${executionId}, ${attemptId}, ${callId}, ${attemptNumber}, 'running', ${workerId ?? null},
7906
7908
  ${claimExpiresAt === undefined ? null : ts(claimExpiresAt)}, ${null}, ${ts(createdAt)}, ${null}
7907
7909
  )
7908
7910
  `.pipe(Effect37.mapError(toRepositoryError17));
@@ -7916,25 +7918,25 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
7916
7918
  createdAt
7917
7919
  };
7918
7920
  });
7919
- const insertAttempt = Effect37.fn("ToolCallRepository.insertAttempt")(function* (tenantId, callId, createdAt, workerId, claimExpiresAt) {
7920
- const attemptNumber = yield* nextAttemptNumber(tenantId, callId);
7921
- return yield* insertAttemptNumber(tenantId, callId, attemptNumber, createdAt, workerId, claimExpiresAt);
7921
+ const insertAttempt = Effect37.fn("ToolCallRepository.insertAttempt")(function* (tenantId, executionId, callId, createdAt, workerId, claimExpiresAt) {
7922
+ const attemptNumber = yield* nextAttemptNumber(tenantId, executionId, callId);
7923
+ return yield* insertAttemptNumber(tenantId, executionId, callId, attemptNumber, createdAt, workerId, claimExpiresAt);
7922
7924
  });
7923
- const loadAttempt = Effect37.fn("ToolCallRepository.loadAttempt")(function* (tenantId, callId, attemptId) {
7925
+ const loadAttempt = Effect37.fn("ToolCallRepository.loadAttempt")(function* (tenantId, executionId, callId, attemptId) {
7924
7926
  const rows = yield* sql`
7925
7927
  SELECT ${attemptColumns}
7926
7928
  FROM relay_tool_attempts
7927
- WHERE tenant_id = ${tenantId} AND tool_call_id = ${callId} AND id = ${attemptId}
7929
+ WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND tool_call_id = ${callId} AND id = ${attemptId}
7928
7930
  `.pipe(Effect37.mapError(toRepositoryError17));
7929
7931
  return rows[0] === undefined ? undefined : yield* decodeAttempt(rows[0]);
7930
7932
  });
7931
- const completeAttempt = Effect37.fn("ToolCallRepository.completeAttempt")(function* (tenantId, callId, attemptId, state, completedAt, error5) {
7933
+ const completeAttempt = Effect37.fn("ToolCallRepository.completeAttempt")(function* (tenantId, executionId, callId, attemptId, state, completedAt, error5) {
7932
7934
  yield* sql`
7933
7935
  UPDATE relay_tool_attempts
7934
7936
  SET state = ${state}, error = ${error5 ?? null}, completed_at = ${ts(completedAt)}
7935
- WHERE tenant_id = ${tenantId} AND tool_call_id = ${callId} AND id = ${attemptId} AND state = 'running'
7937
+ WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND tool_call_id = ${callId} AND id = ${attemptId} AND state = 'running'
7936
7938
  `.pipe(Effect37.mapError(toRepositoryError17));
7937
- const attempt = yield* loadAttempt(tenantId, callId, attemptId);
7939
+ const attempt = yield* loadAttempt(tenantId, executionId, callId, attemptId);
7938
7940
  if (attempt === undefined) {
7939
7941
  return yield* ToolCallRepositoryError.make({ message: `Tool attempt not found: ${attemptId}` });
7940
7942
  }
@@ -7944,7 +7946,7 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
7944
7946
  const tenantId = yield* current();
7945
7947
  return yield* sql.withTransaction(Effect37.gen(function* () {
7946
7948
  yield* insertCallIgnore(tenantId, input, input.definition, input.placement);
7947
- const rows = yield* lockedCallRows(tenantId, input.call.id);
7949
+ const rows = yield* lockedCallRows(tenantId, input.executionId, input.call.id);
7948
7950
  if (rows[0] === undefined)
7949
7951
  return yield* ToolCallNotFound.make({ id: input.call.id });
7950
7952
  const existing = yield* decodeCall(rows[0]);
@@ -7960,7 +7962,7 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
7960
7962
  const prepareExternalWait = Effect37.fn("ToolCallRepository.prepareExternalWait")(function* (input) {
7961
7963
  const tenantId = yield* current();
7962
7964
  return yield* repositoryTransaction(Effect37.gen(function* () {
7963
- const call = yield* readLockedCall(tenantId, input.callId);
7965
+ const call = yield* readLockedCall(tenantId, input.executionId, input.callId);
7964
7966
  if (call.placement.kind !== "client" && call.placement.kind !== "remote") {
7965
7967
  return yield* ToolCallTransitionRejected.make({
7966
7968
  id: input.callId,
@@ -7976,15 +7978,15 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
7976
7978
  UPDATE relay_tool_calls
7977
7979
  SET state = 'waiting', wait_id = ${input.waitId}, available_at = ${ts(input.availableAt)},
7978
7980
  updated_at = ${ts(input.updatedAt)}
7979
- WHERE tenant_id = ${tenantId} AND id = ${input.callId} AND state = 'requested'
7981
+ WHERE tenant_id = ${tenantId} AND execution_id = ${input.executionId} AND id = ${input.callId} AND state = 'requested'
7980
7982
  `.pipe(Effect37.mapError(toRepositoryError17));
7981
- return yield* readLockedCall(tenantId, input.callId);
7983
+ return yield* readLockedCall(tenantId, input.executionId, input.callId);
7982
7984
  }));
7983
7985
  });
7984
7986
  const beginAttempt = Effect37.fn("ToolCallRepository.beginAttempt")(function* (input) {
7985
7987
  const tenantId = yield* current();
7986
7988
  return yield* repositoryTransaction(Effect37.gen(function* () {
7987
- const call = yield* readLockedCall(tenantId, input.callId);
7989
+ const call = yield* readLockedCall(tenantId, input.executionId, input.callId);
7988
7990
  if (call.placement.kind !== "local" && call.placement.kind !== "mcp") {
7989
7991
  return yield* ToolCallTransitionRejected.make({
7990
7992
  id: input.callId,
@@ -7995,13 +7997,13 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
7995
7997
  return yield* ToolCallTransitionRejected.make({ id: input.callId, message: `Call is ${call.state}` });
7996
7998
  }
7997
7999
  if (call.activeAttemptId !== undefined) {
7998
- yield* completeAttempt(tenantId, input.callId, call.activeAttemptId, "abandoned", input.startedAt);
8000
+ yield* completeAttempt(tenantId, input.executionId, input.callId, call.activeAttemptId, "abandoned", input.startedAt);
7999
8001
  }
8000
- const attempt = yield* insertAttempt(tenantId, input.callId, input.startedAt);
8002
+ const attempt = yield* insertAttempt(tenantId, input.executionId, input.callId, input.startedAt);
8001
8003
  yield* sql`
8002
8004
  UPDATE relay_tool_calls
8003
8005
  SET state = 'running', active_attempt_id = ${attempt.id}, updated_at = ${ts(input.startedAt)}
8004
- WHERE tenant_id = ${tenantId} AND id = ${input.callId}
8006
+ WHERE tenant_id = ${tenantId} AND execution_id = ${input.executionId} AND id = ${input.callId}
8005
8007
  `.pipe(Effect37.mapError(toRepositoryError17));
8006
8008
  return attempt;
8007
8009
  }));
@@ -8009,7 +8011,7 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
8009
8011
  const acceptClientOutcome = Effect37.fn("ToolCallRepository.acceptClientOutcome")(function* (input) {
8010
8012
  const tenantId = yield* current();
8011
8013
  return yield* repositoryTransaction(Effect37.gen(function* () {
8012
- const call = yield* readLockedCall(tenantId, input.callId);
8014
+ const call = yield* readLockedCall(tenantId, input.executionId, input.callId);
8013
8015
  if (call.executionId !== input.executionId || call.placement.kind !== "client") {
8014
8016
  return yield* ToolCallTransitionRejected.make({
8015
8017
  id: input.callId,
@@ -8026,7 +8028,7 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
8026
8028
  message: "Accepted attempt is missing"
8027
8029
  });
8028
8030
  }
8029
- const attempt2 = yield* loadAttempt(tenantId, input.callId, call.activeAttemptId);
8031
+ const attempt2 = yield* loadAttempt(tenantId, input.executionId, input.callId, call.activeAttemptId);
8030
8032
  if (attempt2 === undefined) {
8031
8033
  return yield* ToolCallTransitionRejected.make({
8032
8034
  id: input.callId,
@@ -8038,21 +8040,21 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
8038
8040
  if (call.state !== "waiting") {
8039
8041
  return yield* ToolCallTransitionRejected.make({ id: input.callId, message: `Call is ${call.state}` });
8040
8042
  }
8041
- const running = yield* insertAttempt(tenantId, input.callId, input.submittedAt);
8042
- const attempt = yield* completeAttempt(tenantId, input.callId, running.id, input.outcome.kind === "success" ? "completed" : "failed", input.submittedAt, input.outcome.kind === "failure" ? input.outcome.message : undefined);
8043
+ const running = yield* insertAttempt(tenantId, input.executionId, input.callId, input.submittedAt);
8044
+ const attempt = yield* completeAttempt(tenantId, input.executionId, input.callId, running.id, input.outcome.kind === "success" ? "completed" : "failed", input.submittedAt, input.outcome.kind === "failure" ? input.outcome.message : undefined);
8043
8045
  yield* sql`
8044
8046
  UPDATE relay_tool_calls
8045
8047
  SET state = 'submitted', active_attempt_id = ${attempt.id},
8046
8048
  external_outcome_json = ${encodeJson(input.outcome)},
8047
8049
  external_outcome_at = ${ts(input.submittedAt)}, updated_at = ${ts(input.submittedAt)}
8048
- WHERE tenant_id = ${tenantId} AND id = ${input.callId}
8050
+ WHERE tenant_id = ${tenantId} AND execution_id = ${input.executionId} AND id = ${input.callId}
8049
8051
  `.pipe(Effect37.mapError(toRepositoryError17));
8050
- const updated = yield* readLockedCall(tenantId, input.callId);
8052
+ const updated = yield* readLockedCall(tenantId, input.executionId, input.callId);
8051
8053
  return { call: updated, attempt, duplicate: false };
8052
8054
  }));
8053
8055
  });
8054
8056
  const claimCandidate = (tenantId, input) => sql`
8055
- SELECT id
8057
+ SELECT execution_id, id
8056
8058
  FROM relay_tool_calls
8057
8059
  WHERE tenant_id = ${tenantId} AND placement_kind = 'remote' AND placement_key = ${input.queue}
8058
8060
  AND state = 'waiting' AND available_at <= ${ts(input.now)}
@@ -8071,20 +8073,20 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
8071
8073
  orElse: () => claimCandidate
8072
8074
  });
8073
8075
  const claimCall = sql.onDialectOrElse({
8074
- mysql: () => (tenantId, callId, attemptId, input) => sql`
8076
+ mysql: () => (tenantId, executionId, callId, attemptId, input) => sql`
8075
8077
  UPDATE relay_tool_calls
8076
8078
  SET state = 'running', active_attempt_id = ${attemptId}, claim_owner = ${input.workerId},
8077
8079
  claimed_at = ${ts(input.now)}, claim_expires_at = ${ts(input.claimExpiresAt)},
8078
8080
  updated_at = ${ts(input.now)}
8079
- WHERE tenant_id = ${tenantId} AND id = ${callId} AND state = 'waiting'
8081
+ WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND id = ${callId} AND state = 'waiting'
8080
8082
  AND available_at <= ${ts(input.now)}
8081
8083
  `.pipe(Effect37.as([{ id: callId }])),
8082
- orElse: () => (tenantId, callId, attemptId, input) => sql`
8084
+ orElse: () => (tenantId, executionId, callId, attemptId, input) => sql`
8083
8085
  UPDATE relay_tool_calls
8084
8086
  SET state = 'running', active_attempt_id = ${attemptId}, claim_owner = ${input.workerId},
8085
8087
  claimed_at = ${ts(input.now)}, claim_expires_at = ${ts(input.claimExpiresAt)},
8086
8088
  updated_at = ${ts(input.now)}
8087
- WHERE tenant_id = ${tenantId} AND id = ${callId} AND state = 'waiting'
8089
+ WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND id = ${callId} AND state = 'waiting'
8088
8090
  AND available_at <= ${ts(input.now)}
8089
8091
  RETURNING id
8090
8092
  `
@@ -8096,21 +8098,22 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
8096
8098
  const tenantId = yield* current();
8097
8099
  return yield* repositoryTransaction(Effect37.gen(function* () {
8098
8100
  const expiredRows = yield* sql`
8099
- SELECT id, active_attempt_id
8101
+ SELECT execution_id, id, active_attempt_id
8100
8102
  FROM relay_tool_calls
8101
8103
  WHERE tenant_id = ${tenantId} AND placement_kind = 'remote' AND placement_key = ${input.queue}
8102
8104
  AND state = 'running' AND claim_expires_at IS NOT NULL AND claim_expires_at <= ${ts(input.now)}
8103
8105
  `.pipe(Effect37.mapError(toRepositoryError17));
8104
8106
  const expired = yield* Schema35.decodeUnknownEffect(Schema35.Array(ExpiredCallRow))(expiredRows).pipe(Effect37.mapError(toRepositoryError17));
8105
8107
  for (const row of expired) {
8108
+ const executionId2 = exports_ids_schema.ExecutionId.make(row.execution_id);
8106
8109
  if (row.active_attempt_id !== null && row.active_attempt_id !== undefined) {
8107
- yield* completeAttempt(tenantId, exports_ids_schema.ToolCallId.make(row.id), exports_ids_schema.ToolAttemptId.make(row.active_attempt_id), "expired", input.now);
8110
+ yield* completeAttempt(tenantId, executionId2, exports_ids_schema.ToolCallId.make(row.id), exports_ids_schema.ToolAttemptId.make(row.active_attempt_id), "expired", input.now);
8108
8111
  }
8109
8112
  yield* sql`
8110
8113
  UPDATE relay_tool_calls
8111
8114
  SET state = 'waiting', active_attempt_id = NULL, claim_owner = NULL, claimed_at = NULL,
8112
8115
  claim_expires_at = NULL, updated_at = ${ts(input.now)}
8113
- WHERE tenant_id = ${tenantId} AND id = ${row.id} AND state = 'running'
8116
+ WHERE tenant_id = ${tenantId} AND execution_id = ${executionId2} AND id = ${row.id} AND state = 'running'
8114
8117
  `.pipe(Effect37.mapError(toRepositoryError17));
8115
8118
  }
8116
8119
  const candidateRows = yield* selectClaimCandidate(tenantId, input).pipe(Effect37.mapError(toRepositoryError17));
@@ -8118,21 +8121,22 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
8118
8121
  const candidate = candidates[0];
8119
8122
  if (candidate === undefined)
8120
8123
  return;
8124
+ const executionId = exports_ids_schema.ExecutionId.make(candidate.execution_id);
8121
8125
  const callId = exports_ids_schema.ToolCallId.make(candidate.id);
8122
- const call = yield* readLockedCall(tenantId, callId);
8126
+ const call = yield* readLockedCall(tenantId, executionId, callId);
8123
8127
  if (call.definition === undefined || call.placement.kind !== "remote") {
8124
8128
  return yield* ToolCallTransitionRejected.make({
8125
8129
  id: callId,
8126
8130
  message: "Remote call definition snapshot is missing"
8127
8131
  });
8128
8132
  }
8129
- const attemptNumber = yield* nextAttemptNumber(tenantId, callId);
8133
+ const attemptNumber = yield* nextAttemptNumber(tenantId, executionId, callId);
8130
8134
  const attemptId = toolAttemptId(attemptNumber);
8131
- const claimed = yield* claimCall(tenantId, callId, attemptId, input).pipe(Effect37.mapError(toRepositoryError17));
8135
+ const claimed = yield* claimCall(tenantId, executionId, callId, attemptId, input).pipe(Effect37.mapError(toRepositoryError17));
8132
8136
  if (claimed[0] === undefined)
8133
8137
  return;
8134
- const attempt = yield* insertAttemptNumber(tenantId, callId, attemptNumber, input.now, input.workerId, input.claimExpiresAt);
8135
- const updated = yield* readLockedCall(tenantId, callId);
8138
+ const attempt = yield* insertAttemptNumber(tenantId, executionId, callId, attemptNumber, input.now, input.workerId, input.claimExpiresAt);
8139
+ const updated = yield* readLockedCall(tenantId, executionId, callId);
8136
8140
  if (updated.definition === undefined || updated.placement.kind !== "remote") {
8137
8141
  return yield* ToolCallTransitionRejected.make({
8138
8142
  id: callId,
@@ -8152,25 +8156,25 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
8152
8156
  const releaseRemote = Effect37.fn("ToolCallRepository.releaseRemote")(function* (input) {
8153
8157
  const tenantId = yield* current();
8154
8158
  return yield* repositoryTransaction(Effect37.gen(function* () {
8155
- const call = yield* readLockedCall(tenantId, input.callId);
8159
+ const call = yield* readLockedCall(tenantId, input.executionId, input.callId);
8156
8160
  if (call.placement.kind !== "remote" || call.state !== "running" || call.activeAttemptId !== input.attemptId || call.claimOwner !== input.workerId || call.claimExpiresAt === undefined || call.claimExpiresAt <= input.releasedAt) {
8157
8161
  return yield* ToolClaimRejected.make({ message: "Remote claim is not active" });
8158
8162
  }
8159
- yield* completeAttempt(tenantId, input.callId, input.attemptId, "released", input.releasedAt, input.error);
8163
+ yield* completeAttempt(tenantId, input.executionId, input.callId, input.attemptId, "released", input.releasedAt, input.error);
8160
8164
  yield* sql`
8161
8165
  UPDATE relay_tool_calls
8162
8166
  SET state = 'waiting', available_at = ${ts(input.nextAvailableAt)}, active_attempt_id = NULL,
8163
8167
  claim_owner = NULL, claimed_at = NULL, claim_expires_at = NULL,
8164
8168
  updated_at = ${ts(input.releasedAt)}
8165
- WHERE tenant_id = ${tenantId} AND id = ${input.callId}
8169
+ WHERE tenant_id = ${tenantId} AND execution_id = ${input.executionId} AND id = ${input.callId}
8166
8170
  `.pipe(Effect37.mapError(toRepositoryError17));
8167
- return yield* readLockedCall(tenantId, input.callId);
8171
+ return yield* readLockedCall(tenantId, input.executionId, input.callId);
8168
8172
  }));
8169
8173
  });
8170
8174
  const acceptRemoteOutcome = Effect37.fn("ToolCallRepository.acceptRemoteOutcome")(function* (input) {
8171
8175
  const tenantId = yield* current();
8172
8176
  return yield* repositoryTransaction(Effect37.gen(function* () {
8173
- const call = yield* readLockedCall(tenantId, input.callId);
8177
+ const call = yield* readLockedCall(tenantId, input.executionId, input.callId);
8174
8178
  if (call.externalOutcome !== undefined) {
8175
8179
  if (!exports_shared_schema.canonicalEquals(call.externalOutcome, input.outcome)) {
8176
8180
  return yield* ToolOutcomeConflict.make({ id: input.callId });
@@ -8178,7 +8182,7 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
8178
8182
  if (call.activeAttemptId !== input.attemptId) {
8179
8183
  return yield* ToolClaimRejected.make({ message: "Remote attempt was not accepted" });
8180
8184
  }
8181
- const attempt2 = yield* loadAttempt(tenantId, input.callId, input.attemptId);
8185
+ const attempt2 = yield* loadAttempt(tenantId, input.executionId, input.callId, input.attemptId);
8182
8186
  if (attempt2 === undefined || attempt2.callId !== input.callId || attempt2.workerId !== input.workerId) {
8183
8187
  return yield* ToolClaimRejected.make({ message: "Remote attempt was not accepted" });
8184
8188
  }
@@ -8187,21 +8191,21 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
8187
8191
  if (call.placement.kind !== "remote" || call.state !== "running" || call.activeAttemptId !== input.attemptId || call.claimOwner !== input.workerId || call.claimExpiresAt === undefined || call.claimExpiresAt <= input.submittedAt) {
8188
8192
  return yield* ToolClaimRejected.make({ message: "Remote claim is not active" });
8189
8193
  }
8190
- const attempt = yield* completeAttempt(tenantId, input.callId, input.attemptId, input.outcome.kind === "success" ? "completed" : "failed", input.submittedAt, input.outcome.kind === "failure" ? input.outcome.message : undefined);
8194
+ const attempt = yield* completeAttempt(tenantId, input.executionId, input.callId, input.attemptId, input.outcome.kind === "success" ? "completed" : "failed", input.submittedAt, input.outcome.kind === "failure" ? input.outcome.message : undefined);
8191
8195
  yield* sql`
8192
8196
  UPDATE relay_tool_calls
8193
8197
  SET state = 'submitted', external_outcome_json = ${encodeJson(input.outcome)},
8194
8198
  external_outcome_at = ${ts(input.submittedAt)}, claim_owner = NULL, claimed_at = NULL,
8195
8199
  claim_expires_at = NULL, updated_at = ${ts(input.submittedAt)}
8196
- WHERE tenant_id = ${tenantId} AND id = ${input.callId}
8200
+ WHERE tenant_id = ${tenantId} AND execution_id = ${input.executionId} AND id = ${input.callId}
8197
8201
  `.pipe(Effect37.mapError(toRepositoryError17));
8198
- const updated = yield* readLockedCall(tenantId, input.callId);
8202
+ const updated = yield* readLockedCall(tenantId, input.executionId, input.callId);
8199
8203
  return { call: updated, attempt, duplicate: false };
8200
8204
  }));
8201
8205
  });
8202
- const listAttempts = Effect37.fn("ToolCallRepository.listAttempts")(function* (callId) {
8206
+ const listAttempts = Effect37.fn("ToolCallRepository.listAttempts")(function* (executionId, callId) {
8203
8207
  const tenantId = yield* current();
8204
- return yield* readAttempts(tenantId, callId);
8208
+ return yield* readAttempts(tenantId, executionId, callId);
8205
8209
  });
8206
8210
  const selectOpenCalls = sql.onDialectOrElse({
8207
8211
  pg: () => (tenantId, input) => sql`
@@ -8229,17 +8233,17 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
8229
8233
  `
8230
8234
  });
8231
8235
  const failCall = sql.onDialectOrElse({
8232
- mysql: () => (tenantId, callId, failedAt) => sql`
8236
+ mysql: () => (tenantId, executionId, callId, failedAt) => sql`
8233
8237
  UPDATE relay_tool_calls
8234
8238
  SET state = 'failed', claim_owner = NULL, claimed_at = NULL, claim_expires_at = NULL,
8235
8239
  updated_at = ${ts(failedAt)}
8236
- WHERE tenant_id = ${tenantId} AND id = ${callId} AND state NOT IN ('submitted', 'completed', 'failed')
8240
+ WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND id = ${callId} AND state NOT IN ('submitted', 'completed', 'failed')
8237
8241
  `.pipe(Effect37.as([{ id: callId }])),
8238
- orElse: () => (tenantId, callId, failedAt) => sql`
8242
+ orElse: () => (tenantId, executionId, callId, failedAt) => sql`
8239
8243
  UPDATE relay_tool_calls
8240
8244
  SET state = 'failed', claim_owner = NULL, claimed_at = NULL, claim_expires_at = NULL,
8241
8245
  updated_at = ${ts(failedAt)}
8242
- WHERE tenant_id = ${tenantId} AND id = ${callId} AND state NOT IN ('submitted', 'completed', 'failed')
8246
+ WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND id = ${callId} AND state NOT IN ('submitted', 'completed', 'failed')
8243
8247
  RETURNING id
8244
8248
  `
8245
8249
  });
@@ -8253,30 +8257,31 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
8253
8257
  for (const call of open) {
8254
8258
  if (selected !== undefined && !selected.has(call.call.id))
8255
8259
  continue;
8256
- const transitioned = yield* failCall(tenantId, call.call.id, input.failedAt).pipe(Effect37.mapError(toRepositoryError17));
8260
+ const transitioned = yield* failCall(tenantId, input.executionId, call.call.id, input.failedAt).pipe(Effect37.mapError(toRepositoryError17));
8257
8261
  if (transitioned[0] === undefined)
8258
8262
  continue;
8259
8263
  if (call.activeAttemptId !== undefined) {
8260
- const attempt = yield* loadAttempt(tenantId, call.call.id, call.activeAttemptId);
8264
+ const attempt = yield* loadAttempt(tenantId, input.executionId, call.call.id, call.activeAttemptId);
8261
8265
  if (attempt?.state === "running") {
8262
- yield* completeAttempt(tenantId, call.call.id, call.activeAttemptId, "failed", input.failedAt, input.message);
8266
+ yield* completeAttempt(tenantId, input.executionId, call.call.id, call.activeAttemptId, "failed", input.failedAt, input.message);
8263
8267
  }
8264
8268
  }
8265
- const existingResult = yield* selectResultByKey(tenantId, call.call.id).pipe(Effect37.mapError(toRepositoryError17));
8269
+ const existingResult = yield* selectResultByKey(tenantId, input.executionId, call.call.id).pipe(Effect37.mapError(toRepositoryError17));
8266
8270
  if (existingResult[0] === undefined) {
8267
8271
  yield* insertResultStatement(tenantId, {
8272
+ executionId: input.executionId,
8268
8273
  result: { call_id: call.call.id, output: null, error: input.message },
8269
8274
  createdAt: input.failedAt
8270
8275
  }).pipe(Effect37.mapError(toRepositoryError17));
8271
8276
  }
8272
- failed.push(yield* readLockedCall(tenantId, call.call.id));
8277
+ failed.push(yield* readLockedCall(tenantId, input.executionId, call.call.id));
8273
8278
  }
8274
8279
  return failed;
8275
8280
  }));
8276
8281
  });
8277
8282
  const recordCall = Effect37.fn("ToolCallRepository.recordCall")(function* (input) {
8278
8283
  const tenantId = yield* current();
8279
- const existing = yield* selectCallByKey(tenantId, input.call.id).pipe(Effect37.mapError(toRepositoryError17));
8284
+ const existing = yield* selectCallByKey(tenantId, input.executionId, input.call.id).pipe(Effect37.mapError(toRepositoryError17));
8280
8285
  if (existing[0] !== undefined)
8281
8286
  return yield* DuplicateToolCall.make({ id: input.call.id });
8282
8287
  const rows = yield* insertCall(tenantId, input).pipe(Effect37.mapError(toRepositoryError17));
@@ -8286,9 +8291,9 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
8286
8291
  }
8287
8292
  return yield* decodeCall(row);
8288
8293
  });
8289
- const getCall = Effect37.fn("ToolCallRepository.getCall")(function* (id) {
8294
+ const getCall = Effect37.fn("ToolCallRepository.getCall")(function* (executionId, id) {
8290
8295
  const tenantId = yield* current();
8291
- const rows = yield* selectCallByKey(tenantId, id).pipe(Effect37.mapError(toRepositoryError17));
8296
+ const rows = yield* selectCallByKey(tenantId, executionId, id).pipe(Effect37.mapError(toRepositoryError17));
8292
8297
  return rows[0] === undefined ? undefined : yield* decodeCall(rows[0]);
8293
8298
  });
8294
8299
  const listCalls = Effect37.fn("ToolCallRepository.listCalls")(function* (executionId) {
@@ -8304,16 +8309,16 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
8304
8309
  const recordResult = Effect37.fn("ToolCallRepository.recordResult")(function* (input) {
8305
8310
  const tenantId = yield* current();
8306
8311
  return yield* repositoryTransaction(Effect37.gen(function* () {
8307
- const call = yield* readLockedCall(tenantId, input.result.call_id);
8308
- const existing = yield* selectResultByKey(tenantId, input.result.call_id).pipe(Effect37.mapError(toRepositoryError17));
8312
+ const call = yield* readLockedCall(tenantId, input.executionId, input.result.call_id);
8313
+ const existing = yield* selectResultByKey(tenantId, input.executionId, input.result.call_id).pipe(Effect37.mapError(toRepositoryError17));
8309
8314
  if (existing[0] !== undefined) {
8310
8315
  return yield* DuplicateToolResult.make({ call_id: input.result.call_id });
8311
8316
  }
8312
8317
  yield* insertResultStatement(tenantId, input).pipe(Effect37.mapError(toRepositoryError17));
8313
8318
  if (call.activeAttemptId !== undefined) {
8314
- const attempt = yield* loadAttempt(tenantId, input.result.call_id, call.activeAttemptId);
8319
+ const attempt = yield* loadAttempt(tenantId, input.executionId, input.result.call_id, call.activeAttemptId);
8315
8320
  if (attempt?.state === "running") {
8316
- yield* completeAttempt(tenantId, input.result.call_id, call.activeAttemptId, input.result.error === undefined ? "completed" : "failed", input.createdAt, input.result.error);
8321
+ yield* completeAttempt(tenantId, input.executionId, input.result.call_id, call.activeAttemptId, input.result.error === undefined ? "completed" : "failed", input.createdAt, input.result.error);
8317
8322
  }
8318
8323
  }
8319
8324
  yield* sql`
@@ -8321,18 +8326,18 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
8321
8326
  SET state = ${input.result.error === undefined ? "completed" : "failed"},
8322
8327
  claim_owner = NULL, claimed_at = NULL, claim_expires_at = NULL,
8323
8328
  updated_at = ${ts(input.createdAt)}
8324
- WHERE tenant_id = ${tenantId} AND id = ${input.result.call_id}
8329
+ WHERE tenant_id = ${tenantId} AND execution_id = ${input.executionId} AND id = ${input.result.call_id}
8325
8330
  `.pipe(Effect37.mapError(toRepositoryError17));
8326
- const rows = yield* selectResultByKey(tenantId, input.result.call_id).pipe(Effect37.mapError(toRepositoryError17));
8331
+ const rows = yield* selectResultByKey(tenantId, input.executionId, input.result.call_id).pipe(Effect37.mapError(toRepositoryError17));
8327
8332
  if (rows[0] === undefined) {
8328
8333
  return yield* ToolCallRepositoryError.make({ message: "Tool result insert returned no row" });
8329
8334
  }
8330
8335
  return toResultRecord(yield* decodeResultRow(rows[0]));
8331
8336
  }));
8332
8337
  });
8333
- const getResult = Effect37.fn("ToolCallRepository.getResult")(function* (callId) {
8338
+ const getResult = Effect37.fn("ToolCallRepository.getResult")(function* (executionId, callId) {
8334
8339
  const tenantId = yield* current();
8335
- const rows = yield* selectResultByKey(tenantId, callId).pipe(Effect37.mapError(toRepositoryError17));
8340
+ const rows = yield* selectResultByKey(tenantId, executionId, callId).pipe(Effect37.mapError(toRepositoryError17));
8336
8341
  return rows[0] === undefined ? undefined : toResultRecord(yield* decodeResultRow(rows[0]));
8337
8342
  });
8338
8343
  return Service38.of({
@@ -8357,7 +8362,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8357
8362
  const callTenants = new Map;
8358
8363
  const results = new Map;
8359
8364
  const attempts = new Map;
8360
- const key3 = (tenantId, callId) => exports_shared_schema.canonicalString([tenantId, callId]);
8365
+ const key3 = (tenantId, executionId, callId) => exports_shared_schema.canonicalString([tenantId, executionId, callId]);
8361
8366
  const same = (left, right) => exports_shared_schema.canonicalEquals(left, right);
8362
8367
  const callRecord = (tenantId, input, definition, placement = { kind: "local" }) => ({
8363
8368
  executionId: input.executionId,
@@ -8370,13 +8375,13 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8370
8375
  createdAt: input.createdAt,
8371
8376
  updatedAt: input.createdAt
8372
8377
  });
8373
- const attemptsFor = (tenantId, callId) => attempts.get(key3(tenantId, callId)) ?? [];
8374
- const replaceAttempt = (tenantId, attempt) => {
8375
- const callAttempts = attemptsFor(tenantId, attempt.callId);
8376
- attempts.set(key3(tenantId, attempt.callId), callAttempts.map((existing) => existing.id === attempt.id ? attempt : existing));
8378
+ const attemptsFor = (tenantId, executionId, callId) => attempts.get(key3(tenantId, executionId, callId)) ?? [];
8379
+ const replaceAttempt = (tenantId, executionId, attempt) => {
8380
+ const callAttempts = attemptsFor(tenantId, executionId, attempt.callId);
8381
+ attempts.set(key3(tenantId, executionId, attempt.callId), callAttempts.map((existing) => existing.id === attempt.id ? attempt : existing));
8377
8382
  };
8378
- const appendAttempt = (tenantId, callId, createdAt, options = {}) => {
8379
- const callAttempts = attemptsFor(tenantId, callId);
8383
+ const appendAttempt = (tenantId, executionId, callId, createdAt, options = {}) => {
8384
+ const callAttempts = attemptsFor(tenantId, executionId, callId);
8380
8385
  const attemptNumber = callAttempts.length + 1;
8381
8386
  const attempt = {
8382
8387
  id: toolAttemptId(attemptNumber),
@@ -8387,18 +8392,18 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8387
8392
  ...options.claimExpiresAt === undefined ? {} : { claimExpiresAt: options.claimExpiresAt },
8388
8393
  createdAt
8389
8394
  };
8390
- attempts.set(key3(tenantId, callId), [...callAttempts, attempt]);
8395
+ attempts.set(key3(tenantId, executionId, callId), [...callAttempts, attempt]);
8391
8396
  return attempt;
8392
8397
  };
8393
- const requireCall = (tenantId, callId) => {
8394
- const record2 = calls.get(key3(tenantId, callId));
8398
+ const requireCall = (tenantId, executionId, callId) => {
8399
+ const record2 = calls.get(key3(tenantId, executionId, callId));
8395
8400
  return record2 === undefined ? Effect37.fail(ToolCallNotFound.make({ id: callId })) : Effect37.succeed(record2);
8396
8401
  };
8397
8402
  const transitionRejected = (id, message) => Effect37.fail(ToolCallTransitionRejected.make({ id, message }));
8398
8403
  return Service38.of({
8399
8404
  ensureCall: Effect37.fn("ToolCallRepository.memory.ensureCall")(function* (input) {
8400
8405
  const tenantId = yield* current();
8401
- const storageKey = key3(tenantId, input.call.id);
8406
+ const storageKey = key3(tenantId, input.executionId, input.call.id);
8402
8407
  const existing = calls.get(storageKey);
8403
8408
  if (existing !== undefined) {
8404
8409
  if (existing.executionId !== input.executionId || !sameCallIdentity(existing.call, input.call) || !same(existing.definition, input.definition) || !same(existing.placement, input.placement)) {
@@ -8413,7 +8418,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8413
8418
  }),
8414
8419
  recordCall: Effect37.fn("ToolCallRepository.memory.recordCall")(function* (input) {
8415
8420
  const tenantId = yield* current();
8416
- const storageKey = key3(tenantId, input.call.id);
8421
+ const storageKey = key3(tenantId, input.executionId, input.call.id);
8417
8422
  if (calls.has(storageKey))
8418
8423
  return yield* DuplicateToolCall.make({ id: input.call.id });
8419
8424
  const record2 = callRecord(tenantId, input);
@@ -8421,9 +8426,9 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8421
8426
  callTenants.set(storageKey, tenantId);
8422
8427
  return record2;
8423
8428
  }),
8424
- getCall: Effect37.fn("ToolCallRepository.memory.getCall")(function* (id) {
8429
+ getCall: Effect37.fn("ToolCallRepository.memory.getCall")(function* (executionId, id) {
8425
8430
  const tenantId = yield* current();
8426
- return calls.get(key3(tenantId, id));
8431
+ return calls.get(key3(tenantId, executionId, id));
8427
8432
  }),
8428
8433
  listCalls: Effect37.fn("ToolCallRepository.memory.listCalls")(function* (executionId) {
8429
8434
  const tenantId = yield* current();
@@ -8431,7 +8436,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8431
8436
  }),
8432
8437
  recordResult: Effect37.fn("ToolCallRepository.memory.recordResult")(function* (input) {
8433
8438
  const tenantId = yield* current();
8434
- const storageKey = key3(tenantId, input.result.call_id);
8439
+ const storageKey = key3(tenantId, input.executionId, input.result.call_id);
8435
8440
  const call = calls.get(storageKey);
8436
8441
  if (call === undefined)
8437
8442
  return yield* ToolCallNotFound.make({ id: input.result.call_id });
@@ -8439,9 +8444,9 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8439
8444
  return yield* DuplicateToolResult.make({ call_id: input.result.call_id });
8440
8445
  }
8441
8446
  if (call.activeAttemptId !== undefined) {
8442
- const active = attemptsFor(tenantId, input.result.call_id).find((attempt) => attempt.id === call.activeAttemptId);
8447
+ const active = attemptsFor(tenantId, input.executionId, input.result.call_id).find((attempt) => attempt.id === call.activeAttemptId);
8443
8448
  if (active?.state === "running") {
8444
- replaceAttempt(tenantId, {
8449
+ replaceAttempt(tenantId, input.executionId, {
8445
8450
  ...active,
8446
8451
  state: input.result.error === undefined ? "completed" : "failed",
8447
8452
  ...input.result.error === undefined ? {} : { error: input.result.error },
@@ -8458,13 +8463,13 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8458
8463
  });
8459
8464
  return record2;
8460
8465
  }),
8461
- getResult: Effect37.fn("ToolCallRepository.memory.getResult")(function* (callId) {
8466
+ getResult: Effect37.fn("ToolCallRepository.memory.getResult")(function* (executionId, callId) {
8462
8467
  const tenantId = yield* current();
8463
- return results.get(key3(tenantId, callId));
8468
+ return results.get(key3(tenantId, executionId, callId));
8464
8469
  }),
8465
8470
  prepareExternalWait: Effect37.fn("ToolCallRepository.memory.prepareExternalWait")(function* (input) {
8466
8471
  const tenantId = yield* current();
8467
- const call = yield* requireCall(tenantId, input.callId);
8472
+ const call = yield* requireCall(tenantId, input.executionId, input.callId);
8468
8473
  if (call.placement.kind !== "client" && call.placement.kind !== "remote") {
8469
8474
  return yield* transitionRejected(input.callId, "Tool placement is not external");
8470
8475
  }
@@ -8479,12 +8484,12 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8479
8484
  availableAt: input.availableAt,
8480
8485
  updatedAt: input.updatedAt
8481
8486
  };
8482
- calls.set(key3(tenantId, input.callId), updated);
8487
+ calls.set(key3(tenantId, input.executionId, input.callId), updated);
8483
8488
  return updated;
8484
8489
  }),
8485
8490
  beginAttempt: Effect37.fn("ToolCallRepository.memory.beginAttempt")(function* (input) {
8486
8491
  const tenantId = yield* current();
8487
- const call = yield* requireCall(tenantId, input.callId);
8492
+ const call = yield* requireCall(tenantId, input.executionId, input.callId);
8488
8493
  if (call.placement.kind !== "local" && call.placement.kind !== "mcp") {
8489
8494
  return yield* transitionRejected(input.callId, "Tool placement is not immediate");
8490
8495
  }
@@ -8492,13 +8497,13 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8492
8497
  return yield* transitionRejected(input.callId, `Call is ${call.state}`);
8493
8498
  }
8494
8499
  if (call.activeAttemptId !== undefined) {
8495
- const active = attemptsFor(tenantId, input.callId).find((attempt2) => attempt2.id === call.activeAttemptId);
8500
+ const active = attemptsFor(tenantId, input.executionId, input.callId).find((attempt2) => attempt2.id === call.activeAttemptId);
8496
8501
  if (active?.state === "running") {
8497
- replaceAttempt(tenantId, { ...active, state: "abandoned", completedAt: input.startedAt });
8502
+ replaceAttempt(tenantId, input.executionId, { ...active, state: "abandoned", completedAt: input.startedAt });
8498
8503
  }
8499
8504
  }
8500
- const attempt = appendAttempt(tenantId, input.callId, input.startedAt);
8501
- calls.set(key3(tenantId, input.callId), {
8505
+ const attempt = appendAttempt(tenantId, input.executionId, input.callId, input.startedAt);
8506
+ calls.set(key3(tenantId, input.executionId, input.callId), {
8502
8507
  ...call,
8503
8508
  state: "running",
8504
8509
  activeAttemptId: attempt.id,
@@ -8508,7 +8513,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8508
8513
  }),
8509
8514
  acceptClientOutcome: Effect37.fn("ToolCallRepository.memory.acceptClientOutcome")(function* (input) {
8510
8515
  const tenantId = yield* current();
8511
- const call = yield* requireCall(tenantId, input.callId);
8516
+ const call = yield* requireCall(tenantId, input.executionId, input.callId);
8512
8517
  if (call.executionId !== input.executionId || call.placement.kind !== "client") {
8513
8518
  return yield* transitionRejected(input.callId, "Client outcome does not match the call");
8514
8519
  }
@@ -8516,21 +8521,21 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8516
8521
  if (!same(call.externalOutcome, input.outcome)) {
8517
8522
  return yield* ToolOutcomeConflict.make({ id: input.callId });
8518
8523
  }
8519
- const attempt2 = attemptsFor(tenantId, input.callId).find((item) => item.id === call.activeAttemptId);
8524
+ const attempt2 = attemptsFor(tenantId, input.executionId, input.callId).find((item) => item.id === call.activeAttemptId);
8520
8525
  if (attempt2 === undefined)
8521
8526
  return yield* transitionRejected(input.callId, "Accepted attempt is missing");
8522
8527
  return { call, attempt: attempt2, duplicate: true };
8523
8528
  }
8524
8529
  if (call.state !== "waiting")
8525
8530
  return yield* transitionRejected(input.callId, `Call is ${call.state}`);
8526
- const running = appendAttempt(tenantId, input.callId, input.submittedAt);
8531
+ const running = appendAttempt(tenantId, input.executionId, input.callId, input.submittedAt);
8527
8532
  const attempt = {
8528
8533
  ...running,
8529
8534
  state: input.outcome.kind === "success" ? "completed" : "failed",
8530
8535
  ...input.outcome.kind === "failure" ? { error: input.outcome.message } : {},
8531
8536
  completedAt: input.submittedAt
8532
8537
  };
8533
- replaceAttempt(tenantId, attempt);
8538
+ replaceAttempt(tenantId, input.executionId, attempt);
8534
8539
  const updated = {
8535
8540
  ...call,
8536
8541
  state: "submitted",
@@ -8539,7 +8544,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8539
8544
  externalOutcomeAt: input.submittedAt,
8540
8545
  updatedAt: input.submittedAt
8541
8546
  };
8542
- calls.set(key3(tenantId, input.callId), updated);
8547
+ calls.set(key3(tenantId, input.executionId, input.callId), updated);
8543
8548
  return { call: updated, attempt, duplicate: false };
8544
8549
  }),
8545
8550
  claimRemote: Effect37.fn("ToolCallRepository.memory.claimRemote")(function* (input) {
@@ -8551,9 +8556,9 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8551
8556
  if (callTenants.get(storageKey) !== tenantId || call.placement.kind !== "remote" || call.state !== "running" || call.claimExpiresAt === undefined || call.claimExpiresAt > input.now) {
8552
8557
  continue;
8553
8558
  }
8554
- const active = attemptsFor(tenantId, call.call.id).find((attempt2) => attempt2.id === call.activeAttemptId);
8559
+ const active = attemptsFor(tenantId, call.executionId, call.call.id).find((attempt2) => attempt2.id === call.activeAttemptId);
8555
8560
  if (active?.state === "running") {
8556
- replaceAttempt(tenantId, { ...active, state: "expired", completedAt: input.now });
8561
+ replaceAttempt(tenantId, call.executionId, { ...active, state: "expired", completedAt: input.now });
8557
8562
  }
8558
8563
  calls.set(storageKey, {
8559
8564
  ...call,
@@ -8571,7 +8576,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8571
8576
  if (candidate.definition === undefined) {
8572
8577
  return yield* transitionRejected(candidate.call.id, "Remote call definition snapshot is missing");
8573
8578
  }
8574
- const attempt = appendAttempt(tenantId, candidate.call.id, input.now, {
8579
+ const attempt = appendAttempt(tenantId, candidate.executionId, candidate.call.id, input.now, {
8575
8580
  workerId: input.workerId,
8576
8581
  claimExpiresAt: input.claimExpiresAt
8577
8582
  });
@@ -8585,7 +8590,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8585
8590
  claimExpiresAt: input.claimExpiresAt,
8586
8591
  updatedAt: input.now
8587
8592
  };
8588
- calls.set(key3(tenantId, candidate.call.id), updated);
8593
+ calls.set(key3(tenantId, candidate.executionId, candidate.call.id), updated);
8589
8594
  return {
8590
8595
  call: updated,
8591
8596
  attempt,
@@ -8597,14 +8602,14 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8597
8602
  }),
8598
8603
  releaseRemote: Effect37.fn("ToolCallRepository.memory.releaseRemote")(function* (input) {
8599
8604
  const tenantId = yield* current();
8600
- const call = yield* requireCall(tenantId, input.callId);
8605
+ const call = yield* requireCall(tenantId, input.executionId, input.callId);
8601
8606
  const valid = call.placement.kind === "remote" && call.state === "running" && call.activeAttemptId === input.attemptId && call.claimOwner === input.workerId && call.claimExpiresAt !== undefined && call.claimExpiresAt > input.releasedAt;
8602
8607
  if (!valid)
8603
8608
  return yield* ToolClaimRejected.make({ message: "Remote claim is not active" });
8604
- const attempt = attemptsFor(tenantId, input.callId).find((item) => item.id === input.attemptId);
8609
+ const attempt = attemptsFor(tenantId, input.executionId, input.callId).find((item) => item.id === input.attemptId);
8605
8610
  if (attempt === undefined)
8606
8611
  return yield* transitionRejected(input.callId, "Remote attempt is missing");
8607
- replaceAttempt(tenantId, {
8612
+ replaceAttempt(tenantId, input.executionId, {
8608
8613
  ...attempt,
8609
8614
  state: "released",
8610
8615
  ...input.error === undefined ? {} : { error: input.error },
@@ -8620,12 +8625,12 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8620
8625
  claimExpiresAt: undefined,
8621
8626
  updatedAt: input.releasedAt
8622
8627
  };
8623
- calls.set(key3(tenantId, input.callId), updated);
8628
+ calls.set(key3(tenantId, input.executionId, input.callId), updated);
8624
8629
  return updated;
8625
8630
  }),
8626
8631
  acceptRemoteOutcome: Effect37.fn("ToolCallRepository.memory.acceptRemoteOutcome")(function* (input) {
8627
8632
  const tenantId = yield* current();
8628
- const call = yield* requireCall(tenantId, input.callId);
8633
+ const call = yield* requireCall(tenantId, input.executionId, input.callId);
8629
8634
  if (call.externalOutcome !== undefined) {
8630
8635
  if (!same(call.externalOutcome, input.outcome)) {
8631
8636
  return yield* ToolOutcomeConflict.make({ id: input.callId });
@@ -8633,7 +8638,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8633
8638
  if (call.activeAttemptId !== input.attemptId) {
8634
8639
  return yield* ToolClaimRejected.make({ message: "Remote attempt was not accepted" });
8635
8640
  }
8636
- const attempt2 = attemptsFor(tenantId, input.callId).find((item) => item.id === input.attemptId);
8641
+ const attempt2 = attemptsFor(tenantId, input.executionId, input.callId).find((item) => item.id === input.attemptId);
8637
8642
  if (attempt2 === undefined || attempt2.callId !== input.callId || attempt2.workerId !== input.workerId) {
8638
8643
  return yield* ToolClaimRejected.make({ message: "Remote attempt was not accepted" });
8639
8644
  }
@@ -8642,7 +8647,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8642
8647
  const valid = call.placement.kind === "remote" && call.state === "running" && call.activeAttemptId === input.attemptId && call.claimOwner === input.workerId && call.claimExpiresAt !== undefined && call.claimExpiresAt > input.submittedAt;
8643
8648
  if (!valid)
8644
8649
  return yield* ToolClaimRejected.make({ message: "Remote claim is not active" });
8645
- const running = attemptsFor(tenantId, input.callId).find((item) => item.id === input.attemptId);
8650
+ const running = attemptsFor(tenantId, input.executionId, input.callId).find((item) => item.id === input.attemptId);
8646
8651
  if (running === undefined)
8647
8652
  return yield* transitionRejected(input.callId, "Remote attempt is missing");
8648
8653
  const attempt = {
@@ -8651,7 +8656,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8651
8656
  ...input.outcome.kind === "failure" ? { error: input.outcome.message } : {},
8652
8657
  completedAt: input.submittedAt
8653
8658
  };
8654
- replaceAttempt(tenantId, attempt);
8659
+ replaceAttempt(tenantId, input.executionId, attempt);
8655
8660
  const updated = {
8656
8661
  ...call,
8657
8662
  state: "submitted",
@@ -8662,12 +8667,12 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8662
8667
  claimExpiresAt: undefined,
8663
8668
  updatedAt: input.submittedAt
8664
8669
  };
8665
- calls.set(key3(tenantId, input.callId), updated);
8670
+ calls.set(key3(tenantId, input.executionId, input.callId), updated);
8666
8671
  return { call: updated, attempt, duplicate: false };
8667
8672
  }),
8668
- listAttempts: Effect37.fn("ToolCallRepository.memory.listAttempts")(function* (callId) {
8673
+ listAttempts: Effect37.fn("ToolCallRepository.memory.listAttempts")(function* (executionId, callId) {
8669
8674
  const tenantId = yield* current();
8670
- return attemptsFor(tenantId, callId);
8675
+ return attemptsFor(tenantId, executionId, callId);
8671
8676
  }),
8672
8677
  failOpenForExecution: Effect37.fn("ToolCallRepository.memory.failOpenForExecution")(function* (input) {
8673
8678
  const tenantId = yield* current();
@@ -8677,9 +8682,9 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
8677
8682
  continue;
8678
8683
  }
8679
8684
  if (call.activeAttemptId !== undefined) {
8680
- const active = attemptsFor(tenantId, call.call.id).find((attempt) => attempt.id === call.activeAttemptId);
8685
+ const active = attemptsFor(tenantId, input.executionId, call.call.id).find((attempt) => attempt.id === call.activeAttemptId);
8681
8686
  if (active?.state === "running") {
8682
- replaceAttempt(tenantId, {
8687
+ replaceAttempt(tenantId, input.executionId, {
8683
8688
  ...active,
8684
8689
  state: "failed",
8685
8690
  error: input.message,
@@ -8723,9 +8728,9 @@ var recordCall = Effect37.fn("ToolCallRepository.recordCall.call")(function* (in
8723
8728
  const repository = yield* Service38;
8724
8729
  return yield* repository.recordCall(input);
8725
8730
  });
8726
- var getCall = Effect37.fn("ToolCallRepository.getCall.call")(function* (id) {
8731
+ var getCall = Effect37.fn("ToolCallRepository.getCall.call")(function* (executionId, id) {
8727
8732
  const repository = yield* Service38;
8728
- return yield* repository.getCall(id);
8733
+ return yield* repository.getCall(executionId, id);
8729
8734
  });
8730
8735
  var listCalls = Effect37.fn("ToolCallRepository.listCalls.call")(function* (executionId) {
8731
8736
  const repository = yield* Service38;
@@ -8735,9 +8740,9 @@ var recordResult = Effect37.fn("ToolCallRepository.recordResult.call")(function*
8735
8740
  const repository = yield* Service38;
8736
8741
  return yield* repository.recordResult(input);
8737
8742
  });
8738
- var getResult = Effect37.fn("ToolCallRepository.getResult.call")(function* (callId) {
8743
+ var getResult = Effect37.fn("ToolCallRepository.getResult.call")(function* (executionId, callId) {
8739
8744
  const repository = yield* Service38;
8740
- return yield* repository.getResult(callId);
8745
+ return yield* repository.getResult(executionId, callId);
8741
8746
  });
8742
8747
  var ensureCall = Effect37.fn("ToolCallRepository.ensureCall.call")(function* (input) {
8743
8748
  const repository = yield* Service38;
@@ -8767,9 +8772,9 @@ var acceptRemoteOutcome = Effect37.fn("ToolCallRepository.acceptRemoteOutcome.ca
8767
8772
  const repository = yield* Service38;
8768
8773
  return yield* repository.acceptRemoteOutcome(input);
8769
8774
  });
8770
- var listAttempts = Effect37.fn("ToolCallRepository.listAttempts.call")(function* (callId) {
8775
+ var listAttempts = Effect37.fn("ToolCallRepository.listAttempts.call")(function* (executionId, callId) {
8771
8776
  const repository = yield* Service38;
8772
- return yield* repository.listAttempts(callId);
8777
+ return yield* repository.listAttempts(executionId, callId);
8773
8778
  });
8774
8779
  var failOpenForExecution = Effect37.fn("ToolCallRepository.failOpenForExecution.call")(function* (input) {
8775
8780
  const repository = yield* Service38;
@@ -10272,7 +10277,7 @@ var recordRequested = (repository, eventLog, input, tool) => repository.ensureCa
10272
10277
  createdAt: input.createdAt
10273
10278
  }).pipe(Effect43.mapError(mapRepositoryError3), Effect43.tap((call) => ensureToolEvent(eventLog, requestedEvent({ ...input, createdAt: call.createdAt }))));
10274
10279
  var repairResultEvent = (eventLog, input, record2) => eventLog.maxSequence(input.executionId).pipe(Effect43.mapError(mapEventLogError2), Effect43.flatMap((max) => ensureToolEvent(eventLog, resultEvent({ ...input, createdAt: record2.createdAt - 1 }, record2.result, (max ?? input.eventSequence) + 1))));
10275
- var recordReceived = (repository, eventLog, input, result) => repository.recordResult({ result, createdAt: input.createdAt + 1 }).pipe(Effect43.catchTag("DuplicateToolResult", () => repository.getResult(result.call_id).pipe(Effect43.mapError(mapRepositoryError3), Effect43.flatMap((existing) => existing === undefined ? Effect43.fail(ToolRuntimeError.make({ message: "DuplicateToolResult" })) : Effect43.succeed(existing)))), Effect43.mapError(preserveRecordResultError), Effect43.flatMap((record2) => eventLog.maxSequence(input.executionId).pipe(Effect43.mapError(mapEventLogError2), Effect43.flatMap((max) => appendIdempotentTo(eventLog, resultEvent(input, record2.result, (max ?? input.eventSequence) + 1)).pipe(Effect43.mapError(mapEventLogError2))), Effect43.as(record2.result))));
10280
+ var recordReceived = (repository, eventLog, input, result) => repository.recordResult({ executionId: input.executionId, result, createdAt: input.createdAt + 1 }).pipe(Effect43.catchTag("DuplicateToolResult", () => repository.getResult(input.executionId, result.call_id).pipe(Effect43.mapError(mapRepositoryError3), Effect43.flatMap((existing) => existing === undefined ? Effect43.fail(ToolRuntimeError.make({ message: "DuplicateToolResult" })) : Effect43.succeed(existing)))), Effect43.mapError(preserveRecordResultError), Effect43.flatMap((record2) => eventLog.maxSequence(input.executionId).pipe(Effect43.mapError(mapEventLogError2), Effect43.flatMap((max) => appendIdempotentTo(eventLog, resultEvent(input, record2.result, (max ?? input.eventSequence) + 1)).pipe(Effect43.mapError(mapEventLogError2))), Effect43.as(record2.result))));
10276
10281
  var nonEmptyName = (name) => Schema40.decodeUnknownSync(exports_shared_schema.NonEmptyString)(name);
10277
10282
  var needsApprovalFromEffectTool = (tool) => tool.needsApproval === undefined ? undefined : typeof tool.needsApproval === "boolean" ? tool.needsApproval : true;
10278
10283
  var definitionFromEffectTool = (modelTool, options) => ({
@@ -10390,6 +10395,7 @@ var runExternalTool = (repository, waits, call, input) => Effect43.gen(function*
10390
10395
  }).pipe(Effect43.mapError(mapWaitServiceError));
10391
10396
  }
10392
10397
  const waitingCall = call.state === "requested" ? yield* repository.prepareExternalWait({
10398
+ executionId: input.executionId,
10393
10399
  callId: input.call.id,
10394
10400
  waitId,
10395
10401
  availableAt: input.createdAt,
@@ -10429,7 +10435,7 @@ var makeService = (initialTools) => Effect43.gen(function* () {
10429
10435
  yield* ensureAllowed(registeredTool, input);
10430
10436
  yield* validateInput(registeredTool, input);
10431
10437
  const call = yield* recordRequested(repository, eventLog, input, registeredTool);
10432
- const existingResult = yield* repository.getResult(input.call.id).pipe(Effect43.mapError(mapRepositoryError3));
10438
+ const existingResult = yield* repository.getResult(input.executionId, input.call.id).pipe(Effect43.mapError(mapRepositoryError3));
10433
10439
  if (existingResult !== undefined) {
10434
10440
  yield* repairResultEvent(eventLog, input, existingResult);
10435
10441
  return existingResult.result;
@@ -10451,7 +10457,11 @@ var makeService = (initialTools) => Effect43.gen(function* () {
10451
10457
  }
10452
10458
  }
10453
10459
  }
10454
- const rawResult = call.placement.kind === "client" || call.placement.kind === "remote" ? yield* runExternalTool(repository, waits, call, effectiveInput) : yield* repository.beginAttempt({ callId: input.call.id, startedAt: effectiveInput.createdAt }).pipe(Effect43.mapError(mapRepositoryError3), Effect43.flatMap(() => finalToolResult(registeredTool, effectiveInput, call.idempotencyKey)), Effect43.catchTag("ToolExecutionFailed", (error5) => Effect43.succeed(placementFailureResult(input, error5.message))));
10460
+ const rawResult = call.placement.kind === "client" || call.placement.kind === "remote" ? yield* runExternalTool(repository, waits, call, effectiveInput) : yield* repository.beginAttempt({
10461
+ executionId: input.executionId,
10462
+ callId: input.call.id,
10463
+ startedAt: effectiveInput.createdAt
10464
+ }).pipe(Effect43.mapError(mapRepositoryError3), Effect43.flatMap(() => finalToolResult(registeredTool, effectiveInput, call.idempotencyKey)), Effect43.catchTag("ToolExecutionFailed", (error5) => Effect43.succeed(placementFailureResult(input, error5.message))));
10455
10465
  const result = input.transformResult === undefined || rawResult.error !== undefined ? rawResult : yield* input.transformResult(rawResult);
10456
10466
  const received = yield* recordReceived(repository, eventLog, effectiveInput, result);
10457
10467
  yield* recordToolCall(input.call.name, result.error === undefined ? "success" : "failure");
@@ -17941,7 +17951,7 @@ var layerFromRuntime3 = Layer80.effect(Service, Effect90.gen(function* () {
17941
17951
  return yield* ExecutionNotFound.make({ execution_id: executionId });
17942
17952
  const openWaits = yield* envelopeReady.listAllWaits({ executionId, state: "open" }).pipe(Effect90.mapError(toClientError));
17943
17953
  const calls = yield* toolCalls2.listCalls(executionId).pipe(Effect90.mapError(toClientError));
17944
- const pendingChunks = yield* Effect90.forEach(calls, (call) => toolCalls2.getResult(call.call.id).pipe(Effect90.mapError(toClientError), Effect90.map((result) => result === undefined ? [toToolCallSummary(call)] : [])));
17954
+ const pendingChunks = yield* Effect90.forEach(calls, (call) => toolCalls2.getResult(call.executionId, call.call.id).pipe(Effect90.mapError(toClientError), Effect90.map((result) => result === undefined ? [toToolCallSummary(call)] : [])));
17945
17955
  const children = yield* childExecutions.listByExecution(executionId).pipe(Effect90.mapError(toClientError));
17946
17956
  const maxSequence3 = yield* eventLog.maxSequence(executionId).pipe(Effect90.mapError(toClientError));
17947
17957
  const lastEvent = maxSequence3 === undefined ? undefined : yield* eventLog.findBySequence({ executionId, sequence: maxSequence3 }).pipe(Effect90.mapError(toClientError), Effect90.map(Option23.getOrUndefined));
@@ -18407,13 +18417,13 @@ var layerFromRuntime3 = Layer80.effect(Service, Effect90.gen(function* () {
18407
18417
  state: "open",
18408
18418
  ...input.execution_id === undefined ? {} : { executionId: input.execution_id }
18409
18419
  }).pipe(Effect90.mapError(toClientError));
18410
- const records = yield* Effect90.forEach(openWaits.filter((wait) => wait.metadata.kind === "tool-placement"), (wait) => toolCalls2.getCall(exports_ids_schema.ToolCallId.make(String(wait.metadata.tool_call_id ?? ""))).pipe(Effect90.mapError(toClientError), Effect90.map((call) => call?.placement.kind === "client" && call.state === "waiting" ? toPendingToolCall(call) : undefined)));
18420
+ const records = yield* Effect90.forEach(openWaits.filter((wait) => wait.metadata.kind === "tool-placement"), (wait) => toolCalls2.getCall(wait.executionId, exports_ids_schema.ToolCallId.make(String(wait.metadata.tool_call_id ?? ""))).pipe(Effect90.mapError(toClientError), Effect90.map((call) => call?.placement.kind === "client" && call.state === "waiting" ? toPendingToolCall(call) : undefined)));
18411
18421
  const sorted = records.filter((record2) => record2 !== undefined).toSorted((left, right) => left.requested_at - right.requested_at || left.call.id.localeCompare(right.call.id));
18412
18422
  return { tool_calls: input.limit === undefined ? sorted : sorted.slice(0, input.limit) };
18413
18423
  }),
18414
18424
  fulfillToolCall: Effect90.fn("Client.runtime.fulfillToolCall")(function* (input) {
18415
18425
  const coordinated = yield* coordinateToolTransition(Effect90.gen(function* () {
18416
- const call = yield* toolCalls2.getCall(input.tool_call_id).pipe(Effect90.mapError(toClientError));
18426
+ const call = yield* toolCalls2.getCall(input.execution_id, input.tool_call_id).pipe(Effect90.mapError(toClientError));
18417
18427
  if (call === undefined || call.executionId !== input.execution_id || call.placement.kind !== "client") {
18418
18428
  return yield* ClientError.make({ message: `Client tool call not found: ${input.tool_call_id}` });
18419
18429
  }
@@ -18440,7 +18450,7 @@ var layerFromRuntime3 = Layer80.effect(Service, Effect90.gen(function* () {
18440
18450
  }),
18441
18451
  completeToolWork: Effect90.fn("Client.runtime.completeToolWork")(function* (input) {
18442
18452
  const coordinated = yield* coordinateToolTransition(Effect90.gen(function* () {
18443
- const call = yield* toolCalls2.getCall(input.tool_call_id).pipe(Effect90.mapError(toClientError));
18453
+ const call = yield* toolCalls2.getCall(input.execution_id, input.tool_call_id).pipe(Effect90.mapError(toClientError));
18444
18454
  const active = call !== undefined && call.placement.kind === "remote" && call.state === "running" && call.activeAttemptId === input.attempt_id && call.claimOwner === input.worker_id && call.claimExpiresAt !== undefined && call.claimExpiresAt > input.completed_at;
18445
18455
  const acceptedRetry = call !== undefined && call.placement.kind === "remote" && call.state === "submitted" && call.activeAttemptId === input.attempt_id && call.externalOutcome !== undefined;
18446
18456
  if (call === undefined || !active && !acceptedRetry) {
@@ -18448,6 +18458,7 @@ var layerFromRuntime3 = Layer80.effect(Service, Effect90.gen(function* () {
18448
18458
  }
18449
18459
  const wait = yield* resolveToolOutcomeWait(waits, eventLog, call, input.outcome, input.completed_at);
18450
18460
  const accepted2 = yield* toolCalls2.acceptRemoteOutcome({
18461
+ executionId: input.execution_id,
18451
18462
  callId: input.tool_call_id,
18452
18463
  attemptId: input.attempt_id,
18453
18464
  workerId: input.worker_id,
@@ -18461,6 +18472,7 @@ var layerFromRuntime3 = Layer80.effect(Service, Effect90.gen(function* () {
18461
18472
  }),
18462
18473
  releaseToolWork: Effect90.fn("Client.runtime.releaseToolWork")(function* (input) {
18463
18474
  const call = yield* coordinateToolTransition(toolCalls2.releaseRemote({
18475
+ executionId: input.execution_id,
18464
18476
  callId: input.tool_call_id,
18465
18477
  attemptId: input.attempt_id,
18466
18478
  workerId: input.worker_id,
@@ -18475,7 +18487,7 @@ var layerFromRuntime3 = Layer80.effect(Service, Effect90.gen(function* () {
18475
18487
  };
18476
18488
  }),
18477
18489
  listToolAttempts: Effect90.fn("Client.runtime.listToolAttempts")(function* (input) {
18478
- const attempts = yield* toolCalls2.listAttempts(input.tool_call_id).pipe(Effect90.mapError(toClientError));
18490
+ const attempts = yield* toolCalls2.listAttempts(input.execution_id, input.tool_call_id).pipe(Effect90.mapError(toClientError));
18479
18491
  return { attempts: attempts.map(toToolAttempt) };
18480
18492
  }),
18481
18493
  submitInboundEnvelope: Effect90.fn("Client.runtime.submitInboundEnvelope")(function* (input) {