Repository navigation
Conversation
|
Ready to review this PR? Stage has broken it down into 13 individual chapters for you: Chapters generated by Stage for commit 4d5a8f6 on Jun 17, 2026 7:12pm UTC. |
📝 WalkthroughWalkthroughThis PR adds three capabilities to Orca automations. First, automations can now be triggered by inbound HTTP webhooks: a configurable 🚥 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: 8
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)
4038-4043:⚠️ Potential issue | 🟠 Major | ⚡ Quick winRestrict deduplication to scheduled runs only.
The current lookup deduplicates all triggers by
(automationId, scheduledFor). For webhook/manual bursts, two distinct invocations in the same millisecond can collapse into one run and lose an event payload.Proposed fix
createAutomationRun( automation: Automation, scheduledFor: number, trigger: AutomationRunTrigger = 'scheduled', webhookDelivery: AutomationWebhookDelivery | null = null ): AutomationRun { - const existing = (this.state.automationRuns ?? []).find( - (run) => run.automationId === automation.id && run.scheduledFor === scheduledFor - ) - if (existing) { - return existing - } + if (trigger === 'scheduled') { + const existing = (this.state.automationRuns ?? []).find( + (run) => + run.automationId === automation.id && + run.trigger === 'scheduled' && + run.scheduledFor === scheduledFor + ) + if (existing) { + return existing + } + }src/renderer/src/i18n/locales/en.json (1)
10899-11198:⚠️ Potential issue | 🟡 MinorUse auto-keyed catalog entries instead of literal keys.
The locale strings added to
AutomationEditorDialogHeader,AutomationsPage,AutomationProjectCombobox,AutomationAgentConfigSection, andAutomationTemplateSaveDialoguse literal keys (editTemplate,deleteTemplate,search,configure,label, etc.) instead of SHA1 auto-keys. These should be generated viapnpm run sync:localization-catalogto maintain catalog consistency.Source: Learnings
🧹 Nitpick comments (3)
src/main/persistence.test.ts (1)
1256-1280: ⚡ Quick winAssert webhook delivery survives disk round-trip, not just in-memory state.
This test currently validates immediate return data only. Add
store.flush()+ reload assertions so it catches serialization regressions inautomationRuns.src/shared/automation-webhook.test.ts (1)
1-9: ⚡ Quick winAdd a focused test for content-type truncation.
captureWebhookDeliverycapscontentType, but this suite currently only asserts body truncation. A small test here will lock in that limit behavior.Suggested diff
import { captureWebhookDelivery, composeAutomationDispatchPrompt, isWebhookTriggerEnabled, MAX_WEBHOOK_BODY_CHARS, + MAX_WEBHOOK_CONTENT_TYPE_CHARS, normalizeAutomationWebhookConfig } from './automation-webhook' @@ it('truncates and flags oversize bodies', () => { const big = 'x'.repeat(MAX_WEBHOOK_BODY_CHARS + 100) const d = captureWebhookDelivery({ body: big, contentType: null, receivedAt: 1 }) expect(d.truncated).toBe(true) expect(d.body.length).toBe(MAX_WEBHOOK_BODY_CHARS) }) + + it('truncates oversized content-type headers', () => { + const longType = 'a'.repeat(MAX_WEBHOOK_CONTENT_TYPE_CHARS + 32) + const d = captureWebhookDelivery({ body: '{}', contentType: longType, receivedAt: 1 }) + expect(d.contentType).toHaveLength(MAX_WEBHOOK_CONTENT_TYPE_CHARS) + }) })Also applies to: 59-80
src/renderer/src/components/automations/automation-agent-config-draft.ts (1)
52-54: ⚡ Quick winReturn a fresh
agentEnvarray in the null-config branch.Line 53 uses a shallow spread of
EMPTY_AGENT_CONFIG_DRAFT_FIELDS, soagentEnvreuses the same array reference. Returning a new array avoids accidental cross-draft mutation if any caller mutates in place.Suggested patch
export function agentConfigToDraftFields( config: AutomationAgentConfig | null | undefined ): AgentConfigDraftFields { if (!config) { - return { ...EMPTY_AGENT_CONFIG_DRAFT_FIELDS } + return { ...EMPTY_AGENT_CONFIG_DRAFT_FIELDS, agentEnv: [] } } return {
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 9e1777a9-00cb-424d-ad80-768694c3f226
📒 Files selected for processing (55)
src/main/automations/service.test.tssrc/main/automations/service.tssrc/main/index.tssrc/main/ipc/automations.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/AutomationAgentConfigSection.tsxsrc/renderer/src/components/automations/AutomationEditorDialog.tsxsrc/renderer/src/components/automations/AutomationEditorDialogFooter.tsxsrc/renderer/src/components/automations/AutomationEditorDialogHeader.tsxsrc/renderer/src/components/automations/AutomationEditorPromptSection.tsxsrc/renderer/src/components/automations/AutomationSchedulePicker.test.tssrc/renderer/src/components/automations/AutomationTemplateSaveDialog.tsxsrc/renderer/src/components/automations/AutomationWebhookSection.tsxsrc/renderer/src/components/automations/AutomationsPage.tsxsrc/renderer/src/components/automations/automation-agent-config-draft.test.tssrc/renderer/src/components/automations/automation-agent-config-draft.tssrc/renderer/src/components/automations/automation-user-template-draft.test.tssrc/renderer/src/components/automations/automation-user-template-draft.tssrc/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/renderer/src/lib/launch-agent-background-session.tssrc/shared/automation-agent-config.test.tssrc/shared/automation-agent-config.tssrc/shared/automation-agent-launch.test.tssrc/shared/automation-agent-launch.tssrc/shared/automation-run-status.tssrc/shared/automation-user-templates.test.tssrc/shared/automation-user-templates.tssrc/shared/automation-webhook.test.tssrc/shared/automation-webhook.tssrc/shared/automations-types.tssrc/shared/constants.test.tssrc/shared/constants.tssrc/shared/external-automations-types.tssrc/shared/tui-agent-launch-defaults.tssrc/shared/tui-agent-models.test.tssrc/shared/tui-agent-models.tssrc/shared/types.ts
| if (!isWebhookTriggerEnabled(automation)) { | ||
| throw new Error('Webhook trigger is not enabled for this automation.') | ||
| } | ||
| const run = this.store.createAutomationRun(automation, Date.now(), 'webhook', delivery) |
There was a problem hiding this comment.
Respect disabled automations before accepting webhook triggers.
triggerWebhook() only checks automation.webhook.enabled, so an automation with enabled: false and a still-enabled webhook can still create and dispatch runs. Scheduled runs already honor automation.enabled; webhook triggers should use the same kill switch for external invocations.
Proposed fix
- if (!isWebhookTriggerEnabled(automation)) {
+ if (!automation.enabled) {
+ throw new Error('Automation is disabled.')
+ }
+ if (!isWebhookTriggerEnabled(automation)) {
throw new Error('Webhook trigger is not enabled for this automation.')
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (!isWebhookTriggerEnabled(automation)) { | |
| throw new Error('Webhook trigger is not enabled for this automation.') | |
| } | |
| const run = this.store.createAutomationRun(automation, Date.now(), 'webhook', delivery) | |
| if (!automation.enabled) { | |
| throw new Error('Automation is disabled.') | |
| } | |
| if (!isWebhookTriggerEnabled(automation)) { | |
| throw new Error('Webhook trigger is not enabled for this automation.') | |
| } | |
| const run = this.store.createAutomationRun(automation, Date.now(), 'webhook', delivery) |
| const AutomationWebhook = z | ||
| .object({ | ||
| enabled: z.boolean(), | ||
| secretMode: z.enum(['none', 'token', 'hmac_sha256']), | ||
| secret: z.union([z.string(), z.null()]) | ||
| }) | ||
| .nullable() | ||
| .optional() |
There was a problem hiding this comment.
Enforce non-empty secrets for authenticated webhook modes.
AutomationWebhook currently accepts secret: '' for token / hmac_sha256. That makes webhook auth trivially guessable. Add a cross-field check requiring a non-empty secret when authenticated modes are used.
Suggested fix
const AutomationWebhook = z
.object({
enabled: z.boolean(),
secretMode: z.enum(['none', 'token', 'hmac_sha256']),
secret: z.union([z.string(), z.null()])
})
+ .superRefine((value, ctx) => {
+ if (
+ value.enabled &&
+ value.secretMode !== 'none' &&
+ (value.secret === null || value.secret.trim().length === 0)
+ ) {
+ ctx.addIssue({
+ code: 'custom',
+ path: ['secret'],
+ message: 'Missing webhook secret for authenticated mode'
+ })
+ }
+ })
.nullable()
.optional()| scheduleWarning: | ||
| schedule || hasCustomSchedule | ||
| ? null | ||
| : 'This automation has an unsupported saved schedule. Pick a supported schedule before saving changes.' | ||
| : 'This automation has an unsupported saved schedule. Pick a supported schedule before saving changes.', | ||
| webhookEnabled: latest.webhook?.enabled ?? false, | ||
| webhookSecretMode: latest.webhook?.secretMode ?? 'none', | ||
| webhookSecret: latest.webhook?.secret ?? '', | ||
| ...agentConfigToDraftFields(latest.agentConfig) |
There was a problem hiding this comment.
Localize scheduleWarning strings instead of hardcoding English
The newly assigned warning messages are hardcoded and can leak untranslated copy in non-English flows. Use translate(...) for both assignments.
Suggested patch
- scheduleWarning:
- schedule || hasCustomSchedule
- ? null
- : 'This automation has an unsupported saved schedule. Pick a supported schedule before saving changes.',
+ scheduleWarning:
+ schedule || hasCustomSchedule
+ ? null
+ : translate(
+ 'auto.components.automations.AutomationsPage.unsupportedSavedSchedule',
+ 'This automation has an unsupported saved schedule. Pick a supported schedule before saving changes.'
+ ),
...
- scheduleWarning: hasCustomSchedule
- ? null
- : 'This Hermes automation has an unsupported saved schedule. Pick a supported schedule before saving changes.',
+ scheduleWarning: hasCustomSchedule
+ ? null
+ : translate(
+ 'auto.components.automations.AutomationsPage.unsupportedHermesSavedSchedule',
+ 'This Hermes automation has an unsupported saved schedule. Pick a supported schedule before saving changes.'
+ ),Also applies to: 1251-1254
| if (!automationId) { | ||
| 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.' | ||
| } | ||
| } | ||
| // Why: a 0.0.0.0 bind has no usable host in a URL; show a placeholder the | ||
| // user replaces with the machine's reachable address/hostname. | ||
| const host = endpoint.bindAddress === '0.0.0.0' ? 'YOUR-HOST' : endpoint.bindAddress | ||
| return { | ||
| url: `http://${host}:${endpoint.port}/webhook/${automationId}`, | ||
| hint: | ||
| endpoint.bindAddress === '0.0.0.0' | ||
| ? 'Replace YOUR-HOST with this machine’s address reachable by the sender.' | ||
| : 'Point your provider’s webhook at this URL (POST).' | ||
| } |
There was a problem hiding this comment.
Localize webhook readiness hints shown to users.
Line 38, Line 43, Line 53, and Line 54 return user-visible English strings directly. These bypass translations while the rest of this component is localized, so non-English users will see mixed-language UI.
Proposed fix
function resolveWebhookUrl(
endpoint: WebhookServerEndpoint | null,
automationId: string | null
): { url: string | null; hint: string } {
if (!automationId) {
- return { url: null, hint: 'Save the automation to get its webhook URL.' }
+ return {
+ url: null,
+ hint: translate(
+ 'auto.components.automations.AutomationWebhookSection.webhookUrlNeedsSave',
+ '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.'
+ hint: translate(
+ 'auto.components.automations.AutomationWebhookSection.webhookUrlNeedsReceiver',
+ 'Enable the webhook receiver in Settings → Automations to get a URL.'
+ )
}
}
@@
return {
url: `http://${host}:${endpoint.port}/webhook/${automationId}`,
hint:
endpoint.bindAddress === '0.0.0.0'
- ? 'Replace YOUR-HOST with this machine’s address reachable by the sender.'
- : 'Point your provider’s webhook at this URL (POST).'
+ ? translate(
+ 'auto.components.automations.AutomationWebhookSection.webhookUrlReplaceHost',
+ 'Replace YOUR-HOST with this machine’s address reachable by the sender.'
+ )
+ : translate(
+ 'auto.components.automations.AutomationWebhookSection.webhookUrlReady',
+ 'Point your provider’s webhook at this URL (POST).'
+ )
}
}| {!showSecret && | ||
| webhookEndpoint?.running && | ||
| webhookEndpoint.bindAddress !== '127.0.0.1' ? ( | ||
| <p className="text-xs text-destructive"> |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify the bindAddress domain and where it is validated/normalized.
# Expected: either only 127.0.0.1/0.0.0.0 are permitted, or this UI check should be broadened.
fd -i 'WebhookServerSetting.tsx'
fd -i 'types.ts'
fd -i 'automations-types.ts'
fd -i 'webhook-server.ts'
fd -i 'persistence.ts'
rg -n -C3 "bindAddress|WebhookServerSettings|WebhookServerEndpoint|normalizeWebhookServerSettings|127\\.0\\.0\\.1|0\\.0\\.0\\.0|::1|localhost" srcRepository: stablyai/orca
Length of output: 50370
🏁 Script executed:
# Get the exact code at lines 197-200 and surrounding context in AutomationWebhookSection.tsx
find src/renderer/src/components/automations -name 'AutomationWebhookSection.tsx' -exec wc -l {} \;
head -210 src/renderer/src/components/automations/AutomationWebhookSection.tsx | tail -30Repository: stablyai/orca
Length of output: 1322
🏁 Script executed:
# Check the WebhookServerSetting component for any validation on bindAddress input
cat src/renderer/src/components/settings/WebhookServerSetting.tsxRepository: stablyai/orca
Length of output: 5647
Broaden loopback detection to include localhost and IPv6 loopback.
The warning at lines 197–200 only checks bindAddress !== '127.0.0.1' and treats all other addresses as non-local, but the settings UI accepts any free-form string (including localhost and ::1, which are valid loopback addresses). The normalization function does not convert these to 127.0.0.1, so the warning will incorrectly fire for legitimate local-only bindings. Either:
- Validate/normalize
localhostand::1to127.0.0.1before the warning check, or - Extend the check to recognize all loopback patterns (e.g.,
^(localhost|127\.|::1)$).
| const title = 'Webhooks' | ||
| const description = 'Receive inbound webhooks that trigger automations.' | ||
|
|
||
| return ( | ||
| <section className="space-y-3"> | ||
| <SettingsSubsectionHeader title={title} description={description} /> | ||
| <SearchableSetting | ||
| title={title} | ||
| description={description} | ||
| keywords={['webhook', 'automation', 'trigger', 'http', 'receiver']} |
There was a problem hiding this comment.
Translate the section header copy for locale consistency
title and description are hardcoded while adjacent UI strings use translate(...). Localize these two constants as well.
Suggested patch
- const title = 'Webhooks'
- const description = 'Receive inbound webhooks that trigger automations.'
+ const title = translate('auto.components.settings.WebhookServerSetting.sectionTitle', 'Webhooks')
+ const description = translate(
+ 'auto.components.settings.WebhookServerSetting.sectionDescription',
+ 'Receive inbound webhooks that trigger automations.'
+ )📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const title = 'Webhooks' | |
| const description = 'Receive inbound webhooks that trigger automations.' | |
| return ( | |
| <section className="space-y-3"> | |
| <SettingsSubsectionHeader title={title} description={description} /> | |
| <SearchableSetting | |
| title={title} | |
| description={description} | |
| keywords={['webhook', 'automation', 'trigger', 'http', 'receiver']} | |
| const title = translate('auto.components.settings.WebhookServerSetting.sectionTitle', 'Webhooks') | |
| const description = translate( | |
| 'auto.components.settings.WebhookServerSetting.sectionDescription', | |
| 'Receive inbound webhooks that trigger automations.' | |
| ) | |
| return ( | |
| <section className="space-y-3"> | |
| <SettingsSubsectionHeader title={title} description={description} /> | |
| <SearchableSetting | |
| title={title} | |
| description={description} | |
| keywords={['webhook', 'automation', 'trigger', 'http', 'receiver']} |
| if (typeof record.id !== 'string' || !record.id) { | ||
| return null |
There was a problem hiding this comment.
Reject whitespace-only template IDs in normalization.
Line 66 currently accepts IDs like ' '. Since this function is the load-time structural gate, treat trimmed-empty IDs as invalid to avoid persisting unusable identifiers.
💡 Proposed fix
- if (typeof record.id !== 'string' || !record.id) {
+ if (typeof record.id !== 'string' || record.id.trim().length === 0) {
return null
}
+ const id = record.id.trim()
const createdAt = typeof record.createdAt === 'number' ? record.createdAt : 0
return buildUserAutomationTemplate(
@@
{
- id: record.id,
+ id,
createdAt,
now: typeof record.updatedAt === 'number' ? record.updatedAt : createdAt
}
)| const trimmedModel = (model ?? '').trim() | ||
| if (!trimmedModel) { | ||
| return args | ||
| } | ||
| const info = getAgentModelInfo(agent) | ||
| if (!info) { | ||
| return args | ||
| } | ||
| if (argContainsFlag(args, info.flag)) { | ||
| return args | ||
| } | ||
| const base = args.trim() | ||
| const suffix = `${info.flag} ${trimmedModel}` | ||
| return base ? `${base} ${suffix}` : suffix |
There was a problem hiding this comment.
Prevent model text from becoming extra CLI arguments.
At Line 60, trimmedModel is concatenated raw; whitespace in model input (for example, opus --foo) is treated as additional flags. Model should be constrained to a single token before appending.
Suggested patch
export function applyAgentModelToArgs(
agent: TuiAgent,
args: string,
model: string | null | undefined
): string {
const trimmedModel = (model ?? '').trim()
if (!trimmedModel) {
return args
}
+ if (/\s/.test(trimmedModel)) {
+ return args
+ }
const info = getAgentModelInfo(agent)
if (!info) {
return args
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const trimmedModel = (model ?? '').trim() | |
| if (!trimmedModel) { | |
| return args | |
| } | |
| const info = getAgentModelInfo(agent) | |
| if (!info) { | |
| return args | |
| } | |
| if (argContainsFlag(args, info.flag)) { | |
| return args | |
| } | |
| const base = args.trim() | |
| const suffix = `${info.flag} ${trimmedModel}` | |
| return base ? `${base} ${suffix}` : suffix | |
| export function applyAgentModelToArgs( | |
| agent: TuiAgent, | |
| args: string, | |
| model: string | null | undefined | |
| ): string { | |
| const trimmedModel = (model ?? '').trim() | |
| if (!trimmedModel) { | |
| return args | |
| } | |
| if (/\s/.test(trimmedModel)) { | |
| return args | |
| } | |
| const info = getAgentModelInfo(agent) | |
| if (!info) { | |
| return args | |
| } | |
| if (argContainsFlag(args, info.flag)) { | |
| return args | |
| } | |
| const base = args.trim() | |
| const suffix = `${info.flag} ${trimmedModel}` | |
| return base ? `${base} ${suffix}` : suffix | |
| } |
What
Makes automations configurable per agent and adds reusable user templates:
AutomationAgentConfigSection, sharedautomation-agent-config+automation-agent-launch+tui-agent-models).AutomationTemplateSaveDialog, sharedautomation-user-templates,automation-user-template-draft).external-automations-typesto cleanly separate third-party-owned (Hermes/OpenClaw) automation jobs from Orca-owned ones.Why
Different automations want different models/args/env, and teams re-create similar automations repeatedly. Agent config + user templates remove that friction.
Testing
pnpm run typecheck✓ (exit 0)This is stacked on #5617 (webhook triggers) — it builds on the automations type/UI refactor introduced there. Please review/merge after #5617; until then this PR's diff will also show the webhook changes. Once #5617 merges into
main, this diff narrows to just the agent-config + templates work.ELI5
Automations can now pick per-agent model, extra launch args, and env vars. You can also save an automation’s setup as a reusable template and apply it when creating new ones.