Skip to content

Commit 27f185b

Browse files
author
Delta Team
committed
PR_26175_DELTA_002: consolidate replay runtime cloning
1 parent b760048 commit 27f185b

12 files changed

Lines changed: 169 additions & 256 deletions

docs_build/dev/ProjectInstructions/backlog/BACKLOG_MASTER.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ Current OWNER clarification:
241241

242242
### Team Delta
243243

244-
- [ ] Delta - Shared JS consolidation
244+
- [x] Delta - Shared JS consolidation
245+
- Completion reference: PR_26175_DELTA_002_Shared_Runtime_Consolidation.
245246
- [ ] Delta - API client consolidation
246247
- [x] Delta - Runtime performance audit
247248
- Completion reference: PR_26175_DELTA_001_Runtime_Performance_Optimization.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# PR_26175_DELTA_002 Branch Validation
2+
3+
| Gate | Status | Evidence |
4+
| --- | --- | --- |
5+
| Current branch before work | PASS | `main` after PR_001 merge |
6+
| Worktree before work | PASS | Clean |
7+
| Local/origin sync before work | PASS | `0 0` |
8+
| Team ownership | PASS | Team Delta owns Runtime, Shared JS, and technical consolidation. |
9+
| Work branch | PASS | `PR_26175_DELTA_002_Shared_Runtime_Consolidation` |
10+
| Previous Delta PR closed | PASS | PR_001 was merged and `main` was verified before PR_002 started. |
11+
| Scope boundary | PASS | Shared runtime clone helper plus replay runtime adopters and focused test only. |
12+
13+
## Instruction Reads
14+
15+
PASS - All files under `docs_build/dev/ProjectInstructions/` were read before the Delta sequence, and updated instructions were reread after pulling latest `main`.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# PR_26175_DELTA_002 Manual Validation Notes
2+
3+
- Confirmed Team Delta ownership covers Shared JS and Runtime.
4+
- Confirmed replay runtime cloning duplicated local `structuredClone` calls before this PR.
5+
- Confirmed replay model and replay system now use the shared runtime clone helper.
6+
- Confirmed fallback behavior by temporarily disabling `globalThis.structuredClone` in the focused replay test.
7+
- Confirmed no browser-owned data, API contract, UI, or tool state changes were introduced.
8+
- Confirmed backlog completion reference was added for `Delta - Shared JS consolidation`.
9+
- Confirmed source branch disposition should remain `retained`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# PR_26175_DELTA_002 Requirement Checklist
2+
3+
| Requirement | Status | Notes |
4+
| --- | --- | --- |
5+
| Team Delta ownership only | PASS | Shared JS and runtime replay consolidation are Delta-owned. |
6+
| One PR purpose | PASS | Shared runtime clone consolidation only. |
7+
| Preserve backward compatibility | PASS | Added JSON fallback when `structuredClone` is unavailable. |
8+
| Update backlog | PASS | `Delta - Shared JS consolidation` marked complete. |
9+
| Update tool state if applicable | PASS | Not applicable; no tool tile/status changed. |
10+
| Produce governance reports | PASS | Summary, branch validation, checklist, validation lane, manual notes, Codex diff, changed-file list, and ZIP. |
11+
| Runtime validation | PASS | Focused node checks, replay system test, and final systems test passed. |
12+
| No unrelated files | PASS | Changes are limited to shared runtime clone, replay runtime adopters, focused test, backlog, and reports. |
13+
| No branch deletion | PASS | Source branch retained. |
14+
15+
## Compatibility Notes
16+
17+
- Public replay model shape is unchanged.
18+
- Replay frames remain deep-cloned before storage and output.
19+
- Fallback cloning supports runtime environments without native `structuredClone`.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# PR_26175_DELTA_002 Validation Lane
2+
3+
## Commands
4+
5+
```powershell
6+
node --check src/shared/runtime/snapshotClone.js
7+
node --check src/engine/replay/ReplayModel.js
8+
node --check src/engine/replay/ReplaySystem.js
9+
node --check tests/replay/ReplaySystem.test.mjs
10+
node tests/replay/ReplaySystem.test.mjs
11+
node tests/final/FinalSystems.test.mjs
12+
```
13+
14+
## Results
15+
16+
| Command | Status |
17+
| --- | --- |
18+
| `node --check src/shared/runtime/snapshotClone.js` | PASS |
19+
| `node --check src/engine/replay/ReplayModel.js` | PASS |
20+
| `node --check src/engine/replay/ReplaySystem.js` | PASS |
21+
| `node --check tests/replay/ReplaySystem.test.mjs` | PASS |
22+
| `node tests/replay/ReplaySystem.test.mjs` | PASS |
23+
| `node tests/final/FinalSystems.test.mjs` | PASS |
24+
25+
## Browser Validation
26+
27+
SKIP - No browser UI files changed.
28+
29+
## Playwright Validation
30+
31+
SKIP - Runtime replay/shared helper behavior is covered by focused Node tests.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# PR_26175_DELTA_002_Shared_Runtime_Consolidation
2+
3+
## Summary
4+
5+
Team Delta consolidated replay cloning onto the shared runtime helper surface.
6+
7+
`src/shared/runtime/snapshotClone.js` now exports `cloneRuntimeValue(...)`, which gives runtime code one shared cloning path with a `structuredClone` fast path and JSON fallback. Replay model and replay system cloning now use that shared helper instead of local `structuredClone` calls.
8+
9+
## Scope
10+
11+
- Team: Delta
12+
- Backlog item: `Delta - Shared JS consolidation`
13+
- Shared runtime file changed: `src/shared/runtime/snapshotClone.js`
14+
- Runtime replay files changed:
15+
- `src/engine/replay/ReplayModel.js`
16+
- `src/engine/replay/ReplaySystem.js`
17+
- Tests changed: `tests/replay/ReplaySystem.test.mjs`
18+
- Backlog updated: `docs_build/dev/ProjectInstructions/backlog/BACKLOG_MASTER.md`
19+
20+
## Runtime Impact
21+
22+
PASS - Replay cloning behavior remains backward compatible.
23+
24+
- Replay records still deep-clone metadata, initial state, frames, and final state.
25+
- Runtime replay code now works even when `structuredClone` is unavailable.
26+
- Existing replay playback and replacement behavior is preserved.
27+
28+
## Backlog Update
29+
30+
PASS - `Delta - Shared JS consolidation` is marked complete with this PR as the completion reference.
31+
32+
## Tool State Update
33+
34+
SKIP - No Build Path tool status or tool tile state changed.
35+
36+
## Validation Summary
37+
38+
PASS - Focused replay and final system validation completed.
39+
40+
See `PR_26175_DELTA_002_Shared_Runtime_Consolidation-validation.md` for command details.
41+
42+
## Branch Disposition
43+
44+
Source branch should be retained after merge unless OWNER later approves branch deletion.
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
docs_build/dev/ProjectInstructions/backlog/BACKLOG_MASTER.md / updated
2-
src/engine/runtime/runtimeTickLoop.js / updated
3-
tests/engine/RuntimeTickLoop.test.mjs / updated
4-
docs_build/dev/reports/PR_26175_DELTA_001_Runtime_Performance_Optimization.md / added
5-
docs_build/dev/reports/PR_26175_DELTA_001_Runtime_Performance_Optimization-branch-validation.md / added
6-
docs_build/dev/reports/PR_26175_DELTA_001_Runtime_Performance_Optimization-requirement-checklist.md / added
7-
docs_build/dev/reports/PR_26175_DELTA_001_Runtime_Performance_Optimization-validation.md / added
8-
docs_build/dev/reports/PR_26175_DELTA_001_Runtime_Performance_Optimization-manual-validation-notes.md / added
2+
src/shared/runtime/snapshotClone.js / updated
3+
src/engine/replay/ReplayModel.js / updated
4+
src/engine/replay/ReplaySystem.js / updated
5+
tests/replay/ReplaySystem.test.mjs / updated
6+
docs_build/dev/reports/PR_26175_DELTA_002_Shared_Runtime_Consolidation.md / added
7+
docs_build/dev/reports/PR_26175_DELTA_002_Shared_Runtime_Consolidation-branch-validation.md / added
8+
docs_build/dev/reports/PR_26175_DELTA_002_Shared_Runtime_Consolidation-requirement-checklist.md / added
9+
docs_build/dev/reports/PR_26175_DELTA_002_Shared_Runtime_Consolidation-validation.md / added
10+
docs_build/dev/reports/PR_26175_DELTA_002_Shared_Runtime_Consolidation-manual-validation-notes.md / added
911
docs_build/dev/reports/codex_changed_files.txt / updated
1012
docs_build/dev/reports/codex_review.diff / updated

