fix: reconcile terminal Git evidence and finalize delivery reports

This commit is contained in:
Agent Workbench Dev
2026-11-06 14:42:21 +08:00
parent e32996799b
commit 1763d90db7
15 changed files with 983 additions and 15 deletions
+37 -2
View File
@@ -28,6 +28,7 @@ import { CheckRunner } from '../core/check-runner.mjs';
import { inspectProject } from '../core/project-inspector.mjs';
import { projectEnvironment } from '../core/process-environment.mjs';
import { GitDelivery } from '../core/git-delivery.mjs';
import { TerminalGitObserver } from '../core/terminal-git-evidence.mjs';
import { ProjectIndex } from '../core/context/project-index.mjs';
import { RequestPlanner, verifyPlanEvidence } from '../core/context/request-plan.mjs';
import { observeToolSurface } from '../core/context/tool-surface.mjs';
@@ -311,17 +312,37 @@ export class Runtime {
session.failure = null;
this.store.save(session);
const deadline = scheduleDeadline(() => controller.abort(new BudgetExceeded('time_limit', '已到达本次运行的时间预算,执行记录已保存。')), record.budget.maxDurationMs);
run.promise = this.run(session, config, run).finally(() => {
run.promise = this.run(session, config, run).finally(async () => {
deadline?.();
try {
const status = session.status;
if (record.purpose === 'diagnostic') session.status = record.taskStatusBefore;
this.store.finishRun(session, record, run.stopReason ?? null, { status });
await this.finalizeDeliveryReport(session, run);
} finally { this.active.delete(id); }
});
run.promise.catch(() => {});
return session;
}
async finalizeDeliveryReport(session, run) {
if (run.worker || run.record.purpose === 'diagnostic' || session.taskId !== run.taskId || session.runId !== run.id) return;
const inRun = row => row.sessionId === session.id && row.taskId === run.taskId && row.runId === run.id;
const hasEvidence = run.record.terminalGitEvidence?.length || session.changes.some(row => row.taskId === run.taskId && row.runId === run.id && row.status === 'applied')
|| [...this.store.core.artifact.values()].some(row => inRun(row) && row.kind === 'delivery-report')
|| [...this.store.core.delivery_job.values()].some(inRun) || [...this.store.core.check_job.values()].some(inRun);
if (!hasEvidence || run.record.finalDeliveryReport) return;
try {
const saved = await this.gitDelivery().report(session, { source: 'agent' });
if (session.taskId !== run.taskId || session.runId !== run.id) return;
run.record.finalDeliveryReport = { artifactId: saved.artifactId, markdownArtifactId: saved.markdownArtifactId,
status: saved.report.status, runStatus: run.record.status, generatedAt: saved.report.generatedAt };
this.store.save(session, { type: 'delivery.final_report', detail: { runId: run.id, artifactId: saved.artifactId, status: saved.report.status } });
} catch (error) {
if (session.taskId !== run.taskId || session.runId !== run.id) return;
run.record.finalDeliveryReportError = this.provider.redact(error.message);
this.store.save(session, { type: 'delivery.final_report_failed', detail: { runId: run.id, error: run.record.finalDeliveryReportError } });
}
}
async capturePauseInputs(run) {
if (!run.worker && run.record.purpose !== 'diagnostic' && ['no_progress', 'step_limit'].includes(run.stopReason)) {
try { run.record.finalSourceFingerprint = (await inspectProject(run.project)).sourceFingerprint; } catch { /* No fingerprint means no claim of unchanged inputs. */ }
@@ -1007,9 +1028,23 @@ export class Runtime {
if (run.worker?.engine) this.engineRunner().assertCurrent(session, run);
if (execute) return execute();
if (unrestricted(run.config)) await ensureGitBaseline(this.store, session, { signal: run.controller.signal });
return this.executeCommand(command, cwd, run.controller.signal, output => {
let observer, observation, observationError;
try {
observer = this.terminalGit ??= new TerminalGitObserver(this.store, this.gitDelivery());
observation = await observer.before(session, event, run);
} catch (error) { observationError = this.provider.redact(error.message); }
run.controller.signal.throwIfAborted();
const result = await this.executeCommand(command, cwd, run.controller.signal, output => {
event.output = output; this.store.save(session);
}, run.config);
let evidence;
try { evidence = await observer?.after(session, event, run, observation, result); }
catch (error) { observationError = this.provider.redact(error.message); }
if (observationError) {
run.record.terminalGitObservationError = observationError;
evidence = { status: 'unverified', message: observationError };
}
return evidence ? { ...result, terminal_git: evidence } : result;
}
decide(sessionId, approvalId, allow) {
const session = this.store.session(sessionId);