Repository navigation
perf(storage): trim redundant run persistence reads - #1015
Conversation
XuPeng-SH
left a comment
There was a problem hiding this comment.
Technical verdict: no material findings; ready from the code-review perspective.
This is published as a substantive COMMENT review because the authenticated account, XuPeng-SH, is also the PR author. It is not a formal GitHub approval and does not satisfy an approving-review requirement.
Reviewed revision and scope
- Head:
717742e408dbdd10201ce0b06fbcdf88ab52af3e. - Base, current main, and verified merge-base:
b95f23418b73600039eac5b52059132dcffbf29a. - Complete delta: four files, +446/-45, including both production changes, regression tests, and the storage contract.
- The substantive reviewer was explicitly invoked with
model=gpt-6-astra,reasoning_effort=xhigh. Its conclusions were checked against the actual production diff and independently retrieved CI evidence before publication.
Correctness, recovery, and isolation
The canonical owner-backed append still takes the deletion-fence → session → execution-slot locks before the run fence. The existing generation/lease UPDATE now binds the exact user/session/run identity in both variants, so it establishes the identity and run lock previously obtained by the redundant SELECT. Live lease, generation, and status checks remain; paused is admitted only for cancelled settlement. The path without execution authority retains explicit run-existence admission. A zero-row fence rolls back before authoritative terminal reconciliation. See persistence.rs:1097.
Root completion, atomic terminal settlement, and delegated subruns reach that same canonical owner. Canonical events, transcript, counters, terminal evidence, and usage retain their transaction boundary. Exact replay and uncertain-COMMIT reconciliation still verify committed identity, generation, receipts, and payloads before reporting success. Projection repair remains downstream of authoritative persistence.
Generic event append uses the existing exact user/session/run locking reader with a narrow column projection (runs.rs:14690). Its temporary metadata supplies identity, agent ID, and event frontier; the absent checkpoint body is not written back as a cleared checkpoint or used as executable recovery state. The other callers retain the full projection. Immutable-payload checks, idempotency, owner-scoped probes, and event-counter CAS are preserved.
Both transaction paths keep the cancellation-safe physical checkout guard outside the transaction. Cancellation/error/unknown protocol outcomes still close the guarded connection; synchronized successful operations release it. No additional connection, background task, global lock, queue, cache, or storage owner is introduced. Existing isolation and contention boundaries are preserved.
Performance and storage scope
The supported improvement is one fewer locking SQL exchange per owner-backed canonical append, plus omission of the unused checkpoint body from the initial generic-append locking read. Generic append does not remove a query. Exact replay still invokes unchanged full projection repair (runs.rs:14824), which can read the checkpoint body.
Retained checkpoint/event data and durability are unchanged. This does not establish a latency percentage, bounded total history, or a particular number of concurrent agent sessions. The documentation states the narrower benefit accurately.
Test quality and independently verified CI
The new real-database rejection test checks wrong session/owner, missing run, stale generation, expired lease, and ineligible status, asserting absence of event/transcript/accounting effects. The paused-cancellation test reuses the terminal/replay fixture and checks durable evidence, usage, stable counters, delayed exact replay, and changed-payload rejection. The checkpoint test covers absent, small, and 512 KiB payloads, verifies the initial SQL projection, unchanged stored contents, duplicate-free replay, exact frontier increments, and rejection through another active session.
Existing surrounding tests cover rollback on transcript/evidence conflicts, missing/conflicting commit proofs, duplicate-free acknowledgement recovery, cancellation of an acquired connection, checkpoint custody, and independent users/sessions. These assert persisted effects rather than merely accepting an error result.
Upstream logs identify tested merge 8e89c12041915964add025e100b1ee897be699d6, combining this exact head and base:
| Actual selected lane | Result |
|---|---|
| Runtime offline | 5,962 passed; 181 skipped |
| Turn-core/services/plan/prompts offline shard | 5,447 passed; 487 skipped |
| Runtime online | 94 selected tests passed |
| Services online | 471 selected tests passed |
The new runtime tests canonical_append_identity_and_authority_rejections_leave_no_effects and canonical_paused_cancellation_preserves_evidence_and_replay actually passed in runtime database job 116757665361. The new event_append_keeps_checkpoint_durable_without_reading_its_body passed in services database job 116757665299. Those lanes started dependencies and executed tests; they were not successful skip wrappers.
All 38 current check runs were inspected: 35 success, two skipped, one neutral, with no pending/failure/cancellation. The 15 required contexts have 13 successes and two proven scope exclusions (SDK/Web), all attributed to expected GitHub Actions app 15368. Mergify checks are app 10562. All four workflow runs completed successfully, including Test Suite and Static Checks. Checks, suites, statuses, workflow runs/jobs, reviews, inline comments, and conversation comments were paginated and rechecked; second pages are empty and commit statuses are absent. No prior review or discussion required reconciliation.
Local validation and limits
Pinned-toolchain formatting for the three changed Rust files and git diff --check pass; the isolated checkout remains clean. A focused exact-head local behavioral test was attempted but stopped before compilation: the offline cache lacks locked toml 1.1.8+spec-1.1.0. There is no usable local MatrixOne binary. Consequently, no local behavioral/DB pass is claimed; database execution evidence above comes from independently checked upstream CI. The PR's manual TSan results were not independently rerun in this review.
Current rulesets, required contexts/app identities, reviewer identity, open state, head/base, and merge automation were checked. The full classic branch-protection endpoint returns integration 403; required contexts are available from the branch endpoint and corroborated by Mergify. The approval-triggered Mergify queue condition is not satisfied by this COMMENT review.
No product edits, commits/pushes, branch updates, merge, remote CI rerun, deployment, permission change, shared/production-service access, or paid model test was performed. Reproducible source/CI evidence and local validation logs are retained under /tmp/astra-pr1015-review.
Summary
Reduce redundant database work in the shared persistence path used by Server-owned CLI/Edge runs, without changing retained evidence or introducing another state/cache/storage owner.
Related issue
Follow-up to #1013. This is a bounded persistence optimization, not a claim of unlimited database or 10k/100k active-session capacity.
Change type
User and compatibility impact
No new configuration, schema, protocol, compatibility branch, migration, or history deletion. Exact-session authority rejection remains fail-closed. Checkpoint bodies remain stored and recoverable.
Architecture and complexity delta
Physical lines, including comments/blank lines: implementation +82/−37 (net +45), tests +359/−8 (net +351), documentation +5 (net +5). Total net +401. The implementation increase is the existing authority-path distinction and column-projection argument; there is no new state machine. The tests verify real writes and rejected-write effects rather than counting assertions or simulating a second adapter.
Verification
cargo clippy --locked -p astra-runtime -p astra-services --all-targets -- -D warnings: passed;cargo fmt --all -- --checkandgit diff --check: passed.gpt-6.1-sol/xhigh, session01a14223-4fb2-7110-bf3b-1e5dbf647090; final sign-off recorded before submission. Complete delta baseb95f23418, fingerprint11758af797552accd89de2d6a3f5cfc20f76255a04cae6d84ef0d2d736a7aa7f.Performance and storage limits
One fewer locking SQL exchange per owner-backed canonical append at this boundary. Generic append avoids returning one unused checkpoint body on its initial locked lookup (tested absent, small, and 512 KiB payloads). No query-count reduction for generic append, no latency percentage claim, and no reduction of retained rows/bytes.
Accumulated run-event/checkpoint retention is not solved here: read limits and per-checkpoint size caps do not bound total history. Defining retention without preserving recovery/audit references is not a safe incidental optimization.
Final checklist