Files
Eric Allam 5ba8557a51 chore(webapp,core): remove the end-of-life v3 (engine V1) execution stack (#4236)
## Summary

v3 (the engine that ran the SDK v3 era, internally
`RunEngineVersion.V1`) is end-of-life. Following the removal of the v3
execution apps
([#4194](https://github.com/triggerdotdev/trigger.dev/pull/4194)) and
the legacy dev websocket
([#4198](https://github.com/triggerdotdev/trigger.dev/pull/4198)), this
removes the remaining v3 execution stack from the server.

Clients still on v3 (an old SDK or CLI that has not upgraded) keep
getting a clear "upgrade to v4" response. Triggers, batch triggers,
reschedules, and deploys that resolve to v3 are rejected with a graceful
4xx pointing at the migration guide, never a 5xx, so a stale client
cannot affect server health. Self-hosted instances still running v3
should stay on the 4.5.x release line until they migrate.

## What is removed

- The MarQS queue and its shared/dev queue consumers.
- The v3 socket.io namespaces (coordinator, provider, shared-queue) and
the v3 run lifecycle services (attempt, checkpoint, and batch-resume).
- The graphile-worker background job system; all live jobs already run
on `@trigger.dev/redis-worker`.
- The `DEPRECATE_V3_ENABLED` flag: v3 is now rejected unconditionally,
so the flag is gone.
- Unused v3 exports from `@trigger.dev/core` (the `v3/zodNamespace`
subpath and the legacy socket message catalogs) and the now-dead MarQS
environment variables.

## What stays

The v4 engine is untouched. The graceful v3 rejection boundary stays,
`determineEngineVersion` still detects a v3 project so it can reject it,
and the batch service plus batch-completion worker stay for current
clients. Live queue concurrency limits and metrics now read from the v4
run engine instead of MarQS, and a brand-new dev environment now
defaults to v4.



## Dependency cleanup

Removes webapp dependencies left unused by this change: `seedrandom` and
`semver` (only the removed v3 code used them) plus a set that was
already dead, their orphaned `@types` packages, and two dead files. Adds
a `knip:deps` script and a `knip.json` config so unused dependencies can
be found the same way going forward.
2026-07-13 11:32:06 +01:00

120 lines
4.3 KiB
TypeScript

import type { TriggerTaskRequestBody } from "@trigger.dev/core/v3";
import type { RunEngineVersion, TaskRun } from "@trigger.dev/database";
import { env } from "~/env.server";
import { IdempotencyKeyConcern } from "~/runEngine/concerns/idempotencyKeys.server";
import { DefaultPayloadProcessor } from "~/runEngine/concerns/payloads.server";
import { DefaultQueueManager } from "~/runEngine/concerns/queues.server";
import { DefaultTraceEventsConcern } from "~/runEngine/concerns/traceEvents.server";
import { RunEngineTriggerTaskService } from "~/runEngine/services/triggerTask.server";
import { DefaultTriggerTaskValidator } from "~/runEngine/validators/triggerTaskValidator";
import type { AuthenticatedEnvironment } from "~/services/apiAuth.server";
import { determineEngineVersion } from "../engineVersion.server";
import { tracer } from "../tracer.server";
import { V3_TRIGGER_DEPRECATION_MESSAGE } from "../engineDeprecation.server";
import { ServiceValidationError, WithRunEngine } from "./baseService.server";
export type TriggerTaskServiceOptions = {
idempotencyKey?: string;
idempotencyKeyExpiresAt?: Date;
triggerVersion?: string;
traceContext?: Record<string, unknown>;
spanParentAsLink?: boolean;
parentAsLinkType?: "replay" | "trigger";
batchId?: string;
batchIndex?: number;
customIcon?: string;
runFriendlyId?: string;
skipChecks?: boolean;
oneTimeUseToken?: string;
scheduleId?: string;
scheduleInstanceId?: string;
queueTimestamp?: Date;
overrideCreatedAt?: Date;
replayedFromTaskRunFriendlyId?: string;
planType?: string;
realtimeStreamsVersion?: "v1" | "v2";
triggerSource?: string;
triggerAction?: string;
};
export { OutOfEntitlementError } from "../outOfEntitlementError.server";
export type TriggerTaskServiceResult = {
run: TaskRun;
isCached: boolean;
// True when the mollifier gate diverted the trigger to the Redis
// buffer and `run` is a synthesised record (no PG row exists yet).
// The trigger route reads this to skip `saveRequestIdempotency` —
// caching the synth runId would mean a lost-response SDK retry hits
// a PG-miss in `handleRequestIdempotency` and falls through to a
// fresh trigger, producing a duplicate buffer entry for trigger
// calls that don't carry a task-level idempotency key.
isMollified?: boolean;
};
export const MAX_ATTEMPTS = 2;
export class TriggerTaskService extends WithRunEngine {
public async call(
taskId: string,
environment: AuthenticatedEnvironment,
body: TriggerTaskRequestBody,
options: TriggerTaskServiceOptions = {},
version?: RunEngineVersion
): Promise<TriggerTaskServiceResult | undefined> {
return await this.traceWithEnv("call()", environment, async (span) => {
span.setAttribute("taskId", taskId);
const v = await determineEngineVersion({
environment,
workerVersion: body.options?.lockToVersion,
engineVersion: version,
});
switch (v) {
case "V1": {
// v3 (engine V1) is retired. Reject the trigger with a graceful,
// actionable error instead of executing. Covers single, batch,
// schedule, replay, and triggerAndWait, which all route through here.
throw new ServiceValidationError(V3_TRIGGER_DEPRECATION_MESSAGE);
}
case "V2": {
return await this.callV2(taskId, environment, body, options);
}
}
});
}
private async callV2(
taskId: string,
environment: AuthenticatedEnvironment,
body: TriggerTaskRequestBody,
options: TriggerTaskServiceOptions = {}
): Promise<TriggerTaskServiceResult | undefined> {
const traceEventConcern = new DefaultTraceEventsConcern();
const service = new RunEngineTriggerTaskService({
prisma: this._prisma,
engine: this._engine,
queueConcern: new DefaultQueueManager(this._prisma, this._engine, this._replica),
validator: new DefaultTriggerTaskValidator(),
payloadProcessor: new DefaultPayloadProcessor(),
idempotencyKeyConcern: new IdempotencyKeyConcern(
this._prisma,
this._engine,
traceEventConcern
),
traceEventConcern,
tracer: tracer,
metadataMaximumSize: env.TASK_RUN_METADATA_MAXIMUM_SIZE,
});
return await service.call({
taskId,
environment,
body,
options,
});
}
}