Skip to content

fix(code-interpreter): use backend timestamp in JS OutputMessage - #1970

Open
lemonzoey wants to merge 1 commit into
e2b-dev:mainfrom
lemonzoey:zhouyi/fix-output-timestamp
Open

lemonzoey wants to merge 1 commit into
e2b-dev:mainfrom
lemonzoey:zhouyi/fix-output-timestamp

Conversation

@lemonzoey

Copy link
Copy Markdown

Summary

The JS Code Interpreter's parseOutput set OutputMessage.timestamp to new Date().getTime() * 1000 — the client-side clock in microseconds — ignoring the timestamp field the kernel sends with every stdout/stderr message.

This diverged from Python (which uses the backend data["timestamp"] directly) and from the documented contract (OutputMessage.timestamp is described as "Unix epoch in nanoseconds"). The JS value was from the wrong clock and the wrong unit.

Fix: read msg.timestamp in the stdout and stderr branches of parseOutput, matching the Python reference implementation. JS-only — Python is already correct.

Closes #1969.

Why this is a real bug (not a pseudo-gap)

  • Python reads data["timestamp"] with no fallback, so the kernel always sends timestamp; JS reads msg.text from the same message but drops msg.timestamp.
  • Reproduces with no sandbox/API key: feeding parseOutput a stdout message with timestamp: 1234567890 yields ~1791599674953000 (Date.now()*1000), not 1234567890.

Verification

cd packages/code-interpreter-js
pnpm vitest run tests/messaging.test.ts   # 4 passed (2 existing + 2 new)
pnpm run lint      # no new warnings
pnpm run typecheck # passes

New tests assert OutputMessage.timestamp equals the backend msg.timestamp for both stdout and stderr (construct an Execution, feed parseOutput a JSON line with a fixed timestamp, assert the captured message carries it through).

Usage example

import { Sandbox } from '@e2b/code-interpreter'

const sandbox = await Sandbox.create()

await sandbox.runCode('print("hello")', {
  onStdout: (msg) => {
    // Before: msg.timestamp was Date.now()*1000 (client clock, microseconds)
    // After:  msg.timestamp is the kernel's nanosecond timestamp, matching Python
    console.log(msg.line, msg.timestamp)
  },
})

Changeset

@e2b/code-interpreter patch — OutputMessage.timestamp now reflects the backend timestamp instead of the client clock.

The JS SDK's parseOutput set OutputMessage.timestamp to
`new Date().getTime() * 1000` (client clock, microseconds), ignoring the
`timestamp` field the kernel sends in each stdout/stderr message. The
Python SDK uses the backend `data["timestamp"]` directly, and the
OutputMessage docs describe it as "Unix epoch in nanoseconds" — so the
JS value was both from the wrong clock and the wrong unit, diverging
from Python and from the documented contract.

Read `msg.timestamp` instead, matching the Python reference impl. This
is JS-only: Python already does the right thing.

Co-Authored-By: Kscc <noreply@owtffssent.com>
@cla-bot

cla-bot Bot commented Oct 10, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: zhouyi7.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@changeset-bot

changeset-bot Bot commented Oct 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8cd9153

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@e2b/code-interpreter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T03:09:33.618631Z 8cd9153 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JS Code Interpreter OutputMessage.timestamp uses client clock, ignores backend timestamp

1 participant