Skip to content

Instantly share code, notes, and snippets.

@tlkahn
Created September 1, 2026 23:41
Show Gist options
  • Select an option

  • Save tlkahn/f4a033bbd5879228686c5c487a7380ac to your computer and use it in GitHub Desktop.

Select an option

Save tlkahn/f4a033bbd5879228686c5c487a7380ac to your computer and use it in GitHub Desktop.
plantuml from stream-demo.md
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentStyleType="text/css" data-diagram-type="SEQUENCE" height="709px" preserveAspectRatio="none" style="width:798px;height:709px;background:#FFFFFF;" version="1.1" viewBox="0 0 798 709" width="798px" zoomAndPan="magnify"><defs/><g><g class="title" data-source-line="1"><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="700" lengthAdjust="spacing" textLength="400.0732" x="195.7446" y="28.5352">generate(): invocation logic across the thread boundary</text></g><rect fill="none" height="264.7949" style="stroke:#000000;stroke-width:1.5;" width="772.5625" x="10" y="208.3965"/><g class="participant-lifeline" data-entity-uid="part1" data-qualified-name="NET" data-source-line="5" id="part1-lifeline"><g><title>Network side</title><rect fill="#000000" fill-opacity="0.00000" height="617.9004" width="8" x="70.2603" y="90.4648"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5,5;" x1="74" x2="74" y1="90.4648" y2="708.3652"/></g></g><g class="participant-lifeline" data-entity-uid="part2" data-qualified-name="MB" data-source-line="6" id="part2-lifeline"><g><title>Mailbox</title><rect fill="#000000" fill-opacity="0.00000" height="617.9004" width="8" x="330.0566" y="90.4648"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5,5;" x1="333.1162" x2="333.1162" y1="90.4648" y2="708.3652"/></g></g><g class="participant-lifeline" data-entity-uid="part3" data-qualified-name="ENG" data-source-line="7" id="part3-lifeline"><g><title>Engine thread</title><rect fill="#000000" fill-opacity="0.00000" height="617.9004" width="8" x="427.9805" y="90.4648"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5,5;" x1="430.9971" x2="430.9971" y1="90.4648" y2="708.3652"/></g></g><g class="participant-lifeline" data-entity-uid="part4" data-qualified-name="GPU" data-source-line="8" id="part4-lifeline"><g><title>GPU</title><rect fill="#000000" fill-opacity="0.00000" height="617.9004" width="8" x="611.9985" y="90.4648"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5,5;" x1="615.2207" x2="615.2207" y1="90.4648" y2="708.3652"/></g></g><g class="participant-lifeline" data-entity-uid="part5" data-qualified-name="STR" data-source-line="9" id="part5-lifeline"><g><title>Stream</title><rect fill="#000000" fill-opacity="0.00000" height="617.9004" width="8" x="716.189" y="90.4648"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5,5;" x1="719.8154" x2="719.8154" y1="90.4648" y2="708.3652"/></g></g><g class="participant participant-head" data-entity-uid="part1" data-qualified-name="NET" data-source-line="5" id="part1-head"><rect fill="#E2E2F0" height="46.9766" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="108.5205" x="20" y="42.4883"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="88.9014" x="29.8096" y="63.0234">Network side</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="94.5205" x="27" y="79.5117">(client thread)</text></g><g class="participant participant-head" data-entity-uid="part2" data-qualified-name="MB" data-source-line="6" id="part2-head"><rect fill="#E2E2F0" height="46.9766" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="67.8809" x="300.1162" y="42.4883"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="53.8809" x="307.1162" y="63.0234">Mailbox</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="52.958" x="307.5776" y="79.5117">(Queue)</text></g><g class="participant participant-head" data-entity-uid="part3" data-qualified-name="ENG" data-source-line="7" id="part3-head"><rect fill="#E2E2F0" height="30.4883" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="107.9668" x="377.9971" y="58.9766"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="93.9668" x="384.9971" y="79.5117">Engine thread</text></g><g class="participant participant-head" data-entity-uid="part4" data-qualified-name="GPU" data-source-line="8" id="part4-head"><rect fill="#E2E2F0" height="30.4883" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="41.5557" x="595.2207" y="58.9766"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="27.5557" x="602.2207" y="79.5117">GPU</text></g><g class="participant participant-head" data-entity-uid="part5" data-qualified-name="STR" data-source-line="9" id="part5-head"><rect fill="#E2E2F0" height="46.9766" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="104.7471" x="667.8154" y="42.4883"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="47.1064" x="696.6357" y="63.0234">Stream</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="90.7471" x="674.8154" y="79.5117">(per-request)</text></g><g class="message" data-entity-1="part1" data-entity-2="part1" data-source-line="11" id="msg1"><line style="stroke:#181818;stroke-width:1;" x1="74.2603" x2="116.2603" y1="121.7754" y2="121.7754"/><line style="stroke:#181818;stroke-width:1;" x1="116.2603" x2="116.2603" y1="121.7754" y2="134.7754"/><line style="stroke:#181818;stroke-width:1;" x1="75.2603" x2="116.2603" y1="134.7754" y2="134.7754"/><polygon fill="#181818" points="85.2603,130.7754,75.2603,134.7754,85.2603,138.7754,81.2603,134.7754" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="179.1499" x="81.2603" y="117.0332">Request.new -&gt; Stream.new</text></g><g class="message" data-entity-1="part1" data-entity-2="part2" data-source-line="12" id="msg2"><polygon fill="#181818" points="322.0566,160.0859,332.0566,164.0859,322.0566,168.0859,326.0566,164.0859" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;" x1="74.2603" x2="328.0566" y1="164.0859" y2="164.0859"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="235.7964" x="81.2603" y="159.3438">queue &lt;&lt; req (command goes down)</text></g><g class="message" data-entity-1="part2" data-entity-2="part3" data-source-line="13" id="msg3"><polygon fill="#181818" points="419.9805,189.3965,429.9805,193.3965,419.9805,197.3965,423.9805,193.3965" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;stroke-dasharray:2,2;" x1="334.0566" x2="425.9805" y1="193.3965" y2="193.3965"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="49.207" x="341.0566" y="188.6543">pop req</text></g><path d="M10,208.3965 L84.4468,208.3965 L84.4468,215.707 L74.4468,225.707 L10,225.707 L10,208.3965" fill="#EEEEEE" style="stroke:#000000;stroke-width:1.5;"/><rect fill="none" height="264.7949" style="stroke:#000000;stroke-width:1.5;" width="772.5625" x="10" y="208.3965"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="700" lengthAdjust="spacing" textLength="29.4468" x="25" y="221.9648">loop</text><text fill="#000000" font-family="sans-serif" font-size="11" font-weight="700" lengthAdjust="spacing" textLength="158.9575" x="99.4468" y="221.0313">[one decode step per token]</text><g class="message" data-entity-1="part3" data-entity-2="part4" data-source-line="15" id="msg4"><polygon fill="#181818" points="603.9985,243.0176,613.9985,247.0176,603.9985,251.0176,607.9985,247.0176" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;" x1="431.9805" x2="609.9985" y1="247.0176" y2="247.0176"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="160.0181" x="438.9805" y="242.2754">forward pass (sleep 0.05)</text></g><g class="message" data-entity-1="part4" data-entity-2="part3" data-source-line="16" id="msg5"><polygon fill="#181818" points="442.9805,272.3281,432.9805,276.3281,442.9805,280.3281,438.9805,276.3281" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;stroke-dasharray:2,2;" x1="436.9805" x2="614.9985" y1="276.3281" y2="276.3281"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="51.8096" x="448.9805" y="271.5859">token id</text></g><g class="message" data-entity-1="part3" data-entity-2="part5" data-source-line="17" id="msg6"><polygon fill="#181818" points="708.189,301.6387,718.189,305.6387,708.189,309.6387,712.189,305.6387" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;" x1="431.9805" x2="714.189" y1="305.6387" y2="305.6387"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="100.4834" x="438.9805" y="300.8965">cancelled? (poll)</text></g><g class="message" data-entity-1="part3" data-entity-2="part5" data-source-line="18" id="msg7"><polygon fill="#181818" points="708.189,330.9492,718.189,334.9492,708.189,338.9492,712.189,334.9492" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;" x1="431.9805" x2="714.189" y1="334.9492" y2="334.9492"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="131.1553" x="438.9805" y="330.207">push(kind: token, id)</text></g><g class="message" data-entity-1="part3" data-entity-2="part1" data-source-line="19" id="msg8"><polygon fill="#181818" points="85.2603,360.2598,75.2603,364.2598,85.2603,368.2598,81.2603,364.2598" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;" x1="79.2603" x2="430.9805" y1="364.2598" y2="364.2598"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="295.1724" x="91.2603" y="359.5176">broadcast (wakeup, the uv_async_send analog)</text></g><g class="message" data-entity-1="part1" data-entity-2="part5" data-source-line="20" id="msg9"><polygon fill="#181818" points="708.189,389.5703,718.189,393.5703,708.189,397.5703,712.189,393.5703" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;" x1="74.2603" x2="714.189" y1="393.5703" y2="393.5703"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="212.9766" x="81.2603" y="388.8281">next_chunk (blocks until a chunk)</text></g><g class="message" data-entity-1="part5" data-entity-2="part1" data-source-line="21" id="msg10"><polygon fill="#181818" points="85.2603,418.8809,75.2603,422.8809,85.2603,426.8809,81.2603,422.8809" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;stroke-dasharray:2,2;" x1="79.2603" x2="719.189" y1="422.8809" y2="422.8809"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="78.3301" x="91.2603" y="418.1387">token chunk</text></g><g class="message" data-entity-1="part1" data-entity-2="part1" data-source-line="22" id="msg11"><line style="stroke:#181818;stroke-width:1;" x1="74.2603" x2="116.2603" y1="452.1914" y2="452.1914"/><line style="stroke:#181818;stroke-width:1;" x1="116.2603" x2="116.2603" y1="452.1914" y2="465.1914"/><line style="stroke:#181818;stroke-width:1;" x1="75.2603" x2="116.2603" y1="465.1914" y2="465.1914"/><polygon fill="#181818" points="85.2603,461.1914,75.2603,465.1914,85.2603,469.1914,81.2603,465.1914" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="203.2456" x="81.2603" y="447.4492">on_token: detokenize id -&gt; text</text></g><g class="message" data-entity-1="part1" data-entity-2="part5" data-source-line="24" id="msg12"><polygon fill="#181818" points="708.189,497.502,718.189,501.502,708.189,505.502,712.189,501.502" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;" x1="74.2603" x2="714.189" y1="501.502" y2="501.502"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="221.2412" x="81.2603" y="496.7598">req.cancel! (client aborts; sets flag)</text></g><g class="message" data-entity-1="part3" data-entity-2="part5" data-source-line="25" id="msg13"><polygon fill="#181818" points="708.189,526.8125,718.189,530.8125,708.189,534.8125,712.189,530.8125" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;" x1="431.9805" x2="714.189" y1="530.8125" y2="530.8125"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="192.0166" x="438.9805" y="526.0703">cancelled? -&gt; true at next poll</text></g><g class="message" data-entity-1="part3" data-entity-2="part5" data-source-line="26" id="msg14"><polygon fill="#181818" points="708.189,556.123,718.189,560.123,708.189,564.123,712.189,560.123" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;" x1="431.9805" x2="714.189" y1="560.123" y2="560.123"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="264.2085" x="438.9805" y="555.3809">finish(:cancelled): push done chunk, close</text></g><g class="message" data-entity-1="part3" data-entity-2="part1" data-source-line="27" id="msg15"><polygon fill="#181818" points="85.2603,585.4336,75.2603,589.4336,85.2603,593.4336,81.2603,589.4336" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;" x1="79.2603" x2="430.9805" y1="589.4336" y2="589.4336"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="62.1753" x="91.2603" y="584.6914">broadcast</text></g><g class="message" data-entity-1="part1" data-entity-2="part5" data-source-line="28" id="msg16"><polygon fill="#181818" points="708.189,614.7441,718.189,618.7441,708.189,622.7441,712.189,618.7441" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;" x1="74.2603" x2="714.189" y1="618.7441" y2="618.7441"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="73.106" x="81.2603" y="614.002">next_chunk</text></g><g class="message" data-entity-1="part5" data-entity-2="part1" data-source-line="29" id="msg17"><polygon fill="#181818" points="85.2603,644.0547,75.2603,648.0547,85.2603,652.0547,81.2603,648.0547" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><line style="stroke:#181818;stroke-width:1;stroke-dasharray:2,2;" x1="79.2603" x2="719.189" y1="648.0547" y2="648.0547"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="171.1519" x="91.2603" y="643.3125">done chunk (still delivered)</text></g><g class="message" data-entity-1="part1" data-entity-2="part1" data-source-line="30" id="msg18"><line style="stroke:#181818;stroke-width:1;" x1="74.2603" x2="116.2603" y1="677.3652" y2="677.3652"/><line style="stroke:#181818;stroke-width:1;" x1="116.2603" x2="116.2603" y1="677.3652" y2="690.3652"/><line style="stroke:#181818;stroke-width:1;" x1="75.2603" x2="116.2603" y1="690.3652" y2="690.3652"/><polygon fill="#181818" points="85.2603,686.3652,75.2603,690.3652,85.2603,694.3652,81.2603,690.3652" style="stroke:#181818;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:10;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="238.4561" x="81.2603" y="672.623">on_done(:cancelled); generate returns</text></g></g></svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment