Repository navigation
fix(code-interpreter): use backend timestamp in JS OutputMessage #1970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@e2b/code-interpreter': patch | ||
| --- | ||
|
|
||
| Fix `OutputMessage.timestamp` in the JS Code Interpreter to use the backend timestamp (Unix epoch in nanoseconds) sent with each stdout/stderr message, instead of the client clock (`new Date().getTime() * 1000`). The type is unchanged (`number`); this aligns the value with the documented contract and the Python SDK. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -352,7 +352,7 @@ export async function parseOutput( | |
| await onStdout({ | ||
| error: false, | ||
| line: msg.text, | ||
| timestamp: new Date().getTime() * 1000, | ||
| timestamp: msg.timestamp, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Nanosecond output times lose precision For ordinary numeric nanosecond timestamps, Learn moreThe kernel's output timestamp is in Unix-epoch nanoseconds. At today's epoch, it is around 1.7e18, well above Example: A numeric JSON timestamp of Recommended fix: Establish whether the kernel can transmit nanoseconds as decimal strings, then expose them as Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| }) | ||
| } | ||
| break | ||
|
|
@@ -362,7 +362,7 @@ export async function parseOutput( | |
| await onStderr({ | ||
| error: true, | ||
| line: msg.text, | ||
| timestamp: new Date().getTime() * 1000, | ||
| timestamp: msg.timestamp, | ||
| }) | ||
| } | ||
| break | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 String timestamps break the numeric callback contract
When the backend sends a string timestamp,
parseOutputdelivers a string despiteOutputMessage.timestampbeing typed as a number. Both output callbacks expose the wrong type to callers.Learn more
The exported
parseOutputaccepts JSON lines from the kernel. Nanosecond values exceed JavaScript's safe integer range, so a JSON producer can encode them as decimal strings; the previously supported conversion handled those strings. The callback now receives the raw string even though OutputMessage declares a number. The stderr callback has the same behavior.Example: Given
{"type":"stdout","text":"hello","timestamp":"1700000000000999999"}, the callback receives a string rather than a number.Recommended fix: Decide on a representation that preserves the backend value and has an honest public type. Normalize both stdout and stderr through one converter; if strings must remain supported, test their runtime type and precision.
Was this helpful? React with 👍 or 👎 to provide feedback.