Commit Graph
6480 Commits
Author SHA1 Message Date
Tanmay Deep Sharma 89df93e1dd Merge feature/cw-7513 into feature/cw-7513-specs 2026-07-20 11:42:48 +05:30
Tanmay Deep Sharma 0e54bd17e5 fix(automations): reset delayed condition to a supported attribute per event 2026-07-20 11:42:40 +05:30
Tanmay Deep Sharma ee3600be46 Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-20 11:28:50 +05:30
Tanmay Deep Sharma 6830c3273f feat(automations): show what ends the wait in the builder
Make the wait's interrupt explicit (as Intercom does) so users can predict when the
rule runs. An "Ends the wait if …" line adapts to the rule's episode: status change
for conversation rules, customer reply for outgoing message rules, agent reply for
incoming ones — plus "or the conditions no longer match" universally. Behaviour is
unchanged; this only surfaces it.
2026-07-20 11:28:41 +05:30
Tanmay Deep Sharma 9530cca197 Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-20 11:22:22 +05:30
Tanmay Deep Sharma 2c728341e0 refactor(automations): rename "Delayed execution" to "Wait" in the builder
Adopt the simpler Wait concept (as Intercom et al. use): the toggle is labelled
"Wait", the duration reads "Wait for [4] [Hours]", and the block moves to just
before Actions (it applies to the whole rule; if we add ordered steps later it can
become a proper Wait action). The "Runs after 4h" list badge is unchanged, and the
engineering layer (execution_delay column, delayed_automations flag) keeps its name.
2026-07-20 11:22:12 +05:30
Tanmay Deep Sharma 1f713d6dae Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 23:26:53 +05:30
Tanmay Deep Sharma 2b8d1a67b3 fix(automations): preserve actions when a delay resets invalid conditions
Enabling a delay on a rule with delay-unsafe conditions called onEventChange, which
resets conditions AND actions to defaults, silently replacing the user's configured
actions with assign_agent. Reset only the conditions (getDefaultConditions) and leave
the actions intact.
2026-07-15 23:26:44 +05:30
Tanmay Deep Sharma f62b5e51d9 test(automations): claim due_at guard, paused-row resume, factory episode key
- process-job specs make rows due before running (the sweep only enqueues due rows).
- claim! guard: a row pushed into the future isn't claimed.
- reschedule_paused resets overdue rows; re-enabling the account flag enqueues the
  resume job.
- factory derives a current episode key so rows are episode_current.
2026-07-15 23:14:32 +05:30
Tanmay Deep Sharma 9488b7d005 Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 23:11:09 +05:30
Tanmay Deep Sharma f4e0481b00 fix(automations): dont fire rescheduled rows early; resume paused rows past expiry
- claimable? now requires the row to still be due, so a reply-chase reschedule that
  pushes due_at forward after the sweep enqueued the row no longer fires early.
- Re-enabling delayed_automations on an account reschedules its overdue pending rows
  (past DUE_WINDOW) via a job enqueued ahead of the next sweep, so a pause longer than
  the expiry window resumes those rows instead of expiring them.
