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.

29.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>We were running Mercury twice and didn't know it | 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/we-were-running-mercury-twice /><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="Typing felt sluggish on every machine, and the terminal renderer took the blame. The real cause was a second full copy of the agent, started quietly by the launcher. How we found it, and why the fix was an architecture change rather than a performance tweak."/><meta data-rh=true property=og:description content="Typing felt sluggish on every machine, and the terminal renderer took the blame. The real cause was a second full copy of the agent, started quietly by the launcher. How we found it, and why the fix was an architecture change rather than a performance tweak."/><meta data-rh=true name=keywords content="ai agent architecture,daemon attach,node event loop lag,telegram 409 conflict,terminal ui performance,postmortem"/><meta data-rh=true property=og:type content=article /><meta data-rh=true property=article:published_time content=2026-10-14T00:00:00.000Z /><meta data-rh=true property=article:author content=https://github.com/hotheadhacker /><meta data-rh=true property=article:tag content=Engineering,Postmortem,Runtime /><meta data-rh=true property=og:image content="https://mercuryagent.sh/img/og/blog/we-were-running-mercury-twice.jpg?v=2"/><meta data-rh=true property=og:image:secure_url content="https://mercuryagent.sh/img/og/blog/we-were-running-mercury-twice.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="We were running Mercury twice and didn't know it. 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/we-were-running-mercury-twice.jpg?v=2"/><meta data-rh=true name=twitter:image:alt content="We were running Mercury twice and didn't know it. Engineering · 5 min read. Mercury Blog"/><meta data-rh=true property=og:title content="We were running Mercury twice and didn't know it"/><meta data-rh=true name=twitter:title content="We were running Mercury twice and didn't know it"/><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/we-were-running-mercury-twice /><link data-rh=true rel=alternate href=https://mercuryagent.sh/blog/we-were-running-mercury-twice hreflang=en /><link data-rh=true rel=alternate href=https://mercuryagent.sh/blog/we-were-running-mercury-twice hreflang=x-default /><link data-rh=true rel=alternate type=text/markdown href=/blog/we-were-running-mercury-twice.md title="Markdown version"/><script data-rh=true type=application/ld+json>{"@context":"https://schema.org","@id":"https://mercuryagent.sh/blog/we-were-running-mercury-twice","@type":"BlogPosting","author":{"@type":"Person","description":"Founder, Cosmic Stack","image":"https://github.com/hotheadhacker.png","name":"Salman Qureshi","url":"https://github.com/hotheadhacker"},"datePublished":"2026-10-14T00:00:00.000Z","description":"Typing felt sluggish on every machine, and the terminal renderer took the blame. The real cause was a second full copy of the agent, started quietly by the launcher. How we found it, and why the fix was an architecture change rather than a performance tweak.","headline":"We were running Mercury twice and didn't know it","image":{"@id":"https://mercuryagent.sh/assets/images/cover-933703cbe255fc7cb44400b9653f4281.jpg","@type":"ImageObject","caption":"title image for the blog post: We were running Mercury twice and didn't know it","contentUrl":"https://mercuryagent.sh/assets/images/cover-933703cbe255fc7cb44400b9653f4281.jpg","url":"https://mercuryagent.sh/assets/images/cover-933703cbe255fc7cb44400b9653f4281.jpg"},"isPartOf":{"@id":"https://mercuryagent.sh/blog","@type":"Blog","name":"Mercury Blog"},"keywords":["ai agent architecture","daemon attach","node event loop lag","telegram 409 conflict","terminal ui performance","postmortem"],"mainEntityOfPage":"https://mercuryagent.sh/blog/we-were-running-mercury-twice","name":"We were running Mercury twice and didn't know it","url":"https://mercuryagent.sh/blog/we-were-running-mercury-twice"}</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/we-were-running-mercury-twice","name":"We were running Mercury twice and didn't know it","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=https://github.com/hotheadhacker.png /><link rel=preload as=image href=/assets/images/cover-933703cbe255fc7cb44400b9653f4281.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>We were running Mercury twice and didn't know it</h1><p class=mj-post-dek>Typing felt sluggish on every machine, and the terminal renderer took the blame. The real cause was a second full copy of the agent, started quietly by the launcher. How we found it, and why the fix was an architecture change rather than a performance tweak.<div class=mj-post-byline><div class=mj-post-authors><a class=mj-post-author href=/blog/authors/salman><img src=https://github.com/hotheadhacker.png alt="" width=36 height=36 /><span><strong>Salman Qureshi</strong><em>Founder, Cosmic Stack</em></span></a></div><div class=mj-meta><time datetime=2026-10-14T00:00:00.000Z>Oct 14, 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-933703cbe255fc7cb44400b9653f4281.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=#measuring-before-guessing>Measuring before guessing</a><li><a href=#the-process-list-told-the-story>The process list told the story</a><li><a href=#how-we-ended-up-with-two>How we ended up with two</a><li><a href=#why-we-didnt-just-make-it-faster>Why we didn't just make it faster</a><li><a href=#making-lag-measurable>Making lag measurable</a><li><a href=#what-we-got-wrong-and-what-we-changed>What we got wrong, and what we changed</a></ul></div></aside><article class="mj-prose markdown"><p>A few days after shipping the always-on bots, I noticed Mercury felt heavy when I typed. Not broken. Just a beat behind, the way a remote shell feels on bad Wi-Fi. Then people started saying the same thing about the dev build on their own machines, which ruled out my laptop as the problem.</p>
<p>The obvious suspect was the terminal UI. We had just moved to a new version of Ink, our renderer, and added our own patches on top. Renderers are where input lag usually lives. So that's where I started, and that's where I was wrong.</p>
<!-- -->
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=measuring-before-guessing>Measuring before guessing<a href=#measuring-before-guessing class=hash-link aria-label="Direct link to Measuring before guessing" title="Direct link to Measuring before guessing" translate=no>​</a></h2>
<p>The first thing I did was take the renderer out of the argument. I wrote a benchmark that mounts the real terminal UI in a virtual terminal, loads a 100-message conversation and a 14-bot roster, and types 60 characters, timing each one from key press to the frame that shows it.</p>
<p>The median was about 3 ms per keystroke. The worst was around 20 ms. Each frame wrote roughly 74 bytes to the terminal. Then I ran it again with a bot streaming its reasoning into the UI a hundred times a second, and it barely moved: about 6 ms.</p>
<p>That's not a renderer you can feel. Whatever was eating the latency, it wasn't drawing the screen.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=the-process-list-told-the-story>The process list told the story<a href=#the-process-list-told-the-story class=hash-link aria-label="Direct link to The process list told the story" title="Direct link to The process list told the story" translate=no>​</a></h2>
<p>So I stopped benchmarking and looked at what was actually running.</p>
<p>There were two Mercury processes doing real work. One was the background daemon I expected. The other was the terminal session itself, and it had used about four times as much CPU as the daemon. A terminal client should use almost nothing. This one was doing a lot.</p>
<p>The daemon's error log had the second clue: nine copies of the same Telegram error in a single day.</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">409 Conflict: terminated by other getUpdates request</span><br/></div></code></pre></div></div>
<p>Telegram returns that when two programs poll the same bot token at once. There is no way to get it with one process.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=how-we-ended-up-with-two>How we ended up with two<a href=#how-we-ended-up-with-two class=hash-link aria-label="Direct link to How we ended up with two" title="Direct link to How we ended up with two" translate=no>​</a></h2>
<p>The launcher had a branch that looked reasonable in isolation. When you typed <code>mercury</code> and no background daemon was running, it did two things in a row: start the daemon, then start the agent in the foreground.</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 function" style=color:#d73a49>autoDaemonize</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 keyword" style=color:#00009f>await</span><span class="token plain"> </span><span class="token function" style=color:#d73a49>runAgent</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>The intent was to make sure Mercury kept running after you closed the terminal, while still giving you a chat right away. The effect was two complete runtimes. Both built a bot manager on the same queue. Both connected to Telegram. Both registered the same scheduled routines. And the foreground copy ran every bot turn, every tool call and every context compaction on the same thread that renders your keystrokes.</p>
<p>For months this didn't matter much, because bots were mostly idle. Then we made them always-on. The foreground copy suddenly had real work to do, on the worst possible thread, and typing started to lag on every machine that took that path. Which was every machine, because it ran on the first <code>mercury</code> after any reboot.</p>
<p>On my own laptop it was worse. An old install from npm was still registered as the login service and held the web port. Every launch failed to connect to the new daemon, decided the runtime was unhealthy, and took the "start everything" path again.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=why-we-didnt-just-make-it-faster>Why we didn't just make it faster<a href=#why-we-didnt-just-make-it-faster class=hash-link aria-label="Direct link to Why we didn't just make it faster" title="Direct link to Why we didn't just make it faster" translate=no>​</a></h2>
<p>You can imagine a smaller fix: keep the second copy but stop it from polling Telegram, or move bot work to a worker thread. Each of those would have removed one symptom and left the actual problem in place, which is that two programs both believed they were Mercury.</p>
<p>The fix we shipped is a rule instead: <strong>one process owns the runtime, and the terminal attaches to it.</strong></p>
<ul>
<li class="">Launching <code>mercury</code> starts the daemon if needed and then attaches to it. The terminal never becomes a second runtime unless no daemon can run on that platform (Android under Termux is the one case).</li>
<li class="">If a foreground process does start beside a live daemon, for example to open Mercury Code, it runs as a terminal for the main agent only. It doesn't register channels, doesn't create a bot manager, doesn't bind the web port, and doesn't replay scheduled work.</li>
<li class="">Attaching is instant. The daemon now binds its web listener first, before channels and bots finish starting, and answers a lightweight health check with its process ID. If something else owns the port, you get one sentence saying which process it is instead of a 30-second wait followed by a pointless restart.</li>
</ul>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=making-lag-measurable>Making lag measurable<a href=#making-lag-measurable class=hash-link aria-label="Direct link to Making lag measurable" title="Direct link to Making lag measurable" translate=no>​</a></h2>
<p>The part I'm happiest with is small. Mercury now measures its own event loop. <code>/api/health</code> reports the 99th-percentile and worst stall over the last ten seconds, and any stall longer than 250 ms is logged with a warning.</p>
<p>We spent days on this bug partly because "it feels slow" isn't evidence. Now it is. If a bot turn ever does something synchronous that holds the main thread, the daemon's log will say so, with a number.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=what-we-got-wrong-and-what-we-changed>What we got wrong, and what we changed<a href=#what-we-got-wrong-and-what-we-changed class=hash-link aria-label="Direct link to What we got wrong, and what we changed" title="Direct link to What we got wrong, and what we changed" translate=no>​</a></h2>
<p>The honest version: the double runtime existed for a long time and we never noticed, because nothing measured it and the symptom only appeared once the workload changed. The tests passed because each runtime, on its own, worked.</p>
<p>So the fix came with a few guards that would have caught it:</p>
<ul>
<li class="">A contract test asserts the launcher never starts the daemon and then a second runtime.</li>
<li class="">The login service is checked against the running install on every launch and re-pointed if it drifted.</li>
<li class="">Merges now wait for the entire CI run, not just the checks that happen to have reported so far.</li>
</ul>
<p>If you're building something that runs in the background and has a terminal front end, the takeaway is the same one we learned: decide which process is the program, and make everything else a client. It's much easier than working out, later, which of two programs is the real one.</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/we-were-running-mercury-twice.md>View .md</a><button type=button>Copy link</button><a href="https://x.com/intent/post?url=https%3A%2F%2Fmercuryagent.sh%2Fblog%2Fwe-were-running-mercury-twice&text=We%20were%20running%20Mercury%20twice%20and%20didn't%20know%20it" 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%2Fwe-were-running-mercury-twice" 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><a href=/blog/tags/runtime>Runtime</a></div><nav class=mj-pager aria-label="More posts"><a href=/blog/the-wizard-that-quit-at-the-menu><small>Newer</small>The setup wizard that quit at the first menu</a><a class=is-next href=/blog/mercury-1-3><small>Older</small>Mercury 1.3: an agent you can actually leave running</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>