Skip to content

Commit 172ae0b

Browse files
author
DavidQ
committed
Level 11.1: Passive mode guard
- Prevented authoritative mutations in passive mode - No API changes
1 parent f176246 commit 172ae0b

6 files changed

Lines changed: 47 additions & 47 deletions

File tree

docs/dev/CODEX_COMMANDS.md

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,21 @@ MODEL: GPT-5.3-codex
22
REASONING: high
33

44
COMMAND:
5-
Implement BUILD_PR_LEVEL_11_1_HANDOFF_VALIDATION_TIGHTEN.
5+
Implement BUILD_PR_LEVEL_11_1_PASSIVE_MODE_GUARD.
66

77
Modify ONLY:
88
src/advanced/state/transitions.js
99

10-
Apply EXACT replacements:
11-
12-
1. validateApplyScoreDelta:
13-
- Introduce normalizedDelta = Number(payload.delta)
14-
- Enforce Number.isFinite(normalizedDelta)
15-
- Update reason to: applyScoreDelta requires finite numeric payload.delta.
16-
17-
2. validateAdvanceWave:
18-
- Keep validation logic
19-
- Update reason to: advanceWave requires finite amount > 0.
20-
21-
3. validateUpdateObjectiveProgress:
22-
- Replace inline Number(...) checks with:
23-
normalizedCurrent
24-
normalizedTarget
25-
- Enforce Number.isFinite on both
26-
- Update reasons to finite numeric wording
10+
Change:
11+
- Add guard to prevent authoritativeApply execution when in passive mode
2712

2813
Do NOT:
2914
- change APIs
30-
- modify apply functions
31-
- refactor unrelated code
32-
- scan unrelated files
15+
- refactor unrelated logic
3316

3417
Validation:
35-
- All existing tests pass
36-
- Handoff test rejects invalid numeric values
18+
- Passive mode does not mutate state
19+
- Existing tests pass
3720

3821
Output:
39-
Return exactly one repo-structured ZIP at:
40-
<project folder>/tmp/BUILD_PR_LEVEL_11_1_HANDOFF_VALIDATION_TIGHTEN.zip
22+
<project folder>/tmp/BUILD_PR_LEVEL_11_1_PASSIVE_MODE_GUARD.zip

docs/dev/COMMIT_COMMENT.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
Level 11.1: tighten numeric validation at transition boundary
1+
Level 11.1: Passive mode guard
22

3-
- enforce finite numeric validation using Number() normalization
4-
- prevent NaN / Infinity drift
5-
- improve validation clarity
6-
7-
Scope: validation only
3+
- Prevented authoritative mutations in passive mode
4+
- No API changes
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
Updated transition validation to enforce finite numeric inputs.
2-
3-
Targets:
4-
- applyScoreDelta: normalized + finite check
5-
- advanceWave: clarified finite requirement
6-
- updateObjectiveProgress: explicit normalized finite checks
7-
8-
No API or structural changes.
1+
Added passive mode guard to prevent state mutation during non-authoritative execution.
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
[ ] Only src/advanced/state/transitions.js modified
1+
[ ] transitions.js modified only
2+
[ ] Passive mode does not mutate
3+
[ ] Authoritative mode unchanged
24
[ ] No API changes
3-
[ ] No apply function changes
4-
[ ] Number() normalization added
5-
[ ] Number.isFinite enforced
6-
[ ] NaN rejected
7-
[ ] Infinity rejected
8-
[ ] Existing tests pass
5+
[ ] Tests pass
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# BUILD PR — Level 11.1 Passive Mode Guard
2+
3+
## Purpose
4+
Prevent passive mode from mutating authoritative state.
5+
6+
## Scope
7+
- Validation guard only
8+
- No API changes
9+
10+
## File
11+
- src/advanced/state/transitions.js
12+
13+
## Change
14+
- Ensure authoritativeApply is NOT executed in passive mode
15+
16+
## Validation
17+
- Passive mode produces no mutations
18+
- Authoritative mode unchanged

src/advanced/state/transitions.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import { WORLD_GAME_STATE_EVENT_TYPES } from './constants.js';
99
import { isPlainObject } from '../../shared/utils/objectUtils.js';
1010
import { toFiniteNumber } from '../../shared/math/numberNormalization.js';
1111

12+
function isPassiveModeContext(context) {
13+
if (!isPlainObject(context)) return false;
14+
if (context.passiveMode === true) return true;
15+
if (typeof context.mode === 'string' && context.mode.trim().toLowerCase() === 'passive') return true;
16+
return false;
17+
}
18+
1219
function recalcObjectiveSummary(objectivesById) {
1320
const objectiveIds = Object.keys(objectivesById);
1421
let completed = 0;
@@ -60,7 +67,10 @@ function validateApplyScoreDelta(payload) {
6067
return { ok: true };
6168
}
6269

63-
function applyAuthoritativeScoreDelta(snapshot, payload) {
70+
function applyAuthoritativeScoreDelta(snapshot, payload, context = {}) {
71+
if (isPassiveModeContext(context)) {
72+
return { changes: [] };
73+
}
6474
if (!snapshot.worldState || !isPlainObject(snapshot.worldState)) {
6575
snapshot.worldState = {};
6676
}
@@ -112,6 +122,9 @@ function validateUpdateObjectiveProgress(payload) {
112122
}
113123

114124
function applyAuthoritativeObjectiveProgress(snapshot, payload, context = {}) {
125+
if (isPassiveModeContext(context)) {
126+
return { changes: [] };
127+
}
115128
const now = typeof context.now === 'function' ? context.now : () => Date.now();
116129
const objectiveId = String(payload.objectiveId || '').trim();
117130
const objectives = snapshot.worldState && snapshot.worldState.objectives

0 commit comments

Comments
 (0)