Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 73 additions & 2 deletions src/solver/agentTeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { NativeAgentControlInputError } from '../runtime/nativeAgentControl';
import { planApprovalStatus, publishNativeApprovalPlan } from './planApproval';
import { canonicalMathJson, mathDigest, writeMathJsonDurable } from '../math/mathRuntimeIo';
import { bindLeanPackages } from '../math/leanDiagnostics';
import { inspectScopedLeanDeclarations } from '../math/leanSource';
import { inspectLeanSource, inspectScopedLeanDeclarations } from '../math/leanSource';
import { leanNameWithoutRoot } from '../math/leanSyntax';
import type { SolverRunState } from './archive';
import type { WorkerAccess } from './research';
Expand All @@ -22,6 +22,9 @@ import { solverSourceDigest } from './modules/evidence';
import { writeOwnedDeclarationIndex } from './declarationIndex';
import { recordUnconfirmedWriterStartup, stopProofWriter } from './proofWriter';
import { prepareTacticBatteryFailureCacheRoot } from './tacticBatteryFailureCache';
import { TACTIC_BATTERY_TIMEOUT_MS } from './tacticBattery';
import { locateKnowledgeDeclaration } from './theoremKnowledge';
import type { CooperativeTask } from './tasks';
import { ResearchUsage } from './researchUsage';
import { aggregateUsage, buildTokenBudget, initializeUsageAccounting, modelDispatchAllowed } from './usageBudget';
import { agentTeamStateSchema,
Expand Down Expand Up @@ -1121,8 +1124,9 @@ export class AgentResearchTeam {
const { state } = this.input;
try {
assertWriterStopped();
const sourceCommit = task.sourceCommit ?? commitSolverSources(state.problem, worker.worktree);
await this.input.exclusiveCheck(async () => {
const closed = await this.closeSubmittedSorries(worker, task, nominations, access.environment, signal, assertWriterStopped);
const sourceCommit = closed || !task.sourceCommit ? commitSolverSources(state.problem, worker.worktree) : task.sourceCommit;
const expectedCommit = this.archive.canonicalCommit ?? git(state.worktree, ['rev-parse', 'HEAD']);
const result = await landVerifiedHelpers({ state, worktree: state.worktree, expectedCommit,
sourceWorktree: worker.worktree, sourceCommit, seedCommit: task.seedCommit ?? worker.seedCommit,
Expand Down Expand Up @@ -1180,6 +1184,67 @@ export class AgentResearchTeam {
}
}

/**
* Before the Lean check of a submission, try the fixed tactic battery on each nominated theorem whose body is still
* `sorry` or `admit`, against its exact submitted type. A closure is written into the stopped writer's sources and
* committed there; the ordinary check still decides acceptance. A failed or unavailable attempt changes nothing.
* Returns whether any source changed.
*/
private async closeSubmittedSorries(worker: AgentTeamWorker, task: AgentTeamTask,
declarations: readonly { file?: string; name?: string; type?: string; kind?: 'definition' }[], env: NodeJS.ProcessEnv,
signal: AbortSignal, assertWriterStopped: () => void): Promise<boolean> {
const closeTask = this.input.modules.M2.closeTask, { problem } = this.input.state;
if (!closeTask) return false;
// One shared bound per submission, so several open helpers cannot multiply the host delay.
const deadline = Date.now() + Math.min(this.input.proofTimeoutMs ?? Infinity, TACTIC_BATTERY_TIMEOUT_MS);
let changed = false;
for (const declaration of declarations) {
const remaining = deadline - Date.now();
if (remaining <= 0) break;
const { file, name, type } = declaration;
if (declaration.kind === 'definition' || !file || !name || !type || !problem.ownedFiles.includes(file)) continue;
const relative = path.join(problem.projectRelative, file);
let theoremName: string;
try {
const source = fs.readFileSync(path.join(worker.worktree, relative), 'utf8');
const located = locateKnowledgeDeclaration(source, name);
const body = inspectLeanSource(source.slice(located.bodyOffset, located.endOffset));
if (located.kind !== 'theorem' || !body.sorryCount && !body.admitCount) continue;
theoremName = located.qualifiedName;
} catch { continue; }
assertWriterStopped();
let seedCommit: string;
try { seedCommit = commitSolverSources(problem, worker.worktree); } catch { break; }
const helper: CooperativeTask = { id: 'submitted-helper', kind: 'lemma', objective: 'Close submitted helper ' + theoremName,
proofPath: file, theoremName, type, dependsOn: [], revision: 0 };
const started = Date.now();
const battery = await closeTask({ problem, task: helper, worktree: worker.worktree, seedCommit, context: theoremName,
env, signal, timeoutMs: remaining });
signal.throwIfAborted();
let applied = false;
if (battery.status === 'closed' && battery.commit) {
assertWriterStopped();
fs.writeFileSync(path.join(worker.worktree, relative), committedSource(worker.worktree, battery.commit, relative));
commitSolverSources(problem, worker.worktree);
applied = changed = true;
}
this.input.emit('task_tactic_battery', { taskId: task.id, workerId: worker.id, declaration: theoremName, seedCommit,
status: battery.status, reason: battery.reason, durationMs: Date.now() - started, applied,
...(battery.cacheHit ? { cacheHit: true, cacheKey: battery.cacheKey, originDiagnosticDigest: battery.originDiagnosticDigest } : {}),
...(battery.commit ? { commit: battery.commit } : {}), ...(battery.artifact ? { artifact: battery.artifact } : {}),
...(battery.vacuous ? { vacuous: true } : {}) });
if (applied) {
const vacuity = battery.vacuous ? ' Host vacuity probe: its hypotheses alone derive False, so no consumer can discharge them; ' +
'revise the helper unless it is an intended impossible case.' : '';
this.event(null, worker.id, 'message', 'The host tactic battery closed the sorry in ' + theoremName +
' against its submitted type, and your source now contains that proof. The ordinary Lean check still decides the submission.' + vacuity,
{ taskId: task.id });
if (battery.vacuous) this.event(null, 'lead', 'message', worker.id + ' submitted ' + theoremName + '.' + vacuity, { taskId: task.id });
}
}
return changed;
}

private async finishDelivery(worker: AgentTeamWorker) {
await this.closeNativeIdle(worker);
const pending = worker.pendingDelivery;
Expand All @@ -1200,6 +1265,12 @@ export class AgentResearchTeam {
}));
// A submission can replace the inherited spelling (for example, with `_root_.`).
const inferredHelperTypes = pending.declarations.map(evidenceKey).filter(key => inheritedTypes.has(key) && !explicit.has(key));
// A recorded commit is a retry of the same sources; the battery only runs before the first check.
if (!pending.commit && task.declarations?.length) await this.input.exclusiveCheck(() => this.closeSubmittedSorries(worker, task,
task.declarations!, access.environment, signal, () => {
signal.throwIfAborted();
if (worker.writerStopUnconfirmed || this.live.get(worker.id)?.session) throw new Error('math_writer_stop_unconfirmed:' + worker.id);
}));
const commit = commitSolverSources(this.input.state.problem, worker.worktree);
const digest = solverSourceDigest(this.input.state.problem, worker.worktree);
if (pending.commit && (pending.commit !== commit || pending.sourceDigest !== digest)) throw new Error('math_team_delivery_source_changed');
Expand Down
2 changes: 1 addition & 1 deletion src/solver/modules/moduleIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const directSolverModuleIdentity: SolverModuleIdentity = {
id: 'direct-v1',
versions: {
M1: 'bounded-codex-turn-v15/distinct-recovery-delivery-v1/provider-diagnostics-v1/saved-plan-recovery-v1/closed-writer-ownership-v1/advisory-draft-recovery-v1/session-admission-v1/closed-statement-ownership-v1/feasibility-session-v1/observed-turn-ledger-v1/session-scoped-usage-v1/persistent-provider-cooldown-v1/context-overflow-recovery-v1/initial-planning-budget-v1/trusted-local-stop-v1/initial-plan-publication-v1/observed-knowledge-use-v1/diagnostic-log-ownership-v1/turn-ledger-removed-v1/advisory-scratch-ownership-v1/durable-reasoning-checkpoint-v1/lead-thread-continuation-v1/bounded-coordination-checkpoints-v1/live-saved-context-yield-v1/published-context-checkpoint-v1/compaction-aware-checkpoints-v1/cooperative-stray-quarantine-v1/bounded-proof-search-v1/installed-library-before-model-v1/installed-library-reference-observation-v1/agent-library-request-v1/context-proof-ready-handoff-v1/scoped-research-save-notice-v1/early-initial-plan-notice-v1/scoped-advisory-backoff-v1/conditional-connection-checkpoints-v1/sent-responsibility-context-v1/checkpoint-research-handoff-v1/durable-research-handoff-wait-v1/retained-notes-attribution-v1/feasibility-notice-only-handoff-v1/host-library-before-research-v1/final-review-checkpoint-v1',
M2: 'lean-kernel-v14/declaration-prefix-projection-v1/task-root-references-v1/conditional-child-changes-v1/scoped-conditional-projection-v1/exact-input-failure-reuse-v1/conditional-projection-identity-v1/attributed-batch-evidence-v1/fixed-candidate-references-v1/exact-projection-cache-v1/shared-source-index-v1/host-consumer-connection-v1/content-projection-reuse-v1/ready-integration-batches-v1/coded-lean-diagnostics-v1/live-exact-projection-recheck-v1/lean-diagnostic-word-classification-v1/advisory-scratch-checkout-v1/host-tactic-battery-v1/definition-tasks-v1/battery-vacuity-probe-v1/untouched-seed-request-failure-v1/isolated-module-builds-v1/frozen-library-modules-v1/host-family-assembly-v1/projection-dependency-diagnostics-v1/installed-library-application-v1/installed-library-candidate-pool-v1/installed-library-iff-application-v1/installed-library-equality-application-v1/installed-library-named-requests-v1/installed-library-rewrite-v1/installed-library-lemma-pool-v1/installed-library-premise-application-v1/installed-library-premise-retrieval-v1/installed-library-fair-premise-pool-v1/installed-library-composed-applications-v1/import-closure-diagnostics-cache-v1/proof-import-before-theorem-v1/typed-helper-command-rejection-v1/installed-library-conclusion-relevance-v1/notation-source-inputs-v1/implicit-instance-cleanup-v1/persistent-tactic-failure-reuse-v1/notation-quotation-context-v1/static-notation-analysis-v1/conditional-source-context-v1/universe-polymorphic-conditional-projection-v1/original-definition-kind-canonical-check-v1/conditional-lemma-macro-normalization-v1',
M2: 'lean-kernel-v14/declaration-prefix-projection-v1/task-root-references-v1/conditional-child-changes-v1/scoped-conditional-projection-v1/exact-input-failure-reuse-v1/conditional-projection-identity-v1/attributed-batch-evidence-v1/fixed-candidate-references-v1/exact-projection-cache-v1/shared-source-index-v1/host-consumer-connection-v1/content-projection-reuse-v1/ready-integration-batches-v1/coded-lean-diagnostics-v1/live-exact-projection-recheck-v1/lean-diagnostic-word-classification-v1/advisory-scratch-checkout-v1/host-tactic-battery-v1/definition-tasks-v1/battery-vacuity-probe-v1/untouched-seed-request-failure-v1/isolated-module-builds-v1/frozen-library-modules-v1/host-family-assembly-v1/projection-dependency-diagnostics-v1/installed-library-application-v1/installed-library-candidate-pool-v1/installed-library-iff-application-v1/installed-library-equality-application-v1/installed-library-named-requests-v1/installed-library-rewrite-v1/installed-library-lemma-pool-v1/installed-library-premise-application-v1/installed-library-premise-retrieval-v1/installed-library-fair-premise-pool-v1/installed-library-composed-applications-v1/import-closure-diagnostics-cache-v1/proof-import-before-theorem-v1/typed-helper-command-rejection-v1/installed-library-conclusion-relevance-v1/notation-source-inputs-v1/implicit-instance-cleanup-v1/persistent-tactic-failure-reuse-v1/notation-quotation-context-v1/static-notation-analysis-v1/conditional-source-context-v1/universe-polymorphic-conditional-projection-v1/original-definition-kind-canonical-check-v1/conditional-lemma-macro-normalization-v1/submitted-helper-tactic-battery-v1/battery-grind-v1',
M3: 'route-budget-v12/blocker-or-routes-v1/structured-provider-failure-v1/assignable-work-v1/advisory-settlement-v3/goal-scoped-advancement-v1/early-route-checks-v1/ready-consumers-v1/evidence-ranked-routes-v2/capacity-free-ranking-v1/active-or-frontier-v1/context-overflow-recovery-v1/pending-validation-v1/trusted-local-stop-v1/host-consumer-connection-v1/definition-task-readiness-v1/scoped-next-checks-v1/yielded-advisory-proof-frontier-v1/consumer-goal-attribution-v1/fixed-review-requests-v1',
M4: 'task-interface-context-v31/original-goal-frontier-v3/finished-objective-refs-v1/work-contract-v2/research-handoff-batches-v3/resume-drafts-v1/assignment-knowledge-hints-v1/deferred-handoff-inputs-v1/mathematical-route-planning-v1/complete-research-findings-v1/consumer-interfaces-v1/current-feedback-v1/complete-checkpoints-v1/early-feasibility-v1/parallel-questions-v2/local-attempt-feedback-v1/compact-handoff-sources-v1/exact-interface-diversity-v1/bounded-route-focus-v1/compact-inline-manifest-v1/adopted-research-use-v1/bounded-knowledge-metadata-v1/interface-idf-v1/overflow-optional-budget-v1/initial-planning-budget-v1/required-research-challenges-v1/initial-plan-publication-v1/scoped-route-findings-v1/observed-knowledge-use-v1/lean-json-diagnostics-v1/host-consumer-connection-v1/finite-boolean-evidence-v1/live-research-publication-v1/current-residual-goal-v1/continuation-attachments-v1/accepted-consumer-knowledge-v1/single-delivery-protocol-v1/route-focused-knowledge-v1/independent-goal-knowledge-batch-v1/route-finding-batch-v1/primary-led-removed-v1/assigned-proof-only-diagnostics-v1/lean-prover-v1/host-capacity-exploration-v1/explicit-handoff-publication-v1/advisory-scratch-roots-v1/exact-gap-checkpoint-context-v1/lead-continuation-context-v1/shared-new-helper-ownership-v1/compact-proof-role-context-v1/precise-gap-correction-context-v1/full-plan-adoption-context-v1/coordination-first-context-v1/explicit-research-source-context-v1/short-challenge-assessments-v1/live-plan-rejection-feedback-v1/request-scoped-checkpoint-feedback-v1/worker-checkpoint-feedback-v1/lead-planning-inputs-v1/plan-revision-context-v1/lead-inbox-context-v1/definition-task-context-v1/reference-search-context-v1/definition-knowledge-context-v1/math-tools-context-v1/kernel-certificates-v1/goal-path-review-v1/blueprint-fields-v1/theory-modules-v1/definition-sanity-lemmas-v1/goal-path-decisions-context-v1/owned-declaration-index-v1/library-packs-v1/task-families-v1/team-progress-review-context-v1/source-dependency-review-context-v1/atomic-observations-and-application-hints-v1/scoped-relation-pool-v1/executable-next-check-v1/proof-search-context-v1/installed-library-retrieval-v1/installed-library-application-context-v1/reusable-knowledge-index-v1/installed-library-named-requests-v1/conclusion-focused-knowledge-v1/agent-full-library-context-v1/critical-premise-context-v1/executable-initial-plan-context-v1/bounded-owned-declaration-lookup-v1/continuation-query-batches-v1/critical-inference-guidance-v1/plan-connection-guidance-v1/warm-lead-plan-rejection-v1/host-library-context-revalidation-v1/knowledge-candidate-refill-v1/mathematical-knowledge-ranking-v1/scoped-finding-relevance-v1/decorated-quantifier-fallback-v1/bounded-mathematical-reference-recall-v1/review-independence-context-v1/optional-final-review-context-v1/fixed-review-questions-v1',
M5: 'route-cooperation-v33/persistent-failed-input-v1/continuous-frontier-input-v1/research-handoff-batches-v3/assignable-work-v1/resumable-lead-drafts-v1/assignment-deliveries-v1/scoped-research-drafts-v1/review-dispatches-v1/recoverable-delivery-cursors-v1/recoverable-human-edits-v1/recoverable-proof-integration-v1/deferred-handoff-reactivation-v1/concurrent-frontier-recovery-v1/complete-research-findings-v1/consumer-interface-projection-v1/independent-feasibility-v1/ranked-assignment-v1/local-checkpoint-evidence-v1/stable-handoff-inputs-v1/local-attempt-identity-v1/exact-inflight-questions-v1/description-source-recheck-v1/conditional-restore-v1/live-capacity-exploration-v1/snapshot-statement-review-reuse-v1/concurrent-merged-check-v1/adopted-research-use-v1/fixed-candidate-statement-scope-v1/semantic-dependency-review-v1/nonblocking-plan-validation-v1/exact-projection-cache-v1/required-research-challenges-v1/initial-plan-publication-v1/observed-knowledge-use-v1/host-consumer-connection-v1/live-research-publication-v1/typed-helper-preflight-v1/stale-preflight-cancellation-v1/type-projection-preflight-reuse-v1/stale-plan-recheck-stop-v1/shared-statement-preparation-v1/scoped-statement-types-v1/empty-route-list-v1/route-evidence-obligations-v1/primary-led-removed-v1/source-contract-local-repair-v1/unlimited-dispatch-recovery-v1/assignment-condition-snapshot-v1/conditional-dependency-order-v1/original-goal-capacity-coverage-v1/assigned-source-diagnostic-preflight-v1/current-batch-projection-v1/stalled-plan-continuous-recovery-v1/actual-dependency-invalidation-v1/lean-prover-v1/host-capacity-exploration-v1/explicit-handoff-publication-v1/semantic-lead-checkpoints-v1/continuation-handoff-provenance-v1/advisory-stagnation-recovery-v1/explicit-mathematical-gap-recovery-v1/shared-responsibility-assessment-v1/recorded-dispatch-waits-v1/full-plan-explicit-adoption-v1/scoped-delivery-correction-chain-v1/legacy-research-without-finding-v1/research-source-snapshots-v1/source-bound-mathematical-gap-v1/large-delivery-lines-v1/executable-work-assessment-v1/lead-planning-only-v1/plan-revision-patches-v1/lead-inbox-v1/stopped-worker-release-v1/definition-task-dependencies-v1/goal-path-stall-wake-v1/goal-path-answer-coverage-v1/substantive-goal-path-decisions-v1/source-dependency-connect-v1/active-goal-progress-review-v1/executable-goal-review-v1/host-search-checkpoint-v1/executable-next-check-v1/installed-library-dispatch-v1/ascii-forall-statement-shapes-v1/missing-declaration-environment-stability-v1/fresh-goal-progress-v1/missing-research-delivery-recovery-v1/superseded-reservation-release-v1/reseeded-connection-permission-v1/question-bound-advisory-blockers-v1/plan-helper-type-contract-v1/library-probe-advisory-feedback-v1/conditional-research-screening-v1/typed-connection-draft-resume-v1/task-draft-continuation-v1/checkpoint-research-handoff-v1/canonical-dependency-snapshots-v1/verified-canonical-publication-v1/saved-research-transfer-v1/retained-notes-attribution-v1/host-definition-contract-checks-v1/negative-outcome-decisions-v1/definite-type-parser-errors-v1/retained-source-input-discovery-isolation-v1/source-bound-feasibility-drafts-v1/lead-plan-rejection-inbox-v1/checkpointed-connection-prerequisite-yield-v1/fresh-conditional-continuation-reuse-v1/frozen-import-preflight-v1/successor-checked-proof-handoff-v1/final-review-priority-v1/optional-final-review-v1/consumer-finding-notice-v1/fixed-review-requests-v1',
Expand Down
Loading
Loading