Skip to content
Closed
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
6 changes: 6 additions & 0 deletions .server-changes/fix-otlp-nanosecond-bigint-precision.md

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Three unrelated fixes in one PR

The PR describes zero-delay retries but also changes trace timestamps and Realtime status helpers. The contribution guide requires one issue per PR.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
area: webapp
type: fix
---

Fix OTLP trace timestamps losing precision for runs after approximately 2255 AD. Timestamps are now computed with full 64-bit integer arithmetic.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Misleading date in timestamp release note

The old timestamp conversion already rounds some present-day dates. The fix affects server-generated event times, not incoming OTLP timestamps.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

4 changes: 2 additions & 2 deletions apps/webapp/app/v3/eventRepository/common.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function extractContextFromCarrier(carrier: Record<string, unknown>) {
}

export function getNowInNanoseconds(): bigint {
return BigInt(new Date().getTime() * 1_000_000);
return BigInt(new Date().getTime()) * BigInt(1_000_000);
}

export function getDateFromNanoseconds(nanoseconds: bigint): Date {
Expand All @@ -40,7 +40,7 @@ export function calculateDurationFromStart(
) {
const $endtime = typeof endTime === "string" ? new Date(endTime) : endTime;

const duration = Number(BigInt($endtime.getTime() * 1_000_000) - startTime);
const duration = Number(BigInt($endtime.getTime()) * BigInt(1_000_000) - startTime);

if (minimumDuration && duration < minimumDuration) {
return minimumDuration;
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/app/v3/eventRepository/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ async function recordRunEvent(
runId: foundRun.friendlyId,
...attributes,
},
startTime: BigInt((startTime?.getTime() ?? Date.now()) * 1_000_000),
startTime: BigInt(startTime?.getTime() ?? Date.now()) * BigInt(1_000_000),
...optionsRest,
});

Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/app/v3/runEngineHandlers.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ export function registerRunEngineEventBusHandlers() {
);

await eventRepository.recordEvent(retryMessage, {
startTime: BigInt(time.getTime() * 1000000),
startTime: BigInt(time.getTime()) * BigInt(1_000_000),
taskSlug: run.taskIdentifier,
environment,
attributes: {
Expand Down
4 changes: 2 additions & 2 deletions internal-packages/run-engine/src/engine/retrying.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function retryOutcomeFromCompletion(

const delay = calculateNextRetryDelay(oomResult.retrySettings, attemptNumber ?? 1);

if (!delay) {
if (delay === undefined) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Immediate OOM retries exceed attempt limits

When a run reaches its per-run limit and runs out of memory, retryOutcomeFromCompletion can still schedule a zero-delay retry. retryOOMOnMachine uses the task’s retry settings instead of the run’s attempt limit. The extra attempt runs on the fallback machine.

Learn more

The trigger service passes the caller’s maxAttempts to the engine. Dequeue preserves that per-run limit and saves the task’s original retry settings separately. The OOM lookup reads only the task settings, and the ordinary attempt-limit check runs after the OOM branch has already returned. Previously a zero delay stopped that branch before it could use the wrong limit. Now attempt completion requeues the run on the fallback machine.

Example: Deploy a task with retry.maxAttempts: 3, minTimeoutInMs: 0, and an OOM fallback machine. Trigger it with { maxAttempts: 1 } and let the first attempt run out of memory. The engine queues a second attempt instead of ending the run.

Recommended fix: Include the run’s maxAttempts in retryOOMOnMachine’s existing read and use it as the effective attempt limit when present, without discarding the valid zero delay. Add an engine test that compares an immediate OOM retry with and without a one-attempt override.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

//no more retries left
return { outcome: "fail_run", sanitizedError, wasOOMError: true };
}
Expand Down Expand Up @@ -180,7 +180,7 @@ export function retrySettingsFromLockedConfig(

const nextDelay = calculateNextRetryDelay(parsedRetryConfig.data, attemptNumber ?? 1);

if (!nextDelay) {
if (nextDelay === undefined) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/v3/apiClient/runStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ export class RunSubscription<TRunTypes extends AnyRunTypes> {
const queuedStatuses = ["PENDING_VERSION", "QUEUED", "PENDING", "DELAYED"];
const waitingStatuses = ["WAITING"];
const executingStatuses = ["DEQUEUED", "EXECUTING"];
const failedStatuses = ["FAILED", "CRASHED", "SYSTEM_FAILURE", "EXPIRED", "TIMED_OUT"];
const failedStatuses = ["FAILED", "CRASHED", "SYSTEM_FAILURE", "EXPIRED", "TIMED_OUT", "CANCELED"];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Canceled runs reported as failures

When a subscriber receives a canceled run, booleanHelpersFromRunStatus now emits isFailed: true alongside isCancelled: true. The Realtime run contract treats cancellation separately from failure.

Learn more

subscribeToRun delivers run objects with status helpers, and the Realtime contract lists failure statuses separately from cancellation. RunSubscription closes based on finishedAt, not isFailed, so marking the run failed is not necessary to close its subscription.

Example: Cancel a run while subscribed to it. The final update reports status: "CANCELED", isCancelled: true, and now isFailed: true, so a subscription that routes failed runs to a failure handler also routes cancellations there.

Recommended fix: Keep CANCELED out of failedStatuses. If the intended behavior is to mark canceled runs complete, add cancellation to the isCompleted expression separately and update its documentation.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Missing changeset for Realtime status

The package changelog has no changeset for the Realtime status change. The release-note rules require one for user-visible package behavior.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

const successfulStatuses = ["COMPLETED"];

function booleanHelpersFromRunStatus(status: RunStatus) {
Expand Down