@automagik/omni 2.260906.3 → 2.260906.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ -- causationId in the persisted event journal (#957, RFC #925 G3 feature half).
2
+ --
3
+ -- `metadata->correlationId` groups a flow (the bag of events); `causation_id`
4
+ -- gives the tree — the id of the IMMEDIATE parent event whose consumption
5
+ -- caused this one to be published. NULL for root events (external ingress
6
+ -- mints a fresh correlation, no parent) and for every pre-existing row
7
+ -- (forward-only: the ~349k historical journal events have no derivable
8
+ -- parent, no backfill). Not an FK — the parent may never have been persisted
9
+ -- or may have been pruned.
10
+ --
11
+ -- The index serves the `omni events trace` descendants walk
12
+ -- (children = rows WHERE causation_id = :id).
13
+ --
14
+ -- Hand-written following the 0055_asc_flow_handoff_mode precedent (additive,
15
+ -- idempotent — the snapshot chain stops at 0026 so drizzle-kit generate is
16
+ -- not usable here). No explicit BEGIN/COMMIT — the boot migrator executes
17
+ -- this file on a pooled postgres-js connection, which rejects raw transaction
18
+ -- control. ADD COLUMN with no default does not rewrite the table.
19
+
20
+ ALTER TABLE "omni_events"
21
+ ADD COLUMN IF NOT EXISTS "causation_id" uuid;
22
+
23
+ CREATE INDEX IF NOT EXISTS "omni_events_causation_idx"
24
+ ON "omni_events" ("causation_id");
@@ -0,0 +1,55 @@
1
+ -- Ingress idempotency (#958, RFC #925 G2).
2
+ --
3
+ -- `WebhooksService.receive()` published a fresh event on every request with
4
+ -- no dedup anywhere on the path, so a provider redelivery (same GitHub
5
+ -- delivery id, 400ms apart) became two events → two automation firings →
6
+ -- duplicate destination rows. The fix: THE DATABASE dedupes via a unique
7
+ -- index, not application logic.
8
+ --
9
+ -- omni_events.idempotency_key text, NULL for internal events without a
10
+ -- derivation (forward-only: the existing rows
11
+ -- have no reliably derivable key and stay
12
+ -- NULL). Webhook ingress claims the key by
13
+ -- inserting the journal row BEFORE publishing;
14
+ -- an ON CONFLICT miss means redelivery — the
15
+ -- emitter is acked (200) and no event exists.
16
+ -- Automation emit_event re-publishes claim
17
+ -- `derived:{parent_event_id}:{automation_id}:{action_index}`.
18
+ --
19
+ -- omni_events.event_type widened 50 → 255: journaled webhook events
20
+ -- are typed `custom.webhook.{source}` and the
21
+ -- source name alone may be 100 chars.
22
+ --
23
+ -- webhook_sources.idempotency_key_template
24
+ -- per-source key derivation template;
25
+ -- existing sources migrate onto the body-hash
26
+ -- default `{source}:{sha256(body)}`.
27
+ -- webhook_sources.total_duplicates
28
+ -- redeliveries acked without a second event.
29
+ --
30
+ -- Index pair follows the additive-tenancy pattern of webhook_sources' name
31
+ -- indexes: a plain global unique (the ON CONFLICT target through the additive
32
+ -- phase) plus a tenant-scoped partial that positions RLS enforcement.
33
+ -- Postgres treats NULLs as distinct, so legacy rows never collide.
34
+ --
35
+ -- Hand-written following the 0052-0055 precedent (snapshot drift keeps
36
+ -- drizzle-kit generate interactive). Additive + idempotent. No explicit
37
+ -- BEGIN/COMMIT — the boot migrator executes this file on a pooled postgres-js
38
+ -- connection, which rejects raw transaction control.
39
+
40
+ ALTER TABLE "omni_events" ADD COLUMN IF NOT EXISTS "idempotency_key" text;
41
+
42
+ ALTER TABLE "omni_events" ALTER COLUMN "event_type" TYPE varchar(255);
43
+
44
+ CREATE UNIQUE INDEX IF NOT EXISTS "omni_events_idempotency_key_uq"
45
+ ON "omni_events" ("idempotency_key");
46
+
47
+ CREATE UNIQUE INDEX IF NOT EXISTS "omni_events_tenant_idempotency_key_uq"
48
+ ON "omni_events" ("tenant_id", "idempotency_key")
49
+ WHERE "tenant_id" IS NOT NULL AND "idempotency_key" IS NOT NULL;
50
+
51
+ ALTER TABLE "webhook_sources"
52
+ ADD COLUMN IF NOT EXISTS "idempotency_key_template" text NOT NULL DEFAULT '{source}:{sha256(body)}';
53
+
54
+ ALTER TABLE "webhook_sources"
55
+ ADD COLUMN IF NOT EXISTS "total_duplicates" integer NOT NULL DEFAULT 0;
@@ -407,6 +407,20 @@
407
407
  "when": 1785700000000,
408
408
  "tag": "0057_connector_lifecycle_contract",
409
409
  "breakpoints": true
410
+ },
411
+ {
412
+ "idx": 58,
413
+ "version": "7",
414
+ "when": 1785800000000,
415
+ "tag": "0058_omni_events_causation_id",
416
+ "breakpoints": true
417
+ },
418
+ {
419
+ "idx": 59,
420
+ "version": "7",
421
+ "when": 1785900000000,
422
+ "tag": "0059_ingress_idempotency",
423
+ "breakpoints": true
410
424
  }
411
425
  ]
412
426
  }
@@ -3,11 +3,25 @@
3
3
  *
4
4
  * omni events list --instance <id>
5
5
  * omni events stream [flags]
6
+ * omni events trace <id>
6
7
  * omni events search <query>
7
8
  * omni events timeline <person-id>
8
9
  */
9
10
  import type { Event } from '@omni/sdk';
10
11
  import { Command } from 'commander';
12
+ /** One journal row as returned inside a trace response. */
13
+ interface TraceEvent {
14
+ id: string;
15
+ eventType: string;
16
+ receivedAt: string;
17
+ causationId: string | null;
18
+ metadata?: {
19
+ correlationId?: string;
20
+ } | null;
21
+ textContent?: string | null;
22
+ }
23
+ /** One human-readable trace line: type, short id, time, correlation. */
24
+ export declare function formatTraceLine(event: TraceEvent, marker: string): string;
11
25
  /** A registered event schema as returned by the API. */
12
26
  interface EventSchemaData {
13
27
  id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/commands/events.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAc,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsMpC,wDAAwD;AACxD,UAAU,eAAe;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,OAAO,EAAE,OAAO,CA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