Skip to content

Add ExecutionContext module and missing determinism test suite#64

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/add-execution-context-class
Closed

Add ExecutionContext module and missing determinism test suite#64
Copilot wants to merge 2 commits into
mainfrom
copilot/add-execution-context-class

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 8, 2026

The pr28-determinism.yml CI workflow calls python tests/test_determinism.py which did not exist, causing every PR run to fail. The problem statement specifies a full deterministic execution pipeline built around an ExecutionContext class.

New files

  • execution_context.py — Core implementation:

    • ExecutionContext — state container (seed, manifest, commands, repo_state, audit_log)
    • canonicalize() — normalizes CRLF→LF, strips trailing whitespace, sorts JSON keys; returns UTF-8 bytes
    • merkle_root() — binary Merkle tree over canonicalized file contents (odd-node duplication)
    • execute_command()MODE_1_EXECUTE mutates repo_state; MODE_2_SIMULATE is a no-op; both append an audit record
    • integrity_loop() — up to MAX_REPAIR_ATTEMPTS=3 canonicalization passes before enter_mode_0_halt()
    • test_determinism() — runs the command sequence 5× and asserts all Merkle roots agree
  • tests/test_determinism.py — 13 standalone tests (D_001–D_011), runnable via python tests/test_determinism.py (matching the pattern of the existing test_falsification.py):

D_001  canonicalize is idempotent
D_002  sha256 of fixed bytes matches NIST reference
D_003  merkle_root({}) == sha256(b'')
D_004  merkle_root single-file matches sha256(canonicalize(content))
D_005  merkle_root two-file result is stable across calls
D_006  MODE_1_EXECUTE mutates repo_state; MODE_2_SIMULATE does not
D_007  execute_command always appends exactly one audit-log entry
D_008  test_determinism() returns True for a fixed command sequence
D_009  verify_invariants True/False based on manifest match
D_010  integrity_loop repairs CRLF content and returns True
D_011  integrity_loop returns False (MODE_0_HALT) on irrecoverable mismatch
Original prompt

chatgpt: import os
import json
import hashlib
import uuid
from copy import deepcopy
from collections import deque

--- Execution Context ---

class ExecutionContext:
def init(self, seed: str, manifest: dict, commands: list):
self.seed = seed
self.manifest = manifest
self.commands = commands
self.repo_state = {}
self.current_hash = None
self.audit_log = []

--- Canonicalization ---

def canonicalize(content: str) -> str:
content = content.replace('\r\n', '\n').replace('\r', '\n')
content = '\n'.join(line.rstrip() for line in content.split('\n'))
try:
data = json.loads(content)
content = json.dumps(sort_json_keys(data), separators=(',', ':'))
except json.JSONDecodeError:
pass
return content.encode('utf-8')

def sort_json_keys(obj):
if isinstance(obj, dict):
return {k: sort_json_keys(obj[k]) for k in sorted(obj.keys())}
elif isinstance(obj, list):
return [sort_json_keys(e) for e in obj]
else:
return obj

--- Hashing ---

def sha256(data: bytes) -> str:
return hashlib.sha256(data).hexdigest()

def merkle_root(files: dict) -> str:
leaves = [sha256(canonicalize(content)) for content in files.values()]
while len(leaves) > 1:
next_level = []
for i in range(0, len(leaves), 2):
left = leaves[i]
right = leaves[i+1] if i+1 < len(leaves) else left
next_level.append(sha256((left+right).encode()))
leaves = next_level
return leaves[0] if leaves else sha256(b'')

--- Audit Logging ---

def log_operation(ctx: ExecutionContext, command: dict, mode: str, output_hash: str):
ctx.audit_log.append({
"operation_id": str(uuid.uuid4()),
"mode": mode,
"command": command,
"output_hash": output_hash,
"metadata": {}
})

--- Modes ---

def execute_command(ctx: ExecutionContext, command: dict, mode: str):
if mode == "MODE_2_SIMULATE":
pass
elif mode == "MODE_1_EXECUTE":
ctx.repo_state[command['file']] = command['content']
output_hash = merkle_root(ctx.repo_state)
log_operation(ctx, command, mode, output_hash)

--- Verification & Repair ---

MAX_REPAIR_ATTEMPTS = 3

def verify_invariants(ctx: ExecutionContext) -> bool:
return merkle_root(ctx.repo_state) == ctx.manifest['root_hash']

def canonicalize_repo(ctx: ExecutionContext):
new_state = {}
for k, v in ctx.repo_state.items():
new_state[k] = canonicalize(v).decode('utf-8')
ctx.repo_state = new_state
return ctx.repo_state

def integrity_loop(ctx: ExecutionContext):
attempts = 0
while attempts < MAX_REPAIR_ATTEMPTS:
if verify_invariants(ctx):
return True
else:
canonicalize_repo(ctx)
attempts += 1
return enter_mode_0_halt(ctx)

def enter_mode_0_halt(ctx: ExecutionContext):
return False

--- Test Harness ---

def test_determinism(seed: str, manifest: dict, commands: list):
results = []
for _ in range(5):
ctx = ExecutionContext(seed, manifest, deepcopy(commands))
for cmd in commands:
execute_command(ctx, cmd, "MODE_1_EXECUTE")
results.append(merkle_root(ctx.repo_state))
return len(set(results)) == 1

--- Example Usage ---

if name == "main":
manifest = {"root_hash": sha256(b"")}
commands = [{"file": "a.txt", "content": "Hello"}]
ctx = ExecutionContext("seed123", manifest, commands)
for cmd in commands:
execute_command(ctx, cmd, "MODE_1_EXECUTE")
integrity_loop(ctx)

HALTING


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: aidoruao <174227749+aidoruao@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ExecutionContext class for managing state Add ExecutionContext module and missing determinism test suite Mar 8, 2026
aidoruao added a commit that referenced this pull request Apr 4, 2026
…ring issues (#64, #65, #66, #67, #69, #44, #42)

- Analyzed shader integration with Iris/Angelica
- Identified OpenGL state management issues (GL_BLEND, GL_ALPHA_TEST)
- Found compatibility gaps with Mineshot camera and Chisel blocks
- Documented shader pack specific issues (Photon, Solas)
- Generated JSON gap analysis + copy-paste GitHub comments for each issue
- Created master report with cross-batch patterns
- Pipeline: DH-STANDALONE-001
aidoruao added a commit that referenced this pull request Apr 8, 2026
Adds 5 vendored repositories under investigations/darkshadow44/:

1. DistantHorizonsStandalone (GPLv3, 84,441 LOC, 669 files)
   - Primary target for issue #51 and 24 other investigations
   - Includes existing DH_SOURCE_INDEX.json and WIKI.md

2. Angelica (LGPLv3, 100,467 LOC, 1,292 files)
   - Referenced in 6 issue analyses (#56, #42, #47, #64, #65, #72)
   - Critical for understanding SplashProgress replacement

3. ArchaicFix (LGPLv3 with caveats, 9,149 LOC, 190 files)
   - Canonical 1.7.10 performance mod
   - Shows what DH should NOT re-fix

4. Spool (LGPLv3, 20,195 LOC, 158 files)
   - Multithreading mod for 1.7.10 Forge
   - Context for issue #51 'different architecture' comment

5. SeasonalHorizons (LGPLv2.1, 1,336 LOC, 51 files)
   - DarkShadow44's original code (not a fork)
   - Shows his architectural patterns and patch acceptance style

Each repository includes:
- VENDOR_MANIFEST.json with commit hash and Merkle root
- LICENSE file (verbatim from original)
- ATTRIBUTION.md with non-affiliation statement
- sha256_manifest.txt for byte-level verification
- SOURCE_INDEX.json and WIKI.md (for analysis notes)
- src/ containing full source tree (immutable)

Also adds global_merkle.py for computing cross-repo Merkle tree roots:
- Computes individual repo roots from src/ contents
- Computes global root across all repos
- Supports --update-manifests and --verify modes

Global Merkle Root: 6b809444934f0457bb13e0ffc2185e7e0637bcefe82cb7ffa00dc4c60927ec7b

This eliminates epistemic dependency on external clones and makes all
analysis claims falsifiable by providing byte-verifiable source artifacts.
aidoruao added a commit that referenced this pull request Apr 8, 2026
…merkle.py; reconcile directories

## Changes

### Task 1: Fix global_merkle.py SOURCE_EXTS
- Added .java, .kts, .gradle, .toml, .properties, .xml extensions
- Recomputed global Merkle root: 162d7969cc8ac4c5cabf9b807490ce5d87cf9f7ab6d7c071246bd61256a99214
- Now includes all 6,116 source files (up from ~2,400)

### Task 2: Angelica SOURCE_INDEX.json + WIKI.md
- 1,185 Java files, 100,467 LOC indexed
- Identified MixinSplashProgress.java as SplashProgress replacement (critical for DH #56)
- Catalogued 237 mixins with DH overlap analysis
- Documented GLStateManager.java (1,200 LOC) GL context protection
- Cross-referenced DH issues #56, #42, #47, #64, #65, #72

### Task 3: ArchaicFix SOURCE_INDEX.json + WIKI.md
- 177 Java files, 9,149 LOC indexed
- Documented 111 mixins and 45+ config options
- Identified fixes DH should NOT duplicate (Phosphor lighting, tick sync, etc.)
- Analyzed 4 high-risk overlap areas with DH

### Task 4: Spool SOURCE_INDEX.json + WIKI.md
- 145 Java files, 20,195 LOC indexed
- Documented 3 threading modes (distance-based, dimension, sequential)
- Analyzed 50ms tick budget impact
- Compared ConcurrentLinkedQueue usage with DH

### Task 5: SeasonalHorizons SOURCE_INDEX.json + WIKI.md
- 25 Java files, 1,336 LOC indexed
- Documented DarkShadow44's architectural patterns
- Mixin naming convention: seasonalHorizons$ prefix
- Patch acceptance criteria based on his coding style

### Task 6: Reconcile old investigation directory
- Moved tools/, batch1-4/, issue_*_corrected/ to darkshadow44/DistantHorizonsStandalone/
- Removed duplicate DH_SOURCE_INDEX.json and WIKI.md
- Updated references in domain.py, README.md, DEVIN_ONBOARDING.md
- Deleted empty distanthorizons_standalone/ directory

### All repos now have:
- VENDOR_MANIFEST.json with Merkle roots
- SOURCE_INDEX.json with census and critical classes
- WIKI.md with architecture and issue cross-references
- ATTRIBUTION.md with verification instructions
- LICENSE file verbatim from original
- sha256_manifest.txt for byte-level verification
@devin-ai-integration
Copy link
Copy Markdown
Contributor

Closing as stale (Stage D housekeeping).

This Copilot draft has been open without progress and is superseded by:

If the underlying work here is still wanted, re-open a fresh PR rebased on current main; the old branches have substantial drift and CI has moved on. Closing now so the open-PR list reflects reality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants