Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
190 commits
Select commit Hold shift + click to select a range
89eed55
v2.4.0 (#327)
singaraiona Jul 11, 2026
eb66eed
feat(query): support live inserts into parted tables
singaraiona Jul 14, 2026
bbdc419
fix(core): restore total-core -c semantics
singaraiona Jul 15, 2026
9961388
fix(parse) Fix nonstring if not defined
protocolstardust Jul 16, 2026
6cac6e8
Merge pull request #330 from protocolstardust/dev
protocolstardust Jul 16, 2026
f44ab81
Merge branch 'master' into dev
singaraiona Jul 16, 2026
49d8524
fix(store): surface FlushFileBuffers failure in journal SYNC mode (#335)
belowzeroff Jul 18, 2026
cb1c6cd
fix(hnsw): reject build dims whose vector count overflows size_t (#333)
belowzeroff Jul 18, 2026
7475949
fix(store): read full link sidecar to avoid wrong-symbol truncation (…
belowzeroff Jul 18, 2026
ebadd07
fix(hnsw): reject index files whose vector count overflows size_t (#332)
belowzeroff Jul 21, 2026
fa39d9d
fix(docs): remediate F-0001 F-0005 F-0007
singaraiona Jul 22, 2026
ffd784f
fix(docs): remediate CF-0001
singaraiona Jul 22, 2026
1f27e61
fix(docs): remediate CF-0002
singaraiona Jul 22, 2026
465e58e
chore(audit): plan CF-0003 ratification
singaraiona Jul 22, 2026
8f8033c
fix(docs): remediate CF-0003
singaraiona Jul 22, 2026
3ae79f5
feat(docs): redesign website and documentation
singaraiona Jul 22, 2026
5dc8265
Merge branch 'master' into dev
singaraiona Jul 22, 2026
4d2c8f3
fix(null): avoid f64 null casts to integers (#340)
belowzeroff Jul 23, 2026
4e49626
fix(expr): avoid null truthiness casts in fallback binary ops (#339)
belowzeroff Jul 23, 2026
a05886d
ci: make Rayforce audit PR comments best-effort
singaraiona Jul 23, 2026
6ca3d8a
ci: publish Rayforce audit comments from trusted workflow
singaraiona Jul 23, 2026
04d8f3d
ci: resolve fork PRs for audit commenter
singaraiona Jul 23, 2026
6acdc2c
perf: parallelize serial stages around group-by; unify binary-agg nul…
ser-vasilich Jul 23, 2026
a53d98e
Merge branch 'master' into dev
singaraiona Jul 23, 2026
260e018
fix(aggr): preserve slice nullability in binary groups
singaraiona Jul 23, 2026
492c5db
fix(expr): avoid f64 null cast in fallback idiv integer output (#344)
belowzeroff Jul 23, 2026
d250108
fix(group): avoid f64 null read cast in dense aggs (#343)
belowzeroff Jul 23, 2026
95f0a3d
fix(ipc): preserve boxed data list args (#346)
belowzeroff Jul 24, 2026
e10d1ab
fix(group): avoid f64 null cast in DA reads (#348)
belowzeroff Jul 24, 2026
842acc0
ci: use portable march for fuzz jobs (#347)
belowzeroff Jul 24, 2026
84cea17
chore(release): merge master into dev
singaraiona Jul 24, 2026
7a5839e
fix(pivot): preserve generic missing cells as null (#350)
belowzeroff Jul 27, 2026
57628fb
fix(xbar): avoid narrow bucket truncation (#351)
belowzeroff Jul 28, 2026
d7a1f6f
Merge branch 'master' into dev
singaraiona Jul 28, 2026
c501ae0
fix(arith): reject float temporal operands (#353)
belowzeroff Jul 29, 2026
aea9bda
fix(ops): make nested (LIST) columns usable through a parted view (fi…
singaraiona Jul 30, 2026
0605f1a
fix(query): preserve temporal arithmetic semantics (#354)
belowzeroff Jul 30, 2026
282d3a1
Merge branch 'master' into dev
singaraiona Jul 30, 2026
17bf2b8
ci: skip audit comments for cancelled runs
singaraiona Jul 30, 2026
05c8078
fix(query): preserve if temporal branch types (#359)
belowzeroff Jul 31, 2026
488a296
fix(store): reject duplicate splayed column names (#360)
belowzeroff Aug 3, 2026
5684559
fix(builtins): reject malformed strings in TIMESTAMP cast (#361)
belowzeroff Aug 3, 2026
c9b9a66
fix(store): support nested column inserts and persistence (#365)
singaraiona Aug 3, 2026
4c0fa46
fix(eval): enforce restricted mode in compiled lambdas (#366)
singaraiona Aug 3, 2026
8c9300b
feat(core): add bounded poll step for embedders (#367)
singaraiona Aug 3, 2026
3c79632
Merge branch 'master' into dev
singaraiona Aug 3, 2026
9b05f60
fix(test): rely on public runtime declarations (#369)
belowzeroff Aug 4, 2026
add3498
feat: website add consumer
singaraiona Aug 4, 2026
9d255c2
Merge branch 'master' into dev
singaraiona Aug 4, 2026
a1dcfd9
feat(core): expose restricted poll mode (#372)
singaraiona Aug 4, 2026
d5d5240
fix(aggr): preserve grouped nested first and last
singaraiona Aug 4, 2026
c35fa2b
Merge branch 'master' into dev
singaraiona Aug 4, 2026
2cfc70e
fix(join): preserve nested columns (#376)
singaraiona Aug 4, 2026
ac9d0cc
Merge branch 'master' into dev
singaraiona Aug 4, 2026
2fa0fbd
fix(csv): round-trip signed and >=24h TIME values in .csv.read (#379)
belowzeroff Aug 4, 2026
959db02
fix(str): propagate null start/length in substr instead of overflowin…
belowzeroff Aug 4, 2026
2083f24
fix(builtins): clamp out-of-range float in scalar numeric casts (#380)
belowzeroff Aug 5, 2026
5419053
Merge branch 'master' into dev
singaraiona Aug 5, 2026
c731b42
fix(builtins): validate bounds in DATE string cast (#382)
belowzeroff Aug 6, 2026
93db5ce
perf(aggr): specialize reduction scans (#383)
singaraiona Aug 6, 2026
e71798a
perf(collection): parallel radix distinct for fixed-width columns (#384)
protocolstardust Aug 6, 2026
8d6466f
fix(csv): harden import cancellation and schema handling (#387)
singaraiona Aug 7, 2026
8a1cf0c
fix(temporal): guard int64 overflow in DATE/TIMESTAMP decomposition (…
belowzeroff Aug 9, 2026
7bf522a
fix(eval): materialize lazy values at compiled boundaries (#391)
singaraiona Aug 11, 2026
caa529d
fix(arith): wrap scalar integer add/sub/mul on overflow instead of UB…
belowzeroff Aug 11, 2026
a2607ac
fix(builtins): reject malformed strings in TIME cast (#389)
belowzeroff Aug 11, 2026
a14ba5c
Merge branch 'master' into dev
singaraiona Aug 11, 2026
5aa47a5
fix(builtins): validate hex digits and dash layout in GUID string cas…
belowzeroff Aug 12, 2026
d1d256e
feat(core): address Data Vault workflow gaps (#395)
singaraiona Aug 12, 2026
f1d1b71
feat(io): add binary file read and write (#396)
singaraiona Aug 12, 2026
9a4ea60
Merge branch 'master' into dev
singaraiona Aug 12, 2026
776b290
fix(store): repair legacy string hash caches (#398)
singaraiona Aug 12, 2026
afbcf69
fix(builtins): reject trailing garbage and overflow in numeric string…
belowzeroff Aug 13, 2026
31d8970
fix(query): reject STR equality keys in asof-join and window-join (#400)
belowzeroff Aug 14, 2026
95defb7
fix(store): support LIST columns in parted fill (#402)
singaraiona Aug 14, 2026
4098f8b
fix(exec): propagate str_pool in OP_HEAD/OP_TAIL flat-column copies (…
singaraiona Aug 14, 2026
55c6e22
fix(query): evaluate whole-column aggregate args once in ungrouped se…
singaraiona Aug 14, 2026
bafb435
fix(group): sign-extend narrow keys in the DA accumulate loops
singaraiona Aug 14, 2026
4c0ed09
perf(group): size filtered group-by work from the surviving rows (Cli…
singaraiona Aug 14, 2026
68ace96
perf(agg): fix radix hash-bit overlap and rehash ladders in the v2 gr…
singaraiona Aug 15, 2026
76c50e3
perf(group): prime fat-entry radix payload buffers to expected load
singaraiona Aug 15, 2026
75b6901
feat(store): decide hash-vs-zone indexes at csv->splayed conversion; …
singaraiona Aug 15, 2026
2dc9cff
perf(group): route wide-domain SYM emit-filter groups to the parallel…
singaraiona Aug 15, 2026
e9c2d64
perf(group): tighten emit-filter v2 rerouting gates
singaraiona Aug 15, 2026
07ff419
perf(agg): memset the phase-3 order map instead of a scalar -1 loop
singaraiona Aug 15, 2026
399f9dd
perf(agg): parallelize the phase-3 stable-order scatter and compaction
singaraiona Aug 15, 2026
6357a2c
perf(pool): default worker auto-sizing to physical cores, not SMT thr…
singaraiona Aug 15, 2026
212fff3
perf(mem): reuse cache for direct (large) allocations
singaraiona Aug 15, 2026
1842700
fix(mem): public drain for the direct reuse cache + watermark test co…
singaraiona Aug 15, 2026
1ae57b9
refactor(mem): derive the direct-cache budget instead of an env knob
singaraiona Aug 15, 2026
d5867b6
perf(mem): raise the direct-cache cap to 4GB for 100M-row scale
singaraiona Aug 15, 2026
5d318ec
perf(group): pipelined slot prefetch in the v2 direct-insert phase1
singaraiona Aug 15, 2026
88c95bb
test(group): pin high-cardinality radix_v2 group shapes before partit…
singaraiona Aug 15, 2026
f30b578
fix(test): cast I32 key column to ensure radix_v2 path exercises I32 …
singaraiona Aug 15, 2026
9768280
perf(group): partition-major morsel batching in radix_v2 phase1
singaraiona Aug 15, 2026
34c9be0
perf(group): sparse touched-partition histogram + u32 partition ids i…
singaraiona Aug 15, 2026
0ac9aa4
feat(group): fused grouped count-distinct kernel (unwired)
singaraiona Aug 15, 2026
9959cbf
fix(cdfuse): guard dropped dispatch tasks; strengthen fused-cd tests
singaraiona Aug 15, 2026
0c68d3b
perf(query): route single-key unfiltered count-distinct through the f…
singaraiona Aug 15, 2026
94e28b9
perf(cdfuse): pair-hash partitioning with additive per-key merge (ske…
singaraiona Aug 15, 2026
125336f
perf(cdfuse): parallel key-bucketed merge phase
singaraiona Aug 15, 2026
66dcdd2
fix(cdfuse): asymmetric pair-hash combine (k==v cancellation cliff)
singaraiona Aug 15, 2026
c0cf496
fix(cdfuse): memory admission gate, SYM + boundary coverage, self-con…
singaraiona Aug 15, 2026
f3b2cbb
perf(mem): drop the direct-cache absolute cap; watermark/16 is the bound
singaraiona Aug 15, 2026
f1aaa73
perf(query): push a positive take: into grouped DAGs and bound v2's emit
singaraiona Aug 15, 2026
5684d4c
fix(query): guard the grouped take: pushdown and trim LIST columns
singaraiona Aug 15, 2026
2dd36e9
fix(query): pin the parted take guard, drop the take_pre allocation
singaraiona Aug 15, 2026
5784c19
perf(group): packed narrow-key fast path in the fat-entry radix pipeline
singaraiona Aug 15, 2026
ab5053a
fix(group): restore packed-key hash lockstep in the fused radix path
singaraiona Aug 15, 2026
701c7b8
test(group): pin F64 packed-key exclusion; honest 9-key test comment
singaraiona Aug 15, 2026
16bd46d
perf(group): prefetched partition-major probe for COUNT/SUM/AVG near-…
singaraiona Aug 16, 2026
ead2fff
fix(group): bound the grow_cap jump and keep it off the row array
singaraiona Aug 16, 2026
f2fba93
perf(group): parallelize the top-N group compaction
singaraiona Aug 16, 2026
bd9e743
fix(group): guard the top-N pre-pass against a cancelled dispatch
singaraiona Aug 16, 2026
853b3d3
perf(temporal): parallelize the extract/truncate kernels over the pool
singaraiona Aug 16, 2026
d64eb1d
test(temporal): pin the HAS_NULLS fold with vec-gate consumers; slim …
singaraiona Aug 16, 2026
902f294
perf(group): parallelize the radix key-column emit
singaraiona Aug 16, 2026
9e3cb09
test(group): slim the key-emit fixture; correct the take-bounded rout…
singaraiona Aug 16, 2026
d315102
perf(group): fuse the per-partition top-k into radix phase 2
singaraiona Aug 16, 2026
03142f5
fix(group): honour asc: on the top-N group emit filter (#408)
singaraiona Aug 16, 2026
9d95f6f
docs(group): pin the emit-filter .desc contract; honest #408 test com…
singaraiona Aug 16, 2026
c3fb6c6
fix(group): canonicalise -0.0 F64 group keys at the key-read boundary…
singaraiona Aug 16, 2026
2ec5284
fix(group): bit-level -0.0 fold in mode_scalar_key; precise NaN-polic…
singaraiona Aug 16, 2026
d59bb43
fix(collection): reject INT64_MIN count in take/drop instead of overf…
belowzeroff Aug 16, 2026
cd84f48
fix(cal): decode dates near INT32_MAX without int32 overflow (#410)
belowzeroff Aug 16, 2026
91fe7e3
fix(query): support update over parted tables and prevent column dupl…
belowzeroff Aug 16, 2026
66a80fb
fix(arith): keep integer div exact and UB-free (#403)
belowzeroff Aug 16, 2026
9e5f0a1
perf(expr): stop rescanning operands for the integer div gate (#403 f…
singaraiona Aug 16, 2026
2b93010
test(expr): pin the div gate bound; defensive idiv_i64_small reset un…
singaraiona Aug 16, 2026
412b69d
Merge branch 'master' into dev
singaraiona Aug 16, 2026
4fca523
fix(build): clang-clean boolean accumulation in the div gate scans
singaraiona Aug 16, 2026
c303733
docs(query): neutralize a product-name mention in the update by: scat…
singaraiona Aug 16, 2026
e5d87cd
docs(test): neutralize remaining product-name mentions in update-by c…
singaraiona Aug 16, 2026
3b1f533
perf(csv): drop load-time index attach from .csv.read
singaraiona Aug 17, 2026
b3f0275
feat(progress): byte-metered span for multi-phase ops
singaraiona Aug 17, 2026
0273a44
perf(csv): parallel row-offset scan, per-column finalize, whole-load …
singaraiona Aug 17, 2026
9e1592a
test(csv): boundary-dense chunking in test builds + stitching matrix
singaraiona Aug 17, 2026
bfb5b38
fix(core): normalize null and schema handling
singaraiona Aug 17, 2026
82661f4
perf(csv): parallelize the sym intern by per-column local dedupe
singaraiona Aug 17, 2026
2e6f8c8
test(csv): mixed-vocabulary column in sym_id_order; comment corrections
singaraiona Aug 17, 2026
5857e0c
perf(csv): fold bfb5b380's null scan into the finalizer's write sites
singaraiona Aug 17, 2026
3ebf8f2
fix(store): canonical SYM/STR nulls reach converted stores; HAS_NULLS…
singaraiona Aug 17, 2026
dfc0613
perf(query): fused equality on nullable SYM/STR columns
singaraiona Aug 17, 2026
12567b3
fix(group): canonical null for SYM/GUID keys in the radix emit
singaraiona Aug 17, 2026
0fb4d01
test(null): fused-relaxation and converted-store HAS_NULLS differentials
singaraiona Aug 17, 2026
47538c4
fix(collection,query): harden take/drop count-overflow family (#424)
belowzeroff Aug 25, 2026
782a63b
fix(csv): reject malformed separators and trailing garbage in typed t…
belowzeroff Aug 25, 2026
4297e72
fix: silent zero-match predicates — guid equality and like over list …
protocolstardust Aug 25, 2026
ca5a2d3
fix(join): compare GUID keys by full cell bytes (#425)
belowzeroff Aug 25, 2026
955a2fd
fix(agg): keep sum/prod list reductions exact and UB-free for i64 (#423)
belowzeroff Aug 25, 2026
8719121
fix(csv): reject impossible calendar dates in typed DATE/TIMESTAMP pa…
belowzeroff Aug 26, 2026
a4776b7
fix(storage): reject unsafe splayed column names (#434)
belowzeroff Aug 26, 2026
fabd746
fix(builtins): reject out-of-range numeric string casts (#432)
belowzeroff Aug 26, 2026
61c7c9c
fix(format): bound fmt_ensure growth; loud failure past 2GiB output (…
belowzeroff Aug 26, 2026
2b71135
fix(sort): one rule for where a null sorts, across every sort path (#…
ser-vasilich Aug 26, 2026
a4e38f1
fix(query): close the two ways an unresolved name still passed a sele…
ser-vasilich Aug 28, 2026
a93763c
fix(datalog): reject forged dl-program handles instead of dereferenci…
belowzeroff Aug 28, 2026
72f5810
refactor(ops): drop unreachable ISNULL paths; pin load-select mask re…
protocolstardust Aug 28, 2026
3fb5aff
fix(store): let a mapped string column's pool own the region they sha…
ser-vasilich Aug 28, 2026
a8102e6
feat(repl): add .repl.complete namespace completion verb (#441) (#442)
singaraiona Aug 30, 2026
b033fd2
fix(serde): reject table frames with mismatched schema/column counts …
belowzeroff Aug 31, 2026
057f519
fix(system): reject partially-numeric .ipc.open ports (#440)
belowzeroff Aug 31, 2026
86a7941
fix(repl): flush system command output (#443)
vbmithr Aug 31, 2026
322501d
fix: eliminate the three UBSan errors the test suite was swallowing (…
singaraiona Aug 31, 2026
0299511
fix(mem): size the scratch arena window from the backing block's real…
ser-vasilich Aug 31, 2026
dd80619
fix(mem): hand a cross-thread free back to its owner, and return idle…
ser-vasilich Aug 31, 2026
5d6bde8
fix(vec): flag sentinel nulls in every from_raw payload, not just SYM…
singaraiona Sep 1, 2026
ed46884
perf(query): append insert batches into a named table's columns in pl…
singaraiona Sep 1, 2026
657e853
fix(join): a null equi-join key equals another null key (#449)
protocolstardust Sep 1, 2026
14f366b
fix(format): pad table cells by display width, not byte length (#459)
singaraiona Sep 1, 2026
f1c54af
fix(journal): recovery skips log entries the snapshot already contain…
singaraiona Sep 1, 2026
4006e94
perf(join): route heavy-null build sides to the chained path upfront …
singaraiona Sep 2, 2026
5f20751
feat(ipc): bind a listener to a given address — loopback-only listene…
singaraiona Sep 2, 2026
612c0af
fix(serde): validate table/dict counts and lengths on decode (#452)
belowzeroff Sep 2, 2026
30a88e7
fix(query): handle guid membership predicates (#456)
belowzeroff Sep 2, 2026
04dc656
chore: record v2.5.15 squash (#413) as merged into dev
singaraiona Sep 2, 2026
a6eb246
fix(ipc): restrict server-state mutators under -U restricted IPC (#464)
belowzeroff Sep 3, 2026
451b08e
fix(query): accept SYM/STR HAS_NULLS segments on parted insert (#468)
singaraiona Sep 4, 2026
2ead9e7
fix(group): hash null keys identically on rehash and lookup (#467)
singaraiona Sep 4, 2026
adcd751
feat(ipc): add multicast fan-out (#470)
belowzeroff Sep 4, 2026
318b2b5
perf(query): one-pass in-place upsert and where-update for named tabl…
singaraiona Sep 6, 2026
3ab433e
fix(query): count a null as one distinct value in the grouped paralle…
ser-vasilich Sep 6, 2026
e6064d7
test(pool): drop racy main-thread-participation assert in zero_worker…
singaraiona Sep 6, 2026
5a6f9b3
fix(timer): skip missed intervals on overrun, and print a failing cal…
singaraiona Sep 6, 2026
24df86e
fix(app): exit non-zero when -p cannot bind instead of running withou…
singaraiona Sep 6, 2026
baa8c00
fix(ipc): say "timed out" when the wire handshake expires, not "refus…
singaraiona Sep 6, 2026
fd9014f
fix(pivot): keep a temporal type when both branches of an if share it…
ser-vasilich Sep 7, 2026
70d31af
fix(serde): round-trip builtins by full registered name (#482)
belowzeroff Sep 7, 2026
ecc14bd
fix(csv): infer Rayfall temporal forms (#481)
belowzeroff Sep 7, 2026
30712c9
chore: record v2.6.0 squash (#463) as merged into dev
singaraiona Sep 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ dist: release
# caps it; children inherit the env. Override for a fuller parallel stress,
# e.g. `make test TEST_CORES=0` (serial) or `make test TEST_CORES=8`.
TEST_CORES ?= 2
TEST_FILTER ?=
TEST_ARGS = $(if $(TEST_FILTER),-f $(TEST_FILTER),)

# Tests. Depends on $(TARGET) because test/rfl/system/ipc_diff.rfl
# spawns ./$(TARGET) as an IPC server via .sys.exec — both binaries
Expand All @@ -224,7 +226,7 @@ test: LDFLAGS = $(DEBUG_LDFLAGS)
test: $(LIB_OBJ) $(MAIN_OBJ) $(TEST_OBJ)
$(CC) $(CFLAGS) -o $(TARGET) $(LIB_OBJ) $(MAIN_OBJ) $(LIBS) $(LDFLAGS)
$(CC) $(CFLAGS) -o $(TARGET).test $(LIB_OBJ) $(TEST_OBJ) $(LIBS) $(LDFLAGS) -Itest
RAYFORCE_CORES=$(TEST_CORES) ./$(TARGET).test
RAYFORCE_CORES=$(TEST_CORES) ./$(TARGET).test $(TEST_ARGS)

# ─── ThreadSanitizer ────────────────────────────────────────────────
# Data-race detection for the lock-free pool/heap paths, which the
Expand Down
4 changes: 4 additions & 0 deletions docs/docs/language/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ A non-empty functional insert returns a new logical table view; the quoted-symbo

`upsert` is not supported on parted tables. Materialize a flat table or use an application-level update strategy when key-based replacement is required.

`upsert` into a named flat table (`(upsert 'book 'px row)`) writes matched rows in place and appends new keys, so its cost is proportional to the payload rather than to the rows already present. A multi-row payload (a table, or a list of column vectors) is applied in one pass; a key repeated inside the payload resolves to its last row. A single-row `upsert` locates its row through a `.idx.hash` index on the key column when one is attached and fresh, and by one scan of the key column otherwise. A payload with a mistyped value is rejected before anything is written.

`update` with `where:` into a named flat table writes the matched rows in place: the predicate is resolved through a fresh `.idx.hash` index on the column when it is a plain equality (`(== sym 'AAPL)`), elementwise update expressions (arithmetic, comparisons, and other atomic builtins over columns and literals) are evaluated over the matched rows only, and the results are scattered into the live columns. Any other expression, such as one with an aggregate, an order-dependent function like `deltas`, or a free variable, is evaluated over the whole table as before, so both spellings of `from:` agree. A mistyped or wrong-length value is rejected before anything is written.

## Joins

Rayforce supports equi-joins, outer joins, anti-joins, and time-series-aware joins.
Expand Down
4 changes: 3 additions & 1 deletion docs/docs/namespaces/time.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ Errors:
- `type` — non-`i64` `ms` / `num`, or `fn` not a lambda.
- `oom` — heap allocation failed.

The callback's return value is released and discarded — timers are side-effecting procedures. If the callback raises an error, the error is printed to `stderr` (prefixed `timer <id>:`) and the timer continues as if the call had succeeded; one fire is still counted toward `num`.
The callback's return value is released and discarded — timers are side-effecting procedures. If the callback raises an error, the error is printed to `stderr` as `timer <id>: error: <code>: <message>` (the same line the REPL would print) and the timer continues as if the call had succeeded; one fire is still counted toward `num`.

A callback that overruns its period does not replay the fires it missed. After each fire the timer re-arms at its next scheduled deadline, or one period from now if that deadline has already passed, so a periodic timer fires at most once per `ms` and the poll loop gets back to serving I/O between fires.

```lisp
;; Print "tick" every second, three times
Expand Down
354 changes: 354 additions & 0 deletions docs/multicast-implementation-plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,354 @@
# Rayforce Multicast Implementation Plan

## Goal

Add a first-class multicast/pub-sub subsystem to Rayforce as a core engine module, exposed to Rayfall through a `.mc.*` namespace and delivered over the existing IPC wire.

The target model is close to traditional ticker-plant style pub/sub, but adapted to Rayforce's current architecture:

- IPC handles are poll selector ids.
- Server-side code can push to connected clients through the same handle namespace.
- `.ipc.post` already provides async frames, but currently writes directly to the socket.
- The poll loop is single-threaded for IPC dispatch.
- Durable replay already exists through the journal layer.

The implementation should avoid UDP multicast initially. Rayforce needs typed payloads, authentication/restricted-mode behavior, replay, and per-client filtering; those fit application-level multicast over IPC much better than network-level multicast.

## Proposed User API

Expose multicast under reserved namespace `.mc.*`.

```lisp
(.mc.sub topic filter)
(.mc.unsub topic)
(.mc.pub topic payload)
(.mc.stats)
```

Initial semantics:

- `topic`: symbol or string, internally canonicalized to a symbol id or stable string key.
- `filter`: null, symbol vector/list, dict, or lambda. MVP should support only null and simple dict filters; lambdas can be a later phase.
- `payload`: any serializable Rayforce value, normally a table, vector, dict, or list.
- `.mc.pub` returns the assigned sequence number.
- `.mc.pub` returns `0` and does not create a topic when there are no active subscribers.
- `.mc.sub` uses `(.ipc.handle)` when called during inbound IPC evaluation. Optionally support explicit handle form later.
- pushed client message is an async IPC frame containing:

```lisp
(upd topic seq payload)
```

This mirrors the common pub/sub convention where downstream clients implement `upd`. In
Rayforce the delivered `topic` should be a string, not a bare symbol, because
unquoted symbol atoms in expression position are name references in Rayfall.
The payload argument must be wrapped as data on the wire, for example with
`(quote payload)`, so list payloads are not evaluated on the subscriber.

## Module Boundary

Add a static core module, not a dynamic plugin ABI.

Files:

- `src/core/mcast.h`
- `src/core/mcast.c`
- `src/ops/mcast.c` for Rayfall builtin wrappers, or place the wrappers beside the existing IPC builtins in `src/ops/system.c` if that is still the local convention.
- `test/test_mcast.c`
- `docs/docs/namespaces/mc.md`
- update `docs/docs/namespaces/index.md`

Suggested C API:

```c
typedef struct ray_mcast ray_mcast_t;

ray_mcast_t* ray_mcast_create(void);
void ray_mcast_destroy(ray_mcast_t* mc);

ray_t* ray_mcast_sub(ray_poll_t* poll, int64_t handle,
ray_t* topic, ray_t* filter);
ray_t* ray_mcast_unsub(ray_poll_t* poll, int64_t handle,
ray_t* topic);
ray_t* ray_mcast_pub(ray_poll_t* poll, ray_t* topic, ray_t* payload);
ray_t* ray_mcast_replay(ray_poll_t* poll, ray_t* topic,
int64_t from_seq);
ray_t* ray_mcast_stats(ray_poll_t* poll);
void ray_mcast_on_close(ray_poll_t* poll, int64_t handle);
```

Store the module instance on `ray_poll_t` as an opaque pointer:

```c
void* mcast;
```

Reason: Rayforce IPC handles are poll-local selector ids, so multicast subscriptions and outbound queues naturally belong to the poll that owns the connections.

## Internal Data Model

Core structures:

```c
typedef struct ray_mcast_sub {
int64_t handle;
ray_t* filter;
int64_t last_sent_seq;
int64_t dropped;
} ray_mcast_sub_t;

typedef struct ray_mcast_topic {
int64_t topic_sym;
int64_t next_seq;
ray_mcast_sub_t* subs;
int32_t n_subs;
int32_t cap_subs;
} ray_mcast_topic_t;

typedef struct ray_mcast {
ray_mcast_topic_t* topics;
int32_t n_topics;
int32_t cap_topics;
int64_t published;
int64_t delivered;
int64_t dropped;
} ray_mcast_t;
```

MVP can use linear arrays, matching the current small fixed/simple style in the runtime. Replace with hash tables only when subscriber/topic counts make it necessary.

Memory ownership:

- retain `filter` on subscribe;
- release `filter` on unsubscribe/close/destroy;
- publish payload should be retained only while building queued outbound frames;
- avoid storing published payloads in memory unless replay cache is explicitly implemented.

## Delivery Path

Phase 1 can call the existing async IPC send path, but the production design should introduce queued transmit.

Current issue:

- `ray_ipc_send_async` resolves a handle and immediately calls the socket write path.
- That can block the publish path on slow subscribers or large payloads.

Required engine improvement:

1. Split IPC frame creation from socket writing.
2. Add per-selector TX queue.
3. Teach poll backends to watch socket writability when TX queue is non-empty.
4. Let multicast enqueue frames to each subscriber and return quickly.
5. Apply per-connection queue limits.

Suggested helper boundary:

```c
ray_err_t ray_ipc_enqueue_async(ray_poll_t* poll, int64_t handle, ray_t* msg);
ray_err_t ray_ipc_enqueue_frame(ray_poll_t* poll, int64_t handle,
uint8_t msgtype, ray_t* msg,
uint8_t extra_flags);
```

`ray_ipc_send_async` can then become a wrapper over enqueue for poll-owned connections.

## Backpressure Policy

Make slow-client behavior explicit per topic or process.

Policies:

- `disconnect`: default for event streams where loss is unacceptable.
- `drop-oldest`: useful for telemetry and snapshot-like topics.
- `drop-latest`: useful when preserving queued order matters more than newest value.
- `coalesce`: later optimization for keyed state topics, e.g. latest quote per sym.

MVP default:

- bounded queue per connection;
- if full, disconnect subscriber and increment dropped/slow counters.

This is stricter than silently dropping, and easier to reason about for market/event data.

## Filtering

Start narrow.

Phase 1 filters:

- null filter: receive every message for the topic;
- dict filter for common table payload columns, e.g. `{sym: [AAPL MSFT]}`;
- symbol/list filter shorthand can map to `{sym: ...}` only if we explicitly document that convention.

Avoid lambda filters in the first implementation. Calling Rayfall lambdas per subscriber inside publish adds eval reentrancy, no-closure edge cases, unpredictable latency, and error semantics that are not needed for the first useful version.

For table payloads, filtering should create a selected table per subscriber only if needed. If multiple subscribers have the same filter, later optimization can cache the filtered payload for that publish call.

## Durability And Replay

There are two useful stream classes:

- state streams: quotes, metrics, book snapshots; loss can be repaired by a fresh snapshot;
- event streams: trades, orders, audit; loss requires replay or disconnect.

MVP:

- assign sequence numbers per topic;
- `.mc.pub` writes a journal expression before fanout if multicast journaling is enabled;
- `.mc.replay` can initially return an explicit `nyi` until journal indexing is designed.

Durable phase:

- journal each publish as `(list '.mc.apply topic seq payload)`;
- on recovery, rebuild topic sequence counters and optional retained state;
- add a compact side index by topic/seq if replay from large logs matters.

Do not rely on the generic journal alone for efficient replay. It can reconstruct state, but topic-range replay needs indexing or a retained log table.

## Restricted Mode And Security

Recommended builtin flags:

- `.mc.sub`: allowed in restricted IPC mode.
- `.mc.unsub`: allowed in restricted IPC mode.
- `.mc.stats`: allowed, unless it leaks sensitive details.
- `.mc.pub`: restricted by default.
- `.mc.replay`: allowed only if it returns data the caller is already authorized to receive.

Auth should remain at IPC handshake level. Fine-grained authorization can be added through `.ipc.on.auth` or a future `.mc.auth` policy hook, but do not add that in MVP.

## Lifecycle Integration

1. Initialize `poll->mcast` lazily on first `.mc.*` call.
2. Destroy it in `ray_poll_destroy`.
3. Call `ray_mcast_on_close(poll, sel->id)` from IPC close handling before `.ipc.on.close` runs.
4. Ensure selector id reuse cannot leak subscriptions: close cleanup must run before the selector slot can be reused.
5. If listener teardown destroys all selectors, multicast cleanup should release every retained filter and queued message.

## Implementation Phases

### Phase 0: Design Lock

- Add this plan to the repo.
- Decide exact names: `.mc.*` vs `.ipc.pubsub.*`.
- Decide whether topics are symbols only or symbol/string.
- Decide whether `.mc.sub` takes explicit handle in addition to current IPC handle.

Recommended decisions:

- use `.mc.*`;
- accept symbol or string but canonicalize internally;
- MVP uses current IPC handle only; add explicit admin forms later.

### Phase 1: Minimal Core Multicast

- Add `src/core/mcast.h`.
- Add `src/core/mcast.c`.
- Add `void* mcast` to `ray_poll_t`.
- Add create/destroy/lazy-get helpers.
- Implement topic lookup, subscribe, unsubscribe, close cleanup, stats.
- Implement publish using a bounded nonblocking send path or a small internal enqueue placeholder if TX queue work is started immediately.
- Register `.mc.sub`, `.mc.unsub`, `.mc.pub`, `.mc.stats`.
- Add docs page with MVP semantics and limitations.

Tests:

- subscribe from an IPC client;
- publish delivers `(upd topic seq payload)` to that client;
- two clients receive the same message;
- unsubscribe stops delivery;
- close removes subscriptions;
- `.mc.stats` reports topic/subscriber counts.

### Phase 2: TX Queue And Nonblocking Fanout

- Refactor IPC frame serialization into reusable frame builder.
- Add TX queue to `ray_selector`.
- Add poll backend write readiness support for Linux epoll and macOS kqueue.
- Change `.ipc.post` to enqueue instead of direct socket write where possible.
- Add queue byte/message limits.
- Add disconnect-on-overflow policy.

Tests:

- large payload fanout to multiple subscribers does not block publish on the first slow reader;
- queue overflow disconnects or drops according to configured policy;
- queued frames preserve order on a single connection;
- sync `.ipc.send` still pumps inbound pushed async frames correctly.

### Phase 3: Filters

- Implement null filter.
- Implement dict equality/inclusion filter for table payloads.
- Implement topic-level filter validation at subscribe time.
- Return clear `type`/`domain` errors for unsupported filters.

Tests:

- `{sym: [AAPL MSFT]}` receives matching rows only;
- non-table payload with table-column filter errors or is skipped according to documented policy;
- multiple subscribers with different filters get different payloads.

### Phase 4: Durability And Replay

- Add `.mc.config` or process-level config for durable topics.
- Journal publish records before fanout.
- Implement replay API from retained in-memory log or journal side index.
- Add startup recovery behavior for sequence counters.

Tests:

- after replay/restart, next sequence continues after last published seq;
- replay from seq returns expected messages;
- corrupted tail follows existing journal validation behavior.

### Phase 5: Operations Surface

- Add `.mc.topics`.
- Add `.mc.subs topic`.
- Add `.mc.config` for queue limits and policy.
- Add querylog/profile integration if needed.
- Add documentation examples for ticker-plant style market data.

## Test Strategy

Add `test/test_mcast.c` using the existing IPC test style:

- create runtime and poll;
- start poll server thread;
- connect clients with `ray_ipc_connect`;
- install client-side `.ipc.on.async` or use pushed eval side effects as current tests do;
- publish from server-side eval or direct C API;
- use sync round-trip as an ordering barrier.

Also add Rayfall integration tests under `test/rfl/system/` once the `.mc.*` namespace exists.

Regression areas:

- selector id reuse after close;
- restricted mode access;
- non-serializable payloads;
- publish from inside `.ipc.on.sync`;
- publish while a client is already in sync wait;
- large compressed payloads;
- cleanup on poll destroy.

## Open Questions

- Should `.mc.pub` be allowed locally only, or also from authenticated unrestricted IPC clients?
- Should sequence numbers be global or per topic? Recommendation: per topic.
- Should the pushed function name be fixed as `upd`, or configurable per subscription? Recommendation: fixed first.
- Should filters be applied before journaling or after? Recommendation: journal original payload, filter only for delivery.
- Should replay use existing `.log` files or a dedicated multicast log table? Recommendation: use existing journal for recovery, add a topic/seq index for replay.

## Initial Acceptance Criteria

The first merge is useful if it satisfies:

- a Rayforce process can accept two IPC clients;
- both clients can call `.mc.sub`;
- server can call `.mc.pub`;
- both clients receive async `(upd topic seq payload)` messages in order;
- closing one client removes only that client's subscriptions;
- restricted clients can subscribe but cannot publish;
- tests cover lifecycle, fanout, and close cleanup.
Loading
Loading