Skip to main content

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
Concerncoreorchestratorworker
Slack reads (thread, channel context, permalink)✅——
Slack writes👀, "Investigating…", immediate repliesround reports, failures, fix PR link—
Investigation recordcreate, lock, RoundInput, lazy expiry, fixPr compare-and-setpersist results, release lockread-only

Shared code:

  • @alakai/incident-store — types, zod schemas, lifecycle helpers (applyRoundResult, planNextRound, expiry), redaction, and the Redis IncidentStore.
  • @alakai/cloudwatch-logs — CloudWatch Logs Insights service (also used by core's /logs) and console-link builder.

Lifecycle​

StatusMeaningNext mention
awaiting_appShared channel and no app could be resolved; Alakai asked which appresolves the app, starts round 1
runningA worker round is in progress (round lock held)"Still working — I'll include this in the next round"
awaiting_inputReport postedstarts the next round; after the last round, reopens
expiredawaiting_input with no activity for INCIDENT_SUPPORT_AWAITING_TTL_HOURS (checked lazily, silent)reopens
failedFirst round of a budget failedreopens
resolvedFix PR openedreopens

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)​

KeyContentTTL
{prefix}:incident:{channelId}:{threadTs}InvestigationINCIDENT_SUPPORT_RETENTION_DAYS, reset on every write
{prefix}:incident-round:{taskId}RoundInput written by coreround 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"]
}
  • refs maps 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 /logs config) 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, its defaultEnv isn't a key of refs, 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​

VariableDefaultServices
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 / _EFFORTopenai / gpt-6-sol; key requiredworkers
INCIDENT_SUPPORT_MAX_ROUNDS4core
INCIDENT_SUPPORT_AWAITING_TTL_HOURS24core
INCIDENT_SUPPORT_ROUND_TIMEOUT_MIN10 (same value everywhere)core, orchestrator, workers
INCIDENT_SUPPORT_MAX_TOOL_CALLS40workers
INCIDENT_SUPPORT_RETENTION_DAYS7core, orchestrator, workers
INCIDENT_SUPPORT_CHANNEL_CONTEXT_MESSAGES50core

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:write scope and Interactivity enabled, pointing at core's /slack/interactions.
  • Shared worker task role: logs:StartQuery, logs:GetQueryResults, logs:StopQuery, logs:DescribeLogGroups on 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 the incident_fix implementation 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 redactText in @alakai/incident-store when a new secret format shows up.
  • Data residency: redacted logs, thread text and code go to the configured LLM vendor. Keep incidentSupport.enabled: false for apps whose clients forbid that.

Rollout and rollback​

  1. Sandbox: enable one pilot app, run the end-to-end scenarios from the spec (§10).
  2. Prod: enable per app.
  3. Rollback: set incidentSupport.enabled: false for the app. Existing records age out after INCIDENT_SUPPORT_RETENTION_DAYS.