okengine 0.19.0 → 0.19.1

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.
Files changed (74) hide show
  1. package/package.json +1 -1
  2. package/site/content/docs/ai/meta.json +1 -1
  3. package/site/content/docs/ai/skills.mdx +1 -1
  4. package/site/content/docs/client/index.mdx +1 -2
  5. package/site/content/docs/elements/ai/agents.mdx +5 -2
  6. package/site/content/docs/elements/ai/index.mdx +4 -3
  7. package/site/content/docs/elements/ai/prompts.mdx +3 -2
  8. package/site/content/docs/elements/channel/email.mdx +5 -2
  9. package/site/content/docs/elements/channel/index.mdx +1 -1
  10. package/site/content/docs/elements/clock/index.mdx +3 -2
  11. package/site/content/docs/elements/clock/sleep.mdx +10 -7
  12. package/site/content/docs/elements/flow/index.mdx +3 -3
  13. package/site/content/docs/elements/flow/routing.mdx +1 -1
  14. package/site/content/docs/elements/gate/tenancy.mdx +5 -2
  15. package/site/content/docs/elements/signal/broadcast.mdx +6 -4
  16. package/site/content/docs/elements/signal/index.mdx +1 -1
  17. package/site/content/docs/elements/signal/live.mdx +3 -2
  18. package/site/content/docs/elements/signal/once.mdx +3 -2
  19. package/site/content/docs/elements/store/files.mdx +24 -16
  20. package/site/content/docs/elements/store/index.mdx +11 -8
  21. package/site/content/docs/elements/store/kv.mdx +24 -16
  22. package/site/content/docs/elements/store/search.mdx +18 -14
  23. package/site/content/docs/elements/store/sql.mdx +14 -10
  24. package/site/content/docs/elements/vault/config.mdx +5 -2
  25. package/site/content/docs/elements/vault/rotation.mdx +5 -2
  26. package/site/content/docs/elements/vault/secrets.mdx +5 -2
  27. package/site/content/docs/index.mdx +4 -19
  28. package/site/content/docs/reference/cli.mdx +1 -1
  29. package/site/content/docs/reference/fx.mdx +3 -2
  30. package/site/content/docs/reference/security.mdx +2 -2
  31. package/site/content/docs/understand/meta.json +1 -1
  32. package/site/content/docs/understand/the-architecture.mdx +264 -0
  33. package/src/bench/REPORT.md +48 -17
  34. package/src/bench/g17-hybrid-search.bench.ts +13 -13
  35. package/src/console/ui-next/dist/assets/{access-page-DFeymU07.js → access-page-C_qLDhTq.js} +1 -1
  36. package/src/console/ui-next/dist/assets/{agent-disclosure-U1rdfblp.js → agent-disclosure-BHVqr3TN.js} +1 -1
  37. package/src/console/ui-next/dist/assets/{cache-glyph-BeFJeqBG.js → cache-glyph-CKe92lRQ.js} +1 -1
  38. package/src/console/ui-next/dist/assets/{call-pii-button-CVAONPii.js → call-pii-button-DEwTl8ZX.js} +1 -1
  39. package/src/console/ui-next/dist/assets/{collapsible-D2A6NJ-3.js → collapsible-BCBtDrCt.js} +1 -1
  40. package/src/console/ui-next/dist/assets/{duration-tone-Cgk_h5ja.js → duration-tone-JroqeuCp.js} +1 -1
  41. package/src/console/ui-next/dist/assets/flows-page-CVHa0RTt.js +1 -0
  42. package/src/console/ui-next/dist/assets/{highlighted-json-MYZQtRnw.js → highlighted-json-DjJW6hqe.js} +1 -1
  43. package/src/console/ui-next/dist/assets/{http-method-Jrh39p7A.js → http-method-DC5HBdLU.js} +1 -1
  44. package/src/console/ui-next/dist/assets/{index-DXP2dBIF.js → index-CYjiZ3WO.js} +3 -3
  45. package/src/console/ui-next/dist/assets/{observability-page-HvolXxTI.js → observability-page-CAYMyKb3.js} +1 -1
  46. package/src/console/ui-next/dist/assets/{replica-lag-CSh2dzrb.js → replica-lag-yAQYLv75.js} +1 -1
  47. package/src/console/ui-next/dist/assets/request-meta-D0yusGxJ.js +1 -0
  48. package/src/console/ui-next/dist/assets/{store-page-eiKiHnNe.js → store-page-BTKJeJ02.js} +1 -1
  49. package/src/console/ui-next/dist/assets/{trace-detail-sheet-CZkMeKS-.js → trace-detail-sheet-Bp-Yygs5.js} +1 -1
  50. package/src/console/ui-next/dist/assets/{tree-expand-toggle-CW8y5A2h.js → tree-expand-toggle-DoaVDfAM.js} +1 -1
  51. package/src/console/ui-next/dist/assets/{units-page-B_RWJrEO.js → units-page-BRz7xyYL.js} +1 -1
  52. package/src/console/ui-next/dist/assets/{vault-page-CWrg-A68.js → vault-page-3jQt-bOJ.js} +1 -1
  53. package/src/console/ui-next/dist/index.html +1 -1
  54. package/src/console/ui-next/src/features/flows/graph/element-map.test.ts +1 -1
  55. package/src/console/ui-next/src/features/flows/graph/element-map.ts +3 -3
  56. package/src/console/ui-next/src/features/flows/traces/trace-detail.test.ts +4 -5
  57. package/src/console/ui-next/src/features/flows/traces/trace-gates.ts +3 -6
  58. package/src/elements/gate/declare.ts +1 -1
  59. package/src/elements/gate.ts +1 -1
  60. package/src/elements/store/search-lsh.ts +35 -0
  61. package/src/elements/store/search-runtime.pglite.test.ts +186 -0
  62. package/src/elements/store/search-runtime.ts +30 -16
  63. package/src/elements/store/search.test.ts +83 -1
  64. package/src/elements/store.ts +2 -0
  65. package/src/mcp/docs-index.ts +3 -3
  66. package/src/mcp/docs-mcp.test.ts +2 -2
  67. package/src/mcp/docs-tools.ts +2 -1
  68. package/site/content/docs/understand/the-anatomy.mdx +0 -132
  69. package/site/content/docs/understand/the-model.mdx +0 -32
  70. package/site/content/docs/understand/the-problem.mdx +0 -74
  71. package/site/content/docs/understand/the-vocabulary.mdx +0 -26
  72. package/src/console/ui-next/dist/assets/flows-page-Dss7941e.js +0 -1
  73. package/src/console/ui-next/dist/assets/request-meta-BatF8KrK.js +0 -1
  74. /package/site/content/docs/{ai → understand}/try-it.mdx +0 -0
