Bounded history and graph queries¶
These APIs are in the development checkout and are not in published Core 0.2.0. They keep ordinary browsing separate from complete ledger exports. See the CLI reference for command syntax.
Choose the projection¶
from optpilot import experiment
store = "my-project/.optpilot/experiments"
page = experiment.history(store, limit=50)
following = experiment.history(store, limit=50, cursor=page["nextCursor"]) if page["hasMore"] else None
active = experiment.history(store, states=["queued", "running", "waiting"])
canvas = experiment.graph_page(store, limit=50, max_versions=300)
focused = experiment.graph_page(store, focus_run="RUN_ID")
neighbors = experiment.graph_page(store, focus_version="VERSION_ID")
trials = experiment.trial_page(store, "RUN_ID", limit=50)
versions = experiment.version_page(store, limit=100)
For an explicit edit saved settings action, use
experiment.selection_for_run(store, "RUN_ID"). It reads the complete effective
selection from the frozen review in one transaction, without trial bodies or
logs. Graph and summary projections can omit inputs; never use their membership
lists to author a replacement review. The selection API preserves case order,
fixed baselines, generator settings, SSH target and resource budgets, and raises
an error when the frozen review is missing or inconsistent. It does not recover
the author's original alias names or redundant explicit-versus-suite syntax.
| API | Default / maximum | Contents |
|---|---|---|
history |
50 / 100 runs | Run identity, review, state, timestamps, counts and comparison settings. No trial bodies. Optional state filter. |
graph_page |
50 / 100 runs; 300 / 1,000 versions | Run summaries and retained version context. A focus selects one run or a version's indexed neighborhood and related runs. |
trial_page |
50 / 200 trials | Metrics, state and identities. Attempt count is retained; evidence and attempt bodies are omitted by default. |
version_page |
100 / 500 versions | Retained versions in reverse insertion order, including older unexecuted artifacts. |
run_references |
At most 100 specified run IDs | Exact review identity and whether one specified version was actually used. Intended for provenance verification, independent of graph clipping. |
summary |
One specified run | Comparison settings, states and aggregates without trial or generation bodies. |
trial_evidence |
One specified trial; 64 KiB default, 256 KiB maximum | Explicitly selected evidence/attempt record, or unavailable: "too-large". The run ID must match. |
generation_page |
20 / 100 receipts | Generator input and feedback receipts up to 64 KiB each; larger inputs are explicitly omitted. |
graph, detail |
Complete results | Compatibility/export operations that can return the entire graph or every trial in a run. Their payloads grow with the ledger. |
history and trial_page return nextCursor and hasMore alongside their records. The graph puts these fields under page. Pass a cursor back unchanged to the same query and ledger. A changed filter or another ledger requires a fresh first page.
History orders by creation timestamp and run ID, newest first. The first page records an insertion watermark, so later inserts do not move into the remaining pages, even when their timestamps are older. Version pages use the same insertion-membership rule, ordered by retained insertion sequence. Each call reads one SQLite snapshot. Execution state can still change between pages: the cursor does not retain a database transaction across requests. Refresh active-run queries as recovery progresses.
Understand an incomplete graph¶
page.hasMore means older matching runs have another page. page.truncated means version context or summary groups reached a projection limit. Runs with clipped membership or aggregates also carry projectionTruncated. An absent node in such a graph does not prove that a version was unused. Focus that node directly, inspect the complete record, or use exact provenance verification:
The returned run includes usedVersionIds: ["VERSION_ID"] only for an actual retained membership, otherwise an empty list. Unknown run IDs are omitted. The target must be a nonempty string; it need not identify an existing version, allowing a caller to check the returned run identity itself. Reviewed selection alone is not treated as evidence of use.
The first unfocused graph page also includes recent artifacts that have not run. Dependency context and derivations are clipped to the returned node set. This is not an exhaustive catalog of every historical, unexecuted version. Use version_page to browse that history, focus queries for a particular node or an explicit full graph export. Version-page entries retain up to 1,000 direct dependency IDs and mark larger lists with projectionTruncated; fetch the exact version record before using a clipped list to make a pinned selection.
Graph summaries calculate counts and aggregates without transferring raw trial evidence. They include resource-registry summaries scoped to the displayed runs, reading activity owners in batches of 256 from one registry snapshot. At most 100 distinct resource cards are retained per response; omitted cards mark the resource summary unavailable/truncated and the run projection truncated, while visible cards retain complete quantities. Detailed allocation/receipt views remain separate. Harbor summaries prefer reported job totals and fill missing fields from streamed trial usage scalars, without transferring evidence or model-usage maps. Aggregate groups are capped at 1,000 and metric groups at 10,000 per response, with truncation reported. Counts, node limits and preview limits control common response sizes; arbitrary user-authored names and metric keys mean there is no universal fixed byte-size guarantee.
Trial previews expose attemptCount and an empty attempts array when bodies are omitted. With include_evidence=True, a trial whose retained JSON exceeds 64 KiB returns its basic fields and evidenceUnavailable: "too-large". Use the complete detail/export path when the whole record is required. Replay availability is preserved in both preview modes. These previews are not evidence backups.
Routine inspector polling should call summary and request a trial page separately. Its aggregates field is also present under summary.aggregates. A metric includes binarySuccesses only when every scored value is exactly zero or one, so a score visualization does not need raw trials to identify binary outcomes. Optional states and candidate_version_id filters on trial_page select across the entire run and are bound into its cursor.
Fetch trial_evidence when the user selects a trial, and generation_page when viewing generator feedback. A selected trial exceeding the byte budget returns its retained size and an unavailable reason, without transferring the body. Oversized generation receipts return basic identity/state fields and inputUnavailable: "too-large". Complete records remain accessible through explicit detail/export. External summary data in summary is capped at 64 KiB and similarly marked unavailable if larger.
Read and write boundaries¶
experiment.py retains admission, cancellation and execution. _experiment_queries.py owns the complete read projections and _experiment_browse.py owns the bounded ones. The existing public experiment.graph, detail, version and version_file names remain available.
Experiment migrations add history indexes and four derived query tables:
version_edgesindexes dependency links;review_versionsindexes reviewed membership.query_trialsstores compact trial identity, state and metrics without evidence or logs.query_trial_versionsindexes actual retained version use.
SQLite triggers update these projections in the same transaction as their authoritative version, review, native-trial or imported-trial record. Migration backfills existing data. Query tables are excluded from portable evidence bundles; inserting restored primary records rebuilds them. Dependency targets have no foreign key requiring a particular version insertion order.
Means, minima and maxima are still computed from compact trial rows. A small exact numeric accumulator preserves cancellation precision and avoids an overflowing intermediate sum when finite scores are very large. There is no separately cached aggregate that can become stale when a trial changes state. The indexes trade storage and write work for faster reads, so the benchmark records database size and seeding time as well as read latency. Schema upgrades retain the backup and recovery rules.
Reproduce the measurements¶
From the development checkout:
uv run python scripts/benchmark_queries.py \
--runs 1000 10000 --large-run --include-full \
--output query-benchmark.json
The script creates deterministic synthetic ledgers in temporary directories, runs no graders or external services, and removes those ledgers afterward. The default cases have ten trials per run. --large-run adds one run with 100,000 trials and 100,004 versions to exercise a large individual comparison. Results contain no real experiment data.
The following measurements were collected on December 1, 2026 with Python 3.12.12, SQLite 3.50.4, macOS/Darwin arm64 and experiment schema 6. Times include opening and checking the database, building the projection and JSON serialization. Bounded queries use three samples; full exports use one. Filesystem caches were not flushed, so these are local measurements, not cold-start or cross-platform latency guarantees.
| Ledger | History page median | Graph page median | Graph JSON | Full graph export, one sample | Full graph JSON |
|---|---|---|---|---|---|
| 1,000 runs / 10,000 trials | 1.29 ms | 4.47 ms | 117,297 bytes | 64.19 ms | 1,518,167 bytes |
| 10,000 runs / 100,000 trials | 1.35 ms | 4.72 ms | 117,299 bytes | 643.91 ms | 15,162,167 bytes |
| One run / 100,000 trials | 11.37 ms | 129.95 ms | 56,867 bytes | Not measured | Not measured |
For the large individual run, focused run and version queries took 140.92 ms and 140.74 ms respectively; a 50-trial preview took 1.28 ms and returned 17,457 bytes. Before adding the compact trial indexes and capped membership seeks, that run's graph page took 1,080.75 ms median. The 10,000-run synthetic database occupied 221,577,216 bytes after indexing and took 6.83 seconds to seed. Those values describe this fixture, including its deliberately repeated identities and retained evidence. A bounded inspector summary for the 100,000-trial run took 141.89 ms and returned 11,979 bytes; fetching one selected trial took 0.90 ms and returned 491 bytes. These samples were collected during local development; system contention and cache state affect timings.
Raw measurements: current projections and before compact trial indexing. The earlier artifact used the same dataset dimensions and timing method, but predates the compact trial projection and state-filter index.
Unit tests check cursor scope and insertion stability, state filtering, bounded payloads, exact provenance, import coverage, zero scores, replay availability, trigger updates/deletes and query counts that do not grow once per returned run. Latency is measured by the benchmark rather than asserted against a machine-dependent timing threshold in unit tests.