Skip to main content

Runbook: investigate a real bug in the sandbox Time Off app

This is a complete, in-order runbook. You start Alakai on your machine (core, orchestrator, workers), break the deployed sandbox Time Off app from its own UI like a user would, report it in Slack like an engineer would, and let Alakai investigate the real code and CloudWatch logs and open a fix PR.

You in the Time Off UI ──▶ sandbox Time Off API ──▶ CloudWatch /ecs/time-off/prod
You in Slack ──ngrok──▶ core ──▶ LocalStack SQS ──▶ orchestrator ──(make run-latest)──▶ incident-support worker
├─ clones Houlak/alakai_sandbox-time-off@main
└─ queries /ecs/time-off/prod

Locally the orchestrator doesn't start ECS tasks, so you run each worker once by hand (one command per round). Everything else is automatic.

For synthetic scenarios (no real app), see Test Incident Support Locally.


The bug you'll trigger​

Admin → Configuración → "Nuevo Houlaker": creating an employee whose email already belongs to another employee fails with "No se pudo crear el empleado.", because the API answers HTTP 500 "Unexpected server error".

So you can judge Alakai's diagnosis:

  • server/src/routes/employees.ts (POST /api/employees, line 73) only checks that email is a string. Nothing checks whether it's already taken.
  • server/src/services/employeeService.ts:170 (createEmployee) calls Employee.create directly.
  • Postgres rejects it with the unique index employees_email_unique_when_present (server/migrations/20250208120000-init-schema.js:85), so Sequelize throws SequelizeUniqueConstraintError.
  • server/src/middleware/errorHandler.ts turns every non-AppError into a 500 and logs it (console.error), so the error lands in CloudWatch.
  • The same applies to editing an employee's email to an existing one (PATCH /api/employees/:id, line 148), and to a malformed email such as juan.perez@houlak, which fails Sequelize's isEmail validator (SequelizeValidationError) and also returns 500.

A good fix returns a 4xx for both: check for an existing email (case-insensitive) and validate the format, for example 409 "Email already in use" and 400 "Invalid email". Alternatively, map Sequelize unique/validation errors to AppError in the error handler. Ideally it comes with tests.

Verified against the fork's main (bd0d198) with a local Postgres: the duplicate and the malformed email both return 500 with the errors above. A failed create saves nothing.


Part A — Before you start (read once)​

  1. Confirm the target is the sandbox. The fork deploys to ECS service time-off-prod-service on cluster hk-cluster-dev (ENV=local, dev auth enabled) and logs to /ecs/time-off/prod. Make sure that is the sandbox deployment and its web app, not the Time Off app people use day to day.
  2. Don't push to the fork's main during the test: every push to main deploys. PRs only build.
  3. Don't merge Alakai's fix PR unless you mean to deploy it. Verify it locally instead (Part G).
  4. You need: Node 20+ (Node 24 only for Part G), Yarn, Docker, ngrok, redis-cli, jq, AWS CLI v2 with a profile for the sandbox account (868178926296), admin access to the local-dev Slack app, the GitHub App credentials, an LLM key for incident rounds and one for fix PRs, and an admin account in the sandbox Time Off app.

Part B — One-time setup​

B1. Get the code and build the shared packages​

cd ~/houlak_projects/alakai # your alakai checkout
git fetch origin feat/incident-support
git checkout feat/incident-support
yarn install
for p in logger shared-types branch-naming analytics execution-store github llm cloudwatch-logs incident-store; do
yarn workspace @alakai/$p build
done

B2. Check the deployed code and your AWS access​

export AWS_PROFILE=<sandbox-profile> AWS_REGION=us-east-1
aws sso login # if your profile uses SSO

# Which commit is deployed? Should be a commit of the fork's main.
TD=$(aws ecs describe-services --cluster hk-cluster-dev --services time-off-prod-service \
--query 'services[0].taskDefinition' --output text)
aws ecs describe-task-definition --task-definition "$TD" \
--query 'taskDefinition.containerDefinitions[0].image' --output text # …/time-off:<commit-sha>
git ls-remote https://github.com/Houlak/alakai_sandbox-time-off refs/heads/main

# Can you query the logs? (the worker will use this profile)
aws logs describe-log-groups --log-group-name-prefix /ecs/time-off/prod --query 'logGroups[].logGroupName'

If the deployed SHA isn't on the fork's main, the bug is still there, but Alakai's file:line links may be slightly off.

B3. Configure the local-dev Slack app​

