Skip to content

Select a derivation by its version, switch while inputs arrive, keep a paused derivation's dirty marks - #3235

Merged
Sinity merged 3 commits into
masterfrom
derivation-selection-live-store
Nov 26, 2026
Merged

Sinity merged 3 commits into
masterfrom
derivation-selection-live-store

Conversation

@Sinity

@Sinity Sinity commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

On a store that captures continuously, the documented ways to recompute or switch a keyed derivation could not be used after a deploy. This change fixes the three defects behind that and two reads that made a comparison and a switch impractical at the deployed store's size.

What changed

The selection is the version. registry.derivations held the version and the build that selected it, and recompute compared both with the running build, so every deploy left every derivation refusing recompute NAME [--since] with "producer version changed" although no version had changed. The build column is dropped (schema step selection_by_version); recompute, the on-request computation and status compare versions only. The build stays where it is provenance: on each run's manifest, in each comparison and in the producer_switch operation. A derivation that never ran has no selection: recompute is accepted for it and status reports never_run instead of a pending switch. status no longer has selected_build.

A comparison is a trial, not a hold on the inputs. A comparison refused itself at its end, and its switch was refused, if any event of an input kind had been committed since it started. A comparison that outlasts the gap between two inputs could therefore never be selected. The rule is removed, with InputState and its two SQL files. A switch now needs a full comparison, not yet consumed, that the running build made of the same version, declaration and logical-day settings. Unchanged inputs are not needed for correctness: a keyed recompute switch archives the live output chains and marks dirty every key its inputs or outputs name in one writer transaction, and admission marks whatever is committed after it; a per-event recompute switch resets the saved position; keep_history applies from the switch onward. The rule protected only the comparison's counts. What keeps those honest instead: each key is computed and its stored outputs are read in one snapshot, and a key that was dirty in that snapshot (or a per-event input after the saved position) is counted as behind its inputs. The comparison stores that count and the commit positions it ran between, and its summary line shows it.

A derivation turned off is paused. The daemon removed configured-off derivations from the writer's dirty-marking list, so inputs admitted meanwhile marked nothing and those keys stayed stale after the derivation was turned on. The writer now marks the keys of every keyed derivation the build has, as the offline admin commands already did; only the runner's list follows the configuration.

A key's stored outputs are read from its members. derivations::outputs joined derivation.outputs to core.events on the event ID with nothing to bound it. It now takes the key's live member IDs from the membership index and reads their rows by ID inside their ID bounds and under the derivation's name, the leading segment column of compressed batches. The comparison and the provenance stamping of analysis.products and context.packs use this read.

A keyed switch finds its outputs by membership and walks their chains once. The switch selected a derivation's outputs with core.events WHERE source = $1 inside the writer transaction; uncompressed chunks have no index led by source. A keyed derivation's outputs are now read from derivation.outputs. A per-event derivation keeps no such list and still uses the source read (filed as sxnext-pib.27). The walk down the output chains now probes the child index once per event; joined flat, the planner could not size the recursion and scanned the whole core.event_children index once per level. The switch then marks keys from that set directly, where it used to walk the same chains a second time through mark_archived_dirty.

Decisions and the alternatives rejected

  • Build out of the selection, rather than kept and made to follow the running build at start: a column whose only use is to be overwritten at every start invites the comparison back.
  • The comparison stays tied to the build that made it: while a version is being developed and not yet selected, its code changes under the same number, so another build's comparison is not a trial of the code that would switch.
  • No snapshot held for the whole comparison (it would keep chunk locks and hold back vacuum for tens of minutes and the switch would still not depend on it), and no re-comparison of changed keys at the switch.
  • A daemon started without a configuration file also marks keys; marking only for derivations a configuration names would leave the same gap.
  • The decided target sentence in docs/derivations.md said replay --switch ID "refuses changed inputs". That clause described this mechanism, so it now says the switch consumes the trial whatever arrived since. The client form is untouched.

Figures

