Skip to content

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

fix: disqualify only the untrusted slice boundary instead of dropping the leading partial line (#3631)

[._.]/ Adam Eivy9098e45c16c2
diff --git a/server/lib/aiToolkit/errorDetection.js b/server/lib/aiToolkit/errorDetection.js
index 6e118e87b4..50f5698084 100644
--- a/server/lib/aiToolkit/errorDetection.js
+++ b/server/lib/aiToolkit/errorDetection.js
@@ -316,16 +316,20 @@ export function analyzeError(errorText, exitCode = null) {
* than a real line start (the streaming detector keeps only a trailing window).
* A marker anchored with `^…/m` matches a slice boundary too, so a quoted
* banner whose line prefix fell out of the window would be promoted — the very
- * false-bench this gate exists to prevent. When the boundary is untrusted the
- * marker is tested only from the first newline on, so promotion needs a line
- * start the buffer actually witnessed. Pure.
+ * false-bench this gate exists to prevent. An untrusted boundary is therefore
+ * disqualified by prefixing a non-printing, non-line-terminator byte: every
+ * line start the buffer actually witnessed (JS `^…/m` honors a bare `\r` too,
+ * which is how a repainted TUI screen advances) still promotes, and nothing is
+ * discarded. Pure.
*/
+const UNTRUSTED_BOUNDARY = '\x00';
+
function resolveSignalOrigin(signal, text, lineStartTrusted) {
if (!signal.structuredMarker) return 'provider';
const value = text || '';
- const firstNewline = value.indexOf('\n');
- const markerText = lineStartTrusted ? value : (firstNewline === -1 ? '' : value.slice(firstNewline + 1));
- return signal.structuredMarker.test(markerText) ? 'provider' : 'output-scan';
+ return signal.structuredMarker.test(lineStartTrusted ? value : `${UNTRUSTED_BOUNDARY}${value}`)
+ ? 'provider'
+ : 'output-scan';
}
export function detectImmediateFallbackSignal(text, { lineStartTrusted = true } = {}) {
diff --git a/server/lib/aiToolkit/errorDetection.test.js b/server/lib/aiToolkit/errorDetection.test.js
index d93f789379..d2d196bf66 100644
--- a/server/lib/aiToolkit/errorDetection.test.js
+++ b/server/lib/aiToolkit/errorDetection.test.js
@@ -212,6 +212,16 @@ describe('Error Detection', () => {
expect(result).toMatchObject({ origin: 'provider' });
});
+ // A repainted TUI screen advances with a bare `\r` as often as a `\n`, and
+ // JS `^…/m` treats both as line starts — a banner behind a carriage return
+ // must still count as chrome.
+ it('promotes a banner that starts after a bare carriage return', () => {
+ const detect = createImmediateFallbackSignalDetector({ maxBuffer: 200 });
+ detect(`${'x'.repeat(300)}\r`);
+ expect(detect("⎿ We're finishing verifying your account eligibility. This usually takes a moment. Please try again shortly.\r"))
+ .toMatchObject({ origin: 'provider' });
+ });
+
it('promotes a real banner that arrives later in a buffer whose earlier mention is quoted', () => {
const transcript = "I will check whether We're finishing verifying your account eligibility. This usually takes a moment. Please try again shortly. is still firing.\n⎿ We're finishing verifying your account eligibility. This usually takes a moment. Please try again shortly.\n";
expect(detectImmediateFallbackSignal(transcript)).toMatchObject({ origin: 'provider' });