Pull Request Template
Summary
Implements Phase III U2 safety infrastructure: type-verified runner with strict mypy compliance, safety envelope contract (OK/WARN/BLOCK status), AST-based safe evaluation, deterministic snapshots, and structured trace logging. Provides single typed entry point run_u2_experiment() integrating all components.
Strategic Impact
Differentiator Tag: [x] [FM] [x] [ASD]
Strategic Value: Type-safe experiment infrastructure with formal safety contracts enables verifiable Phase III uplift experiments. Strict type checking + performance guardrails = reproducible research infrastructure.
Acquisition Narrative: Demonstrates formal methods integration at the experiment layer—safety envelope validates performance/eval constraints before execution. Automated CI gates enforce type safety and performance thresholds.
Measurable Outcomes:
- 67 tests, 100% passing (0.51s)
- 8 modules, 0 mypy errors (strict mode)
- 100 cycles < 1s baseline performance
- Safety envelope evaluates OK/WARN/BLOCK in <1ms
Doctrine Alignment: Formal methods (AST-based safety), automation (CI gates), algorithms (deterministic snapshots), metrics (performance guardrails)
Scope
Type: [x] Feature [x] Documentation [x] Quality Assurance
Components Modified:
Files Changed:
Created (19 files):
experiments/u2/__init__.py - Package exports
experiments/u2/u2_safe_eval.py - AST-based safe evaluation with lint mode
experiments/u2/runner.py - Type-verified U2Runner (baseline/RFL)
experiments/u2/safety_envelope.py - Safety contract builder
experiments/u2/snapshots.py - Deterministic state capture/restore
experiments/u2/logging.py - Structured trace logging
experiments/u2/schema.py - Pydantic event schemas
experiments/u2/entrypoint.py - run_u2_experiment() entry point
tests/test_u2_safe_eval.py - 19 tests (safe eval + linting)
tests/test_u2_runner_safety.py - 17 tests (runner + envelope)
tests/test_u2_snapshots.py - 21 tests (snapshots)
tests/test_u2_perf_guardrails.py - 10 tests (performance)
docs/MYPY_CI_GUIDE.md - Type safety guide (8KB)
docs/U2_SAFETY_IMPLEMENTATION.md - Implementation summary (9KB)
.github/workflows/u2-safety-gate.yml - CI workflow
Modified:
pyproject.toml - Added strict mypy config for experiments.u2.*, mypy dev dependency
Risk Assessment
Risk Level: [x] Low
Potential Impact:
Rollback Plan:
Test Plan
Unit Tests
# Type checking
mypy experiments/u2/ --config-file pyproject.toml
# Result: Success: no issues found in 8 source files
# All U2 tests
pytest tests/test_u2*.py -v
# Result: 67 passed in 0.51s
# Performance benchmark
pytest tests/test_u2_perf_guardrails.py -v
# Result: 10 passed, 100 cycles < 1s
Test Results:
Integration Testing
Performance Testing (if applicable)
Conflict Watch
Files Also Modified by Other PRs: None
Coordination Notes:
Checklist
Code Quality
Documentation
Security
Performance
Deployment
Additional Notes
Usage Example
from experiments.u2.entrypoint import run_u2_experiment
from experiments.u2.runner import U2Config
config = U2Config(
experiment_id="exp_001",
slice_name="arithmetic",
mode="baseline",
total_cycles=100,
master_seed=42,
)
def execute(item: str, seed: int) -> tuple[bool, dict]:
return True, {"outcome": "VERIFIED"}
results, envelope = run_u2_experiment(
config=config,
items=["1+1", "2+2", "3+3"],
execute_fn=execute,
)
# Safety contract evaluation
assert envelope.safety_status in ["OK", "WARN", "BLOCK"]
if envelope.safety_status == "BLOCK":
raise RuntimeError(f"Blocked: {envelope.warnings}")
Architecture
Safety Envelope Contract:
- Schema v1.0.0
- Performance thresholds: max 5s/cycle, avg 2s/cycle
- Evaluation lint tracking
- Status: OK (all pass) | WARN (threshold breach) | BLOCK (unsafe eval)
Type Safety:
- Strict mypy for
experiments.u2.*
disallow_untyped_defs=true
disallow_any_generics=true
- Zero
Any types
Safe Evaluation:
- AST-based static analysis
- Blocks: imports, attribute access, arbitrary calls
- Allows: arithmetic, comparisons, safe builtins (abs, min, max, etc.)
Performance Metrics
| Metric |
Value |
Note |
| Test suite runtime |
0.51s |
67 tests |
| Mypy type check |
0.3s |
8 modules |
| 100 baseline cycles |
< 1.0s |
Deterministic execution |
| 50 RFL cycles |
< 0.5s |
Policy-driven selection |
| Safety envelope eval |
< 1ms |
In-memory contract |
CI Integration
.github/workflows/u2-safety-gate.yml runs on:
- PRs touching
experiments/u2/**
- Pushes to
main, copilot/**
Gates:
- Mypy strict checking → must pass
- Test suite (67 tests) → must pass
- Performance guardrails → must pass
- Safety envelope smoke test → status ≠ BLOCK
Reviewer Notes:
- New isolated package, no modifications to existing code
- Strategic differentiator: [FM] + [ASD]
- All CI checks passing
- Ready for integration with existing U2 experiments (
run_uplift_u2.py)
Original prompt
🧼 Agent:
sober-refactor
Mission:
Phase III — U2 Safety Envelope & Type-Verified Runner Surface
⏺️ Begin custom agent: sober-refactor — Phase III U2 Safety Envelope & Type-Verified Runner
ROLE
You are sober-refactor, responsible for type-safety, perf, and secure eval in U2.
You delivered:
u2_safe_eval.py with lint mode and SafeEvalLintResult.
- U2Runner core with typed config/results, snapshots, logging, schema.
- Microbenchmark + perf guardrail tests.
- Strict mypy config and resolved type issues for experiments.u2.*.
- docs/MYPY_CI_GUIDE.md.
Your next mission: pull these into a U2 SAFETY ENVELOPE and a TYPE-VERIFIED RUNNER SURFACE that other agents can trust.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
TASK 1 — U2 Safety Envelope Contract
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Implement:
-
build_u2_safety_envelope(run_config: U2Config, perf_stats: Dict[str, Any], eval_lint_results: List[SafeEvalLintResult]) -> Dict[str, Any]:
schema_version
config: selected, safe subset of U2Config (no secrets)
perf_ok: bool, based on perf thresholds
eval_lint_issues: count + top N messages
safety_status: "OK" | "WARN" | "BLOCK"
This is an in-memory object only; no new schema on disk unless explicitly requested.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
TASK 2 — Type-Verified Runner Entry Surface
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Design a small typed interface for the external world:
def run_u2_experiment(config: U2Config) -> Tuple[List[CycleResult], U2SafetyEnvelope]: ...
Enforce:
- Type annotations everywhere,
- Single, well-documented entrypoint that uses:
- the existing U2Runner,
- safe eval where appropriate,
- snapshot + logging modules.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
TASK 3 — CI Type & Safety Gate
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Extend your mypy + tests integration to:
- Add a "safety gate" that:
- Runs mypy on the U2 modules,
- Runs a short perf+eval lint suite,
- Fails CI if:
- new mypy errors appear, OR
- safety envelope indicates status="BLOCK."
Document this in MYPY_CI_GUIDE.md and a short CI snippet.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
DEFINITION OF DONE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✓ U2 safety envelope contract implemented + tests
✓ Typed run_u2_experiment entrypoint implemented + mypy clean
✓ CI safety gate pattern documented + at least one example workflow
⏹️ End custom agent: sober-refactor
Custom agent used: sober-refactor
Performs behavior-preserving code refactors: extracting functions, improving naming, reducing duplication, adding type hints. Operates under strict constraints to avoid changing semantics, breaking determinism, or touching governance-sensitive files. Every refactor
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Uh oh!
There was an error while loading. Please reload this page.
Pull Request Template
Summary
Implements Phase III U2 safety infrastructure: type-verified runner with strict mypy compliance, safety envelope contract (OK/WARN/BLOCK status), AST-based safe evaluation, deterministic snapshots, and structured trace logging. Provides single typed entry point
run_u2_experiment()integrating all components.Strategic Impact
Differentiator Tag: [x] [FM] [x] [ASD]
Strategic Value: Type-safe experiment infrastructure with formal safety contracts enables verifiable Phase III uplift experiments. Strict type checking + performance guardrails = reproducible research infrastructure.
Acquisition Narrative: Demonstrates formal methods integration at the experiment layer—safety envelope validates performance/eval constraints before execution. Automated CI gates enforce type safety and performance thresholds.
Measurable Outcomes:
Doctrine Alignment: Formal methods (AST-based safety), automation (CI gates), algorithms (deterministic snapshots), metrics (performance guardrails)
Scope
Type: [x] Feature [x] Documentation [x] Quality Assurance
Components Modified:
Files Changed:
Created (19 files):
experiments/u2/__init__.py- Package exportsexperiments/u2/u2_safe_eval.py- AST-based safe evaluation with lint modeexperiments/u2/runner.py- Type-verified U2Runner (baseline/RFL)experiments/u2/safety_envelope.py- Safety contract builderexperiments/u2/snapshots.py- Deterministic state capture/restoreexperiments/u2/logging.py- Structured trace loggingexperiments/u2/schema.py- Pydantic event schemasexperiments/u2/entrypoint.py-run_u2_experiment()entry pointtests/test_u2_safe_eval.py- 19 tests (safe eval + linting)tests/test_u2_runner_safety.py- 17 tests (runner + envelope)tests/test_u2_snapshots.py- 21 tests (snapshots)tests/test_u2_perf_guardrails.py- 10 tests (performance)docs/MYPY_CI_GUIDE.md- Type safety guide (8KB)docs/U2_SAFETY_IMPLEMENTATION.md- Implementation summary (9KB).github/workflows/u2-safety-gate.yml- CI workflowModified:
pyproject.toml- Added strict mypy config for experiments.u2.*, mypy dev dependencyRisk Assessment
Risk Level: [x] Low
Potential Impact:
Rollback Plan:
Test Plan
Unit Tests
Test Results:
Integration Testing
Performance Testing (if applicable)
Conflict Watch
Files Also Modified by Other PRs: None
Coordination Notes:
Checklist
Code Quality
Documentation
Security
Performance
Deployment
Additional Notes
Usage Example
Architecture
Safety Envelope Contract:
Type Safety:
experiments.u2.*disallow_untyped_defs=truedisallow_any_generics=trueAnytypesSafe Evaluation:
Performance Metrics
CI Integration
.github/workflows/u2-safety-gate.ymlruns on:experiments/u2/**main,copilot/**Gates:
Reviewer Notes:
run_uplift_u2.py)Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.