Skip to content

perf(sessions): stop rebuilding the entire Git-evidence projection for bounded reads #968

Description

@ScriptedAlchemy

Priority: P1 performance/scalability
Release gate: affected retained-session query acceptance, not a new universal benchmark gate.

Evidence

At #707 607df500b1eb5568aa3a20e07f2924262b46c808:

GlobalDbGitCorrelationStore calls git_evidence_projection() from correlation_index_health, sessions_for_with_relation_and_presence, and sessions_for_with_relation.

GitEvidenceProjectionStore::from_verified_snapshot walks every entity/relation page, JSON-decodes all spans and commit records into vectors, reconstructs GitEvidenceProjectionV1, then calls require_git_evidence_generation, which recomputes the projection-derived identity. Health ultimately needs counts; presence needs booleans; a session query filters the resulting full in-memory projection.

The page size bounds each read, not total materialization or work per request. Sharing one recovered projection between results and presence already removes one duplicate pass, but still rebuilds the whole projection for each facade call. This is a source-confirmed O(total evidence) read/reconstruction path, not a freshly measured latency claim.

Change

Separate full recovery/merge work from the bounded query view. Serve counts/presence from authenticated generation metadata or the verified store's bounded count/exists operations, and serve filtered session queries through generation-bound indexed reads. Reuse existing verified graph APIs; do not create a parallel SQL source of truth for Git evidence.

Perform full payload consistency verification at the owning publication/recovery boundary and preserve the exact verified-generation/read lifetime on subsequent queries. A generation ID string alone must not authorize unverified bytes. If a retained typed view is needed as an interim step, keep one bounded, generation-bound owner rather than request-local full copies or a process-global unbounded cache. Repeated reads must not rerun canonical JSON reconstruction/hash without new evidence requiring it.

Route any remaining blocking recovery through the existing bounded operation owner, and carry request cancellation/deadline into the actual graph read. Do not replace errors with empty results: never-published is a legitimate empty projection; corrupt/unavailable is not.

Acceptance

  • A count/presence read does not decode every span/commit payload.
  • Selective session queries report rows/pages/bytes visited independently of rows returned; enlarging unrelated evidence does not force full projection hydration.
  • Repeated queries against one unchanged generation avoid repeated full decode/hash.
  • Publication racing a read preserves one coherent generation; new readers see the successor, old admitted readers cannot outlive their authority.
  • Tampering, absent projection, wrong namespace/project, cancellation, and relation filters preserve their current distinctions.
  • Compare cold/warm query allocations and p50/p95 against the current path on small and retained-profile-sized data; no budget increase.

Related: #843 tracks missing/background convergence; #915 tracks executor lifetime. This issue is specifically the already-published projection's read amplification, not a duplicate of those failures. Source review only; no repository benchmark executed. Keep #707 draft.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions