-
Notifications
You must be signed in to change notification settings - Fork 17
[Backend] Refactor ipynb kernel messages serialization #436
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
[Backend] Refactor ipynb kernel messages serialization #436
Conversation
ui/src/components/nodes/Code.tsx
Outdated
<Box | ||
component="pre" | ||
whiteSpace="pre-wrap" | ||
key={i + 1} |
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.
runtime/src/zmq-utils.ts
Outdated
// There's no exec_count in display_data, thus we pass in the session exec_count | ||
count: exec_count, |
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.
Could we pass in 0? This value doesn't seem to be useful. Thus, I don't feel maintaining a session exec_count is necessary. It increases the logic complexity.
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.
I think the count in execute_result
is enough.
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.
I think the count in
execute_result
is enough.
The tricky part is that execute_result
is not always available, instead, IIUC, execute_reply
would be the last messages in each cell run. The key is how to update the count
properly, the logic would be either on the frontend or backend.
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.
I think we can wait until the final execution results before setting the count. This should be consistent with the behavior of Jupyter?
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.
I think we can wait until the final execution results before setting the count. This should be consistent with the behavior of Jupyter?
Yes, I think we can make it in the frontend as well.
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.
I'm not sure if maintaining session_exec_count
ourselves is accurate. I'd vote for using msgs.content.execution_count
because it is always accurate and seems enough for the purpose of showing a count.
text?: string; | ||
count: number; | ||
image?: string; | ||
}[]; |
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.
I am not confident about changing this. It is a breaking change, the old values in the DB need migration to work with the new code.
If we really want to change this, we need to supply a DB migration script or procedure/function.
I think the issue you are trying to fix is:
- the order of stderr
- being able to display multiple images (at the end, not to be mixed with stdout/stderr streams)
I think you can fix (1) without introducing this schema change. For 2, I'd suggest skipping it for now, it's not crucial.
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.
Also, using an array to store streams doesn't sound like a good idea. The stream can come at any granularity, e.g., commonly line-by-line using because \n
flushes stream in most languages, or users may call flush()
manually.
I believe "stream" is supposed to be concatenated together upon receiving.
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.
In summary, I suggest fixing only issue 1 here, with minimal change so that we don't have to worry about migration. Forget about 2, it's not important.
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.
It's better to open another PR to fix issue 1, and leave this PR for future reference.
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.
Also, using an array to store streams doesn't sound like a good idea. The stream can come at any granularity, e.g., commonly line-by-line using because
\n
flushes stream in most languages, or users may callflush()
manually.I believe "stream" is supposed to be concatenated together upon receiving.
So the change here is put all the returned messages from kernel in an array, rather than manually separating off each message and concatenating the text
field. Ipynb kernel would decide how to concatenate each line's execution.
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.
I am not confident about changing this. It is a breaking change, the old values in the DB need migration to work with the new code.
If we really want to change this, we need to supply a DB migration script or procedure/function.
I think the issue you are trying to fix is:
- the order of stderr
- being able to display multiple images (at the end, not to be mixed with stdout/stderr streams)
I think you can fix (1) without introducing this schema change. For 2, I'd suggest skipping it for now, it's not crucial.
IIUC, the JSON format change will not render the result
filed correctly in the existing repos, in that case, will a re-execution of each pod overwrite the result field?
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.
Yes, you are right, the re-execution will fix the result field. The only thing that breaks is the existing result, which might not be that important to do a migration for it, especially at this early release point.
What do you say about these two issues? @senwang86 The rest of the code looks good to me. |
These 2 issues are addressed in the ab4818c, can you give it a test? |
ui/src/components/nodes/Code.tsx
Outdated
return <></>; | ||
} | ||
default: | ||
return <></>; |
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.
The console warning is still there, caused by these two lines. Adding key={combineKey}
will fix it.
I see, SG. |
Cool, thanks! |
Summary
Currently, the kernel messages are concatenated and stored in a single object, i.e.,
pod.result
. This concatenation behavior creates a few discrepancy with Colab regarding the output results, e.g., it can't produce multiple plots in a single pod, the order of line execution might confuse users (see screenshots in Test section)Test
Before
After
Follow-up
ResultBlock
inCode.tsx
needs more tuning