Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

refactor(relay): move fallback predicates to their own module [B26]

Corey Olsonab872f74a964
diff --git a/src/relay-move-fallback.js b/src/relay-move-fallback.js
new file mode 100644
index 00000000..a0a2d574
--- /dev/null
+++ b/src/relay-move-fallback.js
@@ -0,0 +1,17 @@
+/** When a relay failure may let a local board move commit without the relay (#919, #341). */
+import { Refused } from './refused.js';
+
+/** Whether the relay has not yet accepted this board's first snapshot, so no ordered history exists to protect. */
+export function baselineNotAccepted(state) {
+ return state.mode === 'ordered' && state.baselineAccepted === false && !state.baselineConflict;
+}
+
+/**
+ * Whether a relay failure says nothing definite about the board: a timeout, a lost connection, a busy relay or a 5xx.
+ * Why: only a definite refusal (auth, a conflicting baseline) may stop a local move before the relay accepts a baseline.
+ */
+export function transientRelayFailure(error) {
+ if (!(error instanceof Refused)) return false;
+ if (['RELAY_UNAVAILABLE', 'RELAY_RESPONSE', 'RELAY_BUSY'].includes(error.code)) return true;
+ return Number.isInteger(error.httpStatus) && (error.httpStatus >= 500 || [408, 425, 429].includes(error.httpStatus));
+}
diff --git a/src/relay.js b/src/relay.js
index 2f5b38eb..4cd6f699 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -84,6 +84,7 @@ import {
unseal,
} from './seal.js';
import { terminalQr } from './qr.js';
+import { baselineNotAccepted, transientRelayFailure } from './relay-move-fallback.js';
import { Refused } from './refused.js';
import { refusalFromReceipt } from './recorded-refusal.js';
import { relaySenderProblem } from './relay-sender.js';
@@ -1170,21 +1171,6 @@ function recoveredMove(root, state, operation, args, command) {
return recovered.move;
}
-/** Whether the relay has not yet accepted this board's first snapshot, so no ordered history exists to protect. */
-function baselineNotAccepted(state) {
- return state.mode === 'ordered' && state.baselineAccepted === false && !state.baselineConflict;
-}
-
-/**
- * Whether a relay failure says nothing definite about the board: a timeout, a lost connection, a busy relay or a 5xx.
- * Why: only a definite refusal (auth, a conflicting baseline) may stop a local move before the relay accepts a baseline.
- */
-function transientRelayFailure(error) {
- if (!(error instanceof Refused)) return false;
- if (['RELAY_UNAVAILABLE', 'RELAY_RESPONSE', 'RELAY_BUSY'].includes(error.code)) return true;
- return Number.isInteger(error.httpStatus) && (error.httpStatus >= 500 || [408, 425, 429].includes(error.httpStatus));
-}
-
/**
* Record that a local move happened while the baseline upload was uncertain, and say so once.
* Why: the saved snapshot predates the move, so the next command seals a fresh baseline that holds it (#919).