Skip to content
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

Large proof state gets split into multiple messages, causes JSON parsing errors that prevent dump state display #18

Closed
klinvill opened this issue Dec 12, 2023 · 1 comment · Fixed by #19

Comments

@klinvill
Copy link
Contributor

I found that dumps failed to display proof states I expect to see in the UI after unfolding large proof states (normalizing with delta). Instead I just saw the dump function signature shown below.
image

It appears that the root cause of this problem is that a large proof state gets fragmented into multiple messages. When the extension then tries to parse these messages into JSON (at

r = JSON.parse(data);
), the fragments are not valid JSON and the messages are ignored. I'm not sure if this fragmentation is because of something the F* executable does intentionally, or if it just happens to correspond to when output buffers are flushed.

I was able to reproduce this behavior with a large enough proof state. A minimal example is given below (note the many spaces in the strings).

module Test

let _ = assert(
    "Hello world                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      "
        ==
        "Goodbye!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      "
        ) by (
        let open FStar.Tactics in
        dump "Current state:";
        smt ()
    )

Ideally I'd expect to see full proof states after dumps regardless of the size, but it may be desirable to still cap it to some large size to prevent potential resource starvation attacks or bugs.

@klinvill
Copy link
Contributor Author

klinvill commented Dec 12, 2023

This could be tied to the buffer size OCaml uses when writing to channels: https://discuss.ocaml.org/t/when-does-printf-printf-flush/12057/3. However it seems to cut off at 8192 bytes, which might be a lower limit on the javascript side.

One potential solution would be to just wait for future messages if only a partial JSON message is received, but this may be highly-susceptible to race conditions and might bork up reading other messages. Although maybe it would be simple enough to check if the next received message can be interpreted as a standalone JSON message, and if so treat it as such, if not, try to append it to the stored incomplete JSON prefix and then try to interpret the combined result as a JSON message.

Another potential solution could be to implement/use some kind of reliable transmission protocol, similar to TCP, for sending messages so that fragmented messages can be reliably assembled. But this feels like a heavyweight solution for the (presumably) rare problem I'm running into.

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 a pull request may close this issue.

1 participant