Skip to content

Instantly share code, notes, and snippets.

@cablehead
cablehead / README.md
Last active October 21, 2026 18:08
stardust: subscription with a schema clause grows on every commit

stardust: subscription with a schema clause grows on every commit

while a subscription to a query with a [schema ...] clause is open, each commit that changes its result adds memory: about 0.25 MB per commit with 4000 matching entities. releasing the subscription doesn't free it, and a new subscription doesn't reuse it. the same query without the schema clause stays flat.

release: stardust-alpha-2610171653, linux_amd64, libstardust.so.

@cablehead
cablehead / README.md
Last active October 22, 2026 03:02
stardust: memory per thread is never reclaimed

stardust: memory per thread is never reclaimed

each os thread that runs a query leaves memory behind, and it isn't freed or reused when the thread exits. so memory grows with the number of distinct threads that ever ran a query, not with the number of queries.

release: stardust-alpha-2610171653, linux_amd64, libstardust.so.

repro (c abi only)

@cablehead
cablehead / fold.md
Last active October 20, 2026 18:09

reactor:

  counter/increment {
    live  true
    query {find  [?i ?c ?next]
           where [[?i impulse tick] [not [?i folded true]]
                  [?c counter true] [?c count ?n]
                  [[+ ?n 1] ?next]]}
 patch {?c {count ?next} ?i {folded true}}
@cablehead
cablehead / stardust-abi.md
Last active October 19, 2026 16:05
stardust c abi (alpha-2610171653)

stardust c abi, alpha-2610171653, STARDUST_ABI_VERSION 1 (releases).

conventions:

  • calls return a uint32_t status (STARDUST_OK = 0) unless marked infallible.
  • inputs are borrowed for the call. each owned output is released once.
  • a failed factory still returns a handle carrying only its error; read it with the matching *_error call, then release it.
@cablehead
cablehead / stardust-alpha-2610171653.md
Last active October 19, 2026 03:07
stardust alpha-2610171653: abi and rust sdk changes

@../stardust-alpha-2610171653 new stardust release. give me an overview of changes in the abi and in the rust sdk

changes from alpha-2610112101 to alpha-2610171653 (released 2026-10-17). releases

set_notify shipped, close to the proposal. rust subscriptions are now async only.

@cablehead
cablehead / ctx-ownership.md
Created October 16, 2026 01:00
stardust_db_subscription_set_notify: who owns ctx

the caller owns the ctx; stardust just keeps a copy of the pointer. the caller MUST keep that memory valid until stardust_db_subscription_release returns (cancel is not enough), and it must be safe to access from any thread, concurrently with the caller's own code.

it relies on a guarantee from stardust:

After release returns, notify is not running and does not run again.

@cablehead
cablehead / stardust-subscribe-signatures.md
Created October 15, 2026 07:09
Stardust Rust: query subscription signatures, sync release vs async docs

Stardust Rust: subscribing to a query today

Sync: release alpha-2610112101 (abi/bindings/rust/src/db.rs)

impl Database {
    pub fn query<'a>(&self, source: impl Into<Source<'a>>) -> Result<Query>; // stored path or inline Document
}

impl Query {
/* Existing: stardust.h, release alpha-2610112101. */
/* Subscribe copies the query's definition (frozen: later
* definition edits do not apply) and parameters. Event 1 is the initial result.
* Later events are full results computed after relevant commits.
* sequence counts events delivered to this subscription.
* superseded counts intermediate computed results this subscription skipped.
* It does not count commits or changed rows.
* The first event has superseded 0.
* transaction is the database head used to compute the result. The caller owns event.result.
@cablehead
cablehead / jev-2048.md
Last active September 23, 2026 13:44
kicking the tires on jev with 2048

kicking the tires on jev with 2048

You can watch these strategies play out here: https://jev-with-2048.ndyg.cross.stream

I finally got a chance to kick the tires on jev (jev-1.13.0). I thought it'd do really well playing 2048.

the strategy I used was: hand it the current board state and give it the option of up, down, left, right. I tried that 4 ways (the jev rows in the table).. each row links to the request I sent.

with just the board it does about as well as making random moves. it does best when code works out what each move would do to the board and jev picks from those.. then it's about as good as a fixed rule (e.g. always left if that moves anything, else down, else right, else up).

@cablehead
cablehead / 2048-score-discrepancy.md
Last active June 19, 2026 18:08
2048: why two identical boards can have different scores (the 432-point discrepancy)

2048: why two identical boards can have different scores

Two long games reached effectively the same position but finished with different scores: 1,811,320 vs 1,810,888, a gap of 432. The boards looked the same, so the scores "should" have matched. They don't, and there is no bug. Here is the full explanation, with the exact numbers.

The snapshot where the two boards coincide

There is a moment where both games show an identical set of 16 tiles (total