Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

34.7 KB
Raw Blame
<!doctype html><html lang=en dir=ltr class="blog-wrapper blog-post-page mj-root plugin-blog plugin-id-default" data-has-hydrated=false><head><meta charset=UTF-8><meta name=generator content="Docusaurus v3.10.0"><title data-rh=true>The setup wizard that quit at the first menu | Mercury Agent</title><meta data-rh=true name=viewport content="width=device-width, initial-scale=1.0"/><meta data-rh=true property=og:url content=https://mercuryagent.sh/blog/the-wizard-that-quit-at-the-menu /><meta data-rh=true property=og:locale content=en /><meta data-rh=true name=docusaurus_locale content=en /><meta data-rh=true name=docusaurus_tag content=default /><meta data-rh=true name=docsearch:language content=en /><meta data-rh=true name=docsearch:docusaurus_tag content=default /><meta data-rh=true name=theme-color content=#0a0d10 media="(prefers-color-scheme: dark)"/><meta data-rh=true name=theme-color content=#fbfbf8 media="(prefers-color-scheme: light)"/><meta data-rh=true name=description content="For six releases, a brand-new Mercury install asked for your name, showed one menu, and exited without an error. A walkthrough of a one-tick race between two readers of the same terminal, and the test that now keeps it from coming back."/><meta data-rh=true property=og:description content="For six releases, a brand-new Mercury install asked for your name, showed one menu, and exited without an error. A walkthrough of a one-tick race between two readers of the same terminal, and the test that now keeps it from coming back."/><meta data-rh=true name=keywords content="node readline,stdin pause,raw mode,cli setup wizard,pseudo terminal test,postmortem,node.js bug"/><meta data-rh=true property=og:type content=article /><meta data-rh=true property=article:published_time content=2026-10-15T00:00:00.000Z /><meta data-rh=true property=article:author content=https://github.com/cosmicstack-labs/mercury-agent /><meta data-rh=true property=article:tag content=Engineering,Postmortem /><meta data-rh=true property=og:image content="https://mercuryagent.sh/img/og/blog/the-wizard-that-quit-at-the-menu.jpg?v=2"/><meta data-rh=true property=og:image:secure_url content="https://mercuryagent.sh/img/og/blog/the-wizard-that-quit-at-the-menu.jpg?v=2"/><meta data-rh=true property=og:image:type content=image/jpeg /><meta data-rh=true property=og:image:width content=1200 /><meta data-rh=true property=og:image:height content=630 /><meta data-rh=true property=og:image:alt content="The setup wizard that quit at the first menu. Engineering · 5 min read. Mercury Blog"/><meta data-rh=true name=twitter:card content=summary_large_image /><meta data-rh=true name=twitter:image content="https://mercuryagent.sh/img/og/blog/the-wizard-that-quit-at-the-menu.jpg?v=2"/><meta data-rh=true name=twitter:image:alt content="The setup wizard that quit at the first menu. Engineering · 5 min read. Mercury Blog"/><meta data-rh=true property=og:title content="The setup wizard that quit at the first menu"/><meta data-rh=true name=twitter:title content="The setup wizard that quit at the first menu"/><meta data-rh=true property=article:section content=Engineering /><meta data-rh=true name=twitter:label1 content=Topic /><meta data-rh=true name=twitter:data1 content=Engineering /><meta data-rh=true name=twitter:label2 content="Reading time"/><meta data-rh=true name=twitter:data2 content="5 min read"/><link data-rh=true rel=icon href=/img/logo-light.png /><link data-rh=true rel=canonical href=https://mercuryagent.sh/blog/the-wizard-that-quit-at-the-menu /><link data-rh=true rel=alternate href=https://mercuryagent.sh/blog/the-wizard-that-quit-at-the-menu hreflang=en /><link data-rh=true rel=alternate href=https://mercuryagent.sh/blog/the-wizard-that-quit-at-the-menu hreflang=x-default /><link data-rh=true rel=alternate type=text/markdown href=/blog/the-wizard-that-quit-at-the-menu.md title="Markdown version"/><script data-rh=true type=application/ld+json>{"@context":"https://schema.org","@id":"https://mercuryagent.sh/blog/the-wizard-that-quit-at-the-menu","@type":"BlogPosting","author":{"@type":"Person","description":"The team behind Mercury","image":"/img/avatar-mercury.png","name":"Mercury Engineering","url":"https://github.com/cosmicstack-labs/mercury-agent"},"datePublished":"2026-10-15T00:00:00.000Z","description":"For six releases, a brand-new Mercury install asked for your name, showed one menu, and exited without an error. A walkthrough of a one-tick race between two readers of the same terminal, and the test that now keeps it from coming back.","headline":"The setup wizard that quit at the first menu","image":{"@id":"https://mercuryagent.sh/assets/images/cover-38161922d5058f5d58b7b27b960490f6.jpg","@type":"ImageObject","caption":"title image for the blog post: The setup wizard that quit at the first menu","contentUrl":"https://mercuryagent.sh/assets/images/cover-38161922d5058f5d58b7b27b960490f6.jpg","url":"https://mercuryagent.sh/assets/images/cover-38161922d5058f5d58b7b27b960490f6.jpg"},"isPartOf":{"@id":"https://mercuryagent.sh/blog","@type":"Blog","name":"Mercury Blog"},"keywords":["node readline","stdin pause","raw mode","cli setup wizard","pseudo terminal test","postmortem","node.js bug"],"mainEntityOfPage":"https://mercuryagent.sh/blog/the-wizard-that-quit-at-the-menu","name":"The setup wizard that quit at the first menu","url":"https://mercuryagent.sh/blog/the-wizard-that-quit-at-the-menu"}</script><script data-rh=true type=application/ld+json>{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","item":"https://mercuryagent.sh/","name":"Mercury","position":1},{"@type":"ListItem","item":"https://mercuryagent.sh/blog","name":"Blog","position":2},{"@type":"ListItem","item":"https://mercuryagent.sh/blog/tags/engineering","name":"Engineering","position":3},{"@type":"ListItem","item":"https://mercuryagent.sh/blog/the-wizard-that-quit-at-the-menu","name":"The setup wizard that quit at the first menu","position":4}]}</script><link rel=alternate type=application/rss+xml href=/blog/rss.xml title="Mercury Blog RSS Feed"><link rel=alternate type=application/atom+xml href=/blog/atom.xml title="Mercury Blog Atom Feed"><link rel=alternate type=application/json href=/blog/feed.json title="Mercury Blog JSON Feed"><meta name=twitter:site content=@mercuryagent><meta property=og:site_name content="Mercury Agent"><meta name=application-name content="Mercury Agent"><link rel=preconnect href=https://fonts.googleapis.com><link rel=preconnect href=https://fonts.gstatic.com crossorigin=anonymous><link rel=stylesheet href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500;600&family=Instrument+Serif:ital@0;1&display=swap"><link rel=apple-touch-icon href=/img/logo-light.png><script src=https://analytics.cosmicstack.org/js/pa--flkUFvdfmsPSUtRivKAK.js async></script><script src=/js/plausible-init.js></script><link rel=stylesheet href=/assets/css/styles.b525f68d.css /><script src=/assets/js/runtime~main.c3075c62.js defer></script><script src=/assets/js/main.69097411.js defer></script></head><body><svg style="display: none;"><defs>
<symbol id=theme-svg-external-link viewBox="0 0 24 24"><path fill=currentColor d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"/></symbol>
</defs></svg>
<script>!function(){var t=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return window.localStorage.getItem("theme-ebb")}catch(t){}}();document.documentElement.setAttribute("data-theme",t||(window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light")),document.documentElement.setAttribute("data-theme-choice",t||"system")}(),function(){try{for(var[t,e]of new URLSearchParams(window.location.search).entries())if(t.startsWith("docusaurus-data-")){var a=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(a,e)}}catch(t){}}(),document.documentElement.setAttribute("data-announcement-bar-initially-dismissed",function(){try{return"true"===localStorage.getItem("docusaurus.announcement.dismiss-ebb")}catch(t){}return!1}())</script><div id=__docusaurus><link rel=preload as=image href=/img/logo-light.png /><link rel=preload as=image href=/img/logo-dark.png /><link rel=preload as=image href=/img/avatar-mercury.png /><link rel=preload as=image href=/assets/images/cover-38161922d5058f5d58b7b27b960490f6.jpg fetchpriority=high /><div role=region aria-label="Skip to main content"><a class=skipToContent_fXgn href=#__docusaurus_skipToContent_fallback>Skip to main content</a></div><div class="theme-announcement-bar announcementBar_mb4j" role=banner><div class=announcementBarPlaceholder_vyr4></div><div class="content_knG7 announcementBarContent_xLdY">☿ Mercury 1.5.0 is out with <strong>Mercury Desktop</strong> for macOS, Windows and Linux, remote access you control, and updates that roll back on their own. <a href=/download>Download it →</a></div><button type=button aria-label=Close class="clean-btn close closeButton_CVFx announcementBarClose_gvF7"><svg viewBox="0 0 15 15" width=14 height=14><g stroke=currentColor stroke-width=3.1><path d="M.75.75l13.5 13.5M14.25.75L.75 14.25"/></g></svg></button></div><nav aria-label=Main class="theme-layout-navbar navbar navbar--fixed-top"><div class=navbar__inner><div class="theme-layout-navbar-left navbar__items"><button aria-label="Toggle navigation bar" aria-expanded=false class="navbar__toggle clean-btn" type=button><svg width=30 height=30 viewBox="0 0 30 30" aria-hidden=true><path stroke=currentColor stroke-linecap=round stroke-miterlimit=10 stroke-width=2 d="M4 7h22M4 15h22M4 23h22"/></svg></button><a class=navbar__brand href=/><div class=navbar__logo><img src=/img/logo-light.png alt="Mercury Agent" class="themedComponent_mlkZ themedComponent--light_NVdE"/><img src=/img/logo-dark.png alt="Mercury Agent" class="themedComponent_mlkZ themedComponent--dark_xIcU"/></div><b class="navbar__title text--truncate">Mercury</b></a><a class="navbar__item navbar__link" href=/docs>Docs</a><a class="navbar__item navbar__link" href=/docs/integrations/coding-workspace>Code</a><a class="navbar__item navbar__link" href=/docs/integrations/mercury-bots>Bots</a><a class="navbar__item navbar__link" href=/cloud>Cloud</a><a href=https://skills.mercuryagent.sh target=_blank rel="noopener noreferrer" class="navbar__item navbar__link">Skills<svg width=13.5 height=13.5 aria-label="(opens in new tab)" class=iconExternalLink_nPIU><use href=#theme-svg-external-link /></svg></a><a aria-current=page class="navbar__item navbar__link navbar__link--active" href=/blog>Blog</a><a class="navbar__item navbar__link" href=/docs/releases>Changelog</a></div><div class="theme-layout-navbar-right navbar__items navbar__items--right"><a href=https://github.com/cosmicstack-labs/mercury-agent target=_blank rel="noopener noreferrer" class="navbar__item navbar__link navbar-github" aria-label="Mercury Agent on GitHub"></a><a class="navbar__item navbar__link navbar-cta" href=/download>Download</a><div class="toggle_vylO colorModeToggle_DEke"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type=button disabled title="system mode" aria-label="Switch between dark and light mode (currently system mode)"><svg viewBox="0 0 24 24" width=24 height=24 aria-hidden=true class="toggleIcon_g3eP lightToggleIcon_pyhR"><path fill=currentColor d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"/></svg><svg viewBox="0 0 24 24" width=24 height=24 aria-hidden=true class="toggleIcon_g3eP darkToggleIcon_wfgR"><path fill=currentColor d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"/></svg><svg viewBox="0 0 24 24" width=24 height=24 aria-hidden=true class="toggleIcon_g3eP systemToggleIcon_QzmC"><path fill=currentColor d="m12 21c4.971 0 9-4.029 9-9s-4.029-9-9-9-9 4.029-9 9 4.029 9 9 9zm4.95-13.95c1.313 1.313 2.05 3.093 2.05 4.95s-0.738 3.637-2.05 4.95c-1.313 1.313-3.093 2.05-4.95 2.05v-14c1.857 0 3.637 0.737 4.95 2.05z"/></svg></button></div><div class=navbarSearchContainer_Bca1><div class="navbar__search searchBarContainer_NW3z" dir=ltr><input placeholder=Search aria-label=Search class="navbar__search-input searchInput_YFbd" value="" /><div class="loadingRing_RJI3 searchBarLoadingRing_YnHq"><div></div><div></div><div></div><div></div></div></div></div></div></div><div role=presentation class=navbar-sidebar__backdrop></div></nav><div id=__docusaurus_skipToContent_fallback class="theme-layout-main main-wrapper mainWrapper_z2l0"><main class=mj-post><div class=mj-progress role=progressbar aria-label="Reading progress" aria-valuemin=0 aria-valuemax=100 aria-valuenow=0><span style=transform:scaleX(0)></span></div><button type=button class=mj-progress-pill aria-label="5 min left. Back to top" tabindex=-1><svg viewBox="0 0 20 20" width=18 height=18 aria-hidden=true><circle cx=10 cy=10 r=8 class=mj-ring-bg /><circle cx=10 cy=10 r=8 class=mj-ring style=stroke-dashoffset:50.27 /></svg><span>5 min left</span></button><header class=mj-post-head><a class=mj-back href=/blog>← Blog</a><a class=mj-post-cat href=/blog/tags/engineering>Engineering</a><h1 class=mj-post-title>The setup wizard that quit at the first menu</h1><p class=mj-post-dek>For six releases, a brand-new Mercury install asked for your name, showed one menu, and exited without an error. A walkthrough of a one-tick race between two readers of the same terminal, and the test that now keeps it from coming back.<div class=mj-post-byline><div class=mj-post-authors><a class=mj-post-author href=/blog/authors/mercury-eng><img src=/img/avatar-mercury.png alt="" width=36 height=36 /><span><strong>Mercury Engineering</strong><em>The team behind Mercury</em></span></a></div><div class=mj-meta><time datetime=2026-10-15T00:00:00.000Z>Oct 15, 2026</time><span aria-hidden=true>·</span><span>5<!-- --> min read</span></div></div></header><div class=mj-post-banner><img src=/assets/images/cover-38161922d5058f5d58b7b27b960490f6.jpg alt="" width=1600 height=900 fetchpriority=high decoding=async /></div><div class="mj-post-layout has-toc"><aside class=mj-post-toc aria-label="On this page"><div class=mj-toc-head><p>On this page</p><span class=mj-toc-left>5 min left</span></div><div class=mj-toc-meter aria-hidden=true><span style=transform:scaleX(0)></span></div><div class=tableOfContentsInline_prmo><ul class=table-of-contents><li><a href=#two-ways-to-read-a-terminal>Two ways to read a terminal</a><li><a href=#the-change-that-introduced-it>The change that introduced it</a><li><a href=#the-race>The race</a><li><a href=#why-it-survived-six-releases>Why it survived six releases</a><li><a href=#the-fix>The fix</a><li><a href=#the-test-that-would-have-caught-it>The test that would have caught it</a><li><a href=#takeaways>Takeaways</a></ul></div></aside><article class="mj-prose markdown"><p>Here's what a new user saw, from first install, on any platform, between versions 1.3.1 and 1.3.6:</p>
<div class="language-text codeBlockContainer_Ckt0 theme-code-block" style=--prism-color:#393A34;--prism-background-color:#f6f8fa><div class=codeBlockContent_QJqH><pre tabindex=0 class="prism-code language-text codeBlock_bY9V thin-scrollbar" style=color:#393A34;background-color:#f6f8fa><code class=codeBlockLines_e6Vv><div class=token-line style=color:#393A34><span class="token plain">  Your name: Ada</span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  Agent name [Mercury]:</span><br/></div><div class=token-line style=color:#393A34><span class="token plain" style=display:inline-block></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  Choose your mode</span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  Use the arrow keys, then press Enter.</span><br/></div><div class=token-line style=color:#393A34><span class="token plain" style=display:inline-block></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  ● Mercury Cloud (hosted, no API keys needed)</span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  · Offline / BYOK (bring your own keys)</span><br/></div><div class=token-line style=color:#393A34><span class="token plain" style=display:inline-block></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">$</span><br/></div></code></pre></div></div>
<p>That <code>$</code> is the shell prompt. Mercury didn't crash and didn't print an error. It drew a menu and then simply wasn't running anymore. The exit code was 0.</p>
<!-- -->
<p>This is a write-up of what happened, because the bug is a good example of a class of problem that's easy to create in any Node.js CLI that mixes line prompts with key-by-key menus.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=two-ways-to-read-a-terminal>Two ways to read a terminal<a href=#two-ways-to-read-a-terminal class=hash-link aria-label="Direct link to Two ways to read a terminal" title="Direct link to Two ways to read a terminal" translate=no>​</a></h2>
<p>Mercury's setup wizard uses two kinds of input.</p>
<p>The name questions use Node's <code>readline</code> interface: you type a line, press Enter, and get a string back. The mode menu reads individual key presses, so it can move the highlight with the arrow keys. That needs the terminal in raw mode and a <code>keypress</code> listener on <code>process.stdin</code>.</p>
<p>Both read from the same stream, so they have to take turns. The question reader has to let go of stdin before the menu takes over.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=the-change-that-introduced-it>The change that introduced it<a href=#the-change-that-introduced-it class=hash-link aria-label="Direct link to The change that introduced it" title="Direct link to The change that introduced it" translate=no>​</a></h2>
<p>In October we fixed an older bug where pressing Ctrl+D during setup made the wizard exit silently. Part of that fix was to share one <code>readline</code> interface across all the consecutive questions, so an end-of-input during any of them would be caught and reported.</p>
<p>Sharing the interface raised a question: when do you close it? You don't want to close and reopen it between two questions that follow each other immediately. So after each answer, the code scheduled the close for the next turn of the event loop:</p>
<div class="language-ts codeBlockContainer_Ckt0 theme-code-block" style=--prism-color:#393A34;--prism-background-color:#f6f8fa><div class=codeBlockContent_QJqH><pre tabindex=0 class="prism-code language-ts codeBlock_bY9V thin-scrollbar" style=color:#393A34;background-color:#f6f8fa><code class=codeBlockLines_e6Vv><div class=token-line style=color:#393A34><span class="token plain">iface</span><span class="token punctuation" style=color:#393A34>.</span><span class="token function" style=color:#d73a49>question</span><span class="token punctuation" style=color:#393A34>(</span><span class="token plain">prompt</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>(</span><span class="token plain">answer</span><span class="token punctuation" style=color:#393A34>)</span><span class="token plain"> </span><span class="token operator" style=color:#393A34>=></span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>{</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  pending </span><span class="token operator" style=color:#393A34>=</span><span class="token plain"> </span><span class="token keyword" style=color:#00009f>null</span><span class="token punctuation" style=color:#393A34>;</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  </span><span class="token function" style=color:#d73a49>scheduleRelease</span><span class="token punctuation" style=color:#393A34>(</span><span class="token punctuation" style=color:#393A34>)</span><span class="token punctuation" style=color:#393A34>;</span><span class="token plain"> </span><span class="token comment" style=color:#999988;font-style:italic>// setImmediate(() => close())</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  </span><span class="token function" style=color:#d73a49>resolve</span><span class="token punctuation" style=color:#393A34>(</span><span class="token plain">answer</span><span class="token punctuation" style=color:#393A34>.</span><span class="token function" style=color:#d73a49>trim</span><span class="token punctuation" style=color:#393A34>(</span><span class="token punctuation" style=color:#393A34>)</span><span class="token punctuation" style=color:#393A34>)</span><span class="token punctuation" style=color:#393A34>;</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"></span><span class="token punctuation" style=color:#393A34>}</span><span class="token punctuation" style=color:#393A34>)</span><span class="token punctuation" style=color:#393A34>;</span><br/></div></code></pre></div></div>
<p>If another question came along before then, it cancelled the scheduled close and reused the interface. That's a sensible design for a sequence of questions. The problem is what happens when the next consumer isn't a question.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=the-race>The race<a href=#the-race class=hash-link aria-label="Direct link to The race" title="Direct link to The race" translate=no>​</a></h2>
<p>Here is the exact order of events after you type your agent's name:</p>
<ol>
<li class="">The answer resolves. A close is scheduled for the next tick.</li>
<li class="">The wizard moves on and opens the arrow-key menu. The menu puts the terminal in raw mode, calls <code>stdin.resume()</code>, and attaches its key listener.</li>
<li class="">The next tick arrives and the scheduled close runs. <code>readline</code>'s <code>close()</code> pauses its input stream, which is <code>process.stdin</code>.</li>
</ol>
<p>Step 3 undid step 2. The menu was waiting for key presses on a stream that was no longer flowing. Nothing else was keeping Node's event loop busy at that moment: no timers, no open sockets, no pending promises tied to I/O. When the event loop has no work left, Node exits. Cleanly. With status 0.</p>
<p>That's why there was no error. Nothing failed. The process just ran out of things to do.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=why-it-survived-six-releases>Why it survived six releases<a href=#why-it-survived-six-releases class=hash-link aria-label="Direct link to Why it survived six releases" title="Direct link to Why it survived six releases" translate=no>​</a></h2>
<p>Every test we had passed, and that's the uncomfortable part.</p>
<p>The unit tests for the question reader passed because, in isolation, it did exactly what it should. The wizard's tests mocked the menu. The binary smoke test in CI ran <code>mercury --version</code>, which never reaches the wizard. And anyone on the team who already had a config file never saw the first-run path at all.</p>
<p>None of those tests had a real terminal in them, and this bug only exists when two readers share one.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=the-fix>The fix<a href=#the-fix class=hash-link aria-label="Direct link to The fix" title="Direct link to The fix" translate=no>​</a></h2>
<p>The fix is one line. The menu releases the shared reader synchronously, before it takes over stdin:</p>
<div class="language-ts codeBlockContainer_Ckt0 theme-code-block" style=--prism-color:#393A34;--prism-background-color:#f6f8fa><div class=codeBlockContent_QJqH><pre tabindex=0 class="prism-code language-ts codeBlock_bY9V thin-scrollbar" style=color:#393A34;background-color:#f6f8fa><code class=codeBlockLines_e6Vv><div class=token-line style=color:#393A34><span class="token keyword" style=color:#00009f>export</span><span class="token plain"> </span><span class="token keyword" style=color:#00009f>async</span><span class="token plain"> </span><span class="token keyword" style=color:#00009f>function</span><span class="token plain"> </span><span class="token function" style=color:#d73a49>selectWithArrowKeys</span><span class="token punctuation" style=color:#393A34>(</span><span class="token plain">title</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"> options</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"> config </span><span class="token operator" style=color:#393A34>=</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>{</span><span class="token punctuation" style=color:#393A34>}</span><span class="token punctuation" style=color:#393A34>)</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>{</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  </span><span class="token comment" style=color:#999988;font-style:italic>// Release the question reader now: its deferred close would otherwise</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  </span><span class="token comment" style=color:#999988;font-style:italic>// pause stdin after we resume it.</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  </span><span class="token function" style=color:#d73a49>closeAsk</span><span class="token punctuation" style=color:#393A34>(</span><span class="token punctuation" style=color:#393A34>)</span><span class="token punctuation" style=color:#393A34>;</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  readline</span><span class="token punctuation" style=color:#393A34>.</span><span class="token function" style=color:#d73a49>emitKeypressEvents</span><span class="token punctuation" style=color:#393A34>(</span><span class="token plain">process</span><span class="token punctuation" style=color:#393A34>.</span><span class="token plain">stdin</span><span class="token punctuation" style=color:#393A34>)</span><span class="token punctuation" style=color:#393A34>;</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  </span><span class="token comment" style=color:#999988;font-style:italic>// ...raw mode, resume, keypress listener</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"></span><span class="token punctuation" style=color:#393A34>}</span><br/></div></code></pre></div></div>
<p><code>closeAsk()</code> cancels the scheduled close and closes the interface immediately. By the time the menu calls <code>resume()</code>, nothing is left that could pause the stream behind its back.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=the-test-that-would-have-caught-it>The test that would have caught it<a href=#the-test-that-would-have-caught-it class=hash-link aria-label="Direct link to The test that would have caught it" title="Direct link to The test that would have caught it" translate=no>​</a></h2>
<p>The part worth copying is the test. CI now runs the compiled binary through the real first-run wizard inside a pseudo-terminal. It types a name, answers the agent name prompt, waits for the mode menu, and then checks one thing: is the process still alive? Then it presses the down arrow and Enter and expects the provider question.</p>
<p>Run against 1.3.6, it fails at the menu. Run against 1.3.7, it passes. It runs on every pull request on Linux and macOS.</p>
<p>There's also a regression test at the unit level that fails if a deferred release can pause the input after an explicit close.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=takeaways>Takeaways<a href=#takeaways class=hash-link aria-label="Direct link to Takeaways" title="Direct link to Takeaways" translate=no>​</a></h2>
<ul>
<li class=""><strong>If two parts of your CLI read stdin, decide the hand-off explicitly.</strong> Don't rely on whoever closes last.</li>
<li class=""><strong>"Exited with code 0" can be a bug.</strong> In Node, a process that runs out of work exits quietly. When an interactive program exits without being asked to, look for a stream that stopped flowing.</li>
<li class=""><strong>Test interactive paths with a real terminal.</strong> Mocks hide the exact class of bug where two components step on each other. A pseudo-terminal test is maybe forty lines of Python and it's the only thing that would have caught this.</li>
</ul>
<p>We're sorry to everyone whose first impression of Mercury was a menu that vanished. If you bounced off it, the current release gets you through setup, and we'd love for you to try again.</article></div><footer class=mj-post-foot><div class=mj-tools aria-label="Share and export"><button type=button>Copy as Markdown</button><a href=/blog/the-wizard-that-quit-at-the-menu.md>View .md</a><button type=button>Copy link</button><a href="https://x.com/intent/post?url=https%3A%2F%2Fmercuryagent.sh%2Fblog%2Fthe-wizard-that-quit-at-the-menu&text=The%20setup%20wizard%20that%20quit%20at%20the%20first%20menu" target=_blank rel="noopener noreferrer">Share on X</a><a href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fmercuryagent.sh%2Fblog%2Fthe-wizard-that-quit-at-the-menu" target=_blank rel="noopener noreferrer">LinkedIn</a></div><div class=mj-post-tags><a href=/blog/tags/engineering>Engineering</a><a href=/blog/tags/postmortem>Postmortem</a></div><nav class=mj-pager aria-label="More posts"><a href=/blog/mercury-bots><small>Newer</small>Mercury Bots: an agent fleet that runs on your machine</a><a class=is-next href=/blog/we-were-running-mercury-twice><small>Older</small>We were running Mercury twice and didn't know it</a></nav><section class=mj-more><h2>More from the blog</h2><ul><li><a href=/blog/what-is-a-personal-ai-assistant>What Is a Personal AI Assistant? 10 Real Tasks in 2026</a><time datetime=2026-11-11T00:00:00.000Z>Nov 11, 2026</time><li><a href=/blog/six-ai-agents-compared-for-real-work>9 Safest, Most Secure, and Permission-Aware AI Agents for Real-World Tasks</a><time datetime=2026-11-05T00:00:00.000Z>Nov 5, 2026</time><li><a href=/blog/mercury-1-5>Mercury 1.5: Mercury Desktop</a><time datetime=2026-11-03T00:00:00.000Z>Nov 3, 2026</time></ul></section></footer></main></div><footer class="theme-layout-footer footer"><div class="container container-fluid"><div class="row footer__links"><div class="theme-layout-footer-column col footer__col"><div class=footer__title>Product</div><ul class="footer__items clean-list"><li class=footer__item><a class=footer__link-item href=/download>Download</a><li class=footer__item><a class=footer__link-item href=/#install>Install on a server</a><li class=footer__item><a class=footer__link-item href=/docs/integrations/coding-workspace>Mercury Code</a><li class=footer__item><a class=footer__link-item href=/docs/integrations/mercury-bots>Mercury Bots</a><li class=footer__item><a class=footer__link-item href=/cloud>Mercury Cloud</a><li class=footer__item><a class=footer__link-item href=/blog>Blog</a><li class=footer__item><a class=footer__link-item href=/docs/releases>Changelog</a></ul></div><div class="theme-layout-footer-column col footer__col"><div class=footer__title>Trust</div><ul class="footer__items clean-list"><li class=footer__item><a class=footer__link-item href=/docs/reference/permissions>Permissions model</a><li class=footer__item><a class=footer__link-item href=/docs/reference/second-brain>Second Brain memory</a><li class=footer__item><a class=footer__link-item href=/docs/reference/completion-architecture>Completion contract</a><li class=footer__item><a class=footer__link-item href=/#compare>Honest comparison</a></ul></div><div class="theme-layout-footer-column col footer__col"><div class=footer__title>Docs</div><ul class="footer__items clean-list"><li class=footer__item><a class=footer__link-item href=/docs>Getting started</a><li class=footer__item><a class=footer__link-item href=/docs/cli-commands/cli-commands>CLI commands</a><li class=footer__item><a class=footer__link-item href=/docs/reference/built-in-tools>Built-in tools</a><li class=footer__item><a class=footer__link-item href=/docs/reference/configuration>Configuration</a></ul></div><div class="theme-layout-footer-column col footer__col"><div class=footer__title>Community</div><ul class="footer__items clean-list"><li class=footer__item><a href=https://github.com/cosmicstack-labs/mercury-agent target=_blank rel="noopener noreferrer" class=footer__link-item>GitHub<svg width=13.5 height=13.5 aria-label="(opens in new tab)" class=iconExternalLink_nPIU><use href=#theme-svg-external-link /></svg></a><li class=footer__item><a href=https://github.com/cosmicstack-labs/mercury-agent/issues target=_blank rel="noopener noreferrer" class=footer__link-item>Issues<svg width=13.5 height=13.5 aria-label="(opens in new tab)" class=iconExternalLink_nPIU><use href=#theme-svg-external-link /></svg></a><li class=footer__item><a href=https://skills.mercuryagent.sh target=_blank rel="noopener noreferrer" class=footer__link-item>Skills registry<svg width=13.5 height=13.5 aria-label="(opens in new tab)" class=iconExternalLink_nPIU><use href=#theme-svg-external-link /></svg></a><li class=footer__item><a href=https://www.npmjs.com/package/@cosmicstack/mercury-agent target=_blank rel="noopener noreferrer" class=footer__link-item>npm<svg width=13.5 height=13.5 aria-label="(opens in new tab)" class=iconExternalLink_nPIU><use href=#theme-svg-external-link /></svg></a></ul></div></div><div class="footer__bottom text--center"><div class=footer__copyright>© 2026 Cosmic Stack · Mercury Agent is MIT-licensed open source.</div></div></div></footer></div></body>