Skip to content

perf(storage): trim redundant run persistence reads - #1015

Merged
XuPeng-SH merged 1 commit into
matrixorigin:mainfrom
XuPeng-SH:perf/session-hotpath-simplification
Oct 16, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:mainfrom
XuPeng-SH:perf/session-hotpath-simplification

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Collaborator

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.

  • Owner-fenced canonical appends use the existing generation/lease UPDATE to establish exact user/session/run identity instead of first issuing a second locking existence SELECT. Both UPDATE variants now bind session identity explicitly.
  • Generic event append reuses the existing locked metadata reader with its checkpoint-free projection. Other callers retain full checkpoint reads. Replay repair, atomic event counters, commit-acknowledgement reconciliation, and cancellation-safe connection ownership remain intact.

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

  • Refactor or performance improvement
  • Test

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

  • Canonical owners: existing runtime canonical append transaction and services run metadata reader.
  • Searched actual admission, settlement, event-append, collaborator and checkpoint callers; no new lifecycle, queue, cache, writer, or table.
  • Removed redundant owner-path preflight read and unused checkpoint-body transfer from the initial generic-append locked lookup.
  • Non-owner existence admission remains necessary. Replay still invokes existing full projection repair and may read the checkpoint there.
  • Regression tests share the existing terminal/replay fixture, covering both normal completion and paused cancellation. Most of the physical delta is real-boundary regression coverage, not a second execution implementation.

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 -- --check and git diff --check: passed.
  • Native affected unit tests: runtime persistence 33 passed; services runs 195 passed.
  • Actual ThreadSanitizer: the same 228 affected unit tests and 42 database tests passed. Used nightly with instrumented standard library and the verified external TSan runtime; no suppressions or race reports. Reused unchanged passing tests after correcting only the new paused-cancellation fixture's required typed field.
  • Actual MatrixOne: dedicated disposable test database, fresh schema bootstrap, existing append/replay/isolation tests plus wrong-active-session/foreign-owner/missing-run/stale-generation/expired-lease/status rejection, canonical rollback and accounting, paused cancellation and exact terminal replay. Services suite follows its documented serial test scheduling; its internally multi-threaded tests retain two Tokio workers.
  • Five additional existing native database boundaries passed: collaborator acknowledgement loss, generic append acknowledgement recovery and missing/conflicting proofs, checkpoint custody, and 256 concurrent appends across users/sessions. This is not 256 complete LLM agent loops.
  • Read-avoidance case covers absent, small and 512 KiB checkpoint payloads; stored checkpoint contents remain identical, replay inserts no extra events, and rejection uses a second active session rather than a nonexistent fixture.
  • Validation caveat: an extra, nonstandard two-test-runner TSan run had one pre-existing SQL trace-count assertion observe zero statements despite correct semantic results. The same internally multi-threaded test passed in isolation and the full documented serial suite passed 28/28. The trace-capture cause is unproven; this PR does not claim parallel-runner stability or fix it by suppression, timeout increases, or changing production behavior.
  • Design and overall review: actual gpt-6.1-sol / xhigh, session 01a14223-4fb2-7110-bf3b-1e5dbf647090; final sign-off recorded before submission. Complete delta base b95f23418, fingerprint 11758af797552accd89de2d6a3f5cfc20f76255a04cae6d84ef0d2d736a7aa7f.
  • New branch CI is pending, not a local validation result. No live-model behavior or model prompt changed; validation targets the real database persistence boundaries rather than a model-owned mock.

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

  • Tests exercise the existing persistence owners and actual MatrixOne boundaries.
  • Owning storage documentation updated.
  • Diff checked for credentials, private endpoints, generated files and user data.
  • Conventional Commit title.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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