letitloop 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- letitloop-0.2.0.dist-info/METADATA +232 -0
- letitloop-0.2.0.dist-info/RECORD +175 -0
- letitloop-0.2.0.dist-info/WHEEL +5 -0
- letitloop-0.2.0.dist-info/entry_points.txt +4 -0
- letitloop-0.2.0.dist-info/licenses/LICENSE +21 -0
- letitloop-0.2.0.dist-info/top_level.txt +1 -0
- orchestrator/SKILL.md +292 -0
- orchestrator/__init__.py +151 -0
- orchestrator/anti_ouroboros.py +78 -0
- orchestrator/approval.py +139 -0
- orchestrator/ast_node_splicer.py +130 -0
- orchestrator/ast_splicer.py +94 -0
- orchestrator/audit.py +88 -0
- orchestrator/budget.py +195 -0
- orchestrator/checkpoint.py +248 -0
- orchestrator/cli.py +1971 -0
- orchestrator/codebase_introspector.py +66 -0
- orchestrator/component_slicer.py +185 -0
- orchestrator/config.py +152 -0
- orchestrator/contract.py +404 -0
- orchestrator/dag_validator.py +172 -0
- orchestrator/elasticity_governor.py +80 -0
- orchestrator/env_doctor.py +166 -0
- orchestrator/errors.py +211 -0
- orchestrator/events.py +120 -0
- orchestrator/evidence.py +203 -0
- orchestrator/exceptions.py +37 -0
- orchestrator/experimental/arena_arbiter.py +260 -0
- orchestrator/experimental/fuzz_engine.py +206 -0
- orchestrator/experimental/mutation_tester.py +382 -0
- orchestrator/failure.py +226 -0
- orchestrator/fast_sandbox.py +126 -0
- orchestrator/feasibility_gate.py +115 -0
- orchestrator/feedback.py +302 -0
- orchestrator/fixtures/__init__.py +0 -0
- orchestrator/fixtures/example_contract.json +50 -0
- orchestrator/fixtures/generated/evidence-cli-run-test-step-1.json +47 -0
- orchestrator/fixtures/generated/evidence-cli-run-test-step-2.json +47 -0
- orchestrator/fixtures/generated/evidence-inject-test-a.json +47 -0
- orchestrator/fixtures/generated/evidence-inject-test-b.json +47 -0
- orchestrator/fixtures/generated/evidence-inject-test-c.json +47 -0
- orchestrator/fixtures/generated/evidence-json-test-a.json +47 -0
- orchestrator/fixtures/generated/evidence-json-test-b.json +47 -0
- orchestrator/fixtures/generated/fail-report-fail-task-1.json +47 -0
- orchestrator/fixtures/generated/fail-report-json-task-1.json +47 -0
- orchestrator/fixtures/generated/fail-report-success-task-1.json +47 -0
- orchestrator/fixtures/generated/fuzz-engine-design.json +63 -0
- orchestrator/fixtures/generated/fuzz-engine-impl.json +62 -0
- orchestrator/fixtures/generated/fuzz-engine-tests.json +62 -0
- orchestrator/fixtures/generated/fuzz-engine-verify.json +62 -0
- orchestrator/fixtures/generated/goal-orch-step-1.json +63 -0
- orchestrator/fixtures/generated/goal-orch-step-2.json +62 -0
- orchestrator/fixtures/generated/goal-orch-step-3.json +62 -0
- orchestrator/fixtures/generated/goal-orch-step-4.json +62 -0
- orchestrator/fixtures/generated/goal-orch-step-5.json +62 -0
- orchestrator/fixtures/generated/goal-orch-step-6.json +63 -0
- orchestrator/fixtures/generated/implement-a-thread-safe-token-bucket-rat-task-1.json +53 -0
- orchestrator/fixtures/generated/orchestrator-checkpoint-rollback-3.json +63 -0
- orchestrator/fixtures/generated/orchestrator-checkpoint-rollback.json +62 -0
- orchestrator/fixtures/generated/orchestrator-live-telemetry-2.json +62 -0
- orchestrator/fixtures/generated/orchestrator-live-telemetry.json +62 -0
- orchestrator/fixtures/generated/orchestrator-spec-synthesis-1.json +62 -0
- orchestrator/fixtures/generated/orchestrator-spec-synthesis.json +62 -0
- orchestrator/fixtures/generated/orchestrator-test-verification-4.json +62 -0
- orchestrator/fixtures/generated/orchestrator-test-verification.json +62 -0
- orchestrator/fixtures/generated/perf-step-1.json +61 -0
- orchestrator/fixtures/generated/perf-step-2.json +62 -0
- orchestrator/fixtures/generated/perf-step-3.json +62 -0
- orchestrator/fixtures/generated/perf-step-4.json +62 -0
- orchestrator/fixtures/generated/perf-step-5.json +63 -0
- orchestrator/fixtures/generated/phase2-proof-two-step-step-1.json +47 -0
- orchestrator/fixtures/generated/phase2-proof-two-step-step-2.json +47 -0
- orchestrator/fixtures/generated/planner-spec-synthesis-impl.json +59 -0
- orchestrator/fixtures/generated/self-evolution-ast-formatter.json +69 -0
- orchestrator/fixtures/generated/self-evolution-checkpoint-rollback.json +70 -0
- orchestrator/fixtures/generated/self-evolution-spec-synthesis.json +70 -0
- orchestrator/fixtures/generated/self-evolution-step-1.json +70 -0
- orchestrator/fixtures/generated/self-evolution-step-2.json +70 -0
- orchestrator/fixtures/generated/self-evolution-step-3.json +70 -0
- orchestrator/fixtures/generated/self-evolution-step-4.json +70 -0
- orchestrator/fixtures/generated/self-evolution-step-5.json +65 -0
- orchestrator/fixtures/generated/self-evolution-telemetry.json +70 -0
- orchestrator/fixtures/generated/self-evolution-tests.json +71 -0
- orchestrator/fixtures/generated/spec-telemetry-research-design.json +64 -0
- orchestrator/fixtures/generated/spec-telemetry-step-1.json +62 -0
- orchestrator/fixtures/generated/spec-telemetry-step-2.json +62 -0
- orchestrator/fixtures/generated/spec-telemetry-step-3.json +62 -0
- orchestrator/fixtures/generated/spec-telemetry-step-4.json +62 -0
- orchestrator/fixtures/generated/spec-telemetry-step-5.json +62 -0
- orchestrator/fixtures/generated/spec-telemetry-verification.json +58 -0
- orchestrator/fixtures/generated/token-bucket-impl.json +69 -0
- orchestrator/fixtures/generated/token-bucket-step-1.json +70 -0
- orchestrator/fixtures/generated/token-bucket-step-2.json +70 -0
- orchestrator/fixtures/generated/token-bucket-step-3.json +60 -0
- orchestrator/fixtures/generated/token-bucket-tests.json +70 -0
- orchestrator/fixtures/generated/token-bucket-verify.json +61 -0
- orchestrator/fixtures/generated/trace-ux-tests-step-1.json +64 -0
- orchestrator/fixtures/generated/trace-ux-tests-step-2.json +64 -0
- orchestrator/fixtures/generated/trace-ux-tests-step-3.json +62 -0
- orchestrator/fixtures/generated/tui-live-telemetry-impl.json +59 -0
- orchestrator/fixtures/phase1_proof_escalation_contract.json +41 -0
- orchestrator/fixtures/phase1_proof_happy_path_contract.json +83 -0
- orchestrator/fixtures/phase1_proof_qc_contract.json +41 -0
- orchestrator/fixtures/phase1_proof_repair_contract.json +41 -0
- orchestrator/fixtures/phase2_proof_two_step_goal.json +15 -0
- orchestrator/fixtures/run_proofs.py +299 -0
- orchestrator/fixtures/test_normalizer.py +16 -0
- orchestrator/generator.py +239 -0
- orchestrator/goal.py +245 -0
- orchestrator/handoff.py +86 -0
- orchestrator/hybrid_worker.py +840 -0
- orchestrator/impossibility.py +162 -0
- orchestrator/limits.py +60 -0
- orchestrator/live_evolution_engine.py +247 -0
- orchestrator/llm.py +291 -0
- orchestrator/local_tool_calling.py +285 -0
- orchestrator/lock.py +404 -0
- orchestrator/mcp_client.py +571 -0
- orchestrator/mcp_server.py +344 -0
- orchestrator/memory_bridge.py +182 -0
- orchestrator/metrics.py +159 -0
- orchestrator/micro_epoch.py +42 -0
- orchestrator/models.py +350 -0
- orchestrator/parsing.py +237 -0
- orchestrator/patch_applier.py +154 -0
- orchestrator/plan_preview.py +138 -0
- orchestrator/plan_quality.py +357 -0
- orchestrator/planner.py +532 -0
- orchestrator/preferences.py +115 -0
- orchestrator/preflight.py +141 -0
- orchestrator/process_guard.py +357 -0
- orchestrator/prometheus_exporter.py +207 -0
- orchestrator/prompts.py +275 -0
- orchestrator/proposal_ledger.py +194 -0
- orchestrator/provenance.py +263 -0
- orchestrator/provider_scheduler.py +394 -0
- orchestrator/qc/__init__.py +153 -0
- orchestrator/qc/aggregator.py +330 -0
- orchestrator/qc/parsing.py +287 -0
- orchestrator/qc/personas.py +242 -0
- orchestrator/qc/runner.py +569 -0
- orchestrator/qc_overrule.py +87 -0
- orchestrator/qc_review.py +282 -0
- orchestrator/quality_lenses.py +314 -0
- orchestrator/quality_plan.py +449 -0
- orchestrator/quality_plane.py +103 -0
- orchestrator/reconcile.py +191 -0
- orchestrator/replanner.py +433 -0
- orchestrator/research.py +176 -0
- orchestrator/review_artifact.py +672 -0
- orchestrator/safety.py +271 -0
- orchestrator/schemas.py +230 -0
- orchestrator/scope.py +466 -0
- orchestrator/sensory_radar.py +79 -0
- orchestrator/skill_installer.py +140 -0
- orchestrator/sse_server.py +160 -0
- orchestrator/state.py +871 -0
- orchestrator/subprocess_helper.py +131 -0
- orchestrator/supervisor/__init__.py +184 -0
- orchestrator/supervisor/_shared.py +164 -0
- orchestrator/supervisor/cleanup.py +185 -0
- orchestrator/supervisor/core.py +1680 -0
- orchestrator/supervisor/recovery.py +367 -0
- orchestrator/supervisor/reporting.py +251 -0
- orchestrator/surgical_extractor.py +119 -0
- orchestrator/telemetry.py +61 -0
- orchestrator/templates.py +268 -0
- orchestrator/token_gate.py +245 -0
- orchestrator/tui.py +649 -0
- orchestrator/verifier.py +1103 -0
- orchestrator/webhooks.py +168 -0
- orchestrator/worker.py +469 -0
- orchestrator/worker_adapters.py +815 -0
- orchestrator/worker_pool.py +121 -0
- orchestrator/worktree.py +364 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Centralized bounded subprocess execution with timeout, capture limits, and cleanup."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import subprocess
|
|
5
|
+
import tempfile
|
|
6
|
+
import time
|
|
7
|
+
from typing import Optional, Tuple
|
|
8
|
+
|
|
9
|
+
from orchestrator.process_guard import attach_containment, close_job_handle, containment_kwargs, kill_process_tree
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class BoundedSubprocessResult:
|
|
13
|
+
def __init__(
|
|
14
|
+
self,
|
|
15
|
+
success: bool,
|
|
16
|
+
stdout: str = "",
|
|
17
|
+
stderr: str = "",
|
|
18
|
+
exit_code: int = -1,
|
|
19
|
+
elapsed_sec: float = 0.0,
|
|
20
|
+
timed_out: bool = False,
|
|
21
|
+
error: str = "",
|
|
22
|
+
):
|
|
23
|
+
self.success = success
|
|
24
|
+
self.stdout = stdout
|
|
25
|
+
self.stderr = stderr
|
|
26
|
+
self.exit_code = exit_code
|
|
27
|
+
self.elapsed_sec = elapsed_sec
|
|
28
|
+
self.timed_out = timed_out
|
|
29
|
+
self.error = error
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
DEFAULT_TIMEOUT = 120
|
|
33
|
+
MAX_CAPTURE_SIZE = 512 * 1024
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _cap_output(text: str, max_size: int = MAX_CAPTURE_SIZE) -> str:
|
|
37
|
+
if text and len(text) > max_size:
|
|
38
|
+
return text[:max_size] + f"\n... [truncated at {max_size} chars]"
|
|
39
|
+
return text or ""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def run_bounded_subprocess(
|
|
43
|
+
cmd: list,
|
|
44
|
+
workspace_root: str,
|
|
45
|
+
timeout_sec: int = DEFAULT_TIMEOUT,
|
|
46
|
+
input_text: Optional[str] = None,
|
|
47
|
+
max_capture: int = MAX_CAPTURE_SIZE,
|
|
48
|
+
) -> BoundedSubprocessResult:
|
|
49
|
+
"""Run a subprocess with bounded timeout and output capture.
|
|
50
|
+
|
|
51
|
+
Handles TimeoutExpired, OSError, and output size limits uniformly.
|
|
52
|
+
Does NOT remove temp files — caller responsibility in finally block.
|
|
53
|
+
"""
|
|
54
|
+
start = time.time()
|
|
55
|
+
try:
|
|
56
|
+
popen_kwargs = dict(
|
|
57
|
+
stdout=subprocess.PIPE,
|
|
58
|
+
stderr=subprocess.PIPE,
|
|
59
|
+
text=True,
|
|
60
|
+
cwd=workspace_root,
|
|
61
|
+
encoding="utf-8",
|
|
62
|
+
errors="replace",
|
|
63
|
+
stdin=subprocess.PIPE if input_text is not None else subprocess.DEVNULL,
|
|
64
|
+
)
|
|
65
|
+
popen_kwargs.update(containment_kwargs())
|
|
66
|
+
proc = subprocess.Popen(cmd, **popen_kwargs) # nosec B603
|
|
67
|
+
job = attach_containment(proc)
|
|
68
|
+
try:
|
|
69
|
+
try:
|
|
70
|
+
stdout, stderr = proc.communicate(input=input_text, timeout=timeout_sec)
|
|
71
|
+
except subprocess.TimeoutExpired:
|
|
72
|
+
kill_process_tree(proc.pid)
|
|
73
|
+
try:
|
|
74
|
+
proc.communicate(timeout=5)
|
|
75
|
+
except Exception:
|
|
76
|
+
pass
|
|
77
|
+
elapsed = time.time() - start
|
|
78
|
+
return BoundedSubprocessResult(
|
|
79
|
+
success=False,
|
|
80
|
+
timed_out=True,
|
|
81
|
+
stderr=f"subprocess timed out after {timeout_sec}s",
|
|
82
|
+
elapsed_sec=elapsed,
|
|
83
|
+
error="timeout",
|
|
84
|
+
)
|
|
85
|
+
elapsed = time.time() - start
|
|
86
|
+
return BoundedSubprocessResult(
|
|
87
|
+
success=proc.returncode == 0,
|
|
88
|
+
stdout=_cap_output(stdout or "", max_capture),
|
|
89
|
+
stderr=_cap_output(stderr or "", max_capture),
|
|
90
|
+
exit_code=proc.returncode,
|
|
91
|
+
elapsed_sec=elapsed,
|
|
92
|
+
)
|
|
93
|
+
finally:
|
|
94
|
+
# Closing the kill-on-close job handle reaps any descendants that are
|
|
95
|
+
# still lingering (e.g. orphans holding our output pipes open).
|
|
96
|
+
close_job_handle(job)
|
|
97
|
+
except OSError as e:
|
|
98
|
+
elapsed = time.time() - start
|
|
99
|
+
return BoundedSubprocessResult(
|
|
100
|
+
success=False,
|
|
101
|
+
stderr=str(e),
|
|
102
|
+
elapsed_sec=elapsed,
|
|
103
|
+
error=f"oserror: {e}",
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def write_temp_prompt(content: str, prefix: str = "prompt") -> Tuple[str, str]:
|
|
108
|
+
"""Write prompt content to a secure temporary file with 0o600 restricted permissions.
|
|
109
|
+
|
|
110
|
+
Caller MUST remove the file in a finally block (e.g. via safe_temp_remove).
|
|
111
|
+
"""
|
|
112
|
+
tmp = tempfile.NamedTemporaryFile(
|
|
113
|
+
mode="w", prefix=f"{prefix}_", suffix=".txt", delete=False, encoding="utf-8", dir=tempfile.gettempdir()
|
|
114
|
+
)
|
|
115
|
+
if hasattr(os, "chmod"):
|
|
116
|
+
try:
|
|
117
|
+
os.chmod(tmp.name, 0o600)
|
|
118
|
+
except OSError:
|
|
119
|
+
pass
|
|
120
|
+
tmp.write(content)
|
|
121
|
+
tmp.close()
|
|
122
|
+
return tmp.name, content
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def safe_temp_remove(filepath: str) -> None:
|
|
126
|
+
"""Remove temp file, ignoring OSError."""
|
|
127
|
+
try:
|
|
128
|
+
if os.path.exists(filepath):
|
|
129
|
+
os.remove(filepath)
|
|
130
|
+
except OSError:
|
|
131
|
+
pass
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"""Backward-compatible package facade for the former supervisor.py monolith.
|
|
2
|
+
|
|
3
|
+
External code (and tests) patch collaborators on THIS namespace via dotted
|
|
4
|
+
paths like ``patch("orchestrator.supervisor.run_worker")``. To keep those
|
|
5
|
+
patches effective, the package module uses a forwarding __setattr__ that
|
|
6
|
+
mirrors every assignment into submodules holding the same global name.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import sys
|
|
10
|
+
import types
|
|
11
|
+
|
|
12
|
+
from orchestrator.supervisor import _shared
|
|
13
|
+
from orchestrator.supervisor._shared import (
|
|
14
|
+
DEFAULT_RUN_DIR as DEFAULT_RUN_DIR,
|
|
15
|
+
)
|
|
16
|
+
from orchestrator.supervisor._shared import (
|
|
17
|
+
FAILURE_CLASS_TASK_CRASHED as FAILURE_CLASS_TASK_CRASHED,
|
|
18
|
+
)
|
|
19
|
+
from orchestrator.supervisor._shared import (
|
|
20
|
+
MAX_SAME_CLASS_STRIKES as MAX_SAME_CLASS_STRIKES,
|
|
21
|
+
)
|
|
22
|
+
from orchestrator.supervisor._shared import (
|
|
23
|
+
WORKSPACE_ROOT as WORKSPACE_ROOT,
|
|
24
|
+
)
|
|
25
|
+
from orchestrator.supervisor._shared import (
|
|
26
|
+
Any as Any,
|
|
27
|
+
)
|
|
28
|
+
from orchestrator.supervisor._shared import (
|
|
29
|
+
ContractGraph as ContractGraph,
|
|
30
|
+
)
|
|
31
|
+
from orchestrator.supervisor._shared import (
|
|
32
|
+
Dict as Dict,
|
|
33
|
+
)
|
|
34
|
+
from orchestrator.supervisor._shared import (
|
|
35
|
+
Goal as Goal,
|
|
36
|
+
)
|
|
37
|
+
from orchestrator.supervisor._shared import (
|
|
38
|
+
IllegalTransitionError as IllegalTransitionError,
|
|
39
|
+
)
|
|
40
|
+
from orchestrator.supervisor._shared import (
|
|
41
|
+
List as List,
|
|
42
|
+
)
|
|
43
|
+
from orchestrator.supervisor._shared import (
|
|
44
|
+
Optional as Optional,
|
|
45
|
+
)
|
|
46
|
+
from orchestrator.supervisor._shared import (
|
|
47
|
+
Plan as Plan,
|
|
48
|
+
)
|
|
49
|
+
from orchestrator.supervisor._shared import (
|
|
50
|
+
StateError as StateError,
|
|
51
|
+
)
|
|
52
|
+
from orchestrator.supervisor._shared import (
|
|
53
|
+
_pid_alive as _pid_alive,
|
|
54
|
+
)
|
|
55
|
+
from orchestrator.supervisor._shared import (
|
|
56
|
+
_retry_fingerprints as _retry_fingerprints,
|
|
57
|
+
)
|
|
58
|
+
from orchestrator.supervisor._shared import (
|
|
59
|
+
annotate_worker_result as annotate_worker_result,
|
|
60
|
+
)
|
|
61
|
+
from orchestrator.supervisor._shared import (
|
|
62
|
+
audit_mod as audit_mod,
|
|
63
|
+
)
|
|
64
|
+
from orchestrator.supervisor._shared import (
|
|
65
|
+
budget_mod as budget_mod,
|
|
66
|
+
)
|
|
67
|
+
from orchestrator.supervisor._shared import (
|
|
68
|
+
classify_failure as classify_failure,
|
|
69
|
+
)
|
|
70
|
+
from orchestrator.supervisor._shared import (
|
|
71
|
+
count_consecutive_same_class as count_consecutive_same_class,
|
|
72
|
+
)
|
|
73
|
+
from orchestrator.supervisor._shared import (
|
|
74
|
+
cp as cp,
|
|
75
|
+
)
|
|
76
|
+
from orchestrator.supervisor._shared import (
|
|
77
|
+
create_initial_state as create_initial_state,
|
|
78
|
+
)
|
|
79
|
+
from orchestrator.supervisor._shared import (
|
|
80
|
+
ev as ev,
|
|
81
|
+
)
|
|
82
|
+
from orchestrator.supervisor._shared import (
|
|
83
|
+
fb as fb,
|
|
84
|
+
)
|
|
85
|
+
from orchestrator.supervisor._shared import (
|
|
86
|
+
hashlib as hashlib,
|
|
87
|
+
)
|
|
88
|
+
from orchestrator.supervisor._shared import (
|
|
89
|
+
hmac as hmac,
|
|
90
|
+
)
|
|
91
|
+
from orchestrator.supervisor._shared import (
|
|
92
|
+
imp as imp,
|
|
93
|
+
)
|
|
94
|
+
from orchestrator.supervisor._shared import (
|
|
95
|
+
json as json,
|
|
96
|
+
)
|
|
97
|
+
from orchestrator.supervisor._shared import (
|
|
98
|
+
lk as lk,
|
|
99
|
+
)
|
|
100
|
+
from orchestrator.supervisor._shared import (
|
|
101
|
+
lm as lm,
|
|
102
|
+
)
|
|
103
|
+
from orchestrator.supervisor._shared import (
|
|
104
|
+
load_contract as load_contract,
|
|
105
|
+
)
|
|
106
|
+
from orchestrator.supervisor._shared import (
|
|
107
|
+
load_state as load_state,
|
|
108
|
+
)
|
|
109
|
+
from orchestrator.supervisor._shared import (
|
|
110
|
+
mb_mod as mb_mod,
|
|
111
|
+
)
|
|
112
|
+
from orchestrator.supervisor._shared import (
|
|
113
|
+
metrics_mod as metrics_mod,
|
|
114
|
+
)
|
|
115
|
+
from orchestrator.supervisor._shared import (
|
|
116
|
+
os as os,
|
|
117
|
+
)
|
|
118
|
+
from orchestrator.supervisor._shared import (
|
|
119
|
+
re as re,
|
|
120
|
+
)
|
|
121
|
+
from orchestrator.supervisor._shared import (
|
|
122
|
+
rec as rec,
|
|
123
|
+
)
|
|
124
|
+
from orchestrator.supervisor._shared import (
|
|
125
|
+
require_divergent_retry as require_divergent_retry,
|
|
126
|
+
)
|
|
127
|
+
from orchestrator.supervisor._shared import (
|
|
128
|
+
run_preflight as run_preflight,
|
|
129
|
+
)
|
|
130
|
+
from orchestrator.supervisor._shared import (
|
|
131
|
+
run_verification as run_verification,
|
|
132
|
+
)
|
|
133
|
+
from orchestrator.supervisor._shared import (
|
|
134
|
+
run_worker as run_worker,
|
|
135
|
+
)
|
|
136
|
+
from orchestrator.supervisor._shared import (
|
|
137
|
+
save_state as save_state,
|
|
138
|
+
)
|
|
139
|
+
from orchestrator.supervisor._shared import (
|
|
140
|
+
sc as sc,
|
|
141
|
+
)
|
|
142
|
+
from orchestrator.supervisor._shared import (
|
|
143
|
+
threading as threading,
|
|
144
|
+
)
|
|
145
|
+
from orchestrator.supervisor._shared import (
|
|
146
|
+
time as time,
|
|
147
|
+
)
|
|
148
|
+
from orchestrator.supervisor._shared import (
|
|
149
|
+
validate_contract_against_plan as validate_contract_against_plan,
|
|
150
|
+
)
|
|
151
|
+
from orchestrator.supervisor._shared import (
|
|
152
|
+
wp as wp,
|
|
153
|
+
)
|
|
154
|
+
from orchestrator.supervisor.cleanup import CleanupMixin # noqa: F401
|
|
155
|
+
from orchestrator.supervisor.core import Supervisor
|
|
156
|
+
from orchestrator.supervisor.recovery import RecoveryMixin # noqa: F401
|
|
157
|
+
from orchestrator.supervisor.reporting import ReportingMixin # noqa: F401
|
|
158
|
+
|
|
159
|
+
_SUBMODULES = (
|
|
160
|
+
_shared,
|
|
161
|
+
sys.modules["orchestrator.supervisor.core"],
|
|
162
|
+
sys.modules["orchestrator.supervisor.recovery"],
|
|
163
|
+
sys.modules["orchestrator.supervisor.reporting"],
|
|
164
|
+
sys.modules["orchestrator.supervisor.cleanup"],
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class _ForwardingModule(types.ModuleType):
|
|
169
|
+
def __setattr__(self, name, value):
|
|
170
|
+
super().__setattr__(name, value)
|
|
171
|
+
for mod in _SUBMODULES:
|
|
172
|
+
if name in vars(mod):
|
|
173
|
+
setattr(mod, name, value)
|
|
174
|
+
|
|
175
|
+
def __delattr__(self, name):
|
|
176
|
+
super().__delattr__(name)
|
|
177
|
+
for mod in _SUBMODULES:
|
|
178
|
+
if name in vars(mod):
|
|
179
|
+
delattr(mod, name)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
sys.modules[__name__].__class__ = _ForwardingModule
|
|
183
|
+
|
|
184
|
+
__all__ = ["Supervisor"]
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"""Supervisor executor: executes multi-contract plans in topological dependency order."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import hmac
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import sys
|
|
9
|
+
import threading
|
|
10
|
+
import time
|
|
11
|
+
from typing import Any, Dict, List, Optional
|
|
12
|
+
|
|
13
|
+
from orchestrator import audit as audit_mod
|
|
14
|
+
from orchestrator import budget as budget_mod
|
|
15
|
+
from orchestrator import checkpoint as cp
|
|
16
|
+
from orchestrator import evidence as ev
|
|
17
|
+
from orchestrator import feedback as fb
|
|
18
|
+
from orchestrator import impossibility as imp
|
|
19
|
+
from orchestrator import limits as lm
|
|
20
|
+
from orchestrator import lock as lk
|
|
21
|
+
from orchestrator import memory_bridge as mb_mod
|
|
22
|
+
from orchestrator import metrics as metrics_mod
|
|
23
|
+
from orchestrator import reconcile as rec
|
|
24
|
+
from orchestrator import scope as sc
|
|
25
|
+
from orchestrator import worker_pool as wp
|
|
26
|
+
from orchestrator.contract import load_contract, validate_contract_against_plan
|
|
27
|
+
from orchestrator.exceptions import IllegalTransitionError, StateError
|
|
28
|
+
from orchestrator.failure import (
|
|
29
|
+
FAILURE_CLASS_TASK_CRASHED,
|
|
30
|
+
MAX_SAME_CLASS_STRIKES,
|
|
31
|
+
annotate_worker_result,
|
|
32
|
+
classify_failure,
|
|
33
|
+
count_consecutive_same_class,
|
|
34
|
+
require_divergent_retry,
|
|
35
|
+
)
|
|
36
|
+
from orchestrator.goal import ContractGraph, Goal, Plan
|
|
37
|
+
from orchestrator.preflight import run_preflight
|
|
38
|
+
from orchestrator.state import create_initial_state, load_state, save_state
|
|
39
|
+
from orchestrator.verifier import run_verification
|
|
40
|
+
from orchestrator.worker import run_worker
|
|
41
|
+
|
|
42
|
+
WORKSPACE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
|
43
|
+
DEFAULT_RUN_DIR = os.path.join(WORKSPACE_ROOT, "scratch", "orchestrator_runs")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _pid_alive(pid: int) -> bool:
|
|
47
|
+
"""Cross-platform liveness check for a process id (no signal sent)."""
|
|
48
|
+
if not pid or pid <= 0:
|
|
49
|
+
return False
|
|
50
|
+
if sys.platform == "win32":
|
|
51
|
+
try:
|
|
52
|
+
import ctypes
|
|
53
|
+
|
|
54
|
+
PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
|
|
55
|
+
handle = ctypes.windll.kernel32.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, False, pid)
|
|
56
|
+
if not handle:
|
|
57
|
+
return False
|
|
58
|
+
ctypes.windll.kernel32.CloseHandle(handle)
|
|
59
|
+
return True
|
|
60
|
+
except (AttributeError, OSError, TypeError, ValueError):
|
|
61
|
+
return False
|
|
62
|
+
try:
|
|
63
|
+
os.kill(pid, 0)
|
|
64
|
+
except ProcessLookupError:
|
|
65
|
+
return False
|
|
66
|
+
except PermissionError:
|
|
67
|
+
return True # exists but owned by another user
|
|
68
|
+
except OSError:
|
|
69
|
+
return False
|
|
70
|
+
return True
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _retry_fingerprints(state, failure_class: str, attempt: int):
|
|
74
|
+
"""Fingerprint a retry from failure class + normalized stderr digest.
|
|
75
|
+
|
|
76
|
+
the fingerprint is attempt-INVARIANT
|
|
77
|
+
so identical failures produce the same fingerprint across retries.
|
|
78
|
+
Perpetual-loop r4: raw stderr is collision-prone (timestamps/PIDs/hex/abs
|
|
79
|
+
paths differ run-to-run) — normalize those away before hashing, and fold
|
|
80
|
+
in exit_code + last exception class for discrimination. Returns
|
|
81
|
+
(strategy_fingerprint, prior_fingerprint).
|
|
82
|
+
"""
|
|
83
|
+
last_result = state.worker_results[-1] if state.worker_results else {}
|
|
84
|
+
stderr = str(last_result.get("stderr", "") or "")
|
|
85
|
+
normalized = re.sub(r"\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}", "<TS>", stderr)
|
|
86
|
+
normalized = re.sub(r"\bpid(?:=|\s+)\d+\b", "pid=<PID>", normalized, flags=re.I)
|
|
87
|
+
normalized = re.sub(r"0x[0-9a-fA-F]{6,}", "0x<HEX>", normalized)
|
|
88
|
+
normalized = re.sub(r"(?i)[a-z]:[\\/][^\s\"']+", "<PATH>", normalized)
|
|
89
|
+
normalized = re.sub(r"(?i)([a-z0-9_/\\-]+/)+[a-z0-9_\\-]+\.(?:py|js|ts|exe|cmd|bat)", "<F>", normalized)
|
|
90
|
+
# POSIX paths are not stripped by the drive-letter regex above; normalize
|
|
91
|
+
# them too so retry fingerprints are stable across platforms (QC 2026-08-01).
|
|
92
|
+
normalized = re.sub(r"(?i)/(?:home|tmp|usr|var|opt|etc|root|mnt|run)/[^\s\"']*", "<POSIX>", normalized)
|
|
93
|
+
exit_code = last_result.get("exit_code")
|
|
94
|
+
exc_class = ""
|
|
95
|
+
# QC 2026-08-01: the root-cause exception is at the BOTTOM of a Python
|
|
96
|
+
# traceback; re.search grabs the first Error mention (often a log line or
|
|
97
|
+
# docstring) and mislabels the class. Take the LAST match instead.
|
|
98
|
+
matches = re.findall(r"\b(\w+Error|Exception)\b", stderr)
|
|
99
|
+
if matches:
|
|
100
|
+
exc_class = matches[-1]
|
|
101
|
+
stderr_digest = hashlib.sha256(
|
|
102
|
+
f"{exit_code}:{exc_class}:{normalized}".encode("utf-8", errors="replace")
|
|
103
|
+
).hexdigest()[:8]
|
|
104
|
+
strategy_fingerprint = hashlib.sha256(f"{failure_class}:{stderr_digest}".encode("utf-8")).hexdigest()[:8]
|
|
105
|
+
prior_fingerprint = ""
|
|
106
|
+
retry_metadata = state.data.get("retry_metadata", [])
|
|
107
|
+
if isinstance(retry_metadata, list):
|
|
108
|
+
for metadata in reversed(retry_metadata):
|
|
109
|
+
if isinstance(metadata, dict) and metadata.get("strategy_fingerprint"):
|
|
110
|
+
prior_fingerprint = str(metadata["strategy_fingerprint"])
|
|
111
|
+
break
|
|
112
|
+
return strategy_fingerprint, prior_fingerprint
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
__all__ = [
|
|
116
|
+
"Any",
|
|
117
|
+
"ContractGraph",
|
|
118
|
+
"DEFAULT_RUN_DIR",
|
|
119
|
+
"Dict",
|
|
120
|
+
"FAILURE_CLASS_TASK_CRASHED",
|
|
121
|
+
"Goal",
|
|
122
|
+
"IllegalTransitionError",
|
|
123
|
+
"List",
|
|
124
|
+
"MAX_SAME_CLASS_STRIKES",
|
|
125
|
+
"Optional",
|
|
126
|
+
"Plan",
|
|
127
|
+
"StateError",
|
|
128
|
+
"WORKSPACE_ROOT",
|
|
129
|
+
"_pid_alive",
|
|
130
|
+
"_retry_fingerprints",
|
|
131
|
+
"annotate_worker_result",
|
|
132
|
+
"audit_mod",
|
|
133
|
+
"budget_mod",
|
|
134
|
+
"classify_failure",
|
|
135
|
+
"count_consecutive_same_class",
|
|
136
|
+
"cp",
|
|
137
|
+
"create_initial_state",
|
|
138
|
+
"ev",
|
|
139
|
+
"fb",
|
|
140
|
+
"hashlib",
|
|
141
|
+
"hmac",
|
|
142
|
+
"imp",
|
|
143
|
+
"json",
|
|
144
|
+
"lk",
|
|
145
|
+
"lm",
|
|
146
|
+
"load_contract",
|
|
147
|
+
"load_state",
|
|
148
|
+
"mb_mod",
|
|
149
|
+
"metrics_mod",
|
|
150
|
+
"os",
|
|
151
|
+
"re",
|
|
152
|
+
"rec",
|
|
153
|
+
"require_divergent_retry",
|
|
154
|
+
"run_preflight",
|
|
155
|
+
"run_verification",
|
|
156
|
+
"run_worker",
|
|
157
|
+
"save_state",
|
|
158
|
+
"sc",
|
|
159
|
+
"sys",
|
|
160
|
+
"threading",
|
|
161
|
+
"time",
|
|
162
|
+
"validate_contract_against_plan",
|
|
163
|
+
"wp",
|
|
164
|
+
]
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"""CleanupMixin - extracted verbatim from the former monolithic supervisor.py."""
|
|
2
|
+
|
|
3
|
+
from orchestrator.supervisor._shared import (
|
|
4
|
+
DEFAULT_RUN_DIR as DEFAULT_RUN_DIR,
|
|
5
|
+
)
|
|
6
|
+
from orchestrator.supervisor._shared import (
|
|
7
|
+
FAILURE_CLASS_TASK_CRASHED as FAILURE_CLASS_TASK_CRASHED,
|
|
8
|
+
)
|
|
9
|
+
from orchestrator.supervisor._shared import (
|
|
10
|
+
MAX_SAME_CLASS_STRIKES as MAX_SAME_CLASS_STRIKES,
|
|
11
|
+
)
|
|
12
|
+
from orchestrator.supervisor._shared import (
|
|
13
|
+
WORKSPACE_ROOT as WORKSPACE_ROOT,
|
|
14
|
+
)
|
|
15
|
+
from orchestrator.supervisor._shared import (
|
|
16
|
+
Any as Any,
|
|
17
|
+
)
|
|
18
|
+
from orchestrator.supervisor._shared import (
|
|
19
|
+
ContractGraph as ContractGraph,
|
|
20
|
+
)
|
|
21
|
+
from orchestrator.supervisor._shared import (
|
|
22
|
+
Dict as Dict,
|
|
23
|
+
)
|
|
24
|
+
from orchestrator.supervisor._shared import (
|
|
25
|
+
Goal as Goal,
|
|
26
|
+
)
|
|
27
|
+
from orchestrator.supervisor._shared import (
|
|
28
|
+
IllegalTransitionError as IllegalTransitionError,
|
|
29
|
+
)
|
|
30
|
+
from orchestrator.supervisor._shared import (
|
|
31
|
+
List as List,
|
|
32
|
+
)
|
|
33
|
+
from orchestrator.supervisor._shared import (
|
|
34
|
+
Optional as Optional,
|
|
35
|
+
)
|
|
36
|
+
from orchestrator.supervisor._shared import (
|
|
37
|
+
Plan as Plan,
|
|
38
|
+
)
|
|
39
|
+
from orchestrator.supervisor._shared import (
|
|
40
|
+
StateError as StateError,
|
|
41
|
+
)
|
|
42
|
+
from orchestrator.supervisor._shared import (
|
|
43
|
+
_pid_alive as _pid_alive,
|
|
44
|
+
)
|
|
45
|
+
from orchestrator.supervisor._shared import (
|
|
46
|
+
_retry_fingerprints as _retry_fingerprints,
|
|
47
|
+
)
|
|
48
|
+
from orchestrator.supervisor._shared import (
|
|
49
|
+
annotate_worker_result as annotate_worker_result,
|
|
50
|
+
)
|
|
51
|
+
from orchestrator.supervisor._shared import (
|
|
52
|
+
audit_mod as audit_mod,
|
|
53
|
+
)
|
|
54
|
+
from orchestrator.supervisor._shared import (
|
|
55
|
+
budget_mod as budget_mod,
|
|
56
|
+
)
|
|
57
|
+
from orchestrator.supervisor._shared import (
|
|
58
|
+
classify_failure as classify_failure,
|
|
59
|
+
)
|
|
60
|
+
from orchestrator.supervisor._shared import (
|
|
61
|
+
count_consecutive_same_class as count_consecutive_same_class,
|
|
62
|
+
)
|
|
63
|
+
from orchestrator.supervisor._shared import (
|
|
64
|
+
cp as cp,
|
|
65
|
+
)
|
|
66
|
+
from orchestrator.supervisor._shared import (
|
|
67
|
+
create_initial_state as create_initial_state,
|
|
68
|
+
)
|
|
69
|
+
from orchestrator.supervisor._shared import (
|
|
70
|
+
ev as ev,
|
|
71
|
+
)
|
|
72
|
+
from orchestrator.supervisor._shared import (
|
|
73
|
+
fb as fb,
|
|
74
|
+
)
|
|
75
|
+
from orchestrator.supervisor._shared import (
|
|
76
|
+
hashlib as hashlib,
|
|
77
|
+
)
|
|
78
|
+
from orchestrator.supervisor._shared import (
|
|
79
|
+
hmac as hmac,
|
|
80
|
+
)
|
|
81
|
+
from orchestrator.supervisor._shared import (
|
|
82
|
+
imp as imp,
|
|
83
|
+
)
|
|
84
|
+
from orchestrator.supervisor._shared import (
|
|
85
|
+
json as json,
|
|
86
|
+
)
|
|
87
|
+
from orchestrator.supervisor._shared import (
|
|
88
|
+
lk as lk,
|
|
89
|
+
)
|
|
90
|
+
from orchestrator.supervisor._shared import (
|
|
91
|
+
lm as lm,
|
|
92
|
+
)
|
|
93
|
+
from orchestrator.supervisor._shared import (
|
|
94
|
+
load_contract as load_contract,
|
|
95
|
+
)
|
|
96
|
+
from orchestrator.supervisor._shared import (
|
|
97
|
+
load_state as load_state,
|
|
98
|
+
)
|
|
99
|
+
from orchestrator.supervisor._shared import (
|
|
100
|
+
mb_mod as mb_mod,
|
|
101
|
+
)
|
|
102
|
+
from orchestrator.supervisor._shared import (
|
|
103
|
+
metrics_mod as metrics_mod,
|
|
104
|
+
)
|
|
105
|
+
from orchestrator.supervisor._shared import (
|
|
106
|
+
os as os,
|
|
107
|
+
)
|
|
108
|
+
from orchestrator.supervisor._shared import (
|
|
109
|
+
re as re,
|
|
110
|
+
)
|
|
111
|
+
from orchestrator.supervisor._shared import (
|
|
112
|
+
rec as rec,
|
|
113
|
+
)
|
|
114
|
+
from orchestrator.supervisor._shared import (
|
|
115
|
+
require_divergent_retry as require_divergent_retry,
|
|
116
|
+
)
|
|
117
|
+
from orchestrator.supervisor._shared import (
|
|
118
|
+
run_preflight as run_preflight,
|
|
119
|
+
)
|
|
120
|
+
from orchestrator.supervisor._shared import (
|
|
121
|
+
run_verification as run_verification,
|
|
122
|
+
)
|
|
123
|
+
from orchestrator.supervisor._shared import (
|
|
124
|
+
run_worker as run_worker,
|
|
125
|
+
)
|
|
126
|
+
from orchestrator.supervisor._shared import (
|
|
127
|
+
save_state as save_state,
|
|
128
|
+
)
|
|
129
|
+
from orchestrator.supervisor._shared import (
|
|
130
|
+
sc as sc,
|
|
131
|
+
)
|
|
132
|
+
from orchestrator.supervisor._shared import (
|
|
133
|
+
sys as sys,
|
|
134
|
+
)
|
|
135
|
+
from orchestrator.supervisor._shared import (
|
|
136
|
+
threading as threading,
|
|
137
|
+
)
|
|
138
|
+
from orchestrator.supervisor._shared import (
|
|
139
|
+
time as time,
|
|
140
|
+
)
|
|
141
|
+
from orchestrator.supervisor._shared import (
|
|
142
|
+
validate_contract_against_plan as validate_contract_against_plan,
|
|
143
|
+
)
|
|
144
|
+
from orchestrator.supervisor._shared import (
|
|
145
|
+
wp as wp,
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class CleanupMixin:
|
|
150
|
+
"""Cleanup responsibilities of Supervisor (moved verbatim)."""
|
|
151
|
+
|
|
152
|
+
def _auto_clean_undeclared_outputs(self, contract, state):
|
|
153
|
+
"""AUT-002: delete newly-created undeclared files before a retry.
|
|
154
|
+
|
|
155
|
+
A worker that leaves a temp helper script (despite the brief
|
|
156
|
+
forbidding extra files) currently poisons the retry — the leftover
|
|
157
|
+
file trips undeclared_outputs again. Delete only NEWLY-CREATED
|
|
158
|
+
outside-scope/denied files; never modified pre-existing files.
|
|
159
|
+
Records what was removed for the audit trail.
|
|
160
|
+
"""
|
|
161
|
+
undeclared = state.data.get("undeclared_outputs", [])
|
|
162
|
+
if not isinstance(undeclared, list):
|
|
163
|
+
return
|
|
164
|
+
declared = {o.get("path", "") for o in (contract.outputs or [])}
|
|
165
|
+
cleaned = []
|
|
166
|
+
for v in undeclared:
|
|
167
|
+
if not isinstance(v, dict):
|
|
168
|
+
continue
|
|
169
|
+
if not v.get("created_new"):
|
|
170
|
+
continue # never auto-delete modified pre-existing files
|
|
171
|
+
if v.get("violation_type") not in ("outside_scope", "denied_new"):
|
|
172
|
+
continue
|
|
173
|
+
path = str(v.get("path", ""))
|
|
174
|
+
if not path or path in declared:
|
|
175
|
+
continue
|
|
176
|
+
full = path if os.path.isabs(path) else os.path.join(self.workspace_root, path)
|
|
177
|
+
try:
|
|
178
|
+
if os.path.isfile(full):
|
|
179
|
+
os.remove(full)
|
|
180
|
+
cleaned.append(path)
|
|
181
|
+
print(f"[supervisor] auto-cleaned undeclared file: {path}", file=sys.stderr)
|
|
182
|
+
except OSError:
|
|
183
|
+
pass
|
|
184
|
+
if cleaned:
|
|
185
|
+
state.patch_data({"auto_cleaned_undeclared_outputs": cleaned})
|