Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
10418d8
fix(realtime): gracefully recover from ECONNRESET errors when sending…
ericallam Oct 17, 2025
fb2d548
Add support for multiple writers to a single stream by removing the E…
ericallam Oct 17, 2025
4bdda7a
Make the MetadataStream client more robust to failure and add tests
ericallam Oct 17, 2025
278aad2
Make the stream client more resilient and robust, including implement…
ericallam Oct 18, 2025
de51c26
Add some more streaming examples and markdown streaming
ericallam Oct 18, 2025
17ffdf3
s2 WIP
ericallam Oct 20, 2025
500bf15
Added realtimeStreams column to TaskRun to replace using metadata for…
ericallam Oct 21, 2025
f56ad0c
Write to s2 from the client instead of the server
ericallam Oct 21, 2025
bbdbe71
WIP
ericallam Oct 22, 2025
d6ef9be
Add env var
ericallam Oct 22, 2025
dccd43f
Loads more stuff
ericallam Oct 23, 2025
c084c1a
The stream.read() span now works better when specifying a startIndex
ericallam Oct 23, 2025
d6af637
WIP
ericallam Oct 23, 2025
33887cc
Configure the waitUntil timeout via an env var
ericallam Oct 23, 2025
a4ab169
Return stream parts from SSE class
ericallam Oct 23, 2025
fceefd9
Adds new streams icon
samejr Oct 23, 2025
5f4de7f
Layout improvements to streams inspector
samejr Oct 23, 2025
3ff8dc8
Improve layout of streams inspector
samejr Oct 23, 2025
3516897
Remove tabs if only Overview is shown
samejr Oct 23, 2025
16c17e0
Added compact view for streams and sticky copy button
ericallam Oct 23, 2025
12ddd4b
Add AI SDK demo
ericallam Oct 23, 2025
8c1e384
experiment_throttle is now just throttle
ericallam Oct 23, 2025
908dd1c
Show textwrapping, copy and modal buttons on the Properties code blocks
samejr Oct 24, 2025
d299a38
Use simplr library for plurals and flex wrap the heading info nicely
samejr Oct 24, 2025
1f00978
Moves toggle button functionality into the header with new icons
samejr Oct 24, 2025
9f837b5
Make sure the scroll view knows if it’s at the top or bottom even if …
samejr Oct 24, 2025
2303ec2
Improve loading states
samejr Oct 24, 2025
ad0954f
Add divide between heads and inspector content
samejr Oct 24, 2025
77cb137
Remove 0 padding
samejr Oct 24, 2025
6c30fda
Adds nice behaviour if a long stream key is used
samejr Oct 24, 2025
4253f84
Disable the header buttons if the content is loading
samejr Oct 24, 2025
8b3b8a5
Fixed failing test
ericallam Oct 25, 2025
6bd2354
Improved X-Resume-From-Chunk header parsing
ericallam Oct 25, 2025
92e85d8
Unify inactivity timeout threshold
ericallam Oct 25, 2025
c0f7612
If v2 streams is requested, throw an error if S2 env vars are not set
ericallam Oct 25, 2025
0326f5f
Use implicit radix arg when calling parseInt
ericallam Oct 25, 2025
83823e8
Consistent API client creation
ericallam Oct 25, 2025
81ea750
Normalize the stream source to an async iterable before passing to th…
ericallam Oct 25, 2025
3fc6e96
Refactor the metadata streams stuff to be better
ericallam Oct 25, 2025
a8110c4
properly abort streams when the waitUntil timeout occurs
ericallam Oct 25, 2025
178b490
fix the new configurable waitUntil timeout
ericallam Oct 25, 2025
234bd93
prevent memory leaks by cleaning up responses and requests
ericallam Oct 25, 2025
fd40ab7
Fix timer leak
ericallam Oct 25, 2025
4c76837
use server provided options for the s2 writer
ericallam Oct 25, 2025
f0d5e42
s2 stream writer now handles abort signals
ericallam Oct 25, 2025
581135c
Fixed core tests
ericallam Oct 25, 2025
5dcf303
No need to use keys and a Map for stream management
ericallam Oct 25, 2025
9286e9b
Fixed runStream tests
ericallam Oct 25, 2025
9e5460d
Implement TRIGGER_V2_REALTIME_STREAMS env var
ericallam Oct 25, 2025
bd18134
New streams API (sync pipe with default)
ericallam Nov 2, 2025
57db0a6
Fixed useRealtimeStream issue because of overloading
ericallam Nov 2, 2025
f80e4c0
Prevent initializing a realtime stream on a completed run
ericallam Nov 2, 2025
d4d7f01
Add streams.append
ericallam Nov 2, 2025
3cc9ba6
Nicer API and update the s2 writer to use the new append session
ericallam Nov 5, 2025
5a4deac
Use a readable stream directly
ericallam Nov 5, 2025
396f325
Implement s2 chunk deduping
ericallam Nov 5, 2025
d4e1c98
Fix tests
ericallam Nov 8, 2025
37eb03a
couple of fixes
ericallam Nov 8, 2025
e979f52
Improve stream dashboard perf with virtualization
ericallam Nov 10, 2025
a0c3963
Fix streams.append for s2, and a bunch of other little things, plus t…
ericallam Nov 10, 2025
b5db525
close the controller when signal aborts
ericallam Nov 10, 2025
967f418
Fix waitForStreams async executor
ericallam Nov 10, 2025
557b48a
change info logs to debug
ericallam Nov 10, 2025
1626195
fix streams test
ericallam Nov 10, 2025
211d804
Update changeset to be a minor update
ericallam Nov 11, 2025
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
6 changes: 6 additions & 0 deletions .changeset/quiet-falcons-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@trigger.dev/sdk": minor
"@trigger.dev/react-hooks": minor
---

