fix(dsh): reconcile orphan schedules and preserve audit evidence
This commit is contained in:
1 parent
4aaebcb65a
commit
282252a5fb
16 files changed
+578
-27
No files matched your search
@@ -54,7 +54,21 @@ def seed(service, output, data):
|
||||
write(directory / 'snapshot.json', {'fixture': True, 'task_id': ids['Board-A']})
|
||||
write(directory / 'verification.json', {'queue_complete': True, 'failed_items': 0,
|
||||
'interrupted': False, 'paused': False, 'saved_items': 0, 'no_match_items': 1})
|
||||
manifest = {'tasks': ids, 'sourceHashes': hashes, 'data': str(data)}
|
||||
from dx_productivity.dsh.scheduling import ScheduleStore
|
||||
from dx_productivity.trial_task_center.task_queue import _plan_hash
|
||||
schedules = ScheduleStore(data)
|
||||
orphan = schedules.save({'task_ids': [ids['Board-C']], 'not_before': '2026-10-30T12:00:00Z'},
|
||||
{ids['Board-C']: _plan_hash(service.for_project_task(ids['Board-C']), ids['Board-C'])})
|
||||
schedules.claim(orphan['schedule_id'], run_id='f' * 32)
|
||||
# Force one real bounded archival pass; no original audit event is deleted
|
||||
# unless its lossless local JSONL has been durably written and verified.
|
||||
with schedules._connect() as db:
|
||||
db.execute('BEGIN IMMEDIATE')
|
||||
for index in range(6000):
|
||||
schedules._event(db, '0' * 32, '2026-10-30T12:00:00Z', 'result', None,
|
||||
{'status': 'completed', 'fixture': True, 'index': index})
|
||||
db.execute('COMMIT')
|
||||
manifest = {'tasks': ids, 'sourceHashes': hashes, 'data': str(data), 'orphanSchedule': orphan['schedule_id']}
|
||||
write(output / 'manifest.json', manifest)
|
||||
return manifest
|
||||
|
||||
@@ -143,6 +157,9 @@ def phase(args):
|
||||
modal.setProperty('acceptanceClicked', True)
|
||||
text = modal.preview.toPlainText()
|
||||
cancel = False
|
||||
if modal.windowTitle().endswith('核对失联排期'):
|
||||
state['reconciliationDialogs'] = state.get('reconciliationDialogs', 0) + 1
|
||||
cancel = state['reconciliationDialogs'] == 1
|
||||
if args.phase == 'initial' and modal.windowTitle().endswith('执行所选任务'):
|
||||
state['executionConfirmations'] = state.get('executionConfirmations', 0) + 1
|
||||
# A safe pause is a user decision. Exercise cancellation
|
||||
@@ -269,10 +286,16 @@ def main():
|
||||
if args.audit_fault:
|
||||
original = json.loads((output / 'audit-fault.json').read_text(encoding='utf8'))
|
||||
assert hashlib.sha256((data / 'dsh/decisions.jsonl').read_bytes()).hexdigest() == original['sha256']
|
||||
from dx_productivity.dsh.scheduling import ScheduleStore
|
||||
schedules = ScheduleStore(data)
|
||||
assert schedules.get(json.loads((output / 'manifest.json').read_text(encoding='utf8'))['orphanSchedule'])['status'] == 'interrupted'
|
||||
archive_status = schedules.audit_status()
|
||||
assert archive_status['archived_events'] > 0
|
||||
write(output / 'report.json', {'status': 'passed', 'processes': 2, 'calls': calls,
|
||||
'realCadStarted': False, 'remoteIssuesCreated': False, 'sourceFixtureHashesUnchanged': True,
|
||||
'auditFault': args.audit_fault, 'auditFaultPreserved': True if args.audit_fault else None,
|
||||
'cleanShutdowns': [value['cleanShutdown'] for value in phases],
|
||||
'orphanScheduleReconciled': True, 'scheduleAudit': archive_status,
|
||||
'modelToolCalls': [json.loads(line) for line in audit.read_text(encoding='utf8').splitlines()] if audit.is_file() else [],
|
||||
'data': str(data)})
|
||||
print(json.dumps({'status': 'passed', 'output': str(output), 'controlledCalls': len(calls)}))
|
||||
|
||||
@@ -33,4 +33,8 @@ assert.equal(scheduleSnapshot.operations.schedules[0].requires_confirmation,fals
|
||||
assert.equal(scheduleSnapshot.operations.schedule_events.length,10);
|
||||
assert.equal(scheduleSnapshot.operations.schedule_events[0].payload.authority,'native_future_authorization');
|
||||
assert.ok(!JSON.stringify(scheduleSnapshot).includes('frozen'));
|
||||
const archiveSnapshot=modelSnapshot({operations:{schedule_audit:{status:'ok',live_events:5000,archived_events:3,
|
||||
retained_limit:5000,files:['local-private-path']}}});
|
||||
assert.equal(archiveSnapshot.operations.schedule_audit.archived_events,3);
|
||||
assert.equal(archiveSnapshot.operations.schedule_audit.files,undefined);
|
||||
console.log(JSON.stringify({status:'passed',committedIdsPreserved:true,impactRowsBounded:true,snapshotBounded:true}));
|
||||
@@ -26,6 +26,23 @@ const element=id=>`document.querySelector('[data-testid="${id}"]')`;
|
||||
async function click(id){await wait(()=>c.evaluate(`!!${element(id)}&&!${element(id)}.disabled`),id);await c.click(element(id));}
|
||||
async function tab(id){await click('dx-operations-tab-'+id);}
|
||||
async function idle(){await wait(()=>c.evaluate(`![...document.querySelectorAll('button[aria-label="停止生成"]')].some(e=>e.getBoundingClientRect().width>0)`),'generation idle');}
|
||||
async function nativeScheduleStep(test,label){
|
||||
report.scheduleClicks??=[];
|
||||
for(let attempt=1;attempt<=3;attempt++){
|
||||
await wait(async()=>!(await context()).operations?.busy,'native operations settled');
|
||||
await click('dx-schedule-new');
|
||||
try{
|
||||
await wait(test,label,5000);report.scheduleClicks.push({label,attempt,accepted:true});return;
|
||||
}catch(error){
|
||||
if(!error.message.startsWith('Timed out:'))throw error;
|
||||
await wait(async()=>!(await context()).operations?.busy,'schedule request settled');
|
||||
if(await test()){report.scheduleClicks.push({label,attempt,accepted:true});return;}
|
||||
const notice=await c.evaluate(`document.querySelector('[data-testid="dx-operations-notice"]')?.textContent||''`);
|
||||
report.scheduleClicks.push({label,attempt,accepted:false,notice});
|
||||
}
|
||||
}
|
||||
throw Error('Native schedule clicks were not admitted: '+label);
|
||||
}
|
||||
async function pauseLiveRun(){
|
||||
const original=(await context()).operations.live_run;
|
||||
report.pauseClicks=[];
|
||||
@@ -89,6 +106,20 @@ try{
|
||||
report.checks.push('corrupt audit remains explicit while native health and independent operations refresh successfully');
|
||||
}
|
||||
if(phase==='initial'){
|
||||
await tab('schedules');await click('dx-schedules-refresh');
|
||||
const orphanId=manifest.orphanSchedule;
|
||||
await click('dx-schedule-reconcile-'+orphanId);
|
||||
await wait(async()=>(await context()).operations?.activity?.status==='cancelled','orphan reconciliation native cancel');
|
||||
assert.equal((await context()).operations.schedules.find(row=>row.schedule_id===orphanId).status,'claimed');
|
||||
await click('dx-schedule-reconcile-'+orphanId);
|
||||
await wait(async()=>(await context()).operations?.schedules?.find(row=>row.schedule_id===orphanId)?.status==='interrupted','orphan reconciliation native confirmation');
|
||||
await wait(async()=>(await context()).operations?.schedule_events?.some(row=>row.schedule_id===orphanId&&row.payload?.reconciled),'orphan reconciliation audit visible');
|
||||
await click('dx-schedules-refresh');
|
||||
await wait(async()=>((await context()).operations?.schedule_audit?.archived_events||0)>0,'lossless archive status');
|
||||
await wait(()=>c.evaluate(`document.body.innerText.includes('已归档')&&document.body.innerText.includes('旧记录完整保留')`),'archive status rendered');
|
||||
report.scheduleAudit=(await context()).operations.schedule_audit;
|
||||
await c.screenshot(path.join(output,'orphan-reconciled-and-archive.png'));
|
||||
report.checks.push('actual native cancel preserves claimed orphan; native confirm reconciles without execution; archive counts visible');
|
||||
await send('只读检查当前 Board-A 任务的执行影响、已有执行历史和本地异常经验。说明匹配器件数量是否已知,暂时不要执行或修改任务。');
|
||||
await wait(async()=>(await context()).operations?.impact?.task_ids?.includes(manifest.tasks['Board-A'])||(await context()).operations?.impact?.coverage==='mapping_only','real-model impact response');await idle();
|
||||
await tab('impact');await click('dx-impact-refresh');
|
||||
@@ -112,8 +143,21 @@ try{
|
||||
await wait(()=>c.evaluate(`fetch('/dx/runtime').then(r=>r.json()).then(x=>x.settings.response_timeout_seconds===120&&x.settings.model_context_limit===12000)`),'usage settings persisted');
|
||||
report.checks.push('actual numeric input and save configure response timeout and context limit');
|
||||
await select('Board-A');
|
||||
const beforeExecute=(await context()).lifecycle?.request_id;
|
||||
await send('现在执行 Board-A 任务,只运行这一个工程,按原生确认的范围处理。结束后告诉我真实保存、失败和未命中数量。');
|
||||
await wait(async()=>(await context()).operations?.live_run?.active===true,'live controlled run');
|
||||
let clarified=false;
|
||||
await wait(async()=>{
|
||||
const data=await context();
|
||||
if(data.operations?.live_run?.active===true)return true;
|
||||
const generating=await c.evaluate(`[...document.querySelectorAll('button[aria-label="停止生成"]')].some(e=>e.getBoundingClientRect().width>0)`);
|
||||
if(!clarified&&!generating&&data.lifecycle?.status==='preflight'&&data.lifecycle.request_id!==beforeExecute){
|
||||
clarified=true;
|
||||
// Simulate a human answering the model's optional-baseline question.
|
||||
// The actual task still has to pass native preflight/confirmation.
|
||||
await send('继续立即执行 Board-A,仅此一个工程,并在原生窗口中确认。可选探测基线缺失请如实报告;按任务中心实际门禁处理,结束后只报告真实计数。');
|
||||
}
|
||||
return false;
|
||||
},'live controlled run after natural-language clarification',120000);
|
||||
assert.equal((await context()).operations.health.checks.find(row=>row.name==='execution')?.code,'execution_running');
|
||||
await pauseLiveRun();
|
||||
await wait(async()=>{const d=await context();return d.operations?.last_execution?.status==='paused'&&!d.operations?.live_run?.active;},'safe pause receipt');
|
||||
@@ -140,20 +184,25 @@ try{
|
||||
}
|
||||
await wait(async()=>(await context()).operations?.last_execution?.status==='completed','restarted original queue completed');
|
||||
const result=(await context()).operations.last_execution;assert.equal(result.run_id,prior.run_id);assert.equal(result.queue_id,prior.queue_id);assert.equal(result.tasks[0].no_match_items,2);
|
||||
await tab('running');await click('dx-history-refresh');
|
||||
await wait(async()=>(await context()).operations?.runs?.find(row=>row.run_id===prior.run_id)?.counters?.no_match_items===2,'terminal history persisted total');
|
||||
assert.equal((await context()).operations.runs.find(row=>row.run_id===prior.run_id).counters.saved_items,0);
|
||||
report.checks.push('terminal history displays persisted totals instead of unknown');
|
||||
report.checks.push('second actual application process resumed original frozen queue and skipped completed item');
|
||||
await select('Board-C');await tab('schedules');await click('dx-schedule-new');
|
||||
await wait(async()=>(await context()).operations?.activity?.status==='cancelled','native schedule cancellation');
|
||||
assert.equal((await context()).operations.schedules.length,0);
|
||||
await click('dx-schedule-new');await wait(async()=>(await context()).operations?.schedules?.length===1,'natively authorized schedule saved');
|
||||
await wait(async()=>(await context()).operations?.schedules?.[0]?.status==='completed','automatic due schedule completed',70000);
|
||||
const schedule=(await context()).operations.schedules[0];assert.equal(schedule.auto_start,true);report.schedule=schedule;
|
||||
await select('Board-C');await tab('schedules');
|
||||
await nativeScheduleStep(async()=>(await context()).operations?.activity?.status==='cancelled','native schedule cancellation');
|
||||
assert.equal((await context()).operations.schedules.filter(row=>row.schedule_id!==manifest.orphanSchedule).length,0);
|
||||
const ownSchedule=async()=>(await context()).operations?.schedules?.find(row=>row.schedule_id!==manifest.orphanSchedule);
|
||||
await nativeScheduleStep(async()=>!!(await ownSchedule()),'natively authorized schedule saved');
|
||||
await wait(async()=>(await ownSchedule())?.status==='completed','automatic due schedule completed',70000);
|
||||
const schedule=await ownSchedule();assert.equal(schedule.auto_start,true);report.schedule=schedule;
|
||||
await new Promise(r=>setTimeout(r,17000));await click('dx-schedules-refresh');
|
||||
await wait(async()=>(await context()).operations?.schedules?.[0]?.status==='completed','schedule remains terminal');
|
||||
await wait(async()=>(await ownSchedule())?.status==='completed','schedule remains terminal');
|
||||
await wait(async()=>{const events=(await context()).operations?.schedule_events||[];
|
||||
return events.some(row=>row.event==='dispatch')&&events.some(row=>row.event==='result');},'persisted schedule audit events');
|
||||
const scheduleEvents=(await context()).operations.schedule_events;
|
||||
assert.equal(scheduleEvents.find(row=>row.event==='dispatch').payload.authority,'native_future_authorization');
|
||||
assert.equal(scheduleEvents.find(row=>row.event==='result').payload.receipt.status,'completed');
|
||||
assert.equal(scheduleEvents.find(row=>row.event==='dispatch'&&row.schedule_id===schedule.schedule_id).payload.authority,'native_future_authorization');
|
||||
assert.equal(scheduleEvents.find(row=>row.event==='result'&&row.schedule_id===schedule.schedule_id).payload.receipt.status,'completed');
|
||||
await wait(()=>c.evaluate(`document.body.innerText.includes('排期派发记录')&&document.body.innerText.includes('排期结果记录')`),'schedule audit cards rendered');
|
||||
report.scheduleEvents=scheduleEvents;
|
||||
await c.screenshot(path.join(output,'schedule-audit-events.png'));
|
||||
|
||||
Reference in new issue
Block a user