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 thatemailis a string. Nothing checks whether it's already taken.server/src/services/employeeService.ts:170(createEmployee) callsEmployee.createdirectly.- Postgres rejects it with the unique index
employees_email_unique_when_present(server/migrations/20250208120000-init-schema.js:85), so Sequelize throwsSequelizeUniqueConstraintError. server/src/middleware/errorHandler.tsturns every non-AppErrorinto 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 asjuan.perez@houlak, which fails Sequelize'sisEmailvalidator (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)
- Confirm the target is the sandbox. The fork deploys to ECS service
time-off-prod-serviceon clusterhk-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. - Don't push to the fork's
mainduring the test: every push tomaindeploys. PRs only build. - Don't merge Alakai's fix PR unless you mean to deploy it. Verify it locally instead (Part G).
- 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:
- OAuth & Permissions → Bot Token Scopes:
app_mentions:read,channels:history,chat:write, and addreactions:write. Click Reinstall to Workspace and copy the Bot User OAuth Token (xoxb-…). - Basic Information → Signing Secret: copy it.
- Event Subscriptions: enable. Subscribe to bot events →
app_mention. You'll set the Request URL in Part C, once ngrok is running. - Interactivity & Shortcuts: turn On. You'll set the Request URL in Part C too.
- 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 withC, e.g.C07ABC12345). Use the ID, not the name (#alakai-incident-testwon'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
- 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>andVITE_GOOGLE_CLIENT_IDinapp/.env.local, then runyarn dev:app. In dev mode the login page also has a Dev login box where you can type an admin email.
- If you can't reach a deployed frontend for this API, run the frontend locally against it instead: in the time-off repo, set
- Go to Configuración (Administración → Configuración de balances).
- In Nuevo Houlaker, fill in:
- Nombre
Juan, ApellidoPerez - Email: the email of an employee who already exists (pick one from the list below the form)
- Nombre
- Click Crear. You get "No se pudo crear el empleado." (In the browser devtools Network tab:
POST /api/employees→ 500,{"message":"Unexpected server error"}.) - 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
-
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" -
Within ~3 s: 👀 on your message and "Investigating… (started HH:MM UTC)" in the thread. Terminal 3 logs
incident.round.enqueued; terminal 4 logsWorker launched and message deleted { taskType: 'incident-support', … }. -
Terminal 5:
make run-latestRun 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
| Section | Expected |
|---|---|
| Header | app time-off, env prod, round 1 |
| Summary | 500 on POST /api/employees when the email already exists (unique index), surfaced as a generic error |
| Confidence | high or medium |
| Evidence | SequelizeUniqueConstraintError … 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 cause | server/src/routes/employees.ts#L73 and/or server/src/services/employeeService.ts#L170, links pinned to the checked-out SHA; possibly errorHandler.ts |
| Recent changes | probably 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 steps | duplicate check / format validation returning 4xx |
| Button | Open 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
- Reply in the thread without tagging:
1: yes, people get re-added when they come back from leave. Nothing happens. - Then tag:
@Alakai does editing an existing employee's email to a taken one fail the same way? - 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
-
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>' }. -
Copy that
taskIdintoworkers/implementation/.env(TASK_ID=<id>), then run:cd ../implementation && make run-once -
A few minutes later the thread shows the PR link. On GitHub, check the PR on
Houlak/alakai_sandbox-time-off:- base
main, titlefix: …, labelsai-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
- base
-
Click Open fix PR again: Alakai posts the same PR link and opens nothing new.
make investigation key=…(inworkers/incident-support) showsstatus: "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>inworkers/incident-support.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| No 👀 | Slack Request URL not verified (ngrok restarted?) or bot not in the channel | Update 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/.env | Set them, restart core |
| "Incident support isn't configured for this channel" | Channel ID not in time-off.slackChannelIds | Fix config.json, restart core |
make run-latest: "No running investigation found" | Prefix mismatch, or core didn't enqueue | Same INCIDENT_STORE_KEY_PREFIX everywhere; check terminal 3 for incident.round.enqueued |
Worker: No payload found in Redis | Orchestrator not running, or REDIS_KEY_PREFIX differs | Start terminal 4; match REDIS_KEY_PREFIX |
Worker: Failed to post task completion … fetch failed | ORCHESTRATOR_URL ≠ orchestrator PORT | http://localhost:8080 and PORT=8080 |
| "Investigating…" never replaced | SLACK_BOT_TOKEN or INCIDENT_STORE_KEY_PREFIX missing in orchestrator/.env | Set both, restart terminal 4 |
| Evidence "not available — access denied" | Worker AWS profile can't query /ecs/time-off/prod | aws sso login; check AWS_PROFILE in workers/incident-support/.env |
| Evidence empty | Errors older than the window or not indexed yet | Trigger Part D again; wait a minute |
| Clicking Open fix PR does nothing | Interactivity off or wrong Request URL | Set …/slack/interactions, save |
| No Configuración menu in Time Off | Your user isn't an admin there | Use an admin account |