Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions apps/server/src/cloud/CloudPreferences.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,32 @@ it.effect("changes nothing when the current hold setting can't be read", () =>
}),
),
);

it.effect("an update the client walks away from still finishes", () => {
let release!: () => void;
let started!: () => void;
const released = new Promise<void>((resolve) => {
release = resolve;
});
const atRelay = new Promise<void>((resolve) => {
started = resolve;
});
return withService({ holdFirstRelayCall: { started, released } }, ({ preferences, stored }) =>
Effect.gen(function* () {
const update = yield* preferences
.update({ publishAgentActivity: true, holdWebhooksWhileOffline: true })
.pipe(Effect.forkChild);
yield* Effect.promise(() => atRelay);
// The interrupt is in flight before the relay answers.
const interrupted = yield* Fiber.interrupt(update).pipe(Effect.forkChild);
yield* Effect.yieldNow;
release();
yield* Fiber.join(interrupted);
assert.equal(new TextDecoder().decode(stored.get(PUBLISH_AGENT_ACTIVITY_SECRET)), "true");
assert.equal(
new TextDecoder().decode(stored.get(HOLD_WEBHOOKS_WHILE_OFFLINE_SECRET)),
"true",
);
}),
);
});
3 changes: 3 additions & 0 deletions apps/server/src/cloud/CloudPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ const make = Effect.gen(function* () {
}
yield* awarenessRelay.requestCatchUp();
},
// A client that disconnects mid-update must not stop it between a save and
// its rollback, so an update always finishes or undoes itself.
Effect.uninterruptible,
updateLock.withPermits(1),
);

Expand Down
20 changes: 4 additions & 16 deletions apps/server/src/secrets/SecretRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@ const make = Effect.gen(function* () {
turnItemTypes: ["secret_request"],
messageRoles: [],
})
.pipe(
Effect.mapError(
(cause) => new SecretRequestError({ reason: "load_failed", cause: cause }),
),
);
.pipe(Effect.mapError((cause) => new SecretRequestError({ reason: "load_failed", cause })));
const item = records.turnItems.find((candidate) => candidate.id === input.turnItemId);
if (item?.type !== "secret_request" || item.runId === null || item.nodeId === null) {
return yield* new SecretRequestError({ reason: "not_found" });
Expand Down Expand Up @@ -160,9 +156,7 @@ const make = Effect.gen(function* () {
secretStatus,
})
.pipe(
Effect.mapError(
(cause) => new SecretRequestError({ reason: "record_failed", cause: cause }),
),
Effect.mapError((cause) => new SecretRequestError({ reason: "record_failed", cause })),
// The card still says pending, so the user can save again; the value
// stored above would make that retry look already answered.
Effect.tapError(() =>
Expand All @@ -181,9 +175,7 @@ const make = Effect.gen(function* () {
messageRoles: [],
})
.pipe(
Effect.mapError(
(cause) => new SecretRequestError({ reason: "record_failed", cause: cause }),
),
Effect.mapError((cause) => new SecretRequestError({ reason: "record_failed", cause })),
);
const card = recorded.turnItems.find((candidate) => candidate.id === item.id);
if (card?.type === "secret_request" && card.secretStatus !== "saved") {
Expand Down Expand Up @@ -229,11 +221,7 @@ const make = Effect.gen(function* () {
return yield* new SecretRequestError({ reason: "invalid_ref" });
const stored = yield* store
.get(storeName(input.ref))
.pipe(
Effect.mapError(
(cause) => new SecretRequestError({ reason: "read_failed", cause: cause }),
),
);
.pipe(Effect.mapError((cause) => new SecretRequestError({ reason: "read_failed", cause })));
const decoded = Option.flatMap(stored, (bytes) =>
decodeStored(new TextDecoder().decode(bytes)),
);
Expand Down
Loading