Realtime streams v2
30 changes: 30 additions & 0 deletions apps/webapp/app/assets/icons/ListBulletIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export function ListBulletIcon({ className }: { className?: string }) {
return (
<svg className={className} viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M9 5H20"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M9 12H20"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M9 19H20"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
<circle cx="4" cy="5" r="1" fill="currentColor" />
<circle cx="4" cy="12" r="1" fill="currentColor" />
<circle cx="4" cy="19" r="1" fill="currentColor" />
</svg>
);
}
27 changes: 27 additions & 0 deletions apps/webapp/app/assets/icons/MoveToBottomIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export function MoveToBottomIcon({ className }: { className?: string }) {
return (
<svg className={className} viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M12 15L12 3"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M3 21L21 21"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M7.5 12.5L12 17L16.5 12.5"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
);
}
20 changes: 20 additions & 0 deletions apps/webapp/app/assets/icons/SnakedArrowIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function SnakedArrowIcon({ className }: { className?: string }) {
return (
<svg className={className} viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M5 5H16C17.6569 5 19 6.34315 19 8L19 8.5C19 10.1569 17.6569 11.5 16 11.5H8C6.34314 11.5 5 12.8431 5 14.5L5 15C4.99999 16.6569 6.34314 18 8 18H18.634"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M16 21L19 18L16 15"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
);
}
10 changes: 10 additions & 0 deletions apps/webapp/app/assets/icons/StreamsIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function StreamsIcon({ className }: { className?: string }) {
return (
<svg className={className} viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3 19C3 19 5.01155 17 8 17C10.9885 17 13 18.9973 16 18.9973C19 18.9973 21 17 21 17" stroke="currentColor" strokeWidth="2" strokeLinecap="round"/>
<path d="M3 13.0001C3 13.0001 5.01155 11 8 11C10.9885 11 13 13 16 13C19 13 21 11.0001 21 11.0001" stroke="currentColor" strokeWidth="2" strokeLinecap="round"/>
<path d="M3 7C3 7 5.01155 5 8 5C10.9885 5 13 6.9973 16 6.9973C19 6.9973 21 5 21 5" stroke="currentColor" strokeWidth="2" strokeLinecap="round"/>
</svg>
);
}

3 changes: 3 additions & 0 deletions apps/webapp/app/components/runs/v3/RunIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { TriggerIcon } from "~/assets/icons/TriggerIcon";
import { PythonLogoIcon } from "~/assets/icons/PythonLogoIcon";
import { TraceIcon } from "~/assets/icons/TraceIcon";
import { WaitpointTokenIcon } from "~/assets/icons/WaitpointTokenIcon";
import { StreamsIcon } from "~/assets/icons/StreamsIcon";

