fix(agent99): compact callback incident ids

This commit is contained in:
ogt
2026-07-14 17:00:20 +08:00
parent 29f92f5387
commit 025829434d
2 changed files with 84 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
from __future__ import annotations
from hashlib import sha256
from typing import Any
from sqlalchemy import text
@@ -16,6 +17,18 @@ from src.services.channel_hub import (
record_external_alert_event,
)
_OPERATION_INCIDENT_ID_MAX_LENGTH = 30
def _operation_incident_id(alert_id: str | None) -> str | None:
"""Keep external alert identity while fitting the immutable event schema."""
if not alert_id:
return None
if len(alert_id) <= _OPERATION_INCIDENT_ID_MAX_LENGTH:
return alert_id
digest = sha256(alert_id.encode("utf-8")).hexdigest().upper()[:21]
return f"INC-AG99-{digest}"
async def _load_callback_readback(
*,
@@ -73,6 +86,7 @@ def _operation_context(payload: Agent99CompletionCallbackRequest) -> dict[str, A
"trace_id": payload.trace_id,
"work_item_id": payload.work_item_id,
"alert_id": payload.alert_id,
"operation_incident_id": _operation_incident_id(payload.alert_id),
"correlation_key": payload.correlation_key,
"source": payload.source,
"mode": payload.mode,
@@ -133,6 +147,7 @@ async def record_agent99_completion_callback(
else "warning"
)
context = _operation_context(payload)
operation_incident_id = _operation_incident_id(payload.alert_id)
event_id = await record_external_alert_event(
project_id=payload.project_id,
provider="agent99",
@@ -166,7 +181,7 @@ async def record_agent99_completion_callback(
if int((before or {}).get("execution_count") or 0) == 0:
await repository.append(
"EXECUTION_COMPLETED",
incident_id=payload.alert_id,
incident_id=operation_incident_id,
actor="agent99_completion_callback",
action_detail=f"{payload.mode}:{payload.outcome_state}",
success=payload.verifier_passed,
@@ -175,7 +190,7 @@ async def record_agent99_completion_callback(
if terminal_resolved and int((before or {}).get("resolved_count") or 0) == 0:
await repository.append(
"RESOLVED",
incident_id=payload.alert_id,
incident_id=operation_incident_id,
actor="agent99_completion_callback",
action_detail=f"{payload.mode}:verified_resolved",
success=True,