Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: move handshake re-delivery into the paste controller that owns the submit handle
Adam Eivy036a939b1ce9
diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.jsindex 707d44e92d..a9bc3d5b07 100644--- a/server/lib/tuiHandshake.js+++ b/server/lib/tuiHandshake.js@@ -540,9 +540,9 @@ export function createGenerationActivityTracker() {// on this cadence and only fails over once the retries are exhausted.//// 20s: slow enough that a re-paste can't outrun agy's own reflow + round trip-// (a submission that IS accepted paints `esc to cancel` within ~1s, which closes-// the window before the next retry is due), and fast enough to fit several-// attempts inside the grace window.+// (a submission that IS accepted starts painting `Generating…` within ~1s, which+// closes the window before the next retry is due), and fast enough to fit+// several attempts inside the grace window.export const SELF_CLEARING_RESUBMIT_INTERVAL_MS = 20000;// How often a consumer without its own poll should ASK the gate whether a@@ -590,8 +590,8 @@ export const SELF_CLEARING_RESUBMIT_ECHO_MS = 3000;* lazily on the first post-prompt chunk and may not exist yet when the banner* paints.*- * Usage per chunk: `gate.observe(stripped)` then, on a match,- * `gate.arm(analysis, Date.now())`. `gate.armed` is the idle-suppression+ * Usage per chunk: `gate.observe(stripped, now)` then, on a match,+ * `gate.arm(analysis, now)`. `gate.armed` is the idle-suppression* predicate — a session waiting out a handshake is silent by design, and letting* an idle reaper finalize it would report a bogus success that scrapes the* banner as the answer. `gate.takeResubmit(Date.now())` returns the 1-baseddiff --git a/server/lib/tuiPromptRunner.js b/server/lib/tuiPromptRunner.jsindex 27dbf0d1fc..ad592da7d7 100644--- a/server/lib/tuiPromptRunner.js+++ b/server/lib/tuiPromptRunner.js@@ -726,10 +726,16 @@ ${prompt}`;// has been unregistered, which is also the "don't bother" answer here —// the deadline timer still owns the fail-over.if (submitEnterTimer) clearInterval(submitEnterTimer);- submitEnterTimer = pasteToSession(runId, wrappedPrompt, {+ const submitted = pasteToSession(runId, wrappedPrompt, {label: `[tuiRun ${runId}] provider-handshake resubmit`,- }) || null;- console.log(`🔁 TUI run ${runId} re-submitted its prompt while the provider handshake is open (attempt ${attempt})`);+ });+ submitEnterTimer = submitted || null;+ // Only claim the re-submission that actually went out — `false` here means+ // the PTY is already gone, and a log line saying otherwise would send a+ // post-mortem looking for a paste the provider never received.+ if (submitted) {+ console.log(`🔁 TUI run ${runId} re-submitted its prompt while the provider handshake is open (attempt ${attempt})`);+ }};// Ready watch — paste only once the TUI banner finishes repainting ANDdiff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.jsindex 9e01ee6b6b..e9bca91f5e 100644--- a/server/services/agentTuiSpawning.js+++ b/server/services/agentTuiSpawning.js@@ -329,6 +329,42 @@ function createPasteRetryController({// moved here — sendPrompt is this controller's only setter for it now.let sent = false;+ /**+ * Re-deliver the prompt while a self-clearing provider signal's grace window+ * is open (agy's account-eligibility banner).+ *+ * The banner is the REJECTION of the submission, not a spinner over an+ * in-flight one: agy discards the prompt, empties its composer and returns to+ * its idle footer, so nothing will generate until something re-asks — which is+ * also what the banner instructs ("try again shortly"). Re-pasting the WHOLE+ * prompt is correct precisely because the composer is empty.+ *+ * Lives here rather than in spawnTuiAgent because this controller owns+ * `submitEnterTimer`; leaving the handle in one scope and the re-delivery in+ * another is how you leak an Enter interval past finish(). Nothing here+ * re-runs paste VERIFICATION: the prompt already rendered once (its rejection+ * is why we're here), and routing back through `attemptPaste` would spend the+ * startup paste-retry budget and let a verification hiccup mid-handshake+ * finalize the run as `paste-not-rendered`.+ *+ * @returns {boolean} whether the paste actually went out (false once the+ * session is gone — the caller must not claim a re-submission that didn't+ * happen).+ */+ const resubmit = () => {+ if (isFinalized() || !sessionId) return false;+ // Overwriting a live handle would leak the previous attempt's Enter interval+ // past cancel(); pasteToSession returns a fresh one, or false once the+ // session is gone — which is also the "don't bother" answer, since the+ // grace window's deadline still owns the fail-over.+ if (submitEnterTimer) clearInterval(submitEnterTimer);+ const handle = shellService.pasteToSession(sessionId, prompt, {+ label: '[cosAgents] provider-handshake resubmit',+ });+ submitEnterTimer = handle || null;+ return !!handle;+ };+// Reap the run as a max-runtime failure. Shared by the wrap-up grace window's// expiry and its own "session already died" branch so both produce the same// record: uncommitted work captured for post-mortem, then a@@ -630,7 +666,7 @@ function createPasteRetryController({postPasteBuffer = null;};- return { sendPrompt, ingestChunk, cancel };+ return { sendPrompt, resubmit, ingestChunk, cancel };}export async function spawnTuiAgent({@@ -1137,18 +1173,15 @@ export async function spawnTuiAgent({const resubmitAfterSignal = () => {// A banner that paints during startup (before the prompt was ever submitted)// has nothing to re-send — the ordinary paste path still owns first delivery.- if (finalized || !promptSubmittedAt || !sessionId) return;+ if (finalized || !promptSubmittedAt) return;const attempt = selfClearingGate.takeResubmit(Date.now());if (!attempt) return;- // Overwriting a live handle would leak the previous attempt's Enter interval- // past finish(); pasteToSession returns a fresh one, or false once the- // session is gone — which is also the "don't bother" answer, since the- // deadline still owns the fail-over.- if (submitEnterTimer) clearInterval(submitEnterTimer);- submitEnterTimer = shellService.pasteToSession(sessionId, prompt, {- label: '[cosAgents] provider-handshake resubmit',- }) || null;- appendLine(`🔁 Provider handshake still open — re-submitted the prompt (attempt ${attempt})`);+ // Only claim the re-submission that actually went out — a false return means+ // the session is already gone, and a transcript line saying otherwise would+ // send a post-mortem looking for a paste the provider never received.+ if (pasteController?.resubmit()) {+ appendLine(`🔁 Provider handshake still open — re-submitted the prompt (attempt ${attempt})`);+ }};const handleData = async (data) => {