Incident Support
Overview
Engineers tag @Alakai investigate <description> in an app's Slack channel. Alakai reads the thread and recent channel messages, queries the app's CloudWatch logs, inspects the code on the environment's branch, checks recently merged PRs, and replaces its "Investigating…" message with a structured report. It can ask up to 3 numbered questions per round and continues when someone tags it again. When a report contains a concrete code change, an Open fix PR button lets anyone in the channel have Alakai open a PR against the environment's branch.
Spec: Houlak/alakai#151. To try it locally end to end, see Test Incident Support Locally.
Architecture
Slack app_mention ─▶ core ── shared SQS queue (taskType incident-support) ─▶ orchestrator ─▶ incident-support worker
│ │
│ (Slack reads, 👀, "Investigating…", RoundInput → Redis) │ clone (read-only token), shell,
│ │ CloudWatch, merged PRs, LLM tool loop
▼ ▼
Slack thread ◀──── chat.update report (+ Open fix PR) ──── orchestrator ◀── POST /task-complete (RoundResult)
Slack block_actions ─▶ core /slack/interactions ── shared SQS queue (taskType implementation, source incident_fix)
─▶ orchestrator ─▶ implementation worker ─▶ PR ─▶ orchestrator posts link, investigation → resolved
| Concern | core | orchestrator | worker |
|---|---|---|---|
| Slack reads (thread, channel context, permalink) | ✅ | — | — |
| Slack writes | 👀, "Investigating…", immediate replies | round reports, failures, fix PR link | — |
| Investigation record | create, lock, RoundInput, lazy expiry, fixPr compare-and-set | persist results, release lock | read-only |
Shared code:
@alakai/incident-store— types, zod schemas, lifecycle helpers (applyRoundResult,planNextRound, expiry), redaction, and the RedisIncidentStore.@alakai/cloudwatch-logs— CloudWatch Logs Insights service (also used by core's/logs) and console-link builder.
Lifecycle
| Status | Meaning | Next mention |
|---|---|---|
awaiting_app | Shared channel and no app could be resolved; Alakai asked which app | resolves the app, starts round 1 |
running | A worker round is in progress (round lock held) | "Still working — I'll include this in the next round" |
awaiting_input | Report posted | starts the next round; after the last round, reopens |
expired | awaiting_input with no activity for INCIDENT_SUPPORT_AWAITING_TTL_HOURS (checked lazily, silent) | reopens |
failed | First round of a budget failed | reopens |
resolved | Fix PR opened | reopens |
A reopen keeps the saved summary and starts a fresh round budget. Duplicate or late worker results are dropped by comparing totalRounds (not round, which resets on reopen).
Crash safety: the round lock (SET NX PX, owner = the round's task id, TTL = round timeout + 5 min) is armed by core at enqueue, re-armed by the orchestrator when the worker actually launches (so time queued behind other workers doesn't count), and released by the orchestrator on /task-complete only if that round still owns it. If a worker dies without calling back, the lock expires and the next mention treats the round as failed. No Slack message is posted for a crashed worker.
Redis keys (INCIDENT_STORE_KEY_PREFIX)
| Key | Content | TTL |
|---|---|---|
{prefix}:incident:{channelId}:{threadTs} | Investigation | INCIDENT_SUPPORT_RETENTION_DAYS, reset on every write |
{prefix}:incident-round:{taskId} | RoundInput written by core | round timeout + 15 min |
{prefix}:incident-lock:{channelId}:{threadTs} | round lock (owner = task id) | round timeout + 5 min |
INCIDENT_STORE_KEY_PREFIX must have the same value in core, the orchestrator and the workers.
Configuration
Per application in config.json:
"incidentSupport": {
"enabled": true,
"defaultEnv": "prod",
"refs": { "prod": "main", "staging": "dev" },
"aliases": ["ruki ios"]
}
refsmaps env names to the branch deployed in that env. Reports show the checked-out SHA; keep refs in sync with deploy branches.logs[env](existing/logsconfig) is optional per env; without it, the investigation uses code and recent changes only. Log groups must live in Alakai's own AWS account.- App matching from the mention text uses the app key and
aliases(case-insensitive,-/_/space interchangeable, whole words).app=/env=tokens override it. - Startup fails when an enabled app has no
refs, itsdefaultEnvisn't a key ofrefs, an alias collides with another app's key or alias in the same project, or two enabled apps listening on the same Slack channel share a key or alias (even across projects). - Each "Open fix PR" button is tied to the report that proposed the fix; clicking a button on an older report is rejected. At most one fix PR is opened per investigation (FR-024).
Environment variables
| Variable | Default | Services |
|---|---|---|
INCIDENT_STORE_KEY_PREFIX | — (unset disables the feature in core/orchestrator; required by the worker) | core, orchestrator, workers |
INCIDENT_SUPPORT_LLM_PROVIDER / _MODEL / _API_KEY / _EFFORT | openai / gpt-6-sol; key required | workers |
INCIDENT_SUPPORT_MAX_ROUNDS | 4 | core |
INCIDENT_SUPPORT_AWAITING_TTL_HOURS | 24 | core |
INCIDENT_SUPPORT_ROUND_TIMEOUT_MIN | 10 (same value everywhere) | core, orchestrator, workers |
INCIDENT_SUPPORT_MAX_TOOL_CALLS | 40 | workers |
INCIDENT_SUPPORT_RETENTION_DAYS | 7 | core, orchestrator, workers |
INCIDENT_SUPPORT_CHANNEL_CONTEXT_MESSAGES | 50 | core |
The task definitions set INCIDENT_STORE_KEY_PREFIX=alakai-incidents. Before enabling an app, add INCIDENT_SUPPORT_LLM_API_KEY to the worker secrets (and optionally INCIDENT_SUPPORT_LLM_PROVIDER / _MODEL).
Infrastructure checklist
- Slack app:
reactions:writescope and Interactivity enabled, pointing at core's/slack/interactions. - Shared worker task role:
logs:StartQuery,logs:GetQueryResults,logs:StopQuery,logs:DescribeLogGroupson the configured log groups. - Analytics migration
008-add-incident-support-interaction-type.
Security notes
- Investigation rounds use a read-only GitHub installation token (
contents,pull_requests,metadata: read); the token is stripped from the clone's remote. Push-capable tokens are only minted by theincident_fiximplementation task. - The incident-support worker has no Slack credentials.
- The agent's shell runs in the checkout with a minimal environment (no worker secrets). The worker container still holds the GitHub App key, Redis URL and LLM key; this is an accepted risk given trusted Slack input.
- Every log row, report and summary is redacted (emails, bearer/API keys, key=value secrets, card numbers, phone numbers) before reaching the model or Slack. Extend
redactTextin@alakai/incident-storewhen a new secret format shows up. - Data residency: redacted logs, thread text and code go to the configured LLM vendor. Keep
incidentSupport.enabled: falsefor apps whose clients forbid that.
Rollout and rollback
- Sandbox: enable one pilot app, run the end-to-end scenarios from the spec (§10).
- Prod: enable per app.
- Rollback: set
incidentSupport.enabled: falsefor the app. Existing records age out afterINCIDENT_SUPPORT_RETENTION_DAYS.