Read-only measurements on the deployed store (sinexd a3f4eb3, 2026-11-26, cached):

Read Before After
stored outputs of one state.intervals day key with 594 live outputs cancelled at the 120 s statement timeout 3.5 ms, 1,974 buffers, 30 of 32 chunks excluded
stored outputs of an older day key, 485 live outputs not run 2.9 ms, 1,932 buffers
a switch's selection of state.intervals outputs plan: parallel sequential scan of every uncompressed chunk (96 GB of 113 GB); not run part of the walk below
a switch's walk of state.intervals' output chains (89,917 live outputs, 410,551 events) flat join from the memberships: cancelled at 150 s (plan: one scan of the 79-million-row child index per level) 71 s, one index probe per event, 136,630 buffers read from disk

The "after" rows were measured by running the new statements by hand; the comparison and the switch themselves were not run on the deployed store.

Not improved here: the switch still archives every live output chain in one writer transaction, 410,551 events for state.intervals. That is sxnext-pib.20's subject, which recorded about 390,000 outputs archived in about 30 minutes of writer time.

Verification

  • cargo xtask check on 5ec539e (AgentCTL job 4279).
  • cargo xtask test -p sinex-schema -p sinex-store -p sinexd -E '<schema; store derivations, registry, telemetry, admission; sinexd derivation_runner, api versions and comparisons, daemon, dirty_keys, lifecycle; integration paused_derivation and documents>': 224 passed (AgentCTL job 4271).
  • Hosted run 45896685588 on 5ec539e: check passed; test ran 997 tests and failed one, publisher_resumes_at_its_position_after_the_upgrade, whose fixture rebuilds the schema at version 47 and so lacked the column the new step drops. f12e368 gives the fixture that column; the publisher, reader-context and writer tests pass locally (AgentCTL job 4294). The hosted checks on that head are the verification of record.
  • Hosted Codex security review on 5ec539e: completed with no findings.
  • New and changed tests: a second build identity of the selected version recomputes a time range and stores nothing again; a switch consumes only a comparison its own build made; inputs committed between a comparison and its switch are computed by the switched version, in a key the comparison saw and in one it never saw; a comparison counts the keys behind their inputs and records its positions; a daemon with shell.sessions off admits a command, and the session appears after a restart with it on; the public recompute with a time range marks keys; status shows a pending switch only for another version; a key's outputs are read from plain and compressed chunks; the schema step keeps every selected version.

Not verified: acceptance row 4 of the task (compare, switch and a time-range recompute on the deployed store), which needs the deploy. The full workspace test run is left to the hosted checks.

Deployment

The schema moves from version 50 to 51: stop sinexd, run systemctl start sinex-schema-upgrade, start sinexd. The step drops one column and rewrites nothing.

Task: sxnext-pib.25

🤖 Generated with Claude Code

https://claude.ai/code/session_01UuFixsXwismFLxbfWcuXHU

Sinity and others added 2 commits November 26, 2026 21:48
Work in progress for the three selection defects: the build leaves the
selection, a comparison stops requiring unchanged inputs, and a derivation
turned off keeps its dirty marks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UuFixsXwismFLxbfWcuXHU
The switch joined the recursion flat to core.event_children, which the
planner turned into a scan of the whole child index per level, and then
walked the same chains again through mark_archived_dirty. On the deployed
store the flat walk of state.intervals' chains was cancelled at 150 s; the
probe form took 71 s for 410,551 events.

Stored comparison examples use one form for keyed and per-event
derivations.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UuFixsXwismFLxbfWcuXHU
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-26T21:20:52.246973Z 5ec539e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

… drops

Its database is rebuilt at schema version 47, before selection_by_version,
so the step needs the build column to be there.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UuFixsXwismFLxbfWcuXHU
@Sinity
Sinity merged commit bc3adb9 into master Nov 26, 2026
2 checks passed
@Sinity
Sinity deleted the derivation-selection-live-store branch November 26, 2026 21:45
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