@@ -14,7 +14,7 @@ import {
14
14
  deserializePlanes,
15
15
  lshBucket,
16
16
  lshBucketToSql,
17
- neighborBuckets,
17
+ lshHammingSql,
18
18
  } from "./search-lsh.ts";
19
19
  import {
20
20
  embColumn,
@@ -74,8 +74,9 @@ export interface RunSqlSearchDeps {
74
74
  }
75
75
 
76
76
  /**
77
- * Execute hybrid search against PostgreSQL using GIN + LSH B-tree candidates,
78
- * then BM25F / cosine / fusion in-process (correct, testable math).
77
+ * Execute hybrid search against PostgreSQL using GIN lexical candidates UNION
78
+ * SimHash Hamming-rank (K=64 `bit_count` ORDER BY LIMIT), then BM25F / cosine
79
+ * / fusion in-process (correct, testable math).
79
80
  *
80
81
  * @param deps - Connection, table meta, options
81
82
  */
@@ -103,11 +104,9 @@ export async function runSqlSearch(deps: RunSqlSearchDeps): Promise<SqlSearchRes
103
104
  const embedFields = searchable.filter((c) => c.embed);
104
105
  if (embedFields.length > 0) engines.push("lsh");
105
106
 
106
- // Candidate retrieval: GIN tsvector match OR LSH buckets.
107
- const params: unknown[] = [query];
108
- let whereSql = `${OKE_TSV_COL} @@ plainto_tsquery('english', ?)`;
109
107
  let queryVec: readonly number[] | undefined;
110
- const bucketParams: bigint[] = [];
108
+ const hamExprs: string[] = [];
109
+ const hamParams: unknown[] = [];
111
110
 
112
111
  if (embedFields.length > 0 && deps.embedQuery) {
113
112
  const model = embedFields[0]?.embed?.model;
@@ -137,20 +136,18 @@ export async function runSqlSearch(deps: RunSqlSearchDeps): Promise<SqlSearchRes
137
136
  const planesBuf = row["planes"] as Buffer;
138
137
  const planes = deserializePlanes(Buffer.from(planesBuf), k);
139
138
  const bucket = lshBucket(queryVec, planes);
140
- for (const b of neighborBuckets(bucket, k)) {
141
- bucketParams.push(b);
142
- }
143
- whereSql += ` OR ${lshColumn(field.sqlName)} = ANY(?::bigint[])`;
144
- params.push(`{${bucketParams.map((b) => lshBucketToSql(b)).join(",")}}`);
139
+ hamExprs.push(lshHammingSql(lshColumn(field.sqlName), "?"));
140
+ hamParams.push(lshBucketToSql(bucket));
145
141
  }
146
142
  }
147
143
 
148
- // Compose list-grammar filters.
144
+ let filterClause = "";
145
+ const filterParams: unknown[] = [];
149
146
  if (parsed.page.where) {
150
147
  const compiled = compileWhere(parsed.page.where);
151
148
  if (compiled.clause) {
152
- whereSql = `(${whereSql}) AND (${compiled.clause})`;
153
- params.push(...compiled.params);
149
+ filterClause = ` AND (${compiled.clause})`;
150
+ filterParams.push(...compiled.params);
154
151
  }
155
152
  }
156
153
 
@@ -159,10 +156,27 @@ export async function runSqlSearch(deps: RunSqlSearchDeps): Promise<SqlSearchRes
159
156
  ...searchable.map((c) => quoteIdent(c.sqlName)),
160
157
  ...embedFields.map((c) => quoteIdent(embColumn(c.sqlName))),
161
158
  ].join(", ");
159
+ const tableIdent = quoteIdent(tableName);
162
160
 
163
161
  // Oversample candidates for fusion then truncate.
164
162
  const fetchLimit = Math.min(Math.max(limit * 5, 50), 500);
165
- const candidateSql = `SELECT ${selectCols} FROM ${quoteIdent(tableName)} WHERE ${whereSql} LIMIT ${fetchLimit}`;
163
+ const lexicalSql = `SELECT ${selectCols} FROM ${tableIdent} WHERE ${OKE_TSV_COL} @@ plainto_tsquery('english', ?)${filterClause} LIMIT ${fetchLimit}`;
164
+
165
+ // SimHash k-NN: rank by Hamming over the K=64 bit pack, then LIMIT.
166
+ // Hamming-1 equality (`= ANY(65 buckets)`) is not a candidate set — true
167
+ // near-neighbors sit at distance ~5–16, so that probe recovered ~0 rows.
168
+ let candidateSql: string;
169
+ const params: unknown[] = [];
170
+ if (hamExprs.length > 0) {
171
+ const lshPred = embedFields.map((f) => `${lshColumn(f.sqlName)} IS NOT NULL`).join(" OR ");
172
+ const orderExpr = hamExprs.length === 1 ? hamExprs[0]! : `LEAST(${hamExprs.join(", ")})`;
173
+ const lshSql = `SELECT ${selectCols} FROM ${tableIdent} WHERE (${lshPred})${filterClause} ORDER BY ${orderExpr} ASC NULLS LAST LIMIT ${fetchLimit}`;
174
+ candidateSql = `(${lexicalSql}) UNION (${lshSql})`;
175
+ params.push(query, ...filterParams, ...hamParams, ...filterParams);
176
+ } else {
177
+ candidateSql = lexicalSql;
178
+ params.push(query, ...filterParams);
179
+ }
166
180
  const candidates = await conn.query(candidateSql, params);
167
181
 
