Skip to content

refactor(global): the host's tables, content and the sweep stand behind ports - #307

Merged
rami-hatoum merged 3 commits into
mainfrom
refactor/the-hosts-tables-content-and-sweep-stand-behind-ports
Oct 23, 2026
Merged

rami-hatoum merged 3 commits into
mainfrom
refactor/the-hosts-tables-content-and-sweep-stand-behind-ports

Conversation

@rami-hatoum

Copy link
Copy Markdown
Contributor

What this changes

Three places where a store was bound to one way of reaching it.

  • The workflow host's tables run through the ledger's connection. The host opened its own SQLite file through the native addon, or its own PostgreSQL pool, though its tables must sit in the ledger's database, which the ledger had already opened. Both ledger layers now provide a LedgerConnection beside the Ledger, with its dialect, streams, reads, writes, transactions, consistent reads and clock, and the host runs every statement through it; the host opens, closes and loads no database of its own, its driver dependencies are gone, and the SQLite and PostgreSQL code it held moved into the ledger with its tests. A server holds 14 PostgreSQL connections instead of 24.
  • Content speaks to a bucket. The content store, its staging and the sweep of unfinished uploads were built on an S3 client. They now speak to a Bucket port, put with copy, streaming get, head, delete, list and unfinished, whose one implementation sends the same S3 commands as before.
  • The sweep of orphaned content is a chore a clock calls. The ledger forked an hourly timer of its own; sweepOrphans(now) now sweeps and answers when it is next due, and the host runs it as part of its wake-up, so only the server holding the workflows sweeps, and closing the ledger still waits for a sweep under way.

Tests

  • The host's suite on SQLite and PostgreSQL through the ledger's connection; the content store, staging and sweep against a fake bucket and against S3's commands as before; the chore called directly, with the next due time answered.
  • pnpm check passes on each commit, with the PostgreSQL suites running.

@rami-hatoum
rami-hatoum force-pushed the refactor/the-hosts-tables-content-and-sweep-stand-behind-ports branch from fb45e61 to 90d96d3 Compare October 23, 2026 17:15
rami-hatoum and others added 3 commits October 23, 2026 18:26
… of the ledger it is given

The workflow host opened its tables itself, on a SQLite file through the native addon or on
PostgreSQL, though they must sit in the ledger's own database, which the ledger has already
opened. The ledger's layers now provide, beside Ledger, the connection of the ledger,
LedgerConnection: the dialect it speaks, an event store over its connections for streams kept
beside the ledger, and read, write, transaction, readConsistently, sharedClock and migrated. On
SQLite it runs on the ledger's one pool; on PostgreSQL its statements run on a pool of four the
ledger keeps for them and its streams on the ledger's own pool.

The host's store takes that connection, whatever store it is, and runs its statements, its leases,
its snapshot chunks and its run logs through it. The host opens, closes and loads no database of
its own, and its driver dependencies go. The server reads the connection from its runtime and
hands it to the host's store; the host's own report of a lost connection goes with its pools, since
its connections are the ledger's, which logs those it loses. A private database in memory is now
one database for the ledger and the host.

The tests and the measurements open a ledger on the settings of a database and the host over its
connection, through src/ledger-testing; the tests of the PostgreSQL statements, the snapshots and
the statement move to the ledger with the code they test.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…p speak to a bucket port

Content kept outside the ledger was built directly on an S3 client, so a store of content that is
not S3 had no port to stand behind. The package now names a Bucket port: put, of bytes in hand,
conditional on the key being absent, of a stream, or of another object of the bucket; get, which
streams the object's body; head; delete; list by prefix; and unfinished, the puts of a stream that
never finished, each with its abandon. bucketOnS3 is its one implementation, over the S3 client,
and sends the requests the adapter sent before. objectContentOn keeps content on any bucket: its
puts, reads, staging and sweep of uploads speak to the port alone, and the digest of what is read
back stays the content store's.

Beside put, get, head, delete and list, the port copies, since a content larger than one chunk is
uploaded before its digest is known and moves under its digest without sending its bytes again,
and names the puts that never finished, since an interrupted multipart upload is no object a
listing finds and the sweep aborts it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…'s clock calls

The hourly sweep of orphaned content was forked by the ledger on a clock of its own. It is now a
chore, sweepOrphans(now), which sweeps what puts that never finished left an hour before now and
answers the next time it is due, an hour on, logging a sweep that fails as before; nothing in the
ledger forks a timer. Both layers provide it beside Ledger and the connection, as LedgerChores,
and a close still waits for a sweep under way.

The workflow host performs a chore as due work of its wake-up, choreWork: at the first wake-up,
then whenever the chore answered it is due, in the lane no wake-up waits for. The server reads the
ledger's chores from its runtime and hands the host the sweep so. The host that holds the
database's workflows now sweeps for every server on the database, where every server swept it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@rami-hatoum
rami-hatoum force-pushed the refactor/the-hosts-tables-content-and-sweep-stand-behind-ports branch from 90d96d3 to ae6398e Compare October 23, 2026 17:36
@rami-hatoum
rami-hatoum merged commit 54f59e8 into main Oct 23, 2026
20 checks passed
@rami-hatoum
rami-hatoum deleted the refactor/the-hosts-tables-content-and-sweep-stand-behind-ports branch October 23, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant