feat: add task records and verified engineering check jobs
This commit is contained in:
+29
-7
@@ -52,8 +52,8 @@ export function repairToolPairs(messages, lookupResult = null) {
|
||||
const existing = received.get(call.id);
|
||||
let placeholder = false;
|
||||
try { const value = JSON.parse(existing.content); placeholder = value.status === 'interrupted' && value.requires_verification === true; } catch {}
|
||||
const saved = placeholder ? lookupResult?.(call.id) : null;
|
||||
if (saved && !['unknown', 'interrupted'].includes(saved.status)) { recovered++; result.push({ ...existing, content: JSON.stringify(saved) }); }
|
||||
const saved = lookupResult?.(call.id);
|
||||
if (saved && (saved.status === 'unknown' || placeholder && saved.status !== 'interrupted')) { recovered++; result.push({ ...existing, content: JSON.stringify(saved) }); }
|
||||
else result.push(existing);
|
||||
}
|
||||
else {
|
||||
@@ -175,8 +175,12 @@ export class Store extends EventEmitter {
|
||||
for (const step of this.core.step.values()) if (step.sessionId === session.id && ['running', 'waiting'].includes(step.status)) {
|
||||
step.status = 'interrupted'; step.finishedAt = now(); changed = true;
|
||||
}
|
||||
for (const job of this.core.check_job.values()) if (job.sessionId === session.id && ['running', 'waiting'].includes(job.status)) {
|
||||
job.status = 'unknown'; job.finishedAt = now(); job.requiresVerification = true; changed = true;
|
||||
for (const job of this.core.check_job.values()) if (job.sessionId === session.id && ['queued', 'running', 'waiting'].includes(job.status)) {
|
||||
job.requiresVerification = job.status !== 'queued'; job.status = job.requiresVerification ? 'unknown' : 'interrupted'; job.finishedAt = now();
|
||||
job.summary = job.requiresVerification ? '检查进程中断,未得到完整结果;需要核对实际状态,不自动重放。' : '检查尚未进入执行,恢复不会自动运行。';
|
||||
const task = this.core.task.get(job.taskId);
|
||||
if (task) task.verification = { status: job.status, checkJobId: job.id };
|
||||
changed = true;
|
||||
}
|
||||
for (const event of session.events ?? []) {
|
||||
if (['running', 'waiting', 'retrying'].includes(event.phase)) {
|
||||
@@ -366,7 +370,7 @@ export class Store extends EventEmitter {
|
||||
record.result = { status: record.state, invocation_id: record.id, requires_verification: record.requiresVerification,
|
||||
message: record.requiresVerification ? '执行进入后没有记录完成结果,需要核对实际状态。' : '任务中断,这次调用未执行。' };
|
||||
const event = session.events.find(value => value.id === record.eventId);
|
||||
if (event) { event.phase = 'interrupted'; event.finishedAt = record.finishedAt; event.output = record.result.message; }
|
||||
if (event) { event.phase = record.state; event.finishedAt = record.finishedAt; event.output = record.result.message; }
|
||||
}
|
||||
run.checkpoint.pendingToolIds = [];
|
||||
run.checkpoint.requiresVerification = [...this.core.tool.values()].filter(value => value.runId === run.id && value.requiresVerification).map(value => value.id);
|
||||
@@ -406,6 +410,11 @@ export class Store extends EventEmitter {
|
||||
catch {
|
||||
record.state = 'unknown'; record.requiresVerification = true;
|
||||
record.result = { status: 'unknown', requires_verification: true, invocation_id: record.id, message: '工具结果工件缺失或校验失败,实际结果需要核对。' };
|
||||
const session = this.session(sessionId), event = session.events.find(value => value.id === record.eventId);
|
||||
if (event) { event.phase = 'unknown'; event.output = record.result.message; }
|
||||
const run = this.core.run.get(record.runId);
|
||||
if (run && !run.checkpoint.requiresVerification.includes(record.id)) run.checkpoint.requiresVerification.push(record.id);
|
||||
if (run) run.checkpoint.completedToolIds = run.checkpoint.completedToolIds.filter(id => id !== record.id);
|
||||
}
|
||||
}
|
||||
return record.result;
|
||||
@@ -430,10 +439,13 @@ export class Store extends EventEmitter {
|
||||
return {
|
||||
schemaVersion: 1, task: task ?? null, run: run ?? null,
|
||||
runs: [...this.core.run.values()].filter(value => value.sessionId === session.id).slice(-20).map(value => ({ id: value.id, taskId: value.taskId,
|
||||
status: value.status, startedAt: value.startedAt, finishedAt: value.finishedAt, steps: value.steps, toolCalls: value.toolCalls, usage: value.usage, stopReason: value.stopReason })),
|
||||
status: value.status, startedAt: value.startedAt, finishedAt: value.finishedAt, steps: value.steps, toolCalls: value.toolCalls,
|
||||
usage: value.usage, stopReason: value.stopReason, model: value.model, budget: value.budget, resumeOf: value.resumeOf })),
|
||||
progress: { totalTools: tools.length, completedTools: tools.filter(value => value.state === 'completed').length,
|
||||
requiresVerification: tools.filter(value => value.requiresVerification).map(value => ({ id: value.id, tool: value.tool, callId: value.callId, state: value.state })) },
|
||||
artifacts, checks: jobs, accountedTaskTokens: accountedTokens(task?.usage),
|
||||
artifacts, checks: jobs,
|
||||
plans: [...this.core.check_plan.values()].filter(value => value.sessionId === session.id && value.taskId === task?.id).slice(-5),
|
||||
accountedTaskTokens: accountedTokens(task?.usage),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -450,6 +462,16 @@ export class Store extends EventEmitter {
|
||||
this.storage.transaction(() => this.storage.setMeta('runtimeOwner', { pid: process.pid, id: this.ownerId, startedAt: now() }));
|
||||
}
|
||||
|
||||
invalidateChecks(projectId, reason = '工程文件已变化,需要重新检查。') {
|
||||
for (const job of this.core.check_job.values()) {
|
||||
if (job.projectId !== projectId || job.status !== 'passed' || job.stale) continue;
|
||||
job.stale = true; job.staleReason = reason;
|
||||
const session = this.session(job.sessionId), task = this.core.task.get(job.taskId);
|
||||
if (task?.verification.checkJobId === job.id) task.verification = { ...task.verification, status: 'stale', reason };
|
||||
this.save(session, { type: 'check.stale', detail: { jobId: job.id } });
|
||||
}
|
||||
}
|
||||
|
||||
exportLegacyData(directory) {
|
||||
const target = path.resolve(directory);
|
||||
if (fs.existsSync(target) && fs.readdirSync(target).length) throw new Error('回退导出需要一个新的空目录。');
|
||||
|
||||
Reference in New Issue
Block a user