From 3827f4d0973d6596aaf9167dafefd7dfa2c0be4c Mon Sep 17 00:00:00 2001 From: okxint Date: Fri, 9 Oct 2026 15:21:24 +0530 Subject: [PATCH 1/3] fix: use BigInt arithmetic for nanosecond timestamp conversion Multiplying Date.getTime() by 1_000_000 as a float before converting to BigInt causes IEEE 754 precision loss once the product exceeds Number.MAX_SAFE_INTEGER (~9007T, which ms * 1e6 hits around 2255 AD). The correct pattern already exists in convertDateToNanoseconds(): BigInt(date.getTime()) * BigInt(1_000_000) Apply it consistently to the three call sites that still use the float-multiply pattern (getNowInNanoseconds, calculateDurationFromStart, and the runEngineHandlers retry-event recordEvent call). --- .server-changes/fix-otlp-nanosecond-bigint-precision.md | 6 ++++++ apps/webapp/app/v3/eventRepository/common.server.ts | 4 ++-- apps/webapp/app/v3/eventRepository/index.server.ts | 2 +- apps/webapp/app/v3/runEngineHandlers.server.ts | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 .server-changes/fix-otlp-nanosecond-bigint-precision.md diff --git a/.server-changes/fix-otlp-nanosecond-bigint-precision.md b/.server-changes/fix-otlp-nanosecond-bigint-precision.md new file mode 100644 index 00000000000..c3fc806cfa6 --- /dev/null +++ b/.server-changes/fix-otlp-nanosecond-bigint-precision.md @@ -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. diff --git a/apps/webapp/app/v3/eventRepository/common.server.ts b/apps/webapp/app/v3/eventRepository/common.server.ts index 346e2ab6419..3dce9202eca 100644 --- a/apps/webapp/app/v3/eventRepository/common.server.ts +++ b/apps/webapp/app/v3/eventRepository/common.server.ts @@ -26,7 +26,7 @@ export function extractContextFromCarrier(carrier: Record) { } 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 { @@ -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; diff --git a/apps/webapp/app/v3/eventRepository/index.server.ts b/apps/webapp/app/v3/eventRepository/index.server.ts index c599f4e6b96..670ec60f014 100644 --- a/apps/webapp/app/v3/eventRepository/index.server.ts +++ b/apps/webapp/app/v3/eventRepository/index.server.ts @@ -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, }); diff --git a/apps/webapp/app/v3/runEngineHandlers.server.ts b/apps/webapp/app/v3/runEngineHandlers.server.ts index ee4ef2e278d..08e3194bfc7 100644 --- a/apps/webapp/app/v3/runEngineHandlers.server.ts +++ b/apps/webapp/app/v3/runEngineHandlers.server.ts @@ -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: { From 185d564ce891818cdce4ca003dc285f030e7332e Mon Sep 17 00:00:00 2001 From: okxint Date: Tue, 17 Nov 2026 10:26:41 -0800 Subject: [PATCH 2/3] fix(core): include CANCELED in failedStatuses so isCompleted is true for cancelled runs booleanHelpersFromRunStatus omitted CANCELED from failedStatuses, so realtime run shapes returned isCompleted: false and isFailed: false for cancelled runs. The REST API presenter correctly sets both to true. Consumers checking run.isCompleted to gate teardown logic silently skipped cancelled runs. --- packages/core/src/v3/apiClient/runStream.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/v3/apiClient/runStream.ts b/packages/core/src/v3/apiClient/runStream.ts index 4b600fe7f48..8f6179cc0ff 100644 --- a/packages/core/src/v3/apiClient/runStream.ts +++ b/packages/core/src/v3/apiClient/runStream.ts @@ -957,7 +957,7 @@ export class RunSubscription { 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"]; const successfulStatuses = ["COMPLETED"]; function booleanHelpersFromRunStatus(status: RunStatus) { From 7f7d24a5ea96fb435e92d7f4c20015c1217ac8bd Mon Sep 17 00:00:00 2001 From: okxint Date: Fri, 27 Nov 2026 07:50:09 -0600 Subject: [PATCH 3/3] fix(run-engine): treat delay=0 as immediate retry, not no-retry calculateNextRetryDelay() returns undefined when retries are exhausted and a number (including 0) when a retry should happen. The !delay guard was coercing 0 to false, causing runs configured with an immediate retry (delay of 0ms) to be treated as having no retries left and failed prematurely. Switch to explicit undefined checks in both the OOM retry path and the general retry path. --- internal-packages/run-engine/src/engine/retrying.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal-packages/run-engine/src/engine/retrying.ts b/internal-packages/run-engine/src/engine/retrying.ts index 227334bc4f7..da71569ae2f 100644 --- a/internal-packages/run-engine/src/engine/retrying.ts +++ b/internal-packages/run-engine/src/engine/retrying.ts @@ -67,7 +67,7 @@ export async function retryOutcomeFromCompletion( const delay = calculateNextRetryDelay(oomResult.retrySettings, attemptNumber ?? 1); - if (!delay) { + if (delay === undefined) { //no more retries left return { outcome: "fail_run", sanitizedError, wasOOMError: true }; } @@ -180,7 +180,7 @@ export function retrySettingsFromLockedConfig( const nextDelay = calculateNextRetryDelay(parsedRetryConfig.data, attemptNumber ?? 1); - if (!nextDelay) { + if (nextDelay === undefined) { return; }