Skip to content

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

Merged
mishushakov merged 2 commits into
mainfrom
devin/1793633113-accept-pr-1970
Nov 2, 2026
Merged

mishushakov merged 2 commits into
mainfrom
devin/1793633113-accept-pr-1970

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Lands community PR #1970 by @lemonzoey (squash-merged into this branch) onto main. Closes #1969.

The JS Code Interpreter's parseOutput set OutputMessage.timestamp to the client clock in microseconds, ignoring the kernel-provided timestamp. Python already uses the backend value, and the documented contract is Unix epoch nanoseconds.

- timestamp: new Date().getTime() * 1000,
+ timestamp: msg.timestamp,

Applied to both the stdout and stderr branches in packages/code-interpreter-js/src/messaging.ts. Type stays number. Includes a @e2b/code-interpreter patch changeset.

Precision: nanosecond epochs (~1.7e18) exceed Number.MAX_SAFE_INTEGER, so the JS value is only precise to multiples of 256 ns. Python keeps the exact int. This limit is documented on OutputMessage.timestamp and in the changeset. Tests in tests/messaging.test.ts parse raw JSON lines with a realistic non-multiple-of-256 value and check the rounding.

Usage example

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

const sandbox = await Sandbox.create()
await sandbox.runCode('print("hello")', {
  onStdout: (msg) => {
    // msg.timestamp is now the kernel's Unix-epoch nanosecond timestamp (~256 ns precision)
    console.log(msg.line, msg.timestamp)
  },
})

Link to Devin session: https://app.devin.ai/sessions/e37c31685ac645f785744678cd18146e
Open in Devin Desktop: https://app.devin.ai/desktop/session/e37c31685ac645f785744678cd18146e?variant=devin


Devin Review

## 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`. The type stays `number` (unchanged), matching the Python
reference implementation and the documented nanosecond contract. 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
dropped `msg.timestamp`.
- Reproduces with no sandbox/API key: feeding `parseOutput` a stdout
message with `timestamp: 1700000000000000000` yields `~1791599674953000`
(`Date.now()*1000`), not the backend value.

## Verification

```bash
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

```ts
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 Unix-epoch nanosecond timestamp
    console.log(msg.line, msg.timestamp)
  },
})
```

## Changeset

`@e2b/code-interpreter` **patch** — `OutputMessage.timestamp` now
reflects the backend timestamp instead of the client clock. Type
unchanged (`number`), so no breaking change.

Co-authored-by: lemonzoey <25550414+lemonzoey@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@cla-bot cla-bot Bot added the cla-signed label Nov 2, 2026
@changeset-bot

changeset-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6129dd3

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 Nov 2, 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-11-02T15:27:24.351863Z be57f80 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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TASTE.md review: complies — no violations found (checked T-1 parity, T-27 streaming callbacks, T-52 backend as source of truth, T-54/T-69 public surface & docs); the change brings JS OutputMessage.timestamp in line with the Python SDK and the documented nanosecond contract.

Written by Devin

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from dbb71dd. Download artifacts from this workflow run.

JS SDK (e2b@2.62.1-devin-1793633113-accept-pr-1970.0, with @e2b/dockerfile-utils@0.1.2-devin-1793633113-accept-pr-1970.0):

npm install ./e2b-dockerfile-utils-0.1.2-devin-1793633113-accept-pr-1970.0.tgz ./e2b-2.62.1-devin-1793633113-accept-pr-1970.0.tgz

CLI (@e2b/cli@2.23.1-devin-1793633113-accept-pr-1970.0):

npm install ./e2b-cli-2.23.1-devin-1793633113-accept-pr-1970.0.tgz

Code Interpreter JS SDK (@e2b/code-interpreter@2.9.1-devin-1793633113-accept-pr-1970.0):

npm install ./e2b-code-interpreter-2.9.1-devin-1793633113-accept-pr-1970.0.tgz

Desktop JS SDK (@e2b/desktop@2.5.1-devin-1793633113-accept-pr-1970.0):

npm install ./e2b-desktop-2.5.1-devin-1793633113-accept-pr-1970.0.tgz

Python SDK (e2b==2.62.0+devin.1793633113.accept.pr.1970, with e2b-dockerfile-utils==0.1.1+devin.1793633113.accept.pr.1970):

pip install ./e2b_dockerfile_utils-0.1.1+devin.1793633113.accept.pr.1970-py3-none-any.whl ./e2b-2.62.0+devin.1793633113.accept.pr.1970-py3-none-any.whl

Code Interpreter Python SDK (e2b-code-interpreter==2.11.6+devin.1793633113.accept.pr.1970):

pip install ./e2b_code_interpreter-2.11.6+devin.1793633113.accept.pr.1970-py3-none-any.whl

Desktop Python SDK (e2b-desktop==2.7.2+devin.1793633113.accept.pr.1970):

pip install ./e2b_desktop-2.7.2+devin.1793633113.accept.pr.1970-py3-none-any.whl

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

… in JS OutputMessage

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mishushakov
mishushakov enabled auto-merge (squash) November 2, 2026 18:11
@mishushakov
mishushakov merged commit ac0727b into main Nov 2, 2026
35 checks passed
@mishushakov
mishushakov deleted the devin/1793633113-accept-pr-1970 branch November 2, 2026 18:11
@linear-code

linear-code Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

SDK-359

SDK-40

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants