Skip to content

Commit db63bb8

Browse files
authored
Merge pull request #73 from MrAlders0n/copilot/fix-fail-open-issue
Change capacity check from fail-open to fail-closed and improve status messages
2 parents 05cdc3b + db78f31 commit db63bb8

2 files changed

Lines changed: 42 additions & 29 deletions

File tree

STATUS_MESSAGES.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,23 @@ Status messages follow these consistent conventions:
8989
- **Context**: When connecting to device and checking if a wardriving slot is available
9090
- **Minimum Visibility**: 500ms minimum enforced (or until API response received)
9191

92-
#### WarDriving app has reached capacity or is down
93-
- **Message**: `"WarDriving app has reached capacity or is down"`
92+
#### WarDriving app has reached capacity
93+
- **Message**: `"WarDriving app has reached capacity"`
9494
- **Color**: Red (error)
9595
- **Used in**: `checkCapacity()`, `postToMeshMapperAPI()`
96-
- **Source**: `content/wardrive.js:2051`, `content/wardrive.js:1115`
97-
- **Context**: Capacity check API denies slot on connect, or wardriving API returns allowed=false during active session
96+
- **Source**: `content/wardrive.js:1061`, `content/wardrive.js:1116`
97+
- **Context**: Capacity check API denies slot on connect (returns allowed=false), or wardriving API returns allowed=false during active session
9898
- **Minimum Visibility**: N/A (error state persists until disconnect)
99+
- **Notes**: Displayed when the API successfully responds but indicates capacity is full
100+
101+
#### WarDriving app is down
102+
- **Message**: `"WarDriving app is down"`
103+
- **Color**: Red (error)
104+
- **Used in**: `checkCapacity()`
105+
- **Source**: `content/wardrive.js:1050`, `content/wardrive.js:1072`
106+
- **Context**: Capacity check API returns error status or network is unreachable during connect
107+
- **Minimum Visibility**: N/A (error state persists until disconnect)
108+
- **Notes**: Implements fail-closed policy - connection is denied if API fails or is unreachable
99109

100110
#### Unable to read device public key; try again
101111
- **Message**: `"Unable to read device public key; try again"`
@@ -106,13 +116,12 @@ Status messages follow these consistent conventions:
106116
- **Minimum Visibility**: N/A (error state persists until disconnect)
107117

108118
#### Network issue checking slot, proceeding anyway
109-
- **Message**: `"Network issue checking slot, proceeding anyway"`
119+
- **Message**: `"Network issue checking slot, proceeding anyway"` (DEPRECATED - no longer used)
110120
- **Color**: Amber (warning)
111-
- **Used in**: `checkCapacity()`
112-
- **Source**: `content/wardrive.js:1051`, `content/wardrive.js:1070`
113-
- **Context**: Capacity check API is unreachable or returns error during connect (fail-open behavior)
114-
- **Minimum Visibility**: 1500ms enforced (brief warning before continuing)
115-
- **Notes**: Implements fail-open policy - allows connection to proceed despite API failure
121+
- **Used in**: N/A (removed)
122+
- **Source**: Previously `content/wardrive.js:1051`, `content/wardrive.js:1070`
123+
- **Context**: This message is no longer shown. Network issues now result in connection denial (fail-closed)
124+
- **Notes**: Replaced by fail-closed policy - connection is now denied on network errors
116125

117126
---
118127

@@ -268,9 +277,9 @@ These messages use a hybrid approach: **first display respects 500ms minimum**,
268277
#### Idle
269278
- **Message**: `"Idle"`
270279
- **Color**: Slate (idle)
271-
- **Used in**: `postApiAndRefreshMap()`
272-
- **Source**: `content/wardrive.js:1091`
273-
- **Context**: Manual mode, after API post completes
280+
- **Used in**: `connect()`, `postApiAndRefreshMap()`
281+
- **Source**: `content/wardrive.js:2060`, `content/wardrive.js:1091`
282+
- **Context**: Initial connection complete after capacity check succeeds, or manual mode after API post completes
274283
- **Minimum Visibility**: 500ms minimum enforced
275284

276285
---
@@ -360,9 +369,9 @@ Result: "Message A" (visible 500ms) → "Message C"
360369

