feat(tasks): define investigation report contract and history

This commit is contained in:
2026-10-10 16:02:46 +08:00
parent 4a63fcd7ff
commit 2b6fc5aa52
12 changed files with 1380 additions and 52 deletions
+13 -3
View File
@@ -15,7 +15,13 @@ import httpx
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from app.domain.schemas.operational_task import AgentArtifactsCommand
from app.domain.schemas.operational_task import AgentArtifactsCommand, InvestigationReport
class HistoricalArtifacts(AgentArtifactsCommand):
"""Validate history for inspection without inventing a current outcome."""
report: InvestigationReport
try:
from scripts.run_operational_worker import CredentialProvider, WorkerSettings
@@ -65,13 +71,17 @@ async def run(args):
plan, evidence, report = convert_plan(snapshot)
# Validate the complete payload before reporting readiness or creating a
# backend task. A dry run must catch incompatible historical plan states.
artifacts = AgentArtifactsCommand.model_validate({
artifacts = HistoricalArtifacts.model_validate({
"request_id": str(uuid5(NAMESPACE_URL, f"legacy-artifacts:{metadata.get('projectId')}:{args.session_id}:{snapshot['revision']}")),
"source_session_id": args.session_id, "plan": plan, "evidence": evidence, "report": report,
}).model_dump(mode="json", by_alias=True)
if args.dry_run:
print(f"Ready to import {len(plan['nodes'])} nodes and {len(evidence)} synthetic evidence records; no writes")
print(f"Validated {len(plan['nodes'])} nodes and {len(evidence)} synthetic evidence records; no writes. "
"Historical outcomes are unrecorded; automatic publication as a new report is unavailable.")
return
# A historical read is not a new investigation result. Reject before task
# creation, rather than inventing concluded/insufficient_data from old prose.
artifacts = AgentArtifactsCommand.model_validate(artifacts).model_dump(mode="json", by_alias=True)
settings = WorkerSettings.from_environment()
if metadata.get("projectId") != settings.project_id:
raise ValueError("session does not belong to the worker project")