Repository navigation
Conversation
|
Ready to review this PR? Stage has broken it down into 12 individual chapters for you: Chapters generated by Stage for commit fe33002 on Jun 17, 2026 7:03pm UTC. |
📝 WalkthroughWalkthroughThis pull request adds end-to-end webhook trigger support for automations. New shared types define webhook authentication configuration ( 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 9
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/main/persistence.ts (1)
3984-3989:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAvoid trigger-agnostic deduplication for webhook runs.
Line 3984 deduplicates by
(automationId, scheduledFor)for all triggers. For webhook traffic, two deliveries with the same timestamp can collapse into one run, dropping executions/payloads.Suggested fix
- const existing = (this.state.automationRuns ?? []).find( - (run) => run.automationId === automation.id && run.scheduledFor === scheduledFor - ) + const existing = + trigger === 'scheduled' + ? (this.state.automationRuns ?? []).find( + (run) => + run.automationId === automation.id && + (run.trigger ?? 'scheduled') === 'scheduled' && + run.scheduledFor === scheduledFor + ) + : undefinedsrc/renderer/src/components/automations/AutomationsPage.tsx (1)
1-2: 🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy liftExtract webhook editor logic instead of expanding a max-lines-disabled page.
This page still relies on
eslint-disable max-lines, and the new webhook endpoint/secret/save orchestration adds more responsibility here. Please move the webhook editor state and config-building logic into a focused hook/helper and remove the disable instead of growing this file further.As per coding guidelines, “Never add a
max-linesdisable comment (eslint-disable max-lines,oxlint-disable max-lines, or line-specific variants). Split the file, extract focused modules, move fixtures/builders into named files, or otherwise reduce the counted lines instead.”Also applies to: 454-490, 1385-1418
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c8bcb10f-e0e9-4cff-b0e9-512e7cc7ea2f
📒 Files selected for processing (35)
src/main/automations/service.test.tssrc/main/automations/service.tssrc/main/index.tssrc/main/persistence.test.tssrc/main/persistence.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/rpc/methods/automations.tssrc/main/webhooks/webhook-rate-limiter.test.tssrc/main/webhooks/webhook-rate-limiter.tssrc/main/webhooks/webhook-secret.test.tssrc/main/webhooks/webhook-secret.tssrc/main/webhooks/webhook-server.test.tssrc/main/webhooks/webhook-server.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/components/automations/AutomationEditorDialog.tsxsrc/renderer/src/components/automations/AutomationEditorPromptSection.tsxsrc/renderer/src/components/automations/AutomationSchedulePicker.test.tssrc/renderer/src/components/automations/AutomationWebhookSection.tsxsrc/renderer/src/components/automations/AutomationsPage.tsxsrc/renderer/src/components/settings/AdvancedPane.tsxsrc/renderer/src/components/settings/WebhookServerSetting.tsxsrc/renderer/src/hooks/useAutomationDispatchEvents.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/shared/automation-run-status.tssrc/shared/automation-webhook.test.tssrc/shared/automation-webhook.tssrc/shared/automations-types.tssrc/shared/constants.test.tssrc/shared/constants.tssrc/shared/types.ts
| void webhookServer.apply(store!.getSettings().webhookServer ?? getDefaultWebhookServerSettings()) | ||
| unsubscribeWebhookSettings?.() | ||
| unsubscribeWebhookSettings = store!.onSettingsChanged((updates) => { | ||
| if ('webhookServer' in updates) { | ||
| void webhookServer?.apply( | ||
| store!.getSettings().webhookServer ?? getDefaultWebhookServerSettings() | ||
| ) | ||
| } | ||
| }) |
There was a problem hiding this comment.
Start the webhook listener after dispatch is ready.
Line 1451 can bind and accept POSTs before desktop dispatch is attached in openMainWindow() and before serve-mode headless PTY dispatch is registered. A startup webhook can reach triggerWebhook before there is a ready dispatcher, causing a lost or failed run. Defer the initial apply() and settings subscription until after those readiness points, or gate webhook dispatch until the automation dispatcher is ready.
There was a problem hiding this comment.
Race is real in desktop mode, but deferring apply() misses the window-closed case, and skipped runs still return 202 Accepted. Better: report dispatch availability in the response instead:
// webhook-server.ts, handleRequest — with deps.triggerWebhook typed as Promise<AutomationRun>
const run = await this.deps.triggerWebhook(automationId, delivery)
if (run.status === 'skipped_unavailable' || run.status === 'dispatch_failed') {
res.writeHead(503)
res.end()
return
}
res.writeHead(202)
res.end()There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
cd /repo 2>/dev/null || true
fd -type f service.ts src/main/automations 2>/dev/null
ast-grep run --pattern 'triggerWebhook($$$) {
$$$
}' --lang typescript src/main/automations/service.ts
echo "---dispatch---"
rg -n "dispatch\(" src/main/automations/service.ts | head -30
echo "---status type---"
rg -n "AutomationRunStatus" src/shared/automations-types.ts
echo "---skipped_unavailable---"
rg -n "skipped_unavailable|dispatch_failed" src/shared/automations-types.ts src/main/automations/service.ts
</function_calls>
</invoke>Length of output: 5651
@Viperwow, that's a cleaner fix — it addresses the actual failure mode (nothing ever consumed the delivery) rather than just narrowing the startup window, and it doesn't create the window-closed gap that deferring apply() would.
One thing to line up for this to type-check: WebhookServerDeps.triggerWebhook is currently typed as Promise<unknown> | unknown in src/main/webhooks/webhook-server.ts; it'll need to be narrowed to Promise<AutomationRun> to match AutomationService.triggerWebhook's actual signature so run.status is accessible without a cast.
export type WebhookServerDeps = {
getAutomation(automationId: string): Automation | undefined
triggerWebhook(automationId: string, delivery: AutomationWebhookDelivery): Promise<AutomationRun>
}And in handleRequest, per your snippet:
const run = await this.deps.triggerWebhook(automationId, delivery)
if (run.status === 'skipped_unavailable' || run.status === 'dispatch_failed') {
res.writeHead(503)
res.end()
return
}
res.writeHead(202)
res.end()Worth also handling the case where triggerWebhook throws (e.g., automation not found, webhook not enabled) — that path already falls into the existing catch block and returns 500, but you may want a distinct 404/403 there too if callers need to tell "unknown automation" apart from "server error." Let me know if you'd like me to flag that as a separate follow-up.
🧬 Code Graph Analysis Results
Relevant snippets
src/main/webhooks/webhook-server.ts (lines 87-242)
export class WebhookServer {
// ...
private async handleRequest(req: IncomingMessage, res: ServerResponse): Promise<void> {
try {
if (req.method !== 'POST') {
res.writeHead(405)
res.end()
return
}
const automationId = parseAutomationId(req.url)
if (!automationId) {
res.writeHead(404)
res.end()
return
}
// ...
const automation = this.deps.getAutomation(automationId)
// ...
req.setTimeout(REQUEST_SLOWLORIS_MS, () => req.destroy())
const { body, tooLarge } = await readBodyWithLimit(req)
if (tooLarge) {
res.writeHead(413)
res.end()
return
}
const verification = verifyWebhookSecret({
config: automation.webhook,
headers: req.headers,
rawBody: body
})
if (!verification.ok) {
res.writeHead(401)
res.end()
return
}
const contentType =
typeof req.headers['content-type'] === 'string' ? req.headers['content-type'] : null
const delivery = captureWebhookDelivery({ body, contentType, receivedAt: Date.now() })
await this.deps.triggerWebhook(automationId, delivery)
res.writeHead(202)
res.end()
} catch (err) {
console.error('[webhooks] request handling failed', err)
if (!res.headersSent) {
res.writeHead(500)
}
res.end()
}
}
}Docstring-style summary:
- Function:
handleRequest(req: IncomingMessage, res: ServerResponse): Promise<void> - Behavior: Handles POST webhook requests; validates automation id, webhook enabled/config, rate limits, body size, and webhook secret; captures and forwards the request body as
delivery. - Dispatch call:
await this.deps.triggerWebhook(automationId, delivery) - Response (current behavior in snippet): Always returns
202 AcceptedaftertriggerWebhookresolves, without checking any returnedAutomationRunstatus. - Error handling: On exceptions, logs
[webhooks] request handling failed ...; if headers aren’t already sent, responds with500, thenres.end().
src/main/automations/service.ts (lines 26-185)
export class AutomationService {
// ...
async triggerWebhook(
automationId: string,
delivery: AutomationWebhookDelivery
): Promise<AutomationRun> {
const automation = this.store.listAutomations().find((entry) => entry.id === automationId)
if (!automation) {
throw new Error('Automation not found.')
}
if (!isWebhookTriggerEnabled(automation)) {
throw new Error('Webhook trigger is not enabled for this automation.')
}
const run = this.store.createAutomationRun(automation, Date.now(), 'webhook', delivery)
return await this.requestDispatch(automation, run)
}
async markDispatchResult(result: AutomationDispatchResult): Promise<AutomationRun> {
const run = this.store.updateAutomationRun(result)
if (!isFinalAutomationRunStatus(run.status)) {
return run
}
// ...
}
// ...
}Docstring-style summary:
- Method:
triggerWebhook(automationId: string, delivery: AutomationWebhookDelivery): Promise<AutomationRun> - Validation: Throws if automation id is unknown or webhook trigger is disabled.
- Run creation: Creates an automation run with trigger type
'webhook'and the captureddelivery. - Dispatch: Returns
await this.requestDispatch(automation, run)(the returnedAutomationRunis whatwebhook-server.ts’shandleRequestawaits).
✏️ Learnings added
Learnt from: Viperwow
Repo: stablyai/orca PR: 5617
File: src/main/index.ts:1451-1459
Timestamp: 2026-07-03T10:51:47.843Z
Learning: In `src/main/webhooks/webhook-server.ts`, `WebhookServer.handleRequest` should check the `AutomationRun.status` returned by `deps.triggerWebhook(automationId, delivery)` and return HTTP 503 when the status is `'skipped_unavailable'` or `'dispatch_failed'` (rather than unconditionally returning 202), since `AutomationService.triggerWebhook` (in `src/main/automations/service.ts`) already resolves these statuses synchronously via `requestDispatch` when no dispatcher is ready. Deferring `WebhookServer.apply()` until dispatch is ready was rejected as a fix because it misses the window-closed case in desktop mode. `WebhookServerDeps.triggerWebhook` return type should be `Promise<AutomationRun>`, not `Promise<unknown>`.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
| return { url: null, hint: 'Save the automation to get its webhook URL.' } | ||
| } | ||
| if (!endpoint || !endpoint.running) { | ||
| return { | ||
| url: null, | ||
| hint: 'Enable the webhook receiver in Settings → Automations to get a URL.' | ||
| } |
There was a problem hiding this comment.
Localize resolveWebhookUrl hint strings.
Lines 38-44 and 53-54 use hard-coded English while the rest of the component uses translate(...), so these hints won’t be localized.
Also applies to: 53-54
There was a problem hiding this comment.
Valid — covered by the suggestion in the IPv6 thread above (translate calls with catalog-scheme keys). en.json additions under auto.components.automations.AutomationWebhookSection:
"f817663ae9": "Save the automation to get its webhook URL.",
"3a6c802f95": "Enable the webhook receiver in Settings → Automations to get a URL.",
"6078b095d2": "Replace YOUR-HOST with this machine’s address reachable by the sender.",
"bfbf9f15c9": "Point your provider’s webhook at this URL (POST)."Then pnpm bootstrap:locale-catalog for es/ja/ko/zh.
There was a problem hiding this comment.
@Viperwow, thanks — that approach looks solid. Using catalog-scheme keys (f817663ae9, 3a6c802f95, 6078b095d2, bfbf9f15c9) under auto.components.automations.AutomationWebhookSection in en.json, then running pnpm bootstrap:locale-catalog to propagate to es/ja/ko/zh, will correctly localize the resolveWebhookUrl hints and the YOUR-HOST guidance text. Let me know once it's applied.
✏️ Learnings added
Learnt from: Viperwow
Repo: stablyai/orca PR: 5617
File: src/renderer/src/components/automations/AutomationWebhookSection.tsx:38-44
Timestamp: 2026-07-03T10:49:38.642Z
Learning: In the stablyai/orca repo, English UI strings added to `src/renderer/src/i18n/locales/en.json` follow a catalog-scheme convention: keys are short hashes (e.g., `f817663ae9`) nested under a path mirroring the component's location, such as `auto.components.automations.AutomationWebhookSection`. After adding new English strings, run `pnpm bootstrap:locale-catalog` to propagate/generate corresponding entries for other locales (es/ja/ko/zh).
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
🧠 Learnings used
Learnt from: gsxdsm
Repo: stablyai/orca PR: 5501
File: src/renderer/src/components/right-sidebar/checks-panel-content.tsx:1504-1504
Timestamp: 2026-06-16T15:35:16.815Z
Learning: In the stablyai/orca renderer codebase, Tailwind classes using the custom variant `can-hover` (e.g., `can-hover:opacity-0`) are intentionally treated as self-documenting, with the hover/pointer-only rationale defined once at `src/renderer/src/assets/main.css` via `custom-variant can-hover (media (hover: hover))`. When reviewing `.ts/.tsx` files, do not flag usage sites for missing inline “why” comments or duplicated rationale—assume the variant name and its central definition provide sufficient context.
| const title = 'Webhooks' | ||
| const description = 'Receive inbound webhooks that trigger automations.' |
There was a problem hiding this comment.
Localize section title/description strings.
Lines 47-48 are user-facing hard-coded strings; they should go through translate(...) like the rest of this settings panel.
There was a problem hiding this comment.
Valid (the keywords array stays English — search keywords, consistent with other panes):
| const title = 'Webhooks' | |
| const description = 'Receive inbound webhooks that trigger automations.' | |
| const title = translate('auto.components.settings.WebhookServerSetting.eac8168131', 'Webhooks') | |
| const description = translate( | |
| 'auto.components.settings.WebhookServerSetting.7e6bdce4df', | |
| 'Receive inbound webhooks that trigger automations.' | |
| ) |
en.json under auto.components.settings.WebhookServerSetting:
"eac8168131": "Webhooks",
"7e6bdce4df": "Receive inbound webhooks that trigger automations."Then pnpm bootstrap:locale-catalog for es/ja/ko/zh.
There was a problem hiding this comment.
@Viperwow, thanks for confirming the exact keys and the localization workflow — that looks correct. Once pnpm bootstrap:locale-catalog propagates the eac8168131/7e6bdce4df keys to es/ja/ko/zh, this should be fully localized while keeping the keywords array as plain English search terms.
✏️ Learnings added
Learnt from: Viperwow
Repo: stablyai/orca PR: 5617
File: src/renderer/src/components/settings/WebhookServerSetting.tsx:47-48
Timestamp: 2026-07-03T10:49:36.146Z
Learning: In the stablyai/orca renderer codebase, when localizing user-facing strings in settings components (e.g., `src/renderer/src/components/settings/*.tsx`), use `translate('auto.components.<Dir>.<ComponentFile>.<10-char-hash>', 'Default English text')` with pre-generated hash-based keys added to `en.json` under the `auto.components.<Dir>.<ComponentFile>` namespace, then run `pnpm bootstrap:locale-catalog` to propagate translations to es/ja/ko/zh. Note that `keywords` arrays used for settings search (as in `SearchableSetting`) intentionally remain untranslated/English for consistency with other panes.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
🧠 Learnings used
Learnt from: gsxdsm
Repo: stablyai/orca PR: 5501
File: src/renderer/src/components/right-sidebar/checks-panel-content.tsx:1504-1504
Timestamp: 2026-06-16T15:35:16.815Z
Learning: In the stablyai/orca renderer codebase, Tailwind classes using the custom variant `can-hover` (e.g., `can-hover:opacity-0`) are intentionally treated as self-documenting, with the hover/pointer-only rationale defined once at `src/renderer/src/assets/main.css` via `custom-variant can-hover (media (hover: hover))`. When reviewing `.ts/.tsx` files, do not flag usage sites for missing inline “why” comments or duplicated rationale—assume the variant name and its central definition provide sufficient context.
|
Waiting for it for 2 weeks :) Please, @Ptah-CT, check PR comments. |
|
@brennanb2025 Please check. It unblocks the good pile of functionality for automation. |
|
This receiver would unblock my exact setup, so some real-world demand to report. I run a small agent fleet with a Notion database as the shared task board (Status and Agent properties, connection webhooks on row changes). Today the chain is Notion webhook, a hand-rolled router daemon, then @Ptah-CT the branch is conflicting with main right now, and the last activity was in July. Happy to help rebase and test the receiver on a Linux/systemd runtime as a second pair of hands if you want it moved along, just say the word. |
|
I checked the receiver-to-dispatch boundary at Deferring listener startup until initial renderer readiness would not cover that later window-closed state. The admission result needs to cross the service/HTTP boundary: return a retryable non-success response when dispatch was refused, reserving 202 for an admitted run. A receiver regression should return I also ran the exact |
|
I carried this implementation onto current main in draft #31121, keeping Ptah-CT's original commit in the history. The refresh uses main's durable run writer and current dispatch lanes, and fixes the 202-on-refused-dispatch case discussed above. 391 focused tests, Node/renderer typechecks and scoped lint pass. Rebuilt Electron acceptance also verifies enabling, rebinding and disabling the real receiver through settings. The draft still needs UI proof and does not claim the broader HTTPS/idempotency requirements in #12400. Happy to fold the refresh back here if that is preferable. |
What
Lets incoming webhooks trigger automations. Adds an optional local webhook receiver and a per-automation webhook trigger, so external systems (CI, git hosts, monitors, cron-elsewhere) can kick off an Orca automation by POSTing to it.
Why
Automations could previously only run on a schedule. Many real triggers are event-driven (a push, a deploy, an alert). This adds a first-class, secured inbound path.
What's included
src/main/webhooks/): local HTTP receiver with bind-address control, a per-automation secret (webhook-secret.ts), and a rate limiter (webhook-rate-limiter.ts). Full unit tests.AutomationWebhookSectionto enable a webhook trigger and manage its secret; trigger type surfaced in the prompt/section UI.WebhookServerSettingpane (enable receiver, port, bind address) under Advanced — with a loud warning when binding to0.0.0.0.automation-webhook+automation-run-statusmodels.Security
Testing
pnpm run typecheck✓ELI5
Automations can be started by an incoming HTTP webhook, not only on a schedule. External tools (CI, monitors, other systems) POST to a local webhook receiver to kick off a run.