fix(dsh): reconcile orphan schedules and preserve audit evidence

This commit is contained in:
阿白叔 committed 2026-10-31 20:24:04 +08:00
1 parent 4aaebcb65a
commit 282252a5fb
16 files changed
+578 -27

No files matched your search

+24 -1
View File
@@ -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)}))