Open History to see the last commit
1import {
2 type EnvironmentId,
3 type ServerConfig,
4 type ServerConfigStreamEvent,
5 type ServerLifecycleWelcomePayload,
6 type ServerSelfUpdateProgressEvent,
7 type ServerSelfUpdateResult,
8 WS_METHODS,
9} from "@t3tools/contracts";
10import * as Cause from "effect/Cause";
11import * as Duration from "effect/Duration";
12import * as Effect from "effect/Effect";
13import * as Exit from "effect/Exit";
14import * as Option from "effect/Option";
15import * as Queue from "effect/Queue";
16import * as Ref from "effect/Ref";
17import * as Result from "effect/Result";
18import * as Schema from "effect/Schema";
19import * as Stream from "effect/Stream";
20import * as SubscriptionRef from "effect/SubscriptionRef";
21import { AsyncResult, Atom } from "effect/unstable/reactivity";
22
23import {
24 createAtomCommandScheduler,
25 createEnvironmentRpcCommand,
26 createEnvironmentRpcQueryAtomFamily,
27 createEnvironmentRpcSubscriptionAtomFamily,
28 createRuntimeCommand,
29 scheduleAtomCommandEffect,
30} from "./runtime.ts";
31import { EnvironmentRegistry } from "../connection/registry.ts";
32import { EnvironmentSupervisor } from "../connection/supervisor.ts";
33import { safeErrorLogAttributes } from "../errors/safeLog.ts";
34import { EnvironmentCacheStore } from "../platform/persistence.ts";
35import {
36 isRpcClientError,
37 request,
38 runStream,
39 subscribe,
40 type EnvironmentRpcInput,
41} from "../rpc/client.ts";
42import { followStreamInEnvironment } from "./runtime.ts";
43
44export type ServerUpdateStage = "downloading" | "installing" | "resuming";
45
46export type ServerUpdateState =
47 | { readonly status: "idle" }
48 | {
49 readonly status: "running";
50 readonly stage: ServerUpdateStage;
51 readonly fromVersion: string;
52 readonly targetVersion: string;
53 }
54 | {
55 readonly status: "failed";
56 readonly stage: ServerUpdateStage;
57 readonly fromVersion: string;
58 readonly targetVersion: string;
59 readonly message: string;
60 };
61
62export interface ServerUpdateTarget {
63 readonly environmentId: EnvironmentId;
64 readonly input: EnvironmentRpcInput<typeof WS_METHODS.serverUpdateServer>;
65}
66
67const IDLE_SERVER_UPDATE_STATE: ServerUpdateState = { status: "idle" };
68const EMPTY_SERVER_UPDATE_STATE_ATOM = Atom.make<ServerUpdateState>(IDLE_SERVER_UPDATE_STATE).pipe(
69 Atom.withLabel("environment-data:server:update-state:empty"),
70);
71const serverUpdateStateAtom = Atom.family((environmentId: EnvironmentId) =>
72 Atom.make<ServerUpdateState>(IDLE_SERVER_UPDATE_STATE).pipe(
73 Atom.withLabel(`environment-data:server:update-state:${environmentId}`),
74 ),
75);
76
77export class ServerUpdateResumeTimeoutError extends Schema.TaggedErrorClass<ServerUpdateResumeTimeoutError>()(
78 "ServerUpdateResumeTimeoutError",
79 {
80 environmentId: Schema.String,
81 targetVersion: Schema.String,
82 },
83) {
84 override get message(): string {
85 return `The server did not resume on t3@${this.targetVersion}.`;
86 }
87}
88
89export class ServerUpdateProgressIncompleteError extends Schema.TaggedErrorClass<ServerUpdateProgressIncompleteError>()(
90 "ServerUpdateProgressIncompleteError",
91 {
92 targetVersion: Schema.String,
93 },
94) {
95 override get message(): string {
96 return `The t3@${this.targetVersion} update ended before the server accepted the restart.`;
97 }
98}
99
100export function serverUpdateStateForProgressEvent(
101 fromVersion: string,
102 targetVersion: string,
103 event: ServerSelfUpdateProgressEvent,
104): Extract<ServerUpdateState, { status: "running" }> {
105 return {
106 status: "running",
107 stage: event.type === "complete" ? "resuming" : event.stage,
108 fromVersion,
109 targetVersion,
110 };
111}
112
113export function serverUpdateStateForServerVersion(
114 state: ServerUpdateState,
115 serverVersion: string | null,
116): ServerUpdateState {
117 return state.status === "idle" ||
118 state.status === "running" ||
119 serverVersion === null ||
120 state.fromVersion === serverVersion
121 ? state
122 : IDLE_SERVER_UPDATE_STATE;
123}
124
125function serverUpdateFailureMessage(error: unknown): string {
126 return error instanceof Error ? error.message : "Server update failed.";
127}
128
129function isRpcSocketError(error: unknown): boolean {
130 if (!isRpcClientError(error)) {
131 return false;
132 }
133 switch (error.reason._tag) {
134 case "SocketReadError":
135 case "SocketWriteError":
136 case "SocketCloseError":
137 return true;
138 default:
139 return false;
140 }
141}
142
143export function isLegacyUpdateHandoffLoss(cause: Cause.Cause<unknown>): boolean {
144 if (Cause.hasInterruptsOnly(cause)) {
145 return true;
146 }
147 return (
148 cause.reasons.length > 0 &&
149 cause.reasons.every((reason) => Cause.isFailReason(reason) && isRpcSocketError(reason.error))
150 );
151}
152
153export function resolveServerUpdateProgressResult<E>(
154 targetVersion: string,
155 terminal: Option.Option<ServerSelfUpdateResult>,
156 streamExit: Exit.Exit<void, E>,
157): Effect.Effect<ServerSelfUpdateResult, E | ServerUpdateProgressIncompleteError> {
158 if (
159 Option.isSome(terminal) &&
160 (Exit.isSuccess(streamExit) || isLegacyUpdateHandoffLoss(streamExit.cause))
161 ) {
162 return Effect.succeed(terminal.value);
163 }
164 if (Exit.isFailure(streamExit)) {
165 return Effect.failCause(streamExit.cause);
166 }
167 return Effect.fail(new ServerUpdateProgressIncompleteError({ targetVersion }));
168}
169
170export interface ServerConfigProjection {
171 readonly config: ServerConfig;
172 readonly latestEvent: ServerConfigStreamEvent;
173 readonly source: "cache" | "live";
174}
175
176export function applyServerConfigProjection(
177 current: Option.Option<ServerConfigProjection>,
178 event: ServerConfigStreamEvent,
179): Option.Option<ServerConfigProjection> {
180 switch (event.type) {
181 case "snapshot":
182 return Option.some({
183 config: event.config,
184 latestEvent: event,
185 source: "live",
186 });
187 case "keybindingsUpdated":
188 return Option.map(current, (projection) => ({
189 config: {
190 ...projection.config,
191 keybindings: event.payload.keybindings,
192 issues: event.payload.issues,
193 },
194 latestEvent: event,
195 source: "live",
196 }));
197 case "providerStatuses":
198 return Option.map(current, (projection) => ({
199 config: {
200 ...projection.config,
201 providers: event.payload.providers,
202 },
203 latestEvent: event,
204 source: "live",
205 }));
206 case "settingsUpdated":
207 return Option.map(current, (projection) => ({
208 config: {
209 ...projection.config,
210 settings: event.payload.settings,
211 },
212 latestEvent: event,
213 source: "live",
214 }));
215 }
216}
217
218export function projectServerConfig(
219 current: Option.Option<ServerConfigProjection>,
220 event: ServerConfigStreamEvent,
221): readonly [Option.Option<ServerConfigProjection>, ReadonlyArray<ServerConfigProjection>] {
222 const next = applyServerConfigProjection(current, event);
223 return [next, Option.toArray(next)];
224}
225
226const cachedConfigSnapshotEvent = (config: ServerConfig): ServerConfigStreamEvent => ({
227 version: 1,
228 type: "snapshot",
229 config,
230});
231
232/**
233 * Keeps a complete server configuration available during reconnects. Server
234 * config carries the provider/model catalogue used by task creation, so it is
235 * useful—and safe—to retain after a transport session ends.
236 */
237export const makeEnvironmentServerConfigState = Effect.fn("EnvironmentServerConfigState.make")(
238 function* () {
239 const supervisor = yield* EnvironmentSupervisor;
240 const cache = yield* EnvironmentCacheStore;
241 const environmentId = supervisor.target.environmentId;
242 const cachedConfig = yield* cache.loadServerConfig(environmentId).pipe(
243 Effect.catch((error) =>
244 Effect.logWarning("Could not load cached server configuration.").pipe(
245 Effect.annotateLogs({
246 environmentId,
247 ...safeErrorLogAttributes(error),
248 }),
249 Effect.as(Option.none<ServerConfig>()),
250 ),
251 ),
252 );
253 const state = yield* SubscriptionRef.make<Option.Option<ServerConfigProjection>>(
254 Option.map(cachedConfig, (config) => ({
255 config,
256 latestEvent: cachedConfigSnapshotEvent(config),
257 source: "cache" as const,
258 })),
259 );
260 const persistence = yield* Queue.sliding<ServerConfig>(1);
261 const pendingPersistence = yield* Ref.make<Option.Option<ServerConfig>>(Option.none());
262
263 const persist = Effect.fn("EnvironmentServerConfigState.persist")(function* (
264 config: ServerConfig,
265 ) {
266 return yield* cache.saveServerConfig(environmentId, config).pipe(
267 Effect.as(true),
268 Effect.catch((error) =>
269 Effect.logWarning("Could not persist cached server configuration.").pipe(
270 Effect.annotateLogs({
271 environmentId,
272 ...safeErrorLogAttributes(error),
273 }),
274 Effect.as(false),
275 ),
276 ),
277 );
278 });
279
280 const persistPending = Effect.fn("EnvironmentServerConfigState.persistPending")(function* (
281 config: ServerConfig,
282 ) {
283 if (!(yield* persist(config))) {
284 return;
285 }
286 yield* Ref.update(pendingPersistence, (pending) =>
287 Option.isSome(pending) && pending.value === config ? Option.none() : pending,
288 );
289 });
290
291 yield* Stream.fromQueue(persistence).pipe(
292 Stream.debounce("500 millis"),
293 Stream.runForEach(persistPending),
294 Effect.forkScoped,
295 );
296
297 yield* subscribe(WS_METHODS.subscribeServerConfig, {}).pipe(
298 Stream.runForEach((event) =>
299 Effect.gen(function* () {
300 const next = applyServerConfigProjection(yield* SubscriptionRef.get(state), event);
301 if (Option.isNone(next)) {
302 return;
303 }
304 yield* Ref.set(pendingPersistence, Option.some(next.value.config));
305 yield* SubscriptionRef.set(state, next);
306 yield* Queue.offer(persistence, next.value.config);
307 }),
308 ),
309 Effect.forkScoped,
310 );
311
312 yield* Effect.addFinalizer(() =>
313 Ref.get(pendingPersistence).pipe(
314 Effect.flatMap(
315 Option.match({
316 onNone: () => Effect.void,
317 onSome: (config) => persist(config).pipe(Effect.asVoid),
318 }),
319 ),
320 ),
321 );
322
323 return state;
324 },
325);
326
327export function serverConfigStateChanges(environmentId: EnvironmentId) {
328 return followStreamInEnvironment(
329 environmentId,
330 Stream.unwrap(
331 makeEnvironmentServerConfigState().pipe(
332 Effect.map((state) =>
333 SubscriptionRef.changes(state).pipe(
334 Stream.filterMap((projection) =>
335 Option.match(projection, {
336 onNone: () => Result.failVoid,
337 onSome: (value) => Result.succeed(value),
338 }),
339 ),
340 ),
341 ),
342 ),
343 ),
344 );
345}
346
347export function projectServerWelcome(
348 current: Option.Option<ServerLifecycleWelcomePayload>,
349 event: {
350 readonly type: "welcome" | "ready" | "legacyThreadMigration";
351 readonly payload: unknown;
352 },
353): readonly [
354 Option.Option<ServerLifecycleWelcomePayload>,
355 ReadonlyArray<ServerLifecycleWelcomePayload>,
356] {
357 if (event.type !== "welcome") {
358 return [current, []];
359 }
360 const welcome = event.payload as ServerLifecycleWelcomePayload;
361 return [Option.some(welcome), [welcome]];
362}
363
364export function resolveServerConfigValue(
365 projection: ServerConfigProjection | null,
366 initialConfig: ServerConfig | null,
367): ServerConfig | null {
368 if (
369 projection?.source === "live" &&
370 (initialConfig === null ||
371 projection.config.environment.serverVersion === initialConfig.environment.serverVersion)
372 ) {
373 return projection.config;
374 }
375 return initialConfig ?? projection?.config ?? null;
376}
377
378export function createServerEnvironmentAtoms<R, E>(
379 runtime: Atom.AtomRuntime<EnvironmentRegistry | EnvironmentCacheStore | R, E>,
380 options: {
381 readonly initialConfigValueAtom: (
382 environmentId: EnvironmentId,
383 ) => Atom.Atom<ServerConfig | null>;
384 },
385) {
386 const configScheduler = createAtomCommandScheduler();
387 // Updates stay serial end-to-end, but only their handoff phase occupies the config lane.
388 const updateScheduler = createAtomCommandScheduler();
389 const configConcurrency = {
390 mode: "serial" as const,
391 key: ({ environmentId }: { readonly environmentId: string }) => environmentId,
392 };
393 const configProjectionFamily = Atom.family((environmentId: EnvironmentId) =>
394 runtime
395 .atom(serverConfigStateChanges(environmentId))
396 .pipe(
397 Atom.setIdleTTL(5 * 60_000),
398 Atom.withLabel(`environment-data:server:config-projection:${environmentId}`),
399 ),
400 );
401 const configProjection = (target: {
402 readonly environmentId: EnvironmentId;
403 readonly input: EnvironmentRpcInput<typeof WS_METHODS.subscribeServerConfig>;
404 }) => configProjectionFamily(target.environmentId);
405 const emptyConfigAtom = Atom.make<ServerConfig | null>(null).pipe(
406 Atom.withLabel("environment-data:server:config:empty"),
407 );
408 const configValueAtom = Atom.family((environmentId: EnvironmentId | null) => {
409 if (environmentId === null) {
410 return emptyConfigAtom;
411 }
412 return Atom.make((get): ServerConfig | null => {
413 const projection = Option.getOrNull(
414 AsyncResult.value(get(configProjection({ environmentId, input: {} }))),
415 );
416 return resolveServerConfigValue(
417 projection,
418 get(options.initialConfigValueAtom(environmentId)),
419 );
420 }).pipe(Atom.withLabel(`environment-data:server:config:${environmentId}`));
421 });
422 const updateStateValueAtom = Atom.family((environmentId: EnvironmentId) =>
423 Atom.make((get) =>
424 serverUpdateStateForServerVersion(
425 get(serverUpdateStateAtom(environmentId)),
426 get(configValueAtom(environmentId))?.environment.serverVersion ?? null,
427 ),
428 ).pipe(Atom.withLabel(`environment-data:server:update-state-value:${environmentId}`)),
429 );
430 const updateStateAtom = (environmentId: EnvironmentId | null) =>
431 environmentId === null ? EMPTY_SERVER_UPDATE_STATE_ATOM : updateStateValueAtom(environmentId);
432 const updateServer = createRuntimeCommand<
433 EnvironmentRegistry | EnvironmentCacheStore | R,
434 E,
435 ServerUpdateTarget,
436 ServerSelfUpdateResult,
437 unknown
438 >(runtime, {
439 label: "environment-data:server:update-server",
440 scheduler: updateScheduler,
441 concurrency: configConcurrency,
442 execute: (target, atomRegistry) => {
443 const stateAtom = serverUpdateStateAtom(target.environmentId);
444 const targetVersion = target.input.targetVersion;
445 let fromVersion =
446 atomRegistry.get(configValueAtom(target.environmentId))?.environment.serverVersion ??
447 targetVersion;
448 let currentStage: ServerUpdateStage = "downloading";
449 atomRegistry.set(stateAtom, {
450 status: "running",
451 stage: currentStage,
452 fromVersion,
453 targetVersion,
454 });
455
456 return Effect.gen(function* () {
457 const environmentRegistry = yield* EnvironmentRegistry;
458 const result = yield* scheduleAtomCommandEffect(
459 atomRegistry,
460 configScheduler,
461 configConcurrency,
462 target,
463 Effect.gen(function* () {
464 const currentConfig = atomRegistry.get(configValueAtom(target.environmentId));
465 fromVersion = currentConfig?.environment.serverVersion ?? targetVersion;
466 atomRegistry.set(stateAtom, {
467 status: "running",
468 stage: currentStage,
469 fromVersion,
470 targetVersion,
471 });
472
473 const supportsProgress =
474 currentConfig?.environment.capabilities.serverSelfUpdateProgress === true;
475 const updateResult: ServerSelfUpdateResult = supportsProgress
476 ? yield* Effect.gen(function* () {
477 const terminal = yield* Ref.make<Option.Option<ServerSelfUpdateResult>>(
478 Option.none(),
479 );
480 const streamExit = yield* environmentRegistry
481 .runStream(
482 target.environmentId,
483 runStream(WS_METHODS.serverUpdateServerWithProgress, target.input),
484 )
485 .pipe(
486 Stream.runForEach((event) =>
487 Effect.sync(() => {
488 currentStage = event.type === "complete" ? "resuming" : event.stage;
489 atomRegistry.set(
490 stateAtom,
491 serverUpdateStateForProgressEvent(fromVersion, targetVersion, event),
492 );
493 }).pipe(
494 Effect.andThen(
495 event.type === "complete"
496 ? Ref.set(terminal, Option.some(event.result))
497 : Effect.void,
498 ),
499 ),
500 ),
501 Effect.exit,
502 );
503 return yield* resolveServerUpdateProgressResult(
504 targetVersion,
505 yield* Ref.get(terminal),
506 streamExit,
507 );
508 })
509 : yield* Effect.gen(function* () {
510 const selfUpdateMethod = currentConfig?.environment.capabilities.serverSelfUpdate;
511 const exit = yield* environmentRegistry
512 .run(target.environmentId, request(WS_METHODS.serverUpdateServer, target.input))
513 .pipe(Effect.exit);
514 if (Exit.isSuccess(exit)) {
515 return exit.value;
516 }
517 if (
518 (selfUpdateMethod === "boot-service" || selfUpdateMethod === "respawn") &&
519 isLegacyUpdateHandoffLoss(exit.cause)
520 ) {
521 // Older servers can tear down the transport before their
522 // unary acknowledgement arrives. Treat only that transport
523 // loss as a handoff, then prove it by waiting for target ready.
524 return { targetVersion, method: selfUpdateMethod };
525 }
526 return yield* Effect.failCause(exit.cause);
527 });
528
529 currentStage = "resuming";
530 atomRegistry.set(stateAtom, {
531 status: "running",
532 stage: currentStage,
533 fromVersion,
534 targetVersion,
535 });
536 return updateResult;
537 }),
538 );
539
540 // The update restart is intentional. As soon as the supervisor sees
541 // that first failed connection, discard any prior backoff debt and
542 // retry immediately instead of carrying an old 16-second delay.
543 yield* environmentRegistry.stateChanges(target.environmentId).pipe(
544 Stream.filter((state) => state.phase === "backoff"),
545 Stream.take(1),
546 Stream.runDrain,
547 Effect.andThen(environmentRegistry.retryNow(target.environmentId)),
548 Effect.timeoutOption(Duration.seconds(30)),
549 Effect.ignore,
550 Effect.forkChild,
551 );
552
553 const resumed = yield* environmentRegistry
554 .followStream(target.environmentId, subscribe(WS_METHODS.subscribeServerLifecycle, {}))
555 .pipe(
556 Stream.filter(
557 (event) =>
558 event.type === "ready" && event.payload.environment.serverVersion === targetVersion,
559 ),
560 Stream.runHead,
561 Effect.timeoutOption(Duration.seconds(120)),
562 Effect.map(Option.flatten),
563 );
564 if (Option.isNone(resumed)) {
565 return yield* new ServerUpdateResumeTimeoutError({
566 environmentId: target.environmentId,
567 targetVersion,
568 });
569 }
570
571 atomRegistry.set(stateAtom, IDLE_SERVER_UPDATE_STATE);
572 return result;
573 }).pipe(
574 Effect.onExit((exit) =>
575 Effect.sync(() => {
576 if (Exit.isSuccess(exit)) {
577 return;
578 }
579 if (Cause.hasInterruptsOnly(exit.cause)) {
580 atomRegistry.set(stateAtom, IDLE_SERVER_UPDATE_STATE);
581 return;
582 }
583 atomRegistry.set(stateAtom, {
584 status: "failed",
585 stage: currentStage,
586 fromVersion,
587 targetVersion,
588 message: serverUpdateFailureMessage(Cause.squash(exit.cause)),
589 });
590 }),
591 ),
592 );
593 },
594 });
595 const settingsValueAtom = Atom.family((environmentId: EnvironmentId) =>
596 Atom.make((get) => get(configValueAtom(environmentId))?.settings ?? null).pipe(
597 Atom.withLabel(`environment-data:server:settings:${environmentId}`),
598 ),
599 );
600 const providersValueAtom = Atom.family((environmentId: EnvironmentId) =>
601 Atom.make((get) => get(configValueAtom(environmentId))?.providers ?? null).pipe(
602 Atom.withLabel(`environment-data:server:providers:${environmentId}`),
603 ),
604 );
605
606 return {
607 configValueAtom,
608 updateStateAtom,
609 settingsValueAtom,
610 providersValueAtom,
611 traceDiagnostics: createEnvironmentRpcQueryAtomFamily(runtime, {
612 label: "environment-data:server:trace-diagnostics",
613 tag: WS_METHODS.serverGetTraceDiagnostics,
614 }),
615 processDiagnostics: createEnvironmentRpcQueryAtomFamily(runtime, {
616 label: "environment-data:server:process-diagnostics",
617 tag: WS_METHODS.serverGetProcessDiagnostics,
618 }),
619 processResourceHistory: createEnvironmentRpcQueryAtomFamily(runtime, {
620 label: "environment-data:server:process-resource-history",
621 tag: WS_METHODS.serverGetProcessResourceHistory,
622 }),
623 /** Live scheduled-task list: snapshot on subscribe, fresh list after every server-side change. */
624 scheduledTasksLive: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
625 label: "environment-data:server:scheduled-tasks:live",
626 tag: WS_METHODS.scheduledTasksSubscribe,
627 }),
628 resourceTelemetry: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
629 label: "environment-data:server:resource-telemetry",
630 tag: WS_METHODS.subscribeResourceTelemetry,
631 idleTtlMs: 0,
632 }),
633 resourceTelemetryHistory: createEnvironmentRpcQueryAtomFamily(runtime, {
634 label: "environment-data:server:resource-telemetry-history",
635 tag: WS_METHODS.serverGetResourceTelemetryHistory,
636 staleTimeMs: 5_000,
637 }),
638 configProjection,
639 welcome: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
640 label: "environment-data:server:welcome",
641 tag: WS_METHODS.subscribeServerLifecycle,
642 transform: (stream) =>
643 stream.pipe(
644 Stream.mapAccum(Option.none<ServerLifecycleWelcomePayload>, projectServerWelcome),
645 ),
646 }),
647 legacyThreadMigration: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
648 label: "environment-data:server:legacy-thread-migration",
649 tag: WS_METHODS.subscribeServerLifecycle,
650 transform: (stream) =>
651 stream.pipe(
652 Stream.filterMap((event) =>
653 event.type === "legacyThreadMigration"
654 ? Result.succeed(event.payload)
655 : Result.failVoid,
656 ),
657 ),
658 }),
659 refreshProviders: createEnvironmentRpcCommand(runtime, {
660 label: "environment-data:server:refresh-providers",
661 tag: WS_METHODS.serverRefreshProviders,
662 concurrency: {
663 mode: "singleFlight",
664 key: ({ environmentId }) => environmentId,
665 },
666 }),
667 updateProvider: createEnvironmentRpcCommand(runtime, {
668 label: "environment-data:server:update-provider",
669 tag: WS_METHODS.serverUpdateProvider,
670 scheduler: configScheduler,
671 concurrency: configConcurrency,
672 }),
673 updateServer,
674 upsertKeybinding: createEnvironmentRpcCommand(runtime, {
675 label: "environment-data:server:upsert-keybinding",
676 tag: WS_METHODS.serverUpsertKeybinding,
677 scheduler: configScheduler,
678 concurrency: configConcurrency,
679 }),
680 removeKeybinding: createEnvironmentRpcCommand(runtime, {
681 label: "environment-data:server:remove-keybinding",
682 tag: WS_METHODS.serverRemoveKeybinding,
683 scheduler: configScheduler,
684 concurrency: configConcurrency,
685 }),
686 updateSettings: createEnvironmentRpcCommand(runtime, {
687 label: "environment-data:server:update-settings",
688 tag: WS_METHODS.serverUpdateSettings,
689 scheduler: configScheduler,
690 concurrency: configConcurrency,
691 }),
692 signalProcess: createEnvironmentRpcCommand(runtime, {
693 label: "environment-data:server:signal-process",
694 tag: WS_METHODS.serverSignalProcess,
695 }),
696 upsertScheduledTask: createEnvironmentRpcCommand(runtime, {
697 label: "environment-data:server:scheduled-task:upsert",
698 tag: WS_METHODS.scheduledTasksUpsert,
699 scheduler: configScheduler,
700 concurrency: configConcurrency,
701 }),
702 setScheduledTaskEnabled: createEnvironmentRpcCommand(runtime, {
703 label: "environment-data:server:scheduled-task:set-enabled",
704 tag: WS_METHODS.scheduledTasksSetEnabled,
705 scheduler: configScheduler,
706 concurrency: configConcurrency,
707 }),
708 deleteScheduledTask: createEnvironmentRpcCommand(runtime, {
709 label: "environment-data:server:scheduled-task:delete",
710 tag: WS_METHODS.scheduledTasksDelete,
711 scheduler: configScheduler,
712 concurrency: configConcurrency,
713 }),
714 // Deliberately not on the config lane: run-now blocks until the run is
715 // dispatched, and a slow run must not stall settings/keybinding/provider
716 // mutations (or other scheduled-task edits) queued behind it.
717 runScheduledTaskNow: createEnvironmentRpcCommand(runtime, {
718 label: "environment-data:server:scheduled-task:run-now",
719 tag: WS_METHODS.scheduledTasksRunNow,
720 }),
721 retryResourceTelemetry: createEnvironmentRpcCommand(runtime, {
722 label: "environment-data:server:retry-resource-telemetry",
723 tag: WS_METHODS.serverRetryResourceTelemetry,
724 concurrency: {
725 mode: "singleFlight",
726 key: ({ environmentId }) => environmentId,
727 },
728 }),
729 };
730}