type TaskIconProps = {
name: string | undefined;
Expand Down Expand Up @@ -107,6 +108,8 @@ export function RunIcon({ name, className, spanName }: TaskIconProps) {
case "task-hook-onFailure":
case "task-hook-catchError":
return <FunctionIcon className={cn(className, "text-error")} />;
case "streams":
return <StreamsIcon className={cn(className, "text-text-dimmed")} />;
}

return <InformationCircleIcon className={cn(className, "text-text-dimmed")} />;
Expand Down
11 changes: 11 additions & 0 deletions apps/webapp/app/env.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ const EnvironmentSchema = z
.string()
.default(process.env.REDIS_TLS_DISABLED ?? "false"),
REALTIME_STREAMS_REDIS_CLUSTER_MODE_ENABLED: z.string().default("0"),
REALTIME_STREAMS_INACTIVITY_TIMEOUT_MS: z.coerce.number().int().default(60000), // 1 minute

REALTIME_MAXIMUM_CREATED_AT_FILTER_AGE_IN_MS: z.coerce
.number()
Expand Down Expand Up @@ -1222,6 +1223,16 @@ const EnvironmentSchema = z
EVENT_LOOP_MONITOR_UTILIZATION_SAMPLE_RATE: z.coerce.number().default(0.05),

VERY_SLOW_QUERY_THRESHOLD_MS: z.coerce.number().int().optional(),

REALTIME_STREAMS_S2_BASIN: z.string().optional(),
REALTIME_STREAMS_S2_ACCESS_TOKEN: z.string().optional(),
REALTIME_STREAMS_S2_LOG_LEVEL: z
.enum(["log", "error", "warn", "info", "debug"])
.default("info"),
REALTIME_STREAMS_S2_FLUSH_INTERVAL_MS: z.coerce.number().int().default(100),
REALTIME_STREAMS_S2_MAX_RETRIES: z.coerce.number().int().default(10),
REALTIME_STREAMS_S2_WAIT_SECONDS: z.coerce.number().int().default(60),
WAIT_UNTIL_TIMEOUT_MS: z.coerce.number().int().default(600_000),
})
.and(GithubAppEnvSchema)
.and(S2EnvSchema);
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/app/models/organization.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function createOrganization(
role: "ADMIN",
},
},
v3Enabled: !features.isManagedCloud,
v3Enabled: true,
},
include: {
members: true,
Expand Down
36 changes: 36 additions & 0 deletions apps/webapp/app/presenters/v3/SpanPresenter.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { WaitpointPresenter } from "./WaitpointPresenter.server";
import { engine } from "~/v3/runEngine.server";
import { resolveEventRepositoryForStore } from "~/v3/eventRepository/index.server";
import { IEventRepository, SpanDetail } from "~/v3/eventRepository/eventRepository.types";
import { safeJsonParse } from "~/utils/json";

type Result = Awaited<ReturnType<SpanPresenter["call"]>>;
export type Span = NonNullable<NonNullable<Result>["span"]>;
Expand Down Expand Up @@ -551,6 +552,41 @@ export class SpanPresenter extends BasePresenter {
},
};
}
case "realtime-stream": {
if (!span.entity.id) {
logger.error(`SpanPresenter: No realtime stream id`, {
spanId,
realtimeStreamId: span.entity.id,
});
return { ...data, entity: null };
}

const [runId, streamKey] = span.entity.id.split(":");

if (!runId || !streamKey) {
logger.error(`SpanPresenter: Invalid realtime stream id`, {
spanId,
realtimeStreamId: span.entity.id,
});
return { ...data, entity: null };
}

const metadata = span.entity.metadata
? (safeJsonParse(span.entity.metadata) as Record<string, unknown> | undefined)
: undefined;

return {
...data,
entity: {
type: "realtime-stream" as const,
object: {
runId,
streamKey,
metadata,
},
},
};
}
Comment on lines +555 to +589
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Make realtime-stream id parsing robust; normalize metadata null-to-undefined.

Split at the first colon to preserve streamKey with colons; ensure metadata is undefined (not null) on parse failure.

-        const [runId, streamKey] = span.entity.id.split(":");
+        const idx = span.entity.id.indexOf(":");
+        const runId = idx > -1 ? span.entity.id.slice(0, idx) : "";
+        const streamKey = idx > -1 ? span.entity.id.slice(idx + 1) : "";
@@
-        const metadata = span.entity.metadata
-          ? (safeJsonParse(span.entity.metadata) as Record<string, unknown> | undefined)
-          : undefined;
+        const metadata = span.entity.metadata
+          ? ((safeJsonParse(span.entity.metadata) ?? undefined) as
+              | Record<string, unknown>
+              | undefined)
+          : undefined;
🤖 Prompt for AI Agents
In apps/webapp/app/presenters/v3/SpanPresenter.server.ts around lines 555 to
589, the realtime-stream id handling should split only at the first colon and
normalize metadata null to undefined: instead of span.entity.id.split(":"), find
the first colon (indexOf) and derive runId = id.slice(0, idx) and streamKey =
id.slice(idx + 1) so streamKey may contain additional colons; update the
invalid-id check accordingly. For metadata, call safeJsonParse and if it returns
null explicitly convert it to undefined before assigning metadata so the
returned entity.metadata is undefined on parse failure or absence.

