Skip to content

Commit 0c78c23

Browse files
fluffy314cursoragent
authored andcommitted
feat(autoresearch): isolate proof strategy and runtime ownership
Route proof strategy through a host-constrained Cursor adapter, isolate OProver residency behind fail-closed preflight and recovery, and keep MLX streams in one process owner to prevent cross-thread faults. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 88ac2f3 commit 0c78c23

26 files changed

Lines changed: 3772 additions & 86 deletions

autoresearch/prefill/architecture_v7.py

Lines changed: 111 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
from pathlib import Path
77
from typing import Mapping
88

9+
from autoresearch.prefill.cursor_strategy import (
10+
CursorStrategyAdapter,
11+
StrategyProviderError,
12+
compile_memo_to_plan_id,
13+
)
914
from autoresearch.prefill.definition_resolution import (
1015
build_definition_query,
1116
load_resolution_store,
@@ -64,8 +69,6 @@ def run_host_definition_gate(
6469
"""Execute exactly one Autonomous Definition Resolution transaction."""
6570
if checkpoint.proof_state not in {
6671
ProofState.DEFINITION_RESOLUTION,
67-
ProofState.DECOMPOSER,
68-
ProofState.STRATEGY_TOURNAMENT,
6972
ProofState.MATHEMATICAL_STAGNATION,
7073
}:
7174
return checkpoint, ""
@@ -205,37 +208,74 @@ def run_host_definition_gate(
205208
"definition-resolution-commit:environment-changed",
206209
strategy_reused=False,
207210
)
208-
elif result.status == "PARENT_STATEMENT_UNDERSPECIFIED":
209-
checkpoint.transition(
210-
ProofState.PARENT_STATEMENT_UNDERSPECIFIED,
211-
"definition-interpretations-change-parent-truth",
212-
strategy_reused=True,
213-
)
211+
elif result.status in {
212+
"PARENT_STATEMENT_UNDERSPECIFIED",
213+
"INTERFACE_REQUIRED",
214+
"IDENTICAL_QUERY_EXHAUSTED",
215+
}:
214216
checkpoint.definition_backjump_target = (
215217
checkpoint.parent_statement_sha256 or checkpoint.root_goal_sha256
216218
)
217-
checkpoint.transition(
218-
ProofState.PREMISE_AUDIT,
219-
"parent-statement-underspecified:premise-audit-and-backjump",
220-
strategy_reused=True,
219+
checkpoint.premise_outcome_type = (
220+
ProofState.PARENT_STATEMENT_UNDERSPECIFIED.value
221221
)
222-
elif result.status == "INTERFACE_REQUIRED":
223-
checkpoint.definition_backjump_target = (
224-
checkpoint.parent_statement_sha256 or checkpoint.root_goal_sha256
222+
checkpoint.premise_outcome_owner = "definition_resolution"
223+
checkpoint.premise_decision = result.status
224+
checkpoint.premise_confidence = 1.0
225+
checkpoint.premise_evidence = {
226+
"query_hash": result.query_hash,
227+
"exhaustion_hash": result.exhaustion_hash,
228+
"interface_hash": result.interface_hash,
229+
"reason": result.reason,
230+
}
231+
checkpoint.premise_backjump_target = (
232+
checkpoint.definition_backjump_target
225233
)
234+
checkpoint.premise_outcome_fingerprint = result.query_hash
235+
if result.query_hash not in checkpoint.consumed_premise_fingerprints:
236+
checkpoint.consumed_premise_fingerprints.append(result.query_hash)
226237
checkpoint.transition(
227-
ProofState.PREMISE_AUDIT,
228-
"definition-exhaustion:conditional-interface-axioms-required",
229-
strategy_reused=True,
238+
ProofState.PARENT_STATEMENT_UNDERSPECIFIED,
239+
"definition-resolution-exhausted:parent-underspecified",
240+
strategy_reused=False,
241+
)
242+
save_checkpoint(checkpoint_path, checkpoint)
243+
checkpoint.transition(
244+
ProofState.STRATEGY_TOURNAMENT,
245+
"parent-underspecified:typed-backjump-new-target",
246+
strategy_reused=False,
230247
)
231248
else:
232249
checkpoint.definition_backjump_target = (
233250
checkpoint.parent_statement_sha256 or checkpoint.root_goal_sha256
234251
)
252+
checkpoint.premise_outcome_type = (
253+
ProofState.PARENT_STATEMENT_UNDERSPECIFIED.value
254+
)
255+
checkpoint.premise_outcome_owner = "definition_resolution"
256+
checkpoint.premise_decision = result.status
257+
checkpoint.premise_confidence = 1.0
258+
checkpoint.premise_evidence = {
259+
"query_hash": result.query_hash,
260+
"exhaustion_hash": result.exhaustion_hash,
261+
"reason": result.reason,
262+
}
263+
checkpoint.premise_backjump_target = (
264+
checkpoint.definition_backjump_target
265+
)
266+
checkpoint.premise_outcome_fingerprint = result.query_hash
267+
if result.query_hash not in checkpoint.consumed_premise_fingerprints:
268+
checkpoint.consumed_premise_fingerprints.append(result.query_hash)
235269
checkpoint.transition(
236270
ProofState.PARENT_STATEMENT_UNDERSPECIFIED,
237271
"definition-exhaustion:no-viable-interface:typed-backjump",
238-
strategy_reused=True,
272+
strategy_reused=False,
273+
)
274+
save_checkpoint(checkpoint_path, checkpoint)
275+
checkpoint.transition(
276+
ProofState.STRATEGY_TOURNAMENT,
277+
"parent-underspecified:typed-backjump-new-target",
278+
strategy_reused=False,
239279
)
240280
save_checkpoint(checkpoint_path, checkpoint)
241281
return checkpoint, result.status
@@ -270,6 +310,7 @@ def run_architecture_v7_entry(
270310
event_id: str,
271311
elaborated_theorem_id: str = "",
272312
proposition_hash: str = "",
313+
strategy_adapter: CursorStrategyAdapter | None = None,
273314
) -> OrchestrationCheckpoint:
274315
"""Run exactly once per strategy event; never once per outer iteration."""
275316
if checkpoint.proof_state != ProofState.STRATEGY_TOURNAMENT:
@@ -304,6 +345,50 @@ def run_architecture_v7_entry(
304345
elaborated_theorem_id=elaborated_theorem_id,
305346
proposition_hash=proposition_hash,
306347
)
348+
advisory_plan_id = ""
349+
if strategy_adapter is not None:
350+
checkpoint.strategy_provider = "cursor-sdk"
351+
checkpoint.strategy_provider_configured = strategy_adapter.configured()
352+
checkpoint.strategy_model_id = strategy_adapter.model_id
353+
try:
354+
memo, telemetry = strategy_adapter.advise(
355+
evidence={
356+
"event_id": event_id,
357+
"event_type": event_type.value,
358+
"target_ref": target_ref,
359+
"parent_obligation_ref": parent_obligation_ref,
360+
"elaborated_theorem_id": elaborated_theorem_id,
361+
"proposition_hash": proposition_hash,
362+
"definition_ids": definitions,
363+
"unresolved_definition_ids": unresolved_definitions,
364+
"theorem_card_ids": card_ids,
365+
"evidence_refs": evidence_refs,
366+
},
367+
registered_plan_ids=tuple(plan.plan_id for plan in plans),
368+
)
369+
advisory_plan_id = compile_memo_to_plan_id(
370+
memo, tuple(plan.plan_id for plan in plans),
371+
)
372+
checkpoint.strategy_run_status = telemetry.status
373+
checkpoint.strategy_agent_id = telemetry.agent_id
374+
checkpoint.strategy_run_id = telemetry.run_id
375+
checkpoint.strategy_prompt_hash = telemetry.prompt_hash
376+
checkpoint.strategy_evidence_hash = telemetry.evidence_hash
377+
checkpoint.strategy_memo_hash = telemetry.memo_hash
378+
checkpoint.strategy_latency_ms = telemetry.latency_ms
379+
checkpoint.strategy_provider_configured = telemetry.configured
380+
if checkpoint.adapter_status:
381+
checkpoint.clear_adapter_blocked(
382+
"cursor-strategy-authenticated",
383+
)
384+
except StrategyProviderError as exc:
385+
checkpoint.strategy_run_status = exc.code
386+
checkpoint.adapter_blocked(
387+
f"{exc.code}:{exc.classification}",
388+
status="INTEGRATION_BLOCKED",
389+
)
390+
save_checkpoint(checkpoint_path, checkpoint)
391+
return checkpoint
307392
decisions = evaluate_feasibility(
308393
plans,
309394
registered_definition_ids=definitions,
@@ -312,12 +397,18 @@ def run_architecture_v7_entry(
312397
allowed_assumption_ids=(),
313398
no_go_hashes=tuple(checkpoint.invalidated_artifacts),
314399
)
400+
critic_ranked_ids = tuple(plan.plan_id for plan in reversed(plans))
401+
if advisory_plan_id:
402+
critic_ranked_ids = (
403+
advisory_plan_id,
404+
*(item for item in critic_ranked_ids if item != advisory_plan_id),
405+
)
315406
tournament = run_tournament(
316407
event_id=event_id,
317408
event_type=event_type,
318409
plans=plans,
319410
decisions=decisions,
320-
critic_ranked_plan_ids=tuple(plan.plan_id for plan in reversed(plans)),
411+
critic_ranked_plan_ids=critic_ranked_ids,
321412
critic_reason_codes=(CriticReason.MAXIMIZES_INFORMATION_GAIN,),
322413
)
323414
checkpoint.strategy_event_id = event_id
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Architecture 9 direct-cutover entry points."""
2+
from __future__ import annotations
3+
4+
from autoresearch.prefill.architecture_v7 import (
5+
run_architecture_v7_entry,
6+
run_host_definition_gate,
7+
)
8+
from autoresearch.prefill.cursor_strategy import CursorStrategyAdapter
9+
10+
11+
def run_architecture_v9_entry(*args, strategy_adapter=None, **kwargs):
12+
"""Production entry: Cursor strategy is mandatory and has no fallback."""
13+
return run_architecture_v7_entry(
14+
*args,
15+
strategy_adapter=strategy_adapter or CursorStrategyAdapter(),
16+
**kwargs,
17+
)
18+
19+
20+
__all__ = ["run_architecture_v9_entry", "run_host_definition_gate"]

0 commit comments

Comments
 (0)