Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): skip native sessions during bulk import #15634

Mergedmaria-rcksmerged 7 commits intomain fromrefs/pull/15634/headmerged by juliusmarminge View on GitHub

Showing 3 changed files with 23 additions and 0 deletions (loading 2).

x
0 of 3 viewed, 3 left
23 additions and 0 deletionsapps/server/src/orchestration-v2/EventSink.tsModified
View file
@@ -67,11 +67,20 @@
​
export interface EventSinkV2Shape {
readonly write: (input: {
+ /** Return no events if another thread owns this native session at commit time. */
+ readonly unlessNativeThreadOwned?: Pick<
+ OrchestrationV2ProviderThread,
+ "driver" | "providerInstanceId" | "appThreadId" | "nativeThreadRef"
+ >;
readonly guardPendingUserInputCancellations?: boolean;
readonly commandId?: CommandId;
readonly events: ReadonlyArray<OrchestrationV2DomainEvent>;
}) => Effect.Effect<ReadonlyArray<OrchestrationV2StoredEvent>, EventSinkV2Error>;
readonly writeWithEffects: (input: {
+ readonly unlessNativeThreadOwned?: Pick<
+ OrchestrationV2ProviderThread,
+ "driver" | "providerInstanceId" | "appThreadId" | "nativeThreadRef"
+ >;
readonly guardPendingUserInputCancellations?: boolean;
readonly commandId?: CommandId;
readonly events: ReadonlyArray<OrchestrationV2DomainEvent>;
@@ -369,6 +378,20 @@
​
return yield* commitThenPublish(
Effect.gen(function* () {
+ // Check ownership in the same transaction that claims the native session.
+ const imported = input.unlessNativeThreadOwned;
+ if (imported?.nativeThreadRef != null) {
+ const owners = yield* sql`