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

refactor: truncation gate delegates to the OOM gate it mirrors

Adam Eivy42c4387f3765
diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.js
index dbf587d25e..5fbb676f50 100644
--- a/server/lib/tuiHandshake.js
+++ b/server/lib/tuiHandshake.js
@@ -1310,29 +1310,22 @@ export function createOomNudgeGate() {
// that truncates three times in one run is not going to complete on the
// fourth, for the same reason an OOM that outlasts three nudges isn't.
export const TRUNCATION_NUDGE_MAX_ATTEMPTS = OOM_NUDGE_MAX_ATTEMPTS;
-// What gets pasted. The literal word a human typed, for the literal reason it
-// worked: the TUI still holds the conversation and the model just needs a turn.
-export const TRUNCATION_NUDGE_TEXT = 'continue';
+// What gets pasted — the same word the OOM nudge pastes, for the same reason:
+// the TUI still holds the conversation and the model just needs a turn.
+export const TRUNCATION_NUDGE_TEXT = OOM_NUDGE_TEXT;
/**
* State machine for "nudge a TUI session a truncated response left halted".
- * Identical policy to `createOomNudgeGate` — see `createSilenceNudgeGate` for
- * the semantics of `arm` / `takeNudge`.
+ * Delegates to `createOomNudgeGate` — the two conditions share every policy
+ * detail (a dead turn, an intact session, a banner that repaints), so the
+ * gate is literally the same machine under a name that says what it watches
+ * for. See `createSilenceNudgeGate` for the semantics of `arm` / `takeNudge`.
*
* @returns {{ arm: (analysis: object, nowMs: number) => 'armed'|'exhausted'|null,
* takeNudge: (nowMs: number, lastOutputAtMs: number) => number }}
*/
export function createTruncationNudgeGate() {
- const gate = createSilenceNudgeGate({
- cooldownMs: OOM_NUDGE_COOLDOWN_MS,
- settleMs: OOM_NUDGE_SETTLE_MS,
- armWindowMs: OOM_NUDGE_ARM_WINDOW_MS,
- maxAttempts: TRUNCATION_NUDGE_MAX_ATTEMPTS,
- });
- return {
- arm: (analysis, nowMs) => (analysis ? gate.arm(nowMs) : null),
- takeNudge: gate.takeNudge,
- };
+ return createOomNudgeGate();
}
/**
diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.js
index 127e303632..9792ff8eb2 100644
--- a/server/lib/tuiHandshake.test.js
+++ b/server/lib/tuiHandshake.test.js
@@ -1920,8 +1920,11 @@ describe('createOomNudgeGate', () => {
});
describe('createTruncationNudgeGate', () => {
- // Same shape as the OOM gate: a dead turn, an intact session. These pin the
- // policy is truly shared rather than drifting from createOomNudgeGate.
+ // The gate delegates to createOomNudgeGate (same shape: a dead turn, an
+ // intact session), so the full silence/cooldown/budget policy is pinned by
+ // the OOM suite above. These two prove the delegation stays behavioral —
+ // the truncation gate still nudges on quiet and still hands back the
+ // exhausted verdict — rather than asserting constant equality.
const analysis = { category: 'output-length', message: 'Provider cut the response off before completion' };
it('nudges only once the session has actually gone quiet', () => {
@@ -1936,30 +1939,6 @@ describe('createTruncationNudgeGate', () => {
expect(gate.takeNudge(t0 + 60_000, t0 + 5_000)).toBe(0);
});
- it('treats repaints of the same banner as one truncation', () => {
- const gate = createTruncationNudgeGate();
- const t0 = 0;
- expect(gate.arm(analysis, t0)).toBe('armed');
- expect(gate.arm(analysis, t0 + 100)).toBeNull();
- expect(gate.takeNudge(t0 + OOM_NUDGE_SETTLE_MS + 1, t0)).toBe(1);
- // Disarmed, but still inside the dedupe cooldown — a repaint must not
- // spend a second nudge on the same event.
- expect(gate.arm(analysis, t0 + OOM_NUDGE_COOLDOWN_MS - 1)).toBeNull();
- expect(gate.arm(analysis, t0 + OOM_NUDGE_COOLDOWN_MS)).toBe('armed');
- });
-
- it('drops a stale arm the session never went quiet for', () => {
- const gate = createTruncationNudgeGate();
- const t0 = 0;
- gate.arm(analysis, t0);
- // Output kept flowing for the whole window: the session recovered on its
- // own, so the arm expires rather than firing into the next quiet spell.
- expect(gate.takeNudge(t0 + OOM_NUDGE_ARM_WINDOW_MS + 1, t0 + OOM_NUDGE_ARM_WINDOW_MS)).toBe(0);
- const t1 = t0 + OOM_NUDGE_COOLDOWN_MS;
- expect(gate.arm(analysis, t1)).toBe('armed');
- expect(gate.takeNudge(t1 + OOM_NUDGE_SETTLE_MS + 1, t1)).toBe(1);
- });
-
it('hands back an exhausted verdict once the nudge budget is spent', () => {
const gate = createTruncationNudgeGate();
let t = 0;
@@ -1973,12 +1952,6 @@ describe('createTruncationNudgeGate', () => {
// the response, so the caller fails over instead of nudging again.
expect(gate.arm(analysis, t)).toBe('exhausted');
});
-
- it('ignores a null analysis', () => {
- const gate = createTruncationNudgeGate();
- expect(gate.arm(null, 0)).toBeNull();
- expect(gate.takeNudge(OOM_NUDGE_SETTLE_MS + 1, 0)).toBe(0);
- });
});
// The four modals a TUI can paint before its prompt can be delivered used to