feat(escalations): distinguishable notifications, async AI, richer sidebar
Three improvements driven by live wedge testing.
1) Notification title now includes a problem snippet and PSA ticket
suffix when present:
"Escalation from Jane · #12345: Outlook is failing to sync email…"
Replaces the prior "Session escalated by Jane" copy that made every
escalation from the same junior look identical in the bell panel.
Snippet is trimmed to 70 chars with ellipsis. handoff_manager now
passes psa_ticket_id through in the notify() payload so this works
for both /escalate and /handoff entry points.
2) AI enrichment (assessment + enhanced escalation_package) moved to
a FastAPI BackgroundTask. The escalating engineer no longer waits
on 15-25s of Sonnet latency — handoff creation returns as soon as
snapshot, status flip, dual-write, documentation, PSA push, and
notify() are committed. enrich_escalation_async opens its own DB
session, runs both AI calls, updates handoff.ai_assessment +
session.escalation_package, commits, and publishes a new
`handoff_assessment_ready` event on the escalation bus. Frontend
doesn't yet listen for that event — the magic-moment screen still
shows a placeholder ("AI assessment is still generating. Reopen
this view in a few seconds…") which is honest about the state.
Live polling / auto-refresh on the bus event is the natural next
step.
3) ChatSidebar entries now surface the problem summary as a secondary
line and tag PSA-linked sessions with a monospace #ticket badge plus
an "Escalated" pill on in-transit sessions. ChatListItem grew
problem_summary, psa_ticket_id, and status fields; loadChats
populates them from listSessions. The user couldn't tell their own
sessions apart in the sidebar because they all rendered as "New
Chat" with no distinguishing detail — this fixes that for any
session, escalated or not.
Test plan
- Backend full suite: 1103 passed in 255.85s with -n auto.
- Frontend tsc -b clean.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -371,13 +371,35 @@ async def _send_teams_message(
|
||||
def _build_notification_title(event: str, payload: dict[str, Any]) -> str:
|
||||
"""Human-readable title per event type."""
|
||||
titles = {
|
||||
"session.escalated": "Session escalated by {engineer_name}",
|
||||
# Distinguishability matters in the bell panel: with a generic title
|
||||
# ("Session escalated by Jane") two different escalations from the
|
||||
# same junior look like a duplicate notification. Including a short
|
||||
# problem snippet (and ticket number if present) lets the senior
|
||||
# tell them apart at a glance.
|
||||
"session.escalated": "Escalation from {engineer_name}{ticket_suffix}: {problem_snippet}",
|
||||
"session.high_priority": "High-priority session started: {ticket_number}",
|
||||
"proposal.pending": "New flow proposal: {title}",
|
||||
"proposal.approved": "Flow proposal approved: {title}",
|
||||
"knowledge_gap.detected": "Knowledge gap detected: {gap_type}",
|
||||
"test": "Test Notification from ResolutionFlow",
|
||||
}
|
||||
|
||||
# Build the escalation-specific derived fields. Done here rather than at
|
||||
# the call site so every dispatch path (legacy /escalate shim, /handoff,
|
||||
# any future entry point) gets consistent formatting without each one
|
||||
# having to repeat the snippet logic.
|
||||
if event == "session.escalated":
|
||||
problem = (payload.get("problem_summary") or "").strip()
|
||||
if not problem or problem.upper() == "N/A":
|
||||
problem_snippet = "(no summary provided)"
|
||||
elif len(problem) > 70:
|
||||
problem_snippet = problem[:67].rstrip() + "…"
|
||||
else:
|
||||
problem_snippet = problem
|
||||
ticket = payload.get("psa_ticket_id") or payload.get("ticket_number")
|
||||
ticket_suffix = f" · #{ticket}" if ticket else ""
|
||||
payload = {**payload, "problem_snippet": problem_snippet, "ticket_suffix": ticket_suffix}
|
||||
|
||||
template = titles.get(event, f"Notification: {event}")
|
||||
try:
|
||||
return template.format(**payload)
|
||||
|
||||
Reference in New Issue
Block a user