168
182
  const statsRows = await conn.query(
@@ -3,18 +3,23 @@
3
3
  */
4
4
 
5
5
  import { describe, expect, test } from "bun:test";
6
+ import { createHash } from "node:crypto";
6
7
  import { field, store } from "../store.ts";
7
8
  import { bm25fScore, termFrequencies, tokenize } from "./search-bm25.ts";
8
9
  import { fuseLists, fuseRrf, fuseWeighted } from "./search-fusion.ts";
9
- import { RRF_DEFAULT_K, SearchConfigError } from "./search-errors.ts";
10
+ import { LSH_DEFAULT_K, RRF_DEFAULT_K, SearchConfigError } from "./search-errors.ts";
10
11
  import {
11
12
  cosineSimilarity,
13
+ deserializePlanes,
12
14
  generateHyperplanes,
15
+ hammingDistance,
13
16
  hyperplaneSeed,
14
17
  lshBucket,
15
18
  lshBucketFromSql,
16
19
  lshBucketToSql,
20
+ lshHammingSql,
17
21
  neighborBuckets,
22
+ serializePlanes,
18
23
  } from "./search-lsh.ts";
19
24
 
20
25
  describe("field.searchable / .embed", () => {
@@ -101,8 +106,85 @@ describe("LSH", () => {
101
106
  expect(lshBucketFromSql(sql)).toBe(high);
102
107
  expect(lshBucketToSql(42n)).toBe("42");
103
108
  });
109
+
110
+ test("write-time and query-time buckets are identical for the same vector", () => {
111
+ const seed = hyperplaneSeed("g17_docs", "body", 32, LSH_DEFAULT_K);
112
+ const planes = generateHyperplanes(seed, 32, LSH_DEFAULT_K);
113
+ const reloaded = deserializePlanes(serializePlanes(planes), LSH_DEFAULT_K);
114
+ const vector = synthHashBag(
115
+ "refund policy shipping delay. Document 0 discusses refund policy shipping delay.",
116
+ );
117
+ const write = lshBucket(vector, planes);
118
+ const query = lshBucket(vector, reloaded);
119
+ expect(write).toBe(query);
120
+ expect(lshBucketToSql(write)).toBe(lshBucketToSql(query));
121
+ expect(neighborBuckets(write, LSH_DEFAULT_K)).toHaveLength(LSH_DEFAULT_K + 1);
122
+ });
123
+
124
+ test("K=64 Hamming-1 misses G17-like neighbors; Hamming-rank recovers them", () => {
125
+ // Same deterministic hash-bag generator G17 uses — 40 docs, 8 topics.
126
+ const topics = [
127
+ "refund policy shipping delay",
128
+ "password reset two factor auth",
129
+ "invoice payment stripe webhook",
130
+ "search ranking bm25 hybrid",
131
+ "postgres gin btree index plan",
132
+ "tenant isolation row level security",
133
+ "durable flow journal resume",
134
+ "live query fanout subscriber",
135
+ ];
136
+ const planes = generateHyperplanes(hyperplaneSeed("g17_docs", "body", 32, 64), 32, 64);
137
+ const docs = topics.flatMap((topic, t) =>
138
+ [0, 1, 2, 3, 4].map((n) => {
139
+ const i = t + n * 8;
140
+ const body = `${topic}. Document ${i} discusses ${topic} with enough tokens for BM25.`;
141
+ const vec = synthHashBag(body);
142
+ return { i, vec, bucket: lshBucket(vec, planes) };
143
+ }),
144
+ );
145
+ const qVec = synthHashBag(topics[0]!);
146
+ const qBucket = lshBucket(qVec, planes);
147
+ const scored = docs.map((d) => ({
148
+ i: d.i,
149
+ cos: cosineSimilarity(qVec, d.vec),
150
+ ham: hammingDistance(qBucket, d.bucket),
151
+ }));
152
+ const exact = [...scored].sort((a, b) => b.cos - a.cos).slice(0, 10);
153
+ const exactSet = new Set(exact.map((x) => x.i));
154
+ const ham1 = scored.filter((s) => s.ham <= 1);
155
+ const ham1Hits = ham1.filter((s) => exactSet.has(s.i)).length;
156
+ const ranked = [...scored].sort((a, b) => a.ham - b.ham || b.cos - a.cos).slice(0, 50);
157
+ const rankedTop = [...ranked].sort((a, b) => b.cos - a.cos).slice(0, 10);
158
+ const rankedHits = rankedTop.filter((s) => exactSet.has(s.i)).length;
159
+ // Hamming-1 is the broken probe (G17 P@10 ≈ 0). Hamming-rank of the K=64
160
+ // pack recovers the exact cosine top-10 on this 40-row hand case.
161
+ expect(ham1Hits).toBe(0);
162
+ expect(rankedHits).toBe(10);
163
+ expect(exact.every((e) => e.ham > 1)).toBe(true);
164
+ expect(lshHammingSql("__oke_lsh_body")).toContain("bit_count");
165
+ });
104
166
  });
105
167
 
168
+ /**
169
+ * G17 synthetic embedding — deterministic SHA-256 hash bag, L2-normalized.
170
+ *
171
+ * @param text - Source text
172
+ */
173
+ function synthHashBag(text: string, dims = 32): number[] {
174
+ const v = Array.from({ length: dims }, () => 0);
175
+ const tokens = text.toLowerCase().split(/\W+/).filter(Boolean);
176
+ for (const t of tokens) {
177
+ const h = createHash("sha256").update(t).digest();
178
+ for (let i = 0; i < dims; i++) {
179
+ v[i]! += (h[i % h.length]! / 255) * 2 - 1;
180
+ }
181
+ }
182
+ let norm = 0;
183
+ for (const x of v) norm += x * x;
184
+ norm = Math.sqrt(norm) || 1;
185
+ return v.map((x) => x / norm);
186
+ }
187
+
106
188
  describe("fusion", () => {
107
189
  test("RRF default k=60 matches Cormack hand ranks", () => {
108
190
  expect(RRF_DEFAULT_K).toBe(60);
@@ -197,7 +197,9 @@ export {
197
197
  lshBucketToSql,
198
198
  lshBucketFromSql,
199
199
  cosineSimilarity,
200
+ hammingDistance,
200
201
  neighborBuckets,
202
+ lshHammingSql,
201
203
  serializePlanes,
202
204
  deserializePlanes,
203
205
  } from "./store/search-lsh.ts";
@@ -12,7 +12,7 @@ import { join } from "node:path";
12
12
  export interface DocsPage {
13
13
  /** URL slug under `/docs` (`""` for the index page). */
14
14
  readonly slug: string;
15
- /** Content-relative path (e.g. `understand/the-problem.mdx`). */
15
+ /** Content-relative path (e.g. `understand/the-architecture.mdx`). */
16
16
  readonly path: string;
17
17
  /** Frontmatter title. */
18
18
  readonly title: string;
@@ -39,7 +39,7 @@ export interface DocsIndex {
39
39
  /**
40
40
  * Look up a page by slug or content path.
41
41
  *
42
- * @param id - Slug (`understand/the-problem`) or path (`…/the-problem.mdx`)
42
+ * @param id - Slug (`understand/the-architecture`) or path (`…/the-architecture.mdx`)
43
43
  */
44
44
  readonly get: (id: string) => DocsPage | null;
45
45
  /**
@@ -203,7 +203,7 @@ export async function loadDocsIndex(
203
203
  }
204
204
 
205
205
  /**
206
- * @param relativePath - e.g. `understand/the-problem.mdx`
206
+ * @param relativePath - e.g. `understand/the-architecture.mdx`
207
207
  */
208
208
  function pathToSlug(relativePath: string): string {
209
209
  const noExt = relativePath.replace(/\.mdx?$/i, "");
@@ -112,7 +112,7 @@ describe("docs MCP tools", () => {
112
112
 
113
113
  test("oke.docs.get returns body byte-identical to on-disk source", async () => {
114
114
  const mcp = await createDocsMcpServer({ contentDir: CONTENT });
115
- const slug = "understand/the-problem";
115
+ const slug = "understand/the-architecture";
116
116
  const res = await mcpPost(mcp.fetch, {
117
117
  jsonrpc: "2.0",
118
118
  id: 2,
@@ -133,7 +133,7 @@ describe("docs MCP tools", () => {
133
133
  const content = envelope.content as { body: string; slug: string };
134
134
  expect(content.slug).toBe(slug);
135
135
 
136
- const raw = await Bun.file(join(CONTENT, "understand", "the-problem.mdx")).text();
136
+ const raw = await Bun.file(join(CONTENT, "understand", "the-architecture.mdx")).text();
137
137
  expect(content.body).toBe(stripYamlFrontmatter(raw));
138
138
  });
139
139
 
@@ -52,7 +52,8 @@ export const DOCS_MCP_TOOLS: readonly DocsToolDescriptor[] = [
52
52
  properties: {
53
53
  slug: {
54
54
  type: "string",
55
- description: "Page slug (e.g. understand/the-problem) or path (…/the-problem.mdx)",
55
+ description:
56
+ "Page slug (e.g. understand/the-architecture) or path (…/the-architecture.mdx)",
56
57
  },
57
58
  },
58
59
  required: ["slug"],
@@ -1,132 +0,0 @@
1
- ---
2
- title: "The Anatomy"
3
- description: "The five pieces behind on(trigger, flow) — on, trigger, flow, do, and fx — explained one at a time, then combined."
4
- icon: "PenTool"
5
- ---
6
-
7
- Everything a Flow does reduces to one line:
8
-
9
- ```typescript
10
- on(
11
- trigger,
12
- flow({
13
- do: (input, fx) => {
14
- /* ... */
15
- },
16
- }),
17
- );
18
- ```
19
-
20
- If that line doesn't mean much yet, that's what this page is for. Five pieces make it up. We'll take them one at a time, then put them together using a complete signup example.
21
-
22
- ## `on(...)` — wires a trigger to a flow
23
-
24
- `on` does exactly one thing: it connects "something that can happen" to "code that should run when it does." Nothing executes until this connection exists.
25
-
26
- ```typescript
27
- on(someTrigger, someFlow);
28
- ```
29
-
30
- That's the whole job. The interesting parts are what goes in each slot.
31
-
32
- ## A trigger — the answer to "when"
33
-
34
- The first argument to `on` is the trigger: whatever wakes the code up. A trigger doesn't run any of your logic — it only answers one question: _when should this happen?_
35
-
36
- ```typescript
37
- http.post(); // path from the file tree — e.g. src/flows/users/signup.ts → POST /users/signup
38
- ```
39
-
40
- There are five kinds of trigger in total — the table at the end of this page lists them. For now: the trigger is the _when_, and it's the only thing that changes between an endpoint, a scheduled job, and everything else.
41
-
42
- ## `flow(...)` — the actual unit of work
43
-
44
- The second argument to `on` is a Flow — declared with the `flow()` function. It answers _what_: what work is this, and what does it promise about its inputs and outputs?
45
-
46
- ```typescript
47
- flow({
48
- do: /* the actual code — next */,
49
- });
50
- ```
51
-
52
- Omit the name on tree files — the compiler stamps `unit.export` (e.g. `users.signup`).
53
- Pass `flow("users.signup", { … })` only for control: barrels, stable names across
54
- moves, or call-only Flows you `fx.call` by name.
55
-
56
- ## `do` — the code that actually runs
57
-
58
- `do` is a function you write. It answers _how_. It receives two things: `input` (your data) and `fx` (next). Everything your Flow actually does lives here.
59
-
60
- ```typescript
61
- do: async (input, fx) => {
62
- return { ok: true };
63
- };
64
- ```
65
-
66
- ## `fx` — the only door to the outside world
67
-
68
- `fx` is the second argument to `do`, and it's the piece the other four exist to protect. The rule is simple and absolute: **your Flow is not allowed to read a database, send an email, check a clock, or touch anything outside itself except through `fx`.**
69
-
70
- ```typescript
71
- do: async (input, fx) => {
72
- const user = await fx.store(db).insert(users).values(input); // the database, through fx
73
- await fx.send(welcomeEmail, { to: user.email }); // another system, through fx
74
- return user;
75
- };
76
- ```
77
-
78
- This one rule is what made the Month 8 drift from The Problem avoidable: if `fx` is the only door, retries, auditing, and idempotency stop being separate systems teams build by hand, and become properties of the one boundary everything already passes through.
79
-
80
- ## Putting the five pieces together
81
-
82
- Here is the complete signup flow, with every piece labeled where it sits:
83
-
84
- ```typescript title="src/flows/users/signup.ts"
85
- export const signup = on(
86
- http.post(), // ← trigger: when (stamped POST /users/signup)
87
- flow({
88
- // ↑ flow: what (stamped users.signup)
89
- do: async (input, fx) => {
90
- // ← do: how
91
- const user = await fx.store(db).insert(users).values(input); // ← fx: the only way out
92
- await fx.send(welcomeEmail, { to: user.email, data: { name: user.name } });
93
- return user;
94
- },
95
- }),
96
- );
97
- ```
98
-
99
- <Callout title="Call-only flows">
100
- A `flow(...)` declared without `on(...)` around it is internal — nothing outside your code can
101
- start it. Other flows invoke it directly with `fx.call(flowRef, input)`.
102
- </Callout>
103
- ## Checking it against the timeline
104
-
105
- Nothing about the code above looks more complicated than the four lines that started the drift on The Problem — because it isn't. The difference only shows up when the same pressure from that timeline hits it.
106
-
107
- Every fork from that timeline was really the same question, asked at a different point: _is this thing that touches the outside world safe to retry, safe to audit, safe to run twice?_ On The Problem, each answer required a new system, because each system had to invent its own answer. Here, the question has one home:
108
-
109
- - **The traffic spike from Week 2** doesn't need a queue you build and wire up by hand — running this later, safely, is something you ask of the trigger or the effect itself, not infrastructure you assemble.
110
- - **The silent failure from Month 2** doesn't need a hand-picked retry count living in a worker nobody remembers the reasoning for. Retries are a property of the `fx` boundary every effect already passes through.
111
- - **The compliance question from Month 4** doesn't need a `sent_emails` table written by hand from inside a background job. What was sent, and when, is something the system already knows, because nothing was allowed to send anything outside of `fx` in the first place.
112
- - **The double-submit from Month 6** doesn't need dedup logic split across a queue and a database that never check each other. There's one call, through one door — there's no second path left for a duplicate to sneak through.
113
-
114
- None of that required new code beyond what's above. It required the four lines to already be the kind of thing where those questions have a fixed answer, instead of a new one invented per team, per incident.
115
-
116
- ## Five kinds of trigger
117
-
118
- `flow`, `do`, and `fx` never change shape. Only the trigger does — and there are exactly five kinds, one per element that can independently wake a Flow up:
119
-
120
- | Trigger | Element | Starts When |
121
- | --------------------------------------------------- | ------- | -------------------------------- |
122
- | `http.post()` (path from file tree) | Flow | A request arrives |
123
- | `clock("name", { every: "10m" })` | Clock | A time interval elapses |
124
- | `signal.once("name", {…})` / `.broadcast` / `.live` | Signal | Another flow announces something |
125
- | `db.table(users).changed("email")` | Store | A database row changes |
126
- | `mcp.tool("name")` | AI | An AI agent calls it |
127
-
128
- The next section walks through each element in depth — this is just enough to recognize them when you see them.
129
-
130
- ## Where this goes next
131
-
132
- You've seen the problem, the model, the vocabulary, and now the exact anatomy behind every Flow — proven against the timeline that motivated it. The next step is running it yourself: from an empty folder to this exact Flow answering a real request, in one sitting.
@@ -1,32 +0,0 @@
1
- ---
2
- title: "The Model"
3
- description: "The one rule that removes the disagreement between systems — stated plainly, in two parts."
4
- icon: "Compass"
5
- ---
6
-
7
- ## The fix, stated as a rule
8
-
9
- Every seam on the last page came from the same root cause: each system involved had its own idea of when it should run and what it was allowed to touch, and nothing forced those ideas to agree with each other.
10
-
11
- OKE removes the disagreement by removing the choice. It's one rule, in two parts.
12
-
13
- **First: every trigger reduces to the same shape.** An HTTP request, a scheduled tick, a queue message, a database change — whatever wakes the code up, what follows has one identical anatomy: `on(Trigger) → Effects`. Not four systems that happen to look similar. One system, with four ways to wake it up.
14
-
15
- **Second: every effect passes through one door.** Nothing is allowed to touch a database, send an email, check a permission, or read the clock on its own — all of it goes through a single surface. Not because that's tidier. Because it's the only way retries, auditing, idempotency, and permission checks stop being infrastructure every team reinvents at the exact moment they get burned by not having it. Build the door once, correctly, and every trigger that walks through it inherits the same guarantees automatically.
16
-
17
- That's the whole model. Not a bigger toolbox — a smaller number of things that are allowed to happen at all.
18
-
19
- ## Why the door has a fixed vocabulary
20
-
21
- A door that lets anything through isn't actually closed. So the door recognizes a fixed set of things it's willing to do, and nothing new gets added to that set unless it does something none of the existing ones can. What that set is, and why it stops at eight, is the next page.
22
-
23
- ## What this project is called
24
-
25
- One shape for every trigger, one door for every effect, a fixed vocabulary for what the door allows — that's what this project built. It's called **OKE**.
26
-
27
- ---
28
-
29
- <sub>
30
- *OKE isn't an acronym for anything in the code. It comes from Omq Khafi — the organization this
31
- engine grew out of — with "Engine" appended: **O**mq **K**hafi **E**ngine.*
32
- </sub>
@@ -1,74 +0,0 @@
1
- ---
2
- title: "The Problem"
3
- description: "Three unrelated features that hit the exact same wall, and the timeline that shows why."
4
- icon: "TriangleAlert"
5
- ---
6
-
7
- ## Three features, same wall
8
-
9
- **A signup flow.** A user registers. Send them a welcome email. Four lines of code — until traffic spikes, the mail provider starts rate-limiting, and "send an email" quietly needs a queue, a worker, and a retry policy nobody designed on purpose.
10
-
11
- **A payment webhook.** A provider confirms a charge. Mark the order paid. Simple — until the provider retries the same webhook twice during a network hiccup, and "mark the order paid" needs to somehow know it already ran.
12
-
13
- **A nightly report.** Summarize yesterday's activity and email it to managers. Trivial — until a manager's access gets revoked at 11:58pm and the report that runs at midnight has no idea the permission it checked when the feature was built isn't the permission that holds right now.
14
-
15
- Three teams. Three domains. Nobody on any of them talked to the other two. And all three land on the identical fork: **something has to happen later, exactly once, provably — and nothing in the original four lines said what "provably" would end up costing.**
16
-
17
- ## Follow one all the way through
18
-
19
- Take the first one. Just the signup flow, from the day it shipped.
20
-
21
- ```typescript
22
- app.post("/signup", async (req, res) => {
23
- const user = await db.users.create(req.body);
24
- await sendMail(user.email, "Welcome!", welcomeTemplate(user));
25
- res.json(user);
26
- });
27
- ```
28
-
29
- It works. It ships. Two weeks later, a launch drives a traffic spike, the mail provider starts returning `429`, and signups start failing because an unrelated email is slow. You move the send off the request path:
30
-
31
- ```typescript
32
- app.post("/signup", async (req, res) => {
33
- const user = await db.users.create(req.body);
34
- emailQueue.add("welcome", { userId: user.id });
35
- res.json(user);
36
- });
37
- ```
38
-
39
- The endpoint is fast again. It's also no longer one system — it's an endpoint, a queue, a worker, and a Redis connection nobody else on the team knew existed until a missing `REDIS_URL` broke staging.
40
-
41
- From here the same pattern repeats on a longer clock. A support ticket reveals a job failed silently — nobody had configured retries, so you add them, and now a specific number (3? 5? with what backoff?) lives in a file that nobody will remember the reasoning for in six weeks. Compliance asks for proof of every email sent — you add a table written to from inside the worker, and now that worker has two jobs instead of one, quietly capable of disagreeing with itself if the second write fails. Someone double-clicks submit — two jobs enqueue, two emails send, and idempotency becomes a fact that has to live in two systems that were never introduced to each other.
42
-
43
- <SixSystemsDrift />
44
-
45
- None of these were mistakes. Each one was the correct call, made by a competent engineer, in direct response to something that actually happened. That's what makes the drift invisible while it's happening — there's no bad decision anywhere in this story to point at.
46
-
47
- ## What's actually going on
48
-
49
- Look at what the six resulting files have in common: none of them agree with each other about the same three things. What counts as "done." What happens on failure. Who's allowed to do this at all.
50
-
51
- That's the real cost — not the number of tools, but what sits between them:
52
-
53
- - **Failure means something different in each one.** A queue retry, an HTTP 500, and a rejected promise from a mail SDK are three unrelated shapes that all happen to mean "this didn't work."
54
- - **Permission has no fixed address.** It lives wherever whoever wrote that file remembered to put it — which means a reviewer can't point at one place and ask "is this checked?"
55
- - **Two systems both think they own the same fact.** The database says an order is paid. The already-running webhook handler doesn't know that yet. Nothing keeps them honest with each other in the gap.
56
- - **Nobody can see the whole thing at once.** There is no file, diagram, or dashboard where "the signup flow" exists as one object — only as the sum of files that happen to call each other.
57
-
58
- ## If you've been doing this a while
59
-
60
- None of the three stories above are hypothetical to you. You've shipped at least one of them — maybe with a different provider, a different table name, a different Slack channel where the incident got triaged. You've sat in the postmortem. You've written the line in the retro doc that says "we should have thought about retries from the start," knowing full well that thinking about it from the start wouldn't have told you which of forty possible failure modes was going to be the one that mattered.
61
-
62
- That's not a criticism of your judgment. It's the actual shape of the problem: every decision in that timeline was locally correct and still added a system that doesn't speak the same language as the five before it. You didn't do this wrong. The tools you were given don't leave room to do it any other way.
63
-
64
- ## If you haven't yet
65
-
66
- If your code right now still looks like the four lines from Day 1 — on any feature, in any domain — this is the part that matters most: **you will hit this fork.** Not "might." Every one of the three stories above started as a sentence a product manager could say out loud in one breath. The traffic spike, the silent retry, the compliance question, the double-submit — these aren't edge cases that happen to unlucky teams. They're what happens to any trigger that lives long enough to matter, and right now you simply haven't reached that point in the timeline yet.
67
-
68
- The four lines were never wrong. They were just the first data point on a line that already knew where it was going.
69
-
70
- ## The actual question
71
-
72
- Nothing above was avoidable by writing cleaner code inside any single file. The problem was never inside a file — it was that several files had to agree on things none of them were ever designed to agree on.
73
-
74
- What would have to be true on day one for month eight to never happen?
@@ -1,26 +0,0 @@
1
- ---
2
- title: "The Vocabulary"
3
- description: "The eight things the door recognizes — what each one replaces, and why nothing else made the cut."
4
- icon: "Boxes"
5
- ---
6
-
7
- ## What the door recognizes
8
-
9
- The door from the last page isn't open-ended — it recognizes a fixed set of things it's willing to do. Each one made the cut because it has _irreducible physics_: behavior that breaks if you tried to fake it using one of the others. A queue's retry and lease semantics aren't a database's job. A secret's rotation lifecycle isn't a config value's job. Where that distinction is real, it gets a name. Where it isn't, it doesn't — which is why the list stops at eight instead of growing indefinitely.
10
-
11
- | Element | What it is | What it replaces |
12
- | ----------- | -------------------- | ----------------------------------------------------------------------- |
13
- | **Flow** | Execution & behavior | endpoint, handler, consumer, job, workflow, webhook |
14
- | **Signal** | Data in motion | queue, pub/sub, stream, websocket, SSE, event bus |
15
- | **Store** | Data at rest | relational database, cache, key-value store, file storage, search index |
16
- | **Clock** | Time & schedules | cron, delay, timeout, durable sleep, TTL |
17
- | **Gate** | Permission to act | auth, session, tenancy, RBAC, rate limit, quota |
18
- | **Vault** | Protected knowledge | secrets, encryption keys, rotation, environment variables |
19
- | **Channel** | Reaching a human | transactional email, SMS, push notifications, receipts |
20
- | **AI** | Machine intelligence | model calls, structured prompts, agents, MCP tools |
21
-
22
- Read the right column as the honest answer to "what would I have reached for before this?" Every item in it is a separate tool with its own configuration, its own failure modes, and its own place to go wrong. The left column is the same ground, covered by something with one shared door and one shared set of guarantees.
23
-
24
- ## Where this goes next
25
-
26
- The next step is breaking down the five pieces behind every Flow — the exact anatomy that connects a trigger to its effects.