default:
return { ...data, entity: null };
}
Expand Down
12 changes: 4 additions & 8 deletions apps/webapp/app/routes/api.v1.tasks.$taskId.trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const HeadersSchema = z.object({
"x-trigger-client": z.string().nullish(),
"x-trigger-engine-version": RunEngineVersionSchema.nullish(),
"x-trigger-request-idempotency-key": z.string().nullish(),
"x-trigger-realtime-streams-version": z.string().nullish(),
traceparent: z.string().optional(),
tracestate: z.string().optional(),
});
Expand Down Expand Up @@ -63,6 +64,7 @@ const { action, loader } = createActionApiRoute(
"x-trigger-client": triggerClient,
"x-trigger-engine-version": engineVersion,
"x-trigger-request-idempotency-key": requestIdempotencyKey,
"x-trigger-realtime-streams-version": realtimeStreamsVersion,
} = headers;

const cachedResponse = await handleRequestIdempotency(requestIdempotencyKey, {
Expand Down Expand Up @@ -108,14 +110,7 @@ const { action, loader } = createActionApiRoute(
options: body.options,
isFromWorker,
traceContext,
});

logger.debug("[otelContext]", {
taskId: params.taskId,
headers,
options: body.options,
isFromWorker,
traceContext,
realtimeStreamsVersion,
});

const idempotencyKeyExpiresAt = resolveIdempotencyKeyTTL(idempotencyKeyTTL);
Expand All @@ -131,6 +126,7 @@ const { action, loader } = createActionApiRoute(
traceContext,
spanParentAsLink: spanParentAsLink === 1,
oneTimeUseToken,
realtimeStreamsVersion: realtimeStreamsVersion ?? undefined,
},
engineVersion ?? undefined
);
Expand Down
43 changes: 26 additions & 17 deletions apps/webapp/app/routes/realtime.v1.streams.$runId.$streamId.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import { ActionFunctionArgs } from "@remix-run/server-runtime";
import { z } from "zod";
import { $replica } from "~/db.server";
import { relayRealtimeStreams } from "~/services/realtime/relayRealtimeStreams.server";
import { getRealtimeStreamInstance } from "~/services/realtime/v1StreamsGlobal.server";
import { createLoaderApiRoute } from "~/services/routeBuilders/apiBuilder.server";

const ParamsSchema = z.object({
runId: z.string(),
streamId: z.string(),
});

export async function action({ request, params }: ActionFunctionArgs) {
const $params = ParamsSchema.parse(params);

if (!request.body) {
return new Response("No body provided", { status: 400 });
}

return relayRealtimeStreams.ingestData(request.body, $params.runId, $params.streamId);
}

export const loader = createLoaderApiRoute(
{
params: ParamsSchema,
Expand Down Expand Up @@ -51,12 +40,32 @@ export const loader = createLoaderApiRoute(
},
},
async ({ params, request, resource: run, authentication }) => {
return relayRealtimeStreams.streamResponse(
request,
run.friendlyId,
params.streamId,
// Get Last-Event-ID header for resuming from a specific position
const lastEventId = request.headers.get("Last-Event-ID") || undefined;

const timeoutInSecondsRaw = request.headers.get("Timeout-Seconds") ?? undefined;
const timeoutInSeconds = timeoutInSecondsRaw ? parseInt(timeoutInSecondsRaw) : undefined;

if (timeoutInSeconds && isNaN(timeoutInSeconds)) {
return new Response("Invalid timeout seconds", { status: 400 });
}

if (timeoutInSeconds && timeoutInSeconds < 1) {
return new Response("Timeout seconds must be greater than 0", { status: 400 });
}

if (timeoutInSeconds && timeoutInSeconds > 600) {
return new Response("Timeout seconds must be less than 600", { status: 400 });
}

const realtimeStream = getRealtimeStreamInstance(
authentication.environment,
request.signal
run.realtimeStreamsVersion
);

return realtimeStream.streamResponse(request, run.friendlyId, params.streamId, request.signal, {
lastEventId,
timeoutInSeconds,
});
}
);
Loading
Loading