At api.slack.com/apps, open your local-dev app:

  1. OAuth & Permissions → Bot Token Scopes: app_mentions:read, channels:history, chat:write, and add reactions:write. Click Reinstall to Workspace and copy the Bot User OAuth Token (xoxb-…).
  2. Basic Information → Signing Secret: copy it.
  3. Event Subscriptions: enable. Subscribe to bot events → app_mention. You'll set the Request URL in Part C, once ngrok is running.
  4. Interactivity & Shortcuts: turn On. You'll set the Request URL in Part C too.
  5. In Slack, create a public channel (e.g. #alakai-incident-test), run /invite @<your-bot>, and copy the channel ID (channel name → About → bottom, C…).

B4. core/config.json​

cd core
cp config.sample.json config.json # skip if you already have a local config.json

Add this application (inside projects; keep your other entries):

"houlak": {
"applications": {
"time-off": {
"repo": "Houlak/alakai_sandbox-time-off",
"responsibleUsers": ["<your-github-login>"],
"slackChannelIds": ["<C-test-channel>"],
"logs": {
"prod": { "awsAccountId": "868178926296", "awsRegion": "us-east-1", "logGroups": ["/ecs/time-off/prod"] }
},
"incidentSupport": {
"enabled": true,
"defaultEnv": "prod",
"refs": { "prod": "main" },
"aliases": ["time off", "timeoff"]
}
}
}
}

Slack channel (slackChannelIds). This is what connects the Slack channel to the app: Alakai only answers @Alakai investigate in channels listed in an enabled app's slackChannelIds, and that list also decides which apps it can pick from in that channel.

  • Replace <C-test-channel> with the channel ID you copied in B3 step 5 (it starts with C, e.g. C07ABC12345). Use the ID, not the name (#alakai-incident-test won't match).
  • The channel must be public, and the bot must be a member (/invite @<your-bot>).
  • You can list several channels: ["C07ABC12345", "C07DEF67890"].
  • Restart core after editing config.json; it's only read at startup.
  • If it's wrong, Alakai replies "Incident support isn't configured for this channel."

B5. Environment files​

Every process uses the same Redis (redis://localhost:6379), the same INCIDENT_STORE_KEY_PREFIX, and the same INCIDENT_SUPPORT_ROUND_TIMEOUT_MIN. The orchestrator and the workers also share REDIS_KEY_PREFIX.

core/.env: cp .env.sample .env (in core/), then set or add:

ENV=local
PORT=3000
SLACK_SIGNING_SECRET=<from B3>
SLACK_BOT_TOKEN=xoxb-<from B3>
OPENAI_API_KEY=<key> # planner (core won't start without a PLANNER key)
REPO_WORKFLOW_CONFIG_SOURCE=file
TASK_TRACKING_REDIS_URL=redis://localhost:6379
IMPLEMENTATION_SQS_QUEUE_URL=http://localhost:4566/000000000000/alakai-queue
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=test # LocalStack accepts any credentials
AWS_SECRET_ACCESS_KEY=test
GITHUB_APP_ID=<id>
GITHUB_APP_PRIVATE_KEY=<pem with \n escaped newlines>
INCIDENT_STORE_KEY_PREFIX=alakai-incidents-local
INCIDENT_SUPPORT_ROUND_TIMEOUT_MIN=10

orchestrator/.env: cp .env.sample .env (in orchestrator/), then set:

ENV=local
PORT=8080 # core uses 3000
SQS_QUEUE_URL=http://localhost:4566/000000000000/alakai-queue
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=test
AWS_SECRET_ACCESS_KEY=test
REDIS_URL=redis://localhost:6379
REDIS_KEY_PREFIX=alakai-local
SLACK_BOT_TOKEN=xoxb-<from B3> # the orchestrator posts reports and PR links
INCIDENT_STORE_KEY_PREFIX=alakai-incidents-local
INCIDENT_SUPPORT_ROUND_TIMEOUT_MIN=10

workers/incident-support/.env: run make env-init in workers/incident-support/, then set:

REDIS_URL=redis://localhost:6379
REDIS_KEY_PREFIX=alakai-local
INCIDENT_STORE_KEY_PREFIX=alakai-incidents-local
ORCHESTRATOR_URL=http://localhost:8080
INCIDENT_SUPPORT_LLM_PROVIDER=anthropic # or openai
INCIDENT_SUPPORT_LLM_MODEL=claude-opus-5-5 # required for anthropic; leave empty for openai (gpt-6-sol)
INCIDENT_SUPPORT_LLM_API_KEY=<key>
GITHUB_APP_ID=<id>
GITHUB_APP_PRIVATE_KEY=<pem with \n>
AWS_PROFILE=<sandbox-profile> # real AWS, for CloudWatch
INCIDENT_SUPPORT_ROUND_TIMEOUT_MIN=10

workers/implementation/.env: run make env-init in workers/implementation/, then set:

REDIS_URL=redis://localhost:6379
REDIS_KEY_PREFIX=alakai-local
ORCHESTRATOR_URL=http://localhost:8080
INCIDENT_STORE_KEY_PREFIX=alakai-incidents-local
IMPLEMENTATION_LLM_PROVIDER=anthropic
IMPLEMENTATION_LLM_MODEL=claude-opus-5-5
IMPLEMENTATION_LLM_API_KEY=<key>
GITHUB_APP_ID=<id>
GITHUB_APP_PRIVATE_KEY=<pem with \n>
TASK_ID= # filled in Part F

Part C — Start everything (every session)​

Open five terminals at the alakai repo root.

Terminal 1 — Redis + LocalStack SQS

docker start alakai-redis 2>/dev/null || docker run -d --name alakai-redis -p 6379:6379 redis:latest
cd .local-aws && make up && make infra
redis-cli ping # PONG

Terminal 2 — ngrok

ngrok http 3000

Copy the https://<sub>.ngrok-free.app URL. In the Slack app, set:

  • Event Subscriptions → Request URL: https://<sub>.ngrok-free.app/slack/events. It turns Verified once core is up (terminal 3). Save.
  • Interactivity → Request URL: https://<sub>.ngrok-free.app/slack/interactions. Save.

(The ngrok URL changes every time you restart it; update both Request URLs when it does.)

Terminal 3 — core

cd core && yarn dev

Look for Incident support: enabled in the startup logs. Then check: curl -s localhost:3000/healthz.

Terminal 4 — orchestrator

cd orchestrator && yarn dev

Check: curl -s localhost:8080/health → {"ok":true}.

Terminal 5 — workers (you run rounds from here)

cd workers/incident-support
make help

Part D — Break the app from its UI​

  1. Open the sandbox Time Off web app and sign in with Google as an admin.
    • If you can't reach a deployed frontend for this API, run the frontend locally against it instead: in the time-off repo, set VITE_API_BASE_URL=<sandbox API URL>, VITE_API_KEY=<a key from API_KEYS> and VITE_GOOGLE_CLIENT_ID in app/.env.local, then run yarn dev:app. In dev mode the login page also has a Dev login box where you can type an admin email.
  2. Go to Configuración (Administración → Configuración de balances).
  3. In Nuevo Houlaker, fill in:
    • Nombre Juan, Apellido Perez
    • Email: the email of an employee who already exists (pick one from the list below the form)
  4. Click Crear. You get "No se pudo crear el empleado." (In the browser devtools Network tab: POST /api/employees → 500, {"message":"Unexpected server error"}.)
  5. Repeat 2–3 times over a couple of minutes. Optionally also try a malformed email (juan.perez@houlak), which fails the same way.

Nothing is saved: each failed create is rejected by the database.

Confirm the errors reached CloudWatch (in any terminal; usually within a minute):

aws logs filter-log-events --profile <sandbox-profile> --region us-east-1 \
--log-group-name /ecs/time-off/prod \
--start-time $(( ($(date +%s) - 900) * 1000 )) \
--filter-pattern '"SequelizeUniqueConstraintError"' \
--query 'events[].message' --output text | head

You should see SequelizeUniqueConstraintError with duplicate key value violates unique constraint "employees_email_unique_when_present", and access-log lines like POST /api/employees HTTP/1.1 500.


Part E — Report it in Slack and let Alakai investigate​

  1. In your test channel, post a top-level message, the way an engineer would after a teammate complains:

    @Alakai investigate in time off, adding a new Houlaker from Configuración fails with "No se pudo crear el empleado"
  2. Within ~3 s: 👀 on your message and "Investigating… (started HH:MM UTC)" in the thread. Terminal 3 logs incident.round.enqueued; terminal 4 logs Worker launched and message deleted { taskType: 'incident-support', … }.

  3. Terminal 5:

    make run-latest

    Run it within 15 minutes of step 2 (the round lock's lifetime). It takes 1–5 min, then "Investigating…" is replaced by the report.

What a good report looks like

SectionExpected
Headerapp time-off, env prod, round 1
Summary500 on POST /api/employees when the email already exists (unique index), surfaced as a generic error
Confidencehigh or medium
EvidenceSequelizeUniqueConstraintError … employees_email_unique_when_present and POST /api/employees HTTP/1.1 500 lines, each with a working Logs Insights link; any email in the excerpts shows as [REDACTED]
Suspected causeserver/src/routes/employees.ts#L73 and/or server/src/services/employeeService.ts#L170, links pinned to the checked-out SHA; possibly errorHandler.ts
Recent changesprobably none (the fork's last merge was 2026-11-04, outside the window)
Questions≤ 3, e.g. whether re-adding existing people is expected, or whether editing emails fails too
Next stepsduplicate check / format validation returning 4xx
ButtonOpen fix PR, if it proposed a concrete change

Inspect what happened if needed: make running, make investigation key=<channel_id>:<thread_ts>, make round-input TASK_ID=<id>.

E2. Follow-up round​

  1. Reply in the thread without tagging: 1: yes, people get re-added when they come back from leave. Nothing happens.
  2. Then tag: @Alakai does editing an existing employee's email to a taken one fail the same way?
  3. Terminal 5: make run-latest.

Round 2 should use your answer and cover the PATCH route (employees.ts#L148, updateEmployee).


Part F — Open the fix PR​

  1. On the latest report, click Open fix PR. Within ~3 s a confirmation appears in the thread, and terminal 4 logs Worker launched … { taskType: 'implementation', taskId: '<id>' }.

  2. Copy that taskId into workers/implementation/.env (TASK_ID=<id>), then run:

    cd ../implementation && make run-once
  3. A few minutes later the thread shows the PR link. On GitHub, check the PR on Houlak/alakai_sandbox-time-off:

    • base main, title fix: …, labels ai-generated + incident, you as reviewer
    • the body contains the report and the Slack thread link
    • the diff returns a 4xx for a duplicate email (create and update) and for a malformed one, instead of a 500
  4. Click Open fix PR again: Alakai posts the same PR link and opens nothing new. make investigation key=… (in workers/incident-support) shows status: "resolved".

Don't merge it (that deploys). Verify it in Part G.


Part G — Verify the fix locally (optional)​

Run the Time Off API and web app locally on the fix branch. Time Off requires Node 24.

docker run -d --name timeoff-pg -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=time-off -p 5433:5432 postgres:16
git clone https://github.com/Houlak/alakai_sandbox-time-off ~/alakai_sandbox-time-off
cd ~/alakai_sandbox-time-off && git fetch origin <fix-branch> && git checkout <fix-branch>
yarn install

Terminal A — API (migrations and seeders run on start):

cd ~/alakai_sandbox-time-off/server
DATABASE_URL=postgres://postgres:postgres@localhost:5433/time-off API_KEYS=localkey ENV=local \
DEV_AUTH_ENABLED=true DEV_JWT_SECRET=devsecret GOOGLE_CLIENT_ID=x SERVER_PORT=4100 \
npx tsx src/server.ts

Terminal B — web app:

cd ~/alakai_sandbox-time-off/app
printf 'VITE_API_BASE_URL=http://localhost:4100\nVITE_API_KEY=localkey\nVITE_GOOGLE_CLIENT_ID=x\n' > .env.local
yarn dev # open the printed URL

Use Dev login with a seeded admin (e.g. facundo@houlak.com). Repeat Part D steps 2–4 with an existing email (e.g. diego@houlak.com). On the fix branch, the Network tab shows 409/400 instead of 500, and terminal A logs no SequelizeUniqueConstraintError. On main you'll see the 500.

The UI still shows the generic "No se pudo crear el empleado." because the page ignores the server's message. Showing it would be a separate frontend improvement.

Clean up: docker rm -f timeoff-pg.


Part H — Stop and clean up​

# terminals 2–4: Ctrl+C (ngrok, core, orchestrator)
cd .local-aws && make reset && make down # purge + stop LocalStack
docker stop alakai-redis
  • Close the fix PR (and delete its branch) unless the Time Off owners want it.
  • To rerun from scratch: make clear key=<channel_id>:<thread_ts> in workers/incident-support.

Troubleshooting​

SymptomLikely causeFix
No 👀Slack Request URL not verified (ngrok restarted?) or bot not in the channelUpdate the Request URLs, /invite the bot, check terminal 3 for Slack app mention routed
"Incident support isn't configured on this Alakai deployment"INCIDENT_STORE_KEY_PREFIX / TASK_TRACKING_REDIS_URL missing in core/.envSet them, restart core
"Incident support isn't configured for this channel"Channel ID not in time-off.slackChannelIdsFix config.json, restart core
make run-latest: "No running investigation found"Prefix mismatch, or core didn't enqueueSame INCIDENT_STORE_KEY_PREFIX everywhere; check terminal 3 for incident.round.enqueued
Worker: No payload found in RedisOrchestrator not running, or REDIS_KEY_PREFIX differsStart terminal 4; match REDIS_KEY_PREFIX
Worker: Failed to post task completion … fetch failedORCHESTRATOR_URL ≠ orchestrator PORThttp://localhost:8080 and PORT=8080
"Investigating…" never replacedSLACK_BOT_TOKEN or INCIDENT_STORE_KEY_PREFIX missing in orchestrator/.envSet both, restart terminal 4
Evidence "not available — access denied"Worker AWS profile can't query /ecs/time-off/prodaws sso login; check AWS_PROFILE in workers/incident-support/.env
Evidence emptyErrors older than the window or not indexed yetTrigger Part D again; wait a minute
Clicking Open fix PR does nothingInteractivity off or wrong Request URLSet …/slack/interactions, save
No Configuración menu in Time OffYour user isn't an admin thereUse an admin account