2026-07-15 23:10:55 +05:30
Tanmay Deep Sharma b355443642 test(automations): delayed conversation_created rule is valid 2026-07-15 20:15:02 +05:30
Tanmay Deep Sharma 12a53d5a1e Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 20:14:34 +05:30
Tanmay Deep Sharma 67dbcca638 fix(automations): keep all events available for delayed rules
Event-narrowing wrongly hid valid delayed triggers like conversation_created
(new conversation idle 10m -> assign), forcing the event to conversation_updated.
The real guardrail is the Status/Inbox condition narrowing, which stays; the event
list no longer needs restricting since every event supports a delayed rule with
the right conditions.
2026-07-15 20:14:26 +05:30
Tanmay Deep Sharma 8097e329d0 test(automations): delayed conversation rule allows status+inbox, rejects mutable attrs 2026-07-15 18:56:59 +05:30
Tanmay Deep Sharma 8df903b008 Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 18:56:26 +05:30
Tanmay Deep Sharma 1957cd15dc feat(automations): allow inbox filter on delayed conversation rules
inbox_id never changes after a conversation is created, so filtering a delayed
conversation-level rule by inbox is safe: the status episode key still tracks the
only mutable dimension, and inbox rides along as a static fire-time re-check. Allow
status + inbox_id in the validation and the narrowed condition dropdown.
2026-07-15 18:56:15 +05:30
Tanmay Deep Sharma abaf4d9ccb Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 18:42:13 +05:30
Tanmay Deep Sharma 88d3876c2b chore(automations): remove unused IMMEDIATELY i18n string 2026-07-15 18:42:10 +05:30
Tanmay Deep Sharma 55e7cafbac Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 18:41:30 +05:30
Tanmay Deep Sharma 29eecfafcb chore(automations): label the delay toggle 'Delayed execution' 2026-07-15 18:41:21 +05:30
Tanmay Deep Sharma 1fafa7d13d Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 18:36:09 +05:30
Tanmay Deep Sharma dd2f3d80cc feat(automations): narrow condition options for delayed rules instead of warning
When a delay is on, the condition attribute dropdown for conversation-level events
offers only Status, and attribute_changed is dropped from the operator list for any
delayed rule. Toggling the delay on resets conditions the delayed rule can't use.
This makes unsupported delayed rules unconstructable, so the inline restriction
warning (and its i18n strings) are removed.
2026-07-15 18:35:55 +05:30
Tanmay Deep Sharma 852a219e0b feat(automations): narrow condition options for delayed rules instead of warning
When a delay is on, the condition attribute dropdown for conversation-level events
offers only Status, and attribute_changed is dropped from the operator list for any
delayed rule. Toggling the delay on resets conditions the delayed rule can't use.
This makes unsupported delayed rules unconstructable, so the inline restriction
warning (and its i18n strings) are removed.
2026-07-15 18:35:11 +05:30
Tanmay Deep Sharma be381b940d Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 18:12:30 +05:30
Tanmay Deep Sharma 3728d71176 feat(automations): make delayed execution a toggle that narrows the event list
Delayed execution is now a toggle chosen first (above Event). Turning it on limits
the Event dropdown to the events where a delayed rule is meaningful (Conversation
Updated for status waits, Message Created for awaiting-agent/reply-chase) and snaps
an unsupported event to a supported one, so users can't build a delayed rule on an
event the engine can't handle.
2026-07-15 18:12:21 +05:30
Tanmay Deep Sharma 9660b48c27 test(automations): sweep excludes rows for accounts with delayed automations disabled 2026-07-15 16:45:12 +05:30
Tanmay Deep Sharma a44645a7de Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 16:44:10 +05:30
Tanmay Deep Sharma 1e57cff70a fix(automations): exclude paused accounts from the sweep so they can't starve others
Now that a flag-off account's due rows stay pending (paused), order(:due_at).limit
would keep re-selecting that backlog every sweep, starving enabled accounts with
later due_at. Filter the sweep to accounts with delayed_automations enabled via a
for_enabled_accounts scope, so paused rows sit out of the limit until re-enabled.
2026-07-15 16:44:01 +05:30
Tanmay Deep Sharma 4c398b3c85 test(automations): account flag off pauses the row and resumes on re-enable 2026-07-15 16:19:31 +05:30
Tanmay Deep Sharma a521175422 Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 16:19:03 +05:30
Tanmay Deep Sharma a921a38db9 fix(automations): pause (not skip) armed rows when the account flag is off
Marking a due row skipped/flag_disabled was terminal, so re-enabling the account
flag could never resume it (sweepable only sees pending/processing) — the delayed
action was lost, contradicting the banner that says rules resume when re-enabled.
Check the flag before claiming and return, leaving the row pending like the
instance kill switch does, so it fires once the feature is turned back on.
2026-07-15 16:18:55 +05:30
Tanmay Deep Sharma 7c5d6f8d72 Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 15:59:23 +05:30
Tanmay Deep Sharma 7bb90d84cd fix(automations): hydrate delay controls from the edited rule on first open
The edit dialog's delay radios/value were synced once in open() from the automation
model, whose prop only settles a tick later — so the first edit click showed the
previous rule's delay (or immediate). Thread the clicked rule's execution_delay
directly into open() so the delay controls hydrate correctly on the first click.
2026-07-15 15:59:11 +05:30
Tanmay Deep Sharma 466763054c Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 15:31:04 +05:30
Tanmay Deep Sharma 21ea2ae08d revert(search): drop unnecessary reindex_for_search guard; trim automation_rule comments
The guard was dead code: should_index? is only true when searchkick is loaded
(both gated on advanced_search_allowed?), so #reindex is always defined when the
callback fires. It only masked a flaky develop-owned message_spec and contradicts
the fail-loudly-on-impossible-state guideline. Also trim verbose comments in
automation_rule.rb.
2026-07-15 15:30:46 +05:30
Tanmay Deep Sharma fd91ab84af test(automations): status episode keys use microsecond stamp and survive DB reload 2026-07-15 14:59:23 +05:30
Tanmay Deep Sharma e6ae59b8b2 Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 14:58:49 +05:30
Tanmay Deep Sharma 35f14c7e02 fix(automations): use microsecond-integer stamp for status episode keys too
Same float64 imprecision as the awaiting-agent key: a status episode armed from an
in-memory status_changed_at (Time.current, nanosecond) could recompute to a slightly
different float once the worker reloads the DB-rounded value, skipping the row as
episode_moved. Use the shared microsecond_stamp helper so both sides agree.
2026-07-15 14:58:39 +05:30
Tanmay Deep Sharma e2c449a0c2 Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 14:50:52 +05:30
Tanmay Deep Sharma 40b77ca001 fix(search): guard reindex_for_search when searchkick is not loaded
searchkick (which defines #reindex) is only mixed into Message at class-load time
when advanced_search_allowed? (enterprise + OPENSEARCH_URL) is true at boot. A spec
that stubs advanced_search_allowed? true without a loaded index makes should_index?
true and fires the reindex callback, raising NoMethodError. Guard on respond_to?
so it no-ops when no index is available (real deployments without search index
already have should_index? false, so behavior is unchanged).
2026-07-15 14:50:39 +05:30
Tanmay Deep Sharma 40e529fe4d test(automations): fix awaiting-agent key format and tighten job assertions
- Match the microsecond-integer (strftime %s%6N) awaiting-agent key format,
  fixing the CI failure from float epoch imprecision.
- Assert exactly one ProcessPendingExecutionJob is enqueued and the future row
  is not, so an early-fire regression is caught.
- Count the reply-chase follow-up as exactly one so a double-send regression fails.
- Stub the ActionService instance's perform (not new) to raise, exercising the
  job's error/retry path rather than only constructor failures.
2026-07-15 14:42:59 +05:30
Tanmay Deep Sharma d7b25d7db0 Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 14:40:12 +05:30
Tanmay Deep Sharma e2cd372d2d fix(automations): use microsecond-integer stamp for awaiting-agent keys
Float epoch seconds carry ~16 significant digits, exceeding float64 precision,
and the arm path compares an in-memory created_at against the DB-stored
waiting_since. A float rounds differently on each side, so the armed key never
matched at fire time and the awaiting-agent automation was always skipped.
Use strftime('%s%6N') (integer microseconds) on both paths.
2026-07-15 14:40:05 +05:30
Tanmay Deep Sharma 17da6ee3ec test(automations): clone strips execution_delay when feature is disabled 2026-07-15 14:16:54 +05:30
Tanmay Deep Sharma b81f916002 Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 14:16:20 +05:30
Tanmay Deep Sharma a1fdba2783 fix(automations): strip execution_delay when cloning a rule with the feature off
clone duplicates the rule via dup (including execution_delay) with no param for
ensure_execution_delay_allowed to inspect, so it could create new delayed rules
while the feature is disabled. Drop the delay on the clone unless the account has
delayed_automations enabled, matching create/update.
2026-07-15 14:16:10 +05:30
Tanmay Deep Sharma dea4d47602 test(automations): sub-second awaiting-agent keys and stale processing discard 2026-07-15 13:27:43 +05:30
Tanmay Deep Sharma 2728a90a2f Merge branch 'feature/cw-7513' into feature/cw-7513-specs 2026-07-15 13:26:50 +05:30
Tanmay Deep Sharma d55c5660a3 fix(automations): sub-second awaiting-agent keys and discard stale processing rows on edit
- awaiting_agent episode keys use sub-second (.to_f) precision like status keys,
  so a reply then re-wait within the same second is a distinct episode and the
  original armed row no longer matches the later waiting period.
- discard_stale_pending_executions now deletes armed rows (pending and stale
  processing), since the sweep reclaims stale processing rows and would otherwise
  fire them against the edited rule definition.
2026-07-15 13:26:37 +05:30