@opengeni/db 4.0.0-canary.1 → 4.0.0-canary.2
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/canonical-human-identities.js +3 -3
- package/dist/{chunk-2HGYCAXN.js → chunk-B5Y3TCSP.js} +2 -2
- package/dist/{chunk-A5RFBEZR.js → chunk-CQF6G4IF.js} +3 -3
- package/dist/{chunk-FVZINOBB.js → chunk-DUB3LUVM.js} +21 -9
- package/dist/chunk-DUB3LUVM.js.map +1 -0
- package/dist/{chunk-YVDQDD33.js → chunk-L2QFSPFP.js} +2 -2
- package/dist/{chunk-47LKLIIK.js → chunk-NPKBYGAK.js} +2 -2
- package/dist/{chunk-XAKQCOF3.js → chunk-PWJJKCTF.js} +11 -1
- package/dist/chunk-PWJJKCTF.js.map +1 -0
- package/dist/{chunk-I6YPQMAL.js → chunk-VU2IK37Y.js} +2 -2
- package/dist/{chunk-ZQ32COTC.js → chunk-XIYAXH47.js} +2 -2
- package/dist/editable-artifact-durable-export.js +2 -2
- package/dist/editable-artifacts.js +3 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.js +191 -16
- package/dist/index.js.map +1 -1
- package/dist/managed-auth-session-sets.js +3 -3
- package/dist/schema.d.ts +51 -0
- package/dist/schema.js +1 -1
- package/dist/session-background-commands.d.ts +6 -0
- package/dist/session-background-commands.js +4 -4
- package/dist/session-command-output.js +4 -4
- package/dist/session-event-slices.js +2 -2
- package/dist/session-tenancy.js +3 -3
- package/dist/video-generation.js +3 -3
- package/drizzle/0419_background_command_launch_authority.sql +56 -0
- package/package.json +6 -6
- package/src/index.ts +264 -10
- package/src/schema.ts +10 -0
- package/src/session-background-commands.ts +33 -0
- package/dist/chunk-FVZINOBB.js.map +0 -1
- package/dist/chunk-XAKQCOF3.js.map +0 -1
- /package/dist/{chunk-2HGYCAXN.js.map → chunk-B5Y3TCSP.js.map} +0 -0
- /package/dist/{chunk-A5RFBEZR.js.map → chunk-CQF6G4IF.js.map} +0 -0
- /package/dist/{chunk-YVDQDD33.js.map → chunk-L2QFSPFP.js.map} +0 -0
- /package/dist/{chunk-47LKLIIK.js.map → chunk-NPKBYGAK.js.map} +0 -0
- /package/dist/{chunk-I6YPQMAL.js.map → chunk-VU2IK37Y.js.map} +0 -0
- /package/dist/{chunk-ZQ32COTC.js.map → chunk-XIYAXH47.js.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
nestedPostgresSqlState,
|
|
3
3
|
rawRows
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-XIYAXH47.js";
|
|
5
5
|
|
|
6
6
|
// src/managed-auth-session-sets.ts
|
|
7
7
|
import {
|
|
@@ -296,4 +296,4 @@ export {
|
|
|
296
296
|
reapManagedAuthIsolatedSessions,
|
|
297
297
|
reapExpiredManagedAuthSessionSets
|
|
298
298
|
};
|
|
299
|
-
//# sourceMappingURL=chunk-
|
|
299
|
+
//# sourceMappingURL=chunk-VU2IK37Y.js.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
sessions,
|
|
5
5
|
workspaceSessionActivityRevisions,
|
|
6
6
|
workspaces
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-PWJJKCTF.js";
|
|
8
8
|
|
|
9
9
|
// src/persistence-errors.ts
|
|
10
10
|
var SQLSTATE_KEYS = ["sqlState", "sqlstate", "code"];
|
|
@@ -755,4 +755,4 @@ export {
|
|
|
755
755
|
withAccountRls,
|
|
756
756
|
dbBindingFor
|
|
757
757
|
};
|
|
758
|
-
//# sourceMappingURL=chunk-
|
|
758
|
+
//# sourceMappingURL=chunk-XIYAXH47.js.map
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
PostgresEditableArtifactStore,
|
|
9
9
|
listEditableArtifactIdsForSession,
|
|
10
10
|
touchEditableArtifactSessionLink
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-L2QFSPFP.js";
|
|
12
|
+
import "./chunk-XIYAXH47.js";
|
|
13
|
+
import "./chunk-PWJJKCTF.js";
|
|
14
14
|
import "./chunk-PZ5AY32C.js";
|
|
15
15
|
export {
|
|
16
16
|
EDITABLE_ARTIFACT_INTENT_MAX_BYTES,
|
package/dist/index.d.ts
CHANGED
|
@@ -9516,6 +9516,11 @@ export type FailSessionWorkBeforeAttemptClaimInput = {
|
|
|
9516
9516
|
workflowId: string;
|
|
9517
9517
|
trigger: SessionWorkTrigger;
|
|
9518
9518
|
error: string;
|
|
9519
|
+
/** Already-classified admission facts from the failed worker activity. */
|
|
9520
|
+
admissionFailure?: {
|
|
9521
|
+
disposition: "retryable" | "permanent";
|
|
9522
|
+
code: "db_deadlock" | "db_serialization_failure" | "db_failure" | "claim_invariant";
|
|
9523
|
+
};
|
|
9519
9524
|
};
|
|
9520
9525
|
export type FailSessionWorkBeforeAttemptClaimResult = {
|
|
9521
9526
|
action: "failed";
|
|
@@ -9581,6 +9586,7 @@ export declare function settleSessionIdleWithParentOutbox(db: Database, workspac
|
|
|
9581
9586
|
action: "settled";
|
|
9582
9587
|
changed: boolean;
|
|
9583
9588
|
episodeKey: string;
|
|
9589
|
+
notifyParent: boolean;
|
|
9584
9590
|
events: SessionEvent[];
|
|
9585
9591
|
} | {
|
|
9586
9592
|
action: "stale";
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
replayAppliedSessionFork,
|
|
15
15
|
sessionTenancyProductActivated,
|
|
16
16
|
transitionSessionVisibility
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-B5Y3TCSP.js";
|
|
18
18
|
import {
|
|
19
19
|
AgentCommandAuthorityError,
|
|
20
20
|
CHILD_LIFECYCLE_DEDUPE_PREFIX,
|
|
@@ -85,7 +85,7 @@ import {
|
|
|
85
85
|
updateSessionCommandReceiptResult,
|
|
86
86
|
workspaceControlLockBudget,
|
|
87
87
|
workspaceControlRequestLockTimeoutMs
|
|
88
|
-
} from "./chunk-
|
|
88
|
+
} from "./chunk-DUB3LUVM.js";
|
|
89
89
|
import {
|
|
90
90
|
ACTIVE_VIDEO_GENERATION_STATUSES,
|
|
91
91
|
VideoGenerationCapacityError,
|
|
@@ -117,7 +117,7 @@ import {
|
|
|
117
117
|
settleVideoGenerationFailure,
|
|
118
118
|
settleVideoGenerationReady,
|
|
119
119
|
updateWorkspaceVideoGenerationPolicy
|
|
120
|
-
} from "./chunk-
|
|
120
|
+
} from "./chunk-CQF6G4IF.js";
|
|
121
121
|
import {
|
|
122
122
|
ManagedAuthActorMutationInFlightError,
|
|
123
123
|
ManagedAuthLoginSlotAlreadyExistsError,
|
|
@@ -140,7 +140,7 @@ import {
|
|
|
140
140
|
reapManagedAuthIsolatedSessions,
|
|
141
141
|
releaseManagedAuthActorMutationLease,
|
|
142
142
|
validateManagedAuthActorMutationLease
|
|
143
|
-
} from "./chunk-
|
|
143
|
+
} from "./chunk-VU2IK37Y.js";
|
|
144
144
|
import {
|
|
145
145
|
migrate,
|
|
146
146
|
runMigrations
|
|
@@ -181,7 +181,7 @@ import {
|
|
|
181
181
|
getCanonicalHumanIdentityProjection,
|
|
182
182
|
synchronizeCanonicalHumanLoginBindings,
|
|
183
183
|
validateCanonicalHumanSession
|
|
184
|
-
} from "./chunk-
|
|
184
|
+
} from "./chunk-NPKBYGAK.js";
|
|
185
185
|
import {
|
|
186
186
|
EDITABLE_ARTIFACT_INTENT_MAX_BYTES,
|
|
187
187
|
EDITABLE_ARTIFACT_KERNEL_TAIL_MAX_BYTES,
|
|
@@ -192,7 +192,7 @@ import {
|
|
|
192
192
|
PostgresEditableArtifactStore,
|
|
193
193
|
listEditableArtifactIdsForSession,
|
|
194
194
|
touchEditableArtifactSessionLink
|
|
195
|
-
} from "./chunk-
|
|
195
|
+
} from "./chunk-L2QFSPFP.js";
|
|
196
196
|
import {
|
|
197
197
|
SandboxProviderReadLockUnavailableError,
|
|
198
198
|
SessionEventPersistenceError,
|
|
@@ -228,7 +228,7 @@ import {
|
|
|
228
228
|
withWorkspaceSubjectRls,
|
|
229
229
|
withWorkspaceSubjectSessionActivityRls,
|
|
230
230
|
withWorkspaceUsageLock
|
|
231
|
-
} from "./chunk-
|
|
231
|
+
} from "./chunk-XIYAXH47.js";
|
|
232
232
|
import {
|
|
233
233
|
LOSSLESS_CONTENT_CODEC_VERSION,
|
|
234
234
|
LOSSLESS_JSON_STRING_PREFIX,
|
|
@@ -466,7 +466,7 @@ import {
|
|
|
466
466
|
xaiRotationSettings,
|
|
467
467
|
xaiSessionAccountPins,
|
|
468
468
|
xaiSubscriptionCredentials
|
|
469
|
-
} from "./chunk-
|
|
469
|
+
} from "./chunk-PWJJKCTF.js";
|
|
470
470
|
import "./chunk-PZ5AY32C.js";
|
|
471
471
|
|
|
472
472
|
// src/index.ts
|
|
@@ -64938,7 +64938,10 @@ async function adoptManagedSessionBackgroundCommand(db, input) {
|
|
|
64938
64938
|
sessionId: input.sessionId,
|
|
64939
64939
|
commandId: input.processId,
|
|
64940
64940
|
retainedProcessId: input.processId,
|
|
64941
|
-
command: input.command
|
|
64941
|
+
command: input.command,
|
|
64942
|
+
turnId: input.turnId,
|
|
64943
|
+
attemptId: input.attemptId,
|
|
64944
|
+
executionGeneration: input.executionGeneration
|
|
64942
64945
|
});
|
|
64943
64946
|
})
|
|
64944
64947
|
);
|
|
@@ -79219,7 +79222,7 @@ function systemUpdateExecutionAuthorityKey(update) {
|
|
|
79219
79222
|
}
|
|
79220
79223
|
function systemUpdateCausalHumanTurnId(update) {
|
|
79221
79224
|
const lineage = update.lineage && typeof update.lineage === "object" && !Array.isArray(update.lineage) ? update.lineage : null;
|
|
79222
|
-
const value = isChildLifecycleSystemUpdateKind(update.kind) ? lineage?.parentTurnId : update.kind === "goal_continuation" ? lineage?.causalTurnId : null;
|
|
79225
|
+
const value = isChildLifecycleSystemUpdateKind(update.kind) ? lineage?.parentTurnId : update.kind === "goal_continuation" || update.kind === "background_command_result" || update.kind === "session_wait_timeout" ? lineage?.causalTurnId : null;
|
|
79223
79226
|
if (typeof value !== "string" || !/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/iu.test(value)) {
|
|
79224
79227
|
return null;
|
|
79225
79228
|
}
|
|
@@ -79240,7 +79243,7 @@ function agentSteerCausalActor(update) {
|
|
|
79240
79243
|
function systemUpdateCausalExecutionKey(update) {
|
|
79241
79244
|
const targetTurnId = systemUpdateCausalHumanTurnId(update);
|
|
79242
79245
|
if (targetTurnId) return `target-turn:${targetTurnId}`;
|
|
79243
|
-
if (isChildLifecycleSystemUpdateKind(update.kind) || update.kind === "goal_continuation") {
|
|
79246
|
+
if (isChildLifecycleSystemUpdateKind(update.kind) || update.kind === "goal_continuation" || update.kind === "background_command_result" || update.kind === "session_wait_timeout") {
|
|
79244
79247
|
return `${update.kind}-update:${update.id}`;
|
|
79245
79248
|
}
|
|
79246
79249
|
if (update.kind !== "agent_steer_instruction") return null;
|
|
@@ -82390,6 +82393,10 @@ async function settleSessionInputWaitInActivity(db, input) {
|
|
|
82390
82393
|
}
|
|
82391
82394
|
const deadlineAt = expected.inputWaitUntil.toISOString();
|
|
82392
82395
|
const reason = expected.inputWaitReason;
|
|
82396
|
+
const causalAuthority = await sameSessionCausalAuthorityTx(db, {
|
|
82397
|
+
...input,
|
|
82398
|
+
turnId: input.waitTurnId
|
|
82399
|
+
});
|
|
82393
82400
|
try {
|
|
82394
82401
|
const result = await addSessionSystemUpdateWithSourceMutation(
|
|
82395
82402
|
db,
|
|
@@ -82398,6 +82405,9 @@ async function settleSessionInputWaitInActivity(db, input) {
|
|
|
82398
82405
|
workspaceId: input.workspaceId,
|
|
82399
82406
|
sessionId: input.sessionId,
|
|
82400
82407
|
kind: "session_wait_timeout",
|
|
82408
|
+
personalConnectionDelegations: causalAuthority?.personalConnectionDelegations ?? [],
|
|
82409
|
+
xaiProviderAccountAuthoritySnapshot: causalAuthority?.xaiProviderAccountAuthoritySnapshot ?? WORKSPACE_XAI_PROVIDER_ACCOUNT_AUTHORITY_SNAPSHOT_V13,
|
|
82410
|
+
lineage: causalAuthority?.lineage ?? {},
|
|
82401
82411
|
classification: "info",
|
|
82402
82412
|
sourceId: input.waitTurnId,
|
|
82403
82413
|
dedupeKey: `session-input-wait-timeout:${input.waitTurnId}`,
|
|
@@ -82830,6 +82840,8 @@ async function failSessionWorkBeforeAttemptClaim(db, workspaceId, input) {
|
|
|
82830
82840
|
payload: {
|
|
82831
82841
|
status: "failed",
|
|
82832
82842
|
code: "pre_claim_failure",
|
|
82843
|
+
error: input.error,
|
|
82844
|
+
...input.admissionFailure ? { admissionFailure: input.admissionFailure } : {},
|
|
82833
82845
|
...!turn ? { failedSystemUpdateIds } : {}
|
|
82834
82846
|
},
|
|
82835
82847
|
turnId: turn?.id ?? null,
|
|
@@ -83074,6 +83086,8 @@ async function recoverSessionWorkFailedBeforeAttemptClaim(db, workspaceId, input
|
|
|
83074
83086
|
const failedUpdates = await tx.select({
|
|
83075
83087
|
id: sessionSystemUpdates.id,
|
|
83076
83088
|
kind: sessionSystemUpdates.kind,
|
|
83089
|
+
sourceId: sessionSystemUpdates.sourceId,
|
|
83090
|
+
dedupeKey: sessionSystemUpdates.dedupeKey,
|
|
83077
83091
|
lineage: sessionSystemUpdates.lineage,
|
|
83078
83092
|
deliveredTurnId: sessionSystemUpdates.deliveredTurnId,
|
|
83079
83093
|
deliveredHistoryItemId: sessionSystemUpdates.deliveredHistoryItemId,
|
|
@@ -83152,12 +83166,53 @@ async function recoverSessionWorkFailedBeforeAttemptClaim(db, workspaceId, input
|
|
|
83152
83166
|
}
|
|
83153
83167
|
}
|
|
83154
83168
|
const causalTurnIds = /* @__PURE__ */ new Set();
|
|
83169
|
+
const repairedAuthorities = /* @__PURE__ */ new Map();
|
|
83155
83170
|
for (const update of failedUpdates) {
|
|
83156
|
-
|
|
83171
|
+
let causalTurnId = systemUpdateCausalHumanTurnId(update);
|
|
83157
83172
|
const lineage = update.lineage && typeof update.lineage === "object" && !Array.isArray(update.lineage) ? update.lineage : null;
|
|
83158
|
-
if (
|
|
83173
|
+
if (update.deliveredTurnId !== null || update.deliveredHistoryItemId !== null || update.deliveredAt !== null)
|
|
83159
83174
|
return { action: "stale", event: null };
|
|
83160
|
-
|
|
83175
|
+
if (isChildLifecycleSystemUpdateKind(update.kind)) {
|
|
83176
|
+
if (!causalTurnId || lineage?.parentSessionId !== input.sessionId) {
|
|
83177
|
+
return { action: "stale", event: null };
|
|
83178
|
+
}
|
|
83179
|
+
} else if (update.kind === "background_command_result") {
|
|
83180
|
+
if (!update.sourceId || !UUID_PATTERN2.test(update.sourceId) || update.dedupeKey !== `background-command-result:${update.sourceId}`) {
|
|
83181
|
+
return { action: "stale", event: null };
|
|
83182
|
+
}
|
|
83183
|
+
const authority = await backgroundCommandCausalAuthorityTx(tx, {
|
|
83184
|
+
accountId: session.accountId,
|
|
83185
|
+
workspaceId,
|
|
83186
|
+
sessionId: input.sessionId,
|
|
83187
|
+
commandId: update.sourceId
|
|
83188
|
+
});
|
|
83189
|
+
if (!authority) return { action: "stale", event: null };
|
|
83190
|
+
repairedAuthorities.set(update.id, authority);
|
|
83191
|
+
causalTurnId = authority.lineage.causalTurnId;
|
|
83192
|
+
} else if (update.kind === "session_wait_timeout") {
|
|
83193
|
+
if (!update.sourceId || !UUID_PATTERN2.test(update.sourceId) || update.dedupeKey !== `session-input-wait-timeout:${update.sourceId}`) {
|
|
83194
|
+
return { action: "stale", event: null };
|
|
83195
|
+
}
|
|
83196
|
+
const [timeoutProof] = await tx.execute(sql68`
|
|
83197
|
+
select id from session_events
|
|
83198
|
+
where workspace_id = ${workspaceId} and session_id = ${input.sessionId}
|
|
83199
|
+
and type = 'session.wait.finished'
|
|
83200
|
+
and payload ->> 'waitTurnId' = ${update.sourceId}
|
|
83201
|
+
and payload ->> 'outcome' = 'timeout'
|
|
83202
|
+
and sequence < ${input.expectedFailureEventSequence}
|
|
83203
|
+
limit 1`);
|
|
83204
|
+
if (!timeoutProof) return { action: "stale", event: null };
|
|
83205
|
+
const authority = await sameSessionCausalAuthorityTx(tx, {
|
|
83206
|
+
accountId: session.accountId,
|
|
83207
|
+
workspaceId,
|
|
83208
|
+
sessionId: input.sessionId,
|
|
83209
|
+
turnId: update.sourceId
|
|
83210
|
+
});
|
|
83211
|
+
if (!authority) return { action: "stale", event: null };
|
|
83212
|
+
repairedAuthorities.set(update.id, authority);
|
|
83213
|
+
causalTurnId = authority.lineage.causalTurnId;
|
|
83214
|
+
} else return { action: "stale", event: null };
|
|
83215
|
+
if (!causalTurnId) return { action: "stale", event: null };
|
|
83161
83216
|
causalTurnIds.add(causalTurnId);
|
|
83162
83217
|
}
|
|
83163
83218
|
const causalTurns = await tx.select({
|
|
@@ -83176,6 +83231,22 @@ async function recoverSessionWorkFailedBeforeAttemptClaim(db, workspaceId, input
|
|
|
83176
83231
|
)) {
|
|
83177
83232
|
return { action: "stale", event: null };
|
|
83178
83233
|
}
|
|
83234
|
+
for (const update of failedUpdates) {
|
|
83235
|
+
const authority = repairedAuthorities.get(update.id);
|
|
83236
|
+
if (!authority) continue;
|
|
83237
|
+
await tx.update(sessionSystemUpdates).set({
|
|
83238
|
+
personalConnectionDelegations: authority.personalConnectionDelegations,
|
|
83239
|
+
xaiProviderAccountAuthoritySnapshot: authority.xaiProviderAccountAuthoritySnapshot,
|
|
83240
|
+
lineage: { ...update.lineage, ...authority.lineage }
|
|
83241
|
+
}).where(
|
|
83242
|
+
and52(
|
|
83243
|
+
eq53(sessionSystemUpdates.id, update.id),
|
|
83244
|
+
eq53(sessionSystemUpdates.workspaceId, workspaceId),
|
|
83245
|
+
eq53(sessionSystemUpdates.sessionId, input.sessionId),
|
|
83246
|
+
eq53(sessionSystemUpdates.state, "failed")
|
|
83247
|
+
)
|
|
83248
|
+
);
|
|
83249
|
+
}
|
|
83179
83250
|
const restored = await tx.update(sessionSystemUpdates).set({ state: "pending" }).where(
|
|
83180
83251
|
and52(
|
|
83181
83252
|
eq53(sessionSystemUpdates.workspaceId, workspaceId),
|
|
@@ -83386,11 +83457,20 @@ async function settleSessionIdleWithParentOutbox(db, workspaceId, sessionId) {
|
|
|
83386
83457
|
);
|
|
83387
83458
|
}
|
|
83388
83459
|
const episodeKey = String(Number(episodeSequence));
|
|
83389
|
-
|
|
83460
|
+
const waitState = await sessionInputWaitStateTx(tx, workspaceId, sessionId, session);
|
|
83461
|
+
const [goal] = await tx.select({ status: sessionGoals.status }).from(sessionGoals).where(
|
|
83462
|
+
and52(
|
|
83463
|
+
eq53(sessionGoals.workspaceId, workspaceId),
|
|
83464
|
+
eq53(sessionGoals.sessionId, sessionId)
|
|
83465
|
+
)
|
|
83466
|
+
).limit(1);
|
|
83467
|
+
const ongoingWork = waitState.disposition === "held" || waitState.disposition === "timeout" || goal?.status === "active";
|
|
83468
|
+
if (!session.parentSessionId || ongoingWork) {
|
|
83390
83469
|
return {
|
|
83391
83470
|
action: "settled",
|
|
83392
83471
|
changed: events.length > 0,
|
|
83393
83472
|
episodeKey,
|
|
83473
|
+
notifyParent: false,
|
|
83394
83474
|
events
|
|
83395
83475
|
};
|
|
83396
83476
|
}
|
|
@@ -83410,6 +83490,7 @@ async function settleSessionIdleWithParentOutbox(db, workspaceId, sessionId) {
|
|
|
83410
83490
|
action: "settled",
|
|
83411
83491
|
changed: events.length > 0,
|
|
83412
83492
|
episodeKey,
|
|
83493
|
+
notifyParent: true,
|
|
83413
83494
|
events
|
|
83414
83495
|
};
|
|
83415
83496
|
});
|
|
@@ -86781,6 +86862,90 @@ async function addSessionSystemUpdateWithSourceMutation(db, input, mutateSource,
|
|
|
86781
86862
|
})
|
|
86782
86863
|
);
|
|
86783
86864
|
}
|
|
86865
|
+
async function sameSessionCausalAuthorityTx(tx, input) {
|
|
86866
|
+
const [turn] = await tx.select().from(sessionTurns).where(
|
|
86867
|
+
and52(
|
|
86868
|
+
eq53(sessionTurns.accountId, input.accountId),
|
|
86869
|
+
eq53(sessionTurns.workspaceId, input.workspaceId),
|
|
86870
|
+
eq53(sessionTurns.sessionId, input.sessionId),
|
|
86871
|
+
eq53(sessionTurns.id, input.turnId)
|
|
86872
|
+
)
|
|
86873
|
+
).limit(1);
|
|
86874
|
+
if (!turn) return null;
|
|
86875
|
+
const personalConnectionDelegations = personalConnectionDelegationsForSameSessionSuccessor(
|
|
86876
|
+
parsedPersonalConnectionDelegations(
|
|
86877
|
+
turn.personalConnectionDelegations,
|
|
86878
|
+
`session_turns:${turn.id}`
|
|
86879
|
+
),
|
|
86880
|
+
input.sessionId
|
|
86881
|
+
);
|
|
86882
|
+
const xaiProviderAccountAuthoritySnapshot = XaiProviderAccountAuthoritySnapshotV13.parse(
|
|
86883
|
+
turn.xaiProviderAccountAuthoritySnapshot
|
|
86884
|
+
);
|
|
86885
|
+
const human = turn.initiatingHumanSubjectId ?? (turn.initiatorKind === "subject" ? turn.initiatorSubjectId : null);
|
|
86886
|
+
if (!human && (personalConnectionDelegations.some((d) => d.userDelegation) || xaiProviderAccountAuthoritySnapshot.scope === "user")) {
|
|
86887
|
+
throw new SessionControlInvariantError("Causal turn lost its personal execution authority");
|
|
86888
|
+
}
|
|
86889
|
+
return {
|
|
86890
|
+
personalConnectionDelegations,
|
|
86891
|
+
xaiProviderAccountAuthoritySnapshot,
|
|
86892
|
+
lineage: {
|
|
86893
|
+
causalTurnId: turn.id,
|
|
86894
|
+
...human && personalConnectionDelegations.some((d) => d.userDelegation) ? { connectionAuthoritySubjectId: human } : {},
|
|
86895
|
+
...human && xaiProviderAccountAuthoritySnapshot.scope === "user" ? { xaiAuthoritySubjectId: human } : {}
|
|
86896
|
+
}
|
|
86897
|
+
};
|
|
86898
|
+
}
|
|
86899
|
+
async function backgroundCommandCausalAuthorityTx(tx, input) {
|
|
86900
|
+
const [command] = await tx.select().from(sessionBackgroundCommands).where(
|
|
86901
|
+
and52(
|
|
86902
|
+
eq53(sessionBackgroundCommands.accountId, input.accountId),
|
|
86903
|
+
eq53(sessionBackgroundCommands.workspaceId, input.workspaceId),
|
|
86904
|
+
eq53(sessionBackgroundCommands.sessionId, input.sessionId),
|
|
86905
|
+
eq53(sessionBackgroundCommands.id, input.commandId)
|
|
86906
|
+
)
|
|
86907
|
+
).limit(1);
|
|
86908
|
+
if (!command || !["exited", "lost"].includes(command.state) || !command.settledAt) return null;
|
|
86909
|
+
let turnId = command.launchTurnId;
|
|
86910
|
+
let attemptId = command.launchAttemptId;
|
|
86911
|
+
let generation = command.launchExecutionGeneration;
|
|
86912
|
+
if (!turnId && command.provider === "managed" && command.retainedProcessId) {
|
|
86913
|
+
const [process2] = await tx.select().from(sandboxRetainedProcesses).where(
|
|
86914
|
+
and52(
|
|
86915
|
+
eq53(sandboxRetainedProcesses.id, command.retainedProcessId),
|
|
86916
|
+
eq53(sandboxRetainedProcesses.accountId, input.accountId),
|
|
86917
|
+
eq53(sandboxRetainedProcesses.workspaceId, input.workspaceId),
|
|
86918
|
+
eq53(sandboxRetainedProcesses.sessionId, input.sessionId)
|
|
86919
|
+
)
|
|
86920
|
+
).limit(1);
|
|
86921
|
+
if (process2?.ownerActorKind === "turn" && process2.ownerActorId === process2.ownerAttemptId) {
|
|
86922
|
+
turnId = process2.ownerTurnId;
|
|
86923
|
+
attemptId = process2.ownerAttemptId;
|
|
86924
|
+
generation = process2.ownerExecutionGeneration;
|
|
86925
|
+
}
|
|
86926
|
+
}
|
|
86927
|
+
if (!turnId || !attemptId || !generation) return null;
|
|
86928
|
+
const [attempt] = await tx.select({ id: sessionTurnAttempts.id }).from(sessionTurnAttempts).where(
|
|
86929
|
+
and52(
|
|
86930
|
+
eq53(sessionTurnAttempts.id, attemptId),
|
|
86931
|
+
eq53(sessionTurnAttempts.accountId, input.accountId),
|
|
86932
|
+
eq53(sessionTurnAttempts.workspaceId, input.workspaceId),
|
|
86933
|
+
eq53(sessionTurnAttempts.sessionId, input.sessionId),
|
|
86934
|
+
eq53(sessionTurnAttempts.turnId, turnId),
|
|
86935
|
+
eq53(sessionTurnAttempts.executionGeneration, generation)
|
|
86936
|
+
)
|
|
86937
|
+
).limit(1);
|
|
86938
|
+
if (!attempt) return null;
|
|
86939
|
+
const authority = await sameSessionCausalAuthorityTx(tx, { ...input, turnId });
|
|
86940
|
+
return authority ? {
|
|
86941
|
+
...authority,
|
|
86942
|
+
lineage: {
|
|
86943
|
+
...authority.lineage,
|
|
86944
|
+
causalAttemptId: attemptId,
|
|
86945
|
+
causalExecutionGeneration: generation
|
|
86946
|
+
}
|
|
86947
|
+
} : null;
|
|
86948
|
+
}
|
|
86784
86949
|
function backgroundCommandTerminalMutation(input) {
|
|
86785
86950
|
let controlActive = false;
|
|
86786
86951
|
const events = [];
|
|
@@ -86868,6 +87033,10 @@ function backgroundCommandTerminalMutation(input) {
|
|
|
86868
87033
|
...command.failure ? { failure: command.failure } : {},
|
|
86869
87034
|
outputLocator
|
|
86870
87035
|
};
|
|
87036
|
+
const causalAuthority = await backgroundCommandCausalAuthorityTx(tx, {
|
|
87037
|
+
...input,
|
|
87038
|
+
commandId: command.id
|
|
87039
|
+
});
|
|
86871
87040
|
const [insertedUpdate] = await tx.insert(sessionSystemUpdates).values(
|
|
86872
87041
|
withLosslessContentWriteVersion(
|
|
86873
87042
|
withLosslessContentWriteVersion(
|
|
@@ -86881,7 +87050,13 @@ function backgroundCommandTerminalMutation(input) {
|
|
|
86881
87050
|
dedupeKey: `background-command-result:${command.id}`,
|
|
86882
87051
|
summary,
|
|
86883
87052
|
payload,
|
|
86884
|
-
|
|
87053
|
+
personalConnectionDelegations: causalAuthority?.personalConnectionDelegations ?? [],
|
|
87054
|
+
xaiProviderAccountAuthoritySnapshot: causalAuthority?.xaiProviderAccountAuthoritySnapshot ?? WORKSPACE_XAI_PROVIDER_ACCOUNT_AUTHORITY_SNAPSHOT_V13,
|
|
87055
|
+
lineage: {
|
|
87056
|
+
commandId: command.id,
|
|
87057
|
+
provider: command.provider,
|
|
87058
|
+
...causalAuthority?.lineage
|
|
87059
|
+
},
|
|
86885
87060
|
state: "pending"
|
|
86886
87061
|
},
|
|
86887
87062
|
"summary",
|