Worker Pipeline
How the orchestrator chains workers into a multi-step flow, and how to add a step.
The PIPELINE map in orchestrator/src/pipeline.ts is currently empty — every worker
(implementation, bug-hunter, pr-classifier, security-deps, digest, ...) is a terminal step. The mechanism remains as
scaffolding for future multi-step chains (see Adding a step); today, nothing
chains automatically off a worker's completion.
Bug-hunter triggering: core is the single trigger authority
Bug-hunter used to be triggered by an implementation → bug-hunter pipeline transition. That
chain has been removed. Instead, core resolves each repo's configured trigger mode and
enqueues bug-hunter tasks directly from the GitHub pull_request webhook handler
(core/src/interfaces/http/routes/githubWebhooks.ts) — the orchestrator never decides whether to
hunt; it only dispatches whatever core enqueues, exactly like any other worker task.
Trigger modes
Configured per repo under workflows.bugHunter in core/config.json (see
core/config.sample.json), validated by the Zod schema in
core/src/config/repoWorkflowConfig.ts:
| Mode | Behavior |
|---|---|
"off" | Never triggers. Default when the field is absent. |
"alakai-only" | Triggers only for PRs opened by Alakai's implementation worker (pull_request.user.login === githubBotLogin), plus their revisions. |
"always" | Triggers for every eligible PR, human- or Alakai-authored. |
An invalid enum value fails config parsing loudly (fail-fast), so a typo can't silently disable
or mis-trigger hunting. Repos that relied on the old pipeline chain must explicitly set
"alakai-only" to keep the previous behavior.
Trigger conditions
Core enqueues a bug-hunter task when the repo's mode is not "off", the PR title does not
start with docs(prompts): (Alakai's own prompt PRs are never hunted, in any mode), the PR is not
a security PR (head branch starting with alakai/security/, or opened by dependabot[bot] — the
security-deps worker owns those), and the webhook action is one of:
openedwithpull_request.draft === false.ready_for_review(a draft later marked ready — drafts are never hunted before this).synchronize, only when the PR is Alakai-authored (re-hunts Alakai's revisions, e.g. the changes-requested loop). A human push (synchronizeon a non-Alakai PR) is never a trigger.
reopened is never a trigger. In "alakai-only" mode, all of the above additionally require
Alakai authorship; in "always" mode, any author qualifies.
Dedup
Hunting is deduped per commit state via an atomic Redis marker in the shared core/orchestrator
Redis instance: {EXECUTIONS_REDIS_KEY_PREFIX}:bug-hunter:hunted:{repo}:{prNumber}:{headSha},
set with SET NX and a 90-day TTL (core/src/infrastructure/bugHunter/RedisBugHunterDedupStore.ts).
A draft→ready→draft→ready toggle (same head SHA) claims — and hunts — once; a synchronize that
changes the head SHA claims again. If the subsequent enqueue fails, the marker is deleted so a
later event can retry.
Enqueue contract
Core enqueues onto the same SQS queue the orchestrator already consumes for other worker tasks
(SqsBugHunterTaskQueue, using the implementation queue URL), so bug-hunter tasks share one
dispatch/concurrency/retry/DLQ path. The envelope: taskType: "bug-hunter",
payload: { repo, prNumber, source: "github_pr_opened" },
callbacks: { github: { repo, prNumber } }. The enqueue is best-effort and non-blocking —
failures are logged and never fail the webhook response.
PR classifier: terminal worker triggered by core
pr-classifier labels a PR with a risk/merge/size taxonomy and posts a classification comment.
Like bug-hunter, core decides whether to enqueue it from the pull_request webhook handler;
the orchestrator only dispatches it (pr-classifier is in SUPPORTED_TASK_TYPES, uses the same
worker task definition, and WORKER_TYPE is set from the task's taskType). It is a terminal
step: no PIPELINE entry and no follow-up enqueue. On completion the orchestrator only logs
pr-classifier.run.completed / pr-classifier.run.failed (with the classification).
- Triggers:
opened,reopened,ready_for_review;synchronizeonly when the PR already carries arisk:loworrisk:mediumlabel (re-classify; high-risk PRs stay high). Security PRs (head branch starting withalakai/security/, or opened bydependabot[bot]) are never classified. - Config:
prClassifierincore/config.json:apply(on/off switch for the classifier on this application, defaultfalse) andcriticalPaths(path globs that force higher risk; forwarded in the payload). - Taxonomy labels:
risk:*,merge:*,size:*. - Envelope:
taskType: "pr-classifier",payload: { repo, prNumber, source?, criticalPaths },callbacks: { github: { repo, prNumber } }. - Env (worker):
PR_CLASSIFIER_LLM_API_KEY,PR_CLASSIFIER_LLM_MODEL,PR_CLASSIFIER_LLM_PROVIDER(see LLM providers andworkers/.aws/task_definition*.json). - Analytics: recorded as
InteractionType.PrClassification(PR_CLASSIFICATION).
Known v1 limitations: manual risk:*/merge:*/size:* labels are overwritten on re-run; no
comment dedup (each run posts a new comment); no concurrency control for overlapping runs on the
same PR; synchronize does a full re-diff.
Security-deps: terminal worker triggered by a core scheduler
security-deps fixes vulnerable dependencies alongside Dependabot. Unlike bug-hunter and the PR
classifier it is not webhook-driven: core's SecurityDepsScheduler runs a daily, LLM-free
pre-check per enabled application and enqueues a task only when there is work. The orchestrator
only dispatches it (security-deps is in SUPPORTED_TASK_TYPES, uses the same worker task
definition, and WORKER_TYPE is set from the task's taskType). It is a terminal step: no
PIPELINE entry. On completion the orchestrator only logs security-deps.run.completed /
security-deps.run.failed with the outcome per alert group and per Dependabot PR.
- Envelope:
taskType: "security-deps",payload: SecurityDepsPayload(@alakai/shared-types: repo, security branch, alert groups, Dependabot PRs with their action, the open Alakai PR, reviewers, limits),callbacks: { github: { repo } }. - Long runs: a run can take up to 150 minutes, so the orchestrator keeps the stored task for
6 hours (
TASK_TTL_SECONDSinorchestrator/src/redis/redisClient.ts; it was 4 before the security audit). - Analytics: recorded as
InteractionType.SecurityDeps(SECURITY_DEPS), one event per agent run.
Full description: Security dependency updates.
Security-audit: terminal worker with a per-type concurrency cap
security-audit analyzes an application's code for security issues. Like security-deps it is a
terminal step enqueued by a core scheduler (or by @Alakai security-audit in Slack) and has no
PIPELINE entry. Differences that matter to the orchestrator:
- Slack summary: workers have no Slack token, so the orchestrator posts the summary from the
result (
notifySecurityAuditComplete):#cybersecurity(or the requester's thread), silence when nothing new was found unless the run was manual. - Monthly cost counter: on completion the orchestrator adds
estimatedCostUsdof everysecurity-auditandsecurity-depsresult to<REDIS_KEY_PREFIX>:security:cost:<YYYY-MM>. Core reads it before enqueueing an audit (SECURITY_MONTHLY_BUDGET_USD). - Per-type cap:
MAX_CONCURRENT_SECURITY_AUDITS(default 2). An audit received while the cap is reached is pushed to the Redis list{<REDIS_KEY_PREFIX>:security-audit:deferred}and its SQS message is deleted (only after the push succeeds). It is NOT left in SQS: the queue hasmaxReceiveCount: 3, so re-receiving a waiting audit would send it to the DLQ. The reconcile loop and the/task-completehandler launch deferred audits (FIFO) while a global slot and an audit slot are free. The list survives an orchestrator restart (read once at boot). The list and its:processingcompanion share the{…}hash tag so they sit in one Redis Cluster slot: moving an entry between them (LMOVE, the requeue script) is a multi-key command, rejected with CROSSSLOT otherwise. Entries in the old untagged keys are moved to the tagged list at boot and every 10th reconcile tick (an old-code orchestrator can still push there during a rolling deploy), oneLPOPat a time so concurrent instances never duplicate them. - Long runs: a deep audit can run 200 minutes: stored-task TTL is 6 hours.
Full description: Security audit.
How a triggered task reaches a worker
The orchestrator owns a single SQS queue. External producers (core, Slack handlers) drop tasks on it; the orchestrator's consumer reads it and launches the matching worker. Follow-up steps (were any transition configured) would reuse the exact same path.

Why enqueue instead of launching directly?
The orchestrator is the launcher, so enqueueing onto its own queue looks like a detour. It isn't — the queue gives every task (from core, or a future pipeline follow-up) the same properties:
- Backpressure — the consumer only launches when
concurrency.hasAvailableSlot()is true (MAX_CONCURRENT_WORKERS). If slots are full, the message simply waits in the queue. - Durability & retry — if
RunTaskfails or the orchestrator restarts mid-flight, SQS redelivery + the DLQ recover the task. - One launch path — every worker is born the same way, with the same observability and concurrency tracking.
The single source of truth: orchestrator/src/pipeline.ts
The flow is declarative. PIPELINE maps a completed step's taskType to its successor — today,
empty:
const PIPELINE: Record<string, StageTransition | undefined> = {};
Two functions consume it:
nextStage(stored, result)— pure. Returns the nextBackgroundTaskto enqueue, ornullif the step is terminal, unknown, or itsbuildguard didn't pass. No I/O, so it's directly unit-tested. WithPIPELINEempty, every step is terminal today.advancePipeline({ sqs, queueUrl, stored, result })— callsnextStageand, if there's a next step, enqueues it. Best-effort: it never throws, so a failed enqueue is logged but can never break the completing worker's callback.
The callback handler is flow-agnostic — it just calls advancePipeline(...) and knows nothing
about which step follows which.
Structural guarantee
No self-amplification. A step with no PIPELINE entry is terminal. Since the map is
currently empty, no worker completion can ever enqueue another worker through this mechanism —
all cross-worker triggering (today, just bug-hunter) is handled by the producer (core) instead.
Adding a step
Say you want bug-hunter → security-scan → (end). You touch one file, pipeline.ts:
const PIPELINE: Record<string, StageTransition | undefined> = {
'bug-hunter': {
next: 'security-scan',
build: (stored, result) => ({ payload: { /* derive from bug-hunter's stored task/result */ },
callbacks: { ... } }),
},
// 'security-scan' has no entry → new terminal step.
};
Then the usual worker wiring (unchanged by the pipeline refactor):
- Register the type in
SUPPORTED_TASK_TYPES(sqsConsumer.ts) andresolveTaskDefinition(workerLauncher.ts). - Add a
casetonotifier.notifyif the step needs origin notifications. - Add the worker itself under
workers/<name>/and a dispatchcaseinworkers/src/main.ts.
The callback handler and advancePipeline need no changes.
Tests
orchestrator/test/pipeline.test.ts— the transition matrix (purenextStage, currently all terminal) and the enqueue side-effects + no-throw behavior (advancePipeline).core/test/application/bugHunter/resolveBugHunterTrigger.test.ts— the bug-hunter trigger decision matrix (modes × actions × authorship × prompt-PR exclusion).core/test/infrastructure/bugHunter/RedisBugHunterDedupStore.test.ts— the head-SHA dedup marker (claim/release, same-SHA vs. new-SHA).core/test/interfaces/http/githubWebhooksRoute.test.ts— end-to-endpull_requestwebhook coverage for all three modes, draft handling, and dedup.workers/bug-hunter/test/*— the bug-hunter worker lifecycle.
Local note
With ENV=local the orchestrator's WorkerLauncher skips ECS, so an enqueued task is stored but
not auto-launched — run the worker manually (see workers/bug-hunter/README.md).