docs_build/dev/reports/codex_review.diff

Lines changed: 1 addition & 243 deletions
Large diffs are not rendered by default.

src/engine/replay/ReplayModel.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ ReplayModel.js
77
import {
88
SHARED_REPLAY_MODEL_CONTRACT_VERSION,
99
} from "../../shared/contracts/replayContracts.js";
10+
import { cloneRuntimeValue } from "../../shared/runtime/snapshotClone.js";
1011

1112
function cloneOrNull(value) {
12-
return value === undefined || value === null ? null : structuredClone(value);
13+
return cloneRuntimeValue(value);
1314
}
1415

1516
function cloneFrames(frames) {
@@ -18,7 +19,7 @@ function cloneFrames(frames) {
1819
}
1920
const out = [];
2021
for (let i = 0; i < frames.length; i += 1) {
21-
out.push(structuredClone(frames[i]));
22+
out.push(cloneRuntimeValue(frames[i]));
2223
}
2324
return out;
2425
}

src/engine/replay/ReplaySystem.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ David Quesenberry
55
ReplaySystem.js
66
*/
77
import { asNonNegativeInteger } from '../../shared/math/numberNormalization.js';
8+
import { cloneRuntimeValue } from '../../shared/runtime/snapshotClone.js';
89
import { createReplayModel, normalizeReplayModel, withFinalState } from './ReplayModel.js';
910
import { ReplayTimeline } from './ReplayTimeline.js';
1011

@@ -37,7 +38,7 @@ export default class ReplaySystem {
3738

3839
recordFrame(frame) {
3940
if (this.recording) {
40-
const clonedFrame = structuredClone(frame);
41+
const clonedFrame = cloneRuntimeValue(frame);
4142
this.frames.push(clonedFrame);
4243
this.timeline.pushSnapshot(this.frames.length - 1, clonedFrame);
4344
}
@@ -51,7 +52,7 @@ export default class ReplaySystem {
5152
}
5253

5354
getReplay() {
54-
return structuredClone(this.replay);
55+
return cloneRuntimeValue(this.replay);
5556
}
5657

5758
loadReplay(replay) {
@@ -96,7 +97,7 @@ export default class ReplaySystem {
9697
const normalizedFrameId = asNonNegativeInteger(frameId, this.frames.length);
9798
const prefix = this.frames.slice(0, normalizedFrameId);
9899
const replacementFrames = Array.isArray(frames)
99-
? frames.map((frame) => structuredClone(frame))
100+
? frames.map((frame) => cloneRuntimeValue(frame))
100101
: [];
101102
const nextFrames = [...prefix, ...replacementFrames];
102103

0 commit comments

Comments
 (0)