You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(spiraldb): one client and schema-table read per process; as_table counts as it reads (ITL-1457) - #682
Part of ITL-1457. Replaces #553 and #555. #554 was already superseded by #675 (ITL-1774, pinned-handle reuse).
What changes
One SDK client per process, per service address and sign-in. The registry is weak: the client goes with the last connector that uses it, and closing a source affects no other. The key is the address, a digest of the whole environment and the state of the saved login's file (its content is not read). A client whose call failed is given to no new source, so the next new source signs in again. A forked child starts with no clients and no kept rows (os.register_at_fork); an inherited connector is still refused, as on main. No lock is held while a client is made. There are no threads and no new public argument. feat(spiraldb): sources that are given one connector use its client (ITL-1457) #555's connector= argument is not needed.
The schema table's rows are kept per process, for the exact snapshot they were read from (table id and version; keyed by address, project and dataset). Every lookup still opens the schema table, which is the one snapshot-check round trip left. Its rows are read again whenever that snapshot differs. A changed or damaged schema table is read and refused as on main, and rows of another snapshot are never served. Row counts are kept by the shared client (same account), keyed by table id and version.
Fix 7: as_table() with max_rows no longer counts the keys first. It holds every row until it ends, so it reads at most max_rows + 1 rows and raises the same SourceTooLargeError (same text). iter_data and the async read hand rows on as they go, so they still count first (a sync job run reads through as_table, an async one through the async read).
What was measured and not done
Dropping the schema table's separate schema() call: no gain. spiral-sdk's scan plan fetches the schema itself when it was not fetched before. Interleaved fresh processes: schema()+scan 0.71–0.76 s, scan alone 0.69–0.78 s. I kept main's call pattern.
Reading only this table's row by key range: not done. The completion check digests every row of the schema table against its marker, so reading one row would drop the refusal of an interrupted or changed migration. The cost is round trips (a plan and a read), not bytes, so a key-range scan would still make both.
Live check (agent workload; read-only keyed tables of another project; nothing written)
Differential, main vs this branch, 12 tables (1 to over 10,000 rows): identical on every route. Routes compared: source_id, content and pipeline hash, schema, as_table (all info and plain), iter_data, the async read, head, row_count_estimate, the max_rows=1 refusal text from as_table and from iter_data, limit within the cap, and a job run sync and async, each followed by a load-only run. The repository's live source tests pass (9). generate_golden_hashes.py --check passes with no golden change.
Timings: interleaved fresh processes, 5 rounds, medians. Ratios are branch against main, and branch against native spiral-sdk.
vs main
vs SDK
first source in a process (cold build)
1.0x (unchanged)
2.7x the SDK
a second source of the same dataset
3.0x faster
1.6x the SDK
the same table built again
2.6x faster
first as_table() after a build (32 rows)
1.3x faster (no count)
faster than the SDK's first scan
refusal of as_table() over max_rows=10,000 (narrow table)
2.0x slower
The last row is the cost of fix 7. On the refusal path, the read is now max_rows + 1 rows instead of one key column. On a wide table this costs more, in proportion to the width. Only reads that end in the refusal pay it.
What remains of the cold build is a chain of round trips: the client, the table's open and schema(), the schema table's open, schema(), scan plan and read. They run one after another. Overlapping the schema-table read with the table's open would need concurrency, and #553 tried that; its review findings were about ordering. That is not in this PR.
Tests
On the fake, in tests/test_core/sources/test_spiraldb_lookups.py:
a second source makes no client and no schema-table read, and both read alike, sync and async, in both roles and both arrangements;
a new snapshot of the schema table is read again;
an interrupted migration is refused on every build after rows were kept;
a changed environment gives a new client;
a client whose call failed is given to no new source;
the client goes with the last source that uses it;
six sources built in threads share one client;
the fork hook leaves the child empty.
Updated budgets:
as_table makes no count (test_each_read_resolves_once_and_reuses_its_client, test_job_reuses_client_but_refreshes_table_each_run, TestRowCap, with the new test_a_whole_table_over_the_cap_is_refused_without_a_count comparing the refusal text with the counted one);
the preview count test releases the first client so its count is not shared.
Review findings on #553/#554/#555 that apply here:
Sources using the same service address and sign-in now reuse a client and cached schema data within a process. New sources check for schema changes and refresh cached data when needed.
Whole-table reads check for oversized results while scanning, avoiding a separate preliminary count. Streaming reads retain their existing count-first behavior.
Reliability
New sources use a fresh client after credential or environment changes, or when a client call fails. Closing one source does not disrupt others.
…e counts as it reads (ITL-1457)
The SpiralDB sources of one process that use one service address and one sign-in share
one spiral-sdk client (a weak registry keyed by the address, a digest of the environment
and the state of the saved login's file; a client whose call failed is given to no new
source; a forked child starts empty). The rows of a dataset's schema table are kept per
process for the exact snapshot (id and version) they were read from, so a later source
opens the schema table to see its version and reads it again only when it moved. Row
counts are kept by the shared client.
as_table() with max_rows no longer counts the table's keys first: it reads at most one
row past the cap and raises the same SourceTooLargeError. Streaming reads still count
first.
Rows, hashes, source ids, stored paths and refusals are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Limit details: You’ve used the included review currently available. Your 99 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.
The reason will be displayed to describe this comment to others. Learn more.
Architecture findings (2)
Advisory architecture findings (2)
Minor — A new connector can reuse schema rows populated under another sign-in in the same process. Unlike the merge base, it does not have to scan those rows itself. If SpiralDB allows a sign-in to open the matching snapshot without permission to scan it, cached schema metadata can influence schema results or warnings that the merge-base connector could not produce. Snapshot equality establishes freshness, not read authority.
Trivial — The process registry retains a cache entry for every endpoint, project, and dataset tuple used to construct a connector, and retains one decoded snapshot for each populated entry. Closing the last connector does not evict either. Unlike the connector-owned cache in the merge base, memory can accumulate with dataset churn in a long-lived worker and affect other sources in that process.
Limit details: You’ve used the included review currently available. Your 98 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.
Review details
Context from checks skipped due to timeout: 1
GitHub Check: CodeRabbit
Additional context used
Code guidelines: 1
CLAUDE.md — auto-discovered
Path-based instructions: 6
Source excerpt: Every fenced `python` block in `README.md`, `docs/index.md`, `docs/getting-started.md`, `docs/troubleshooting.md`, `docs/concepts/`, `docs/reference/` and `docs/tutorial/` is executed by `tests/test_docs/test_doc_samples.py`...
CodeRabbit inference engine (CLAUDE.md)
Files:
docs/concepts/sources.md
Source excerpt: `docs/` is the only source.
CodeRabbit inference engine (CLAUDE.md)
Files:
docs/concepts/sources.md
Source excerpt: What runs where (developer, November 16, 2026; ITL-1181): Existing type errors and warnings are recorded in `.basedpyright/baseline.json`, a debt list to pay down.
Source excerpt: A pull request never edits `CHANGELOG.md` (developer, November 11, 2026; ITL-961).
CodeRabbit inference engine (CLAUDE.md)
Files:
changelog.d/ITL-1457.md
Source excerpt: What is published is decided in `scripts/docs_site_content.py` (`PUBLISHED_FILES`, `PUBLISHED_FOLDERS`, `EXCLUDED`).
CodeRabbit inference engine (CLAUDE.md)
Files:
docs/concepts/sources.md
Source excerpt: Tests use the **public interface** wherever possible (developer, November 10, 2026): drive an operator by calling it, `op(stream)`, and read the result through the stream's public methods.
Learnt from: CR
Repo: metamorphic-labs/orcapod-python
Timestamp: 2026-11-30T07:43:43.467Z
Learning: Source excerpt:
# Claude Code instructions for orcapod-python
## Lint, format and type checks
What runs where (developer, November 16, 2026; ITL-1181):
- New and changed code must be ruff-clean and ruff-formatted, and must add no
basedpyright errors. Warnings are reported but do not fail the check
(`failOnWarnings = false`); still do not add them needlessly. Run
`uv run ruff format .` and `uv run ruff check .` before committing;
`uv run pre-commit install` once per clone runs both on every commit.
Additional comments: 2
src/orcapod/databases/spiraldb_connector.py: 1
403-403: Data Integrity & Integration
The claim depends on two premises that the available evidence cannot decide. First, the pinned spiral-sdk must choose a different service when an environment endpoint setting changes while api_url is None. Second, the SDK must not guarantee unique resource and version identities across services. The repository code shows the cache key gap, but the SDK source is needed to decide whether the gap can cause a wrong-service rows reuse. This is a missing-evidence result, not a refutation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of ITL-1457. Replaces #553 and #555. #554 was already superseded by #675 (ITL-1774, pinned-handle reuse).
What changes
os.register_at_fork); an inherited connector is still refused, as onmain. No lock is held while a client is made. There are no threads and no new public argument. feat(spiraldb): sources that are given one connector use its client (ITL-1457) #555'sconnector=argument is not needed.main, and rows of another snapshot are never served. Row counts are kept by the shared client (same account), keyed by table id and version.as_table()withmax_rowsno longer counts the keys first. It holds every row until it ends, so it reads at mostmax_rows + 1rows and raises the sameSourceTooLargeError(same text).iter_dataand the async read hand rows on as they go, so they still count first (a sync job run reads throughas_table, an async one through the async read).What was measured and not done
schema()call: no gain. spiral-sdk's scan plan fetches the schema itself when it was not fetched before. Interleaved fresh processes:schema()+scan 0.71–0.76 s, scan alone 0.69–0.78 s. I keptmain's call pattern.Live check (agent workload; read-only keyed tables of another project; nothing written)
Differential,
mainvs this branch, 12 tables (1 to over 10,000 rows): identical on every route. Routes compared:source_id, content and pipeline hash, schema,as_table(all info and plain),iter_data, the async read,head,row_count_estimate, themax_rows=1refusal text fromas_tableand fromiter_data,limitwithin the cap, and a job run sync and async, each followed by a load-only run. The repository's live source tests pass (9).generate_golden_hashes.py --checkpasses with no golden change.Timings: interleaved fresh processes, 5 rounds, medians. Ratios are branch against
main, and branch against native spiral-sdk.mainas_table()after a build (32 rows)as_table()overmax_rows=10,000(narrow table)The last row is the cost of fix 7. On the refusal path, the read is now
max_rows + 1rows instead of one key column. On a wide table this costs more, in proportion to the width. Only reads that end in the refusal pay it.What remains of the cold build is a chain of round trips: the client, the table's open and
schema(), the schema table's open,schema(), scan plan and read. They run one after another. Overlapping the schema-table read with the table's open would need concurrency, and #553 tried that; its review findings were about ordering. That is not in this PR.Tests
On the fake, in
tests/test_core/sources/test_spiraldb_lookups.py:Updated budgets:
as_tablemakes no count (test_each_read_resolves_once_and_reuses_its_client,test_job_reuses_client_but_refreshes_table_each_run,TestRowCap, with the newtest_a_whole_table_over_the_cap_is_refused_without_a_countcomparing the refusal text with the counted one);Review findings on #553/#554/#555 that apply here:
test_a_changed_environment_signs_in_againmain's orderschema()main(#675's pinned handle)test_a_damaged_schema_table_is_refused_after_rows_were_keptNo golden value, hash, source id, stored path or identity moves.
🤖 Generated with Claude Code
Summary by CodeRabbit