361370
## Summary
362371

363-
**Total Status Messages**: 29 unique message patterns
372+
**Total Status Messages**: 30 unique message patterns
364373
- **Connection**: 7 messages
365-
- **Capacity Check**: 4 messages
374+
- **Capacity Check**: 4 messages (1 deprecated)
366375
- **Ping Operation**: 6 messages (consolidated "Ping sent" for both manual and auto)
367376
- **GPS**: 2 messages
368377
- **Countdown Timers**: 6 message patterns (with dynamic countdown values)

content/wardrive.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,32 +1044,33 @@ async function checkCapacity(reason) {
10441044

10451045
if (!response.ok) {
10461046
debugWarn(`Capacity check API returned error status ${response.status}`);
1047-
// Fail open on network errors for connect
1047+
// Fail closed on network errors for connect
10481048
if (reason === "connect") {
1049-
debugWarn("Failing open (allowing connection) due to API error");
1050-
// Show network issue message briefly
1051-
setStatus("Network issue checking slot, proceeding anyway", STATUS_COLORS.warning);
1052-
await new Promise(resolve => setTimeout(resolve, 1500)); // Show message for 1.5s
1053-
return true;
1049+
debugError("Failing closed (denying connection) due to API error");
1050+
setStatus("WarDriving app is down", STATUS_COLORS.error);
1051+
return false;
10541052
}
10551053
return true; // Always allow disconnect to proceed
10561054
}
10571055

10581056
const data = await response.json();
10591057
debugLog(`Capacity check response: allowed=${data.allowed}`);
10601058

1059+
// Handle capacity full vs. allowed cases separately
1060+
if (data.allowed === false && reason === "connect") {
1061+
setStatus("WarDriving app has reached capacity", STATUS_COLORS.error);
1062+
}
1063+
10611064
return data.allowed === true;
10621065

10631066
} catch (error) {
10641067
debugError(`Capacity check failed: ${error.message}`);
10651068

1066-
// Fail open on network errors for connect
1069+
// Fail closed on network errors for connect
10671070
if (reason === "connect") {
1068-
debugWarn("Failing open (allowing connection) due to network error");
1069-
// Show network issue message briefly
1070-
setStatus("Network issue checking slot, proceeding anyway", STATUS_COLORS.warning);
1071-
await new Promise(resolve => setTimeout(resolve, 1500)); // Show message for 1.5s
1072-
return true;
1071+
debugError("Failing closed (denying connection) due to network error");
1072+
setStatus("WarDriving app is down", STATUS_COLORS.error);
1073+
return false;
10731074
}
10741075

10751076
return true; // Always allow disconnect to proceed
@@ -1112,7 +1113,7 @@ async function postToMeshMapperAPI(lat, lon, heardRepeats) {
11121113
const data = await response.json();
11131114
if (data.allowed === false) {
11141115
debugWarn("MeshMapper API returned allowed=false, disconnecting");
1115-
setStatus("WarDriving app has reached capacity or is down", STATUS_COLORS.error);
1116+
setStatus("WarDriving app has reached capacity", STATUS_COLORS.error);
11161117
// Disconnect after a brief delay to ensure user sees the message
11171118
setTimeout(() => {
11181119
disconnect().catch(err => debugError(`Disconnect after capacity denial failed: ${err.message}`));
@@ -2048,11 +2049,14 @@ async function connect() {
20482049
const allowed = await checkCapacity("connect");
20492050
if (!allowed) {
20502051
debugWarn("Capacity check denied, disconnecting");
2051-
setStatus("WarDriving app has reached capacity or is down", STATUS_COLORS.error);
2052+
// Status message already set by checkCapacity()
20522053
// Disconnect after a brief delay to ensure user sees the message
20532054
setTimeout(() => {
20542055
disconnect().catch(err => debugError(`Disconnect after capacity denial failed: ${err.message}`));
20552056
}, 1500);
2057+
} else {
2058+
// Connection complete, set status to Idle
2059+
setStatus("Idle", STATUS_COLORS.idle);
20562060
}
20572061
} catch (e) {
20582062
debugError(`Channel setup failed: ${e.message}`, e);

0 commit comments

Comments
 (0)