Skip to content

perf(query): optimize snapshot decision hot path (<100ms)#322

Open
fagemx wants to merge 6 commits intomainfrom
agent/GH-319
Open

perf(query): optimize snapshot decision hot path (<100ms)#322
fagemx wants to merge 6 commits intomainfrom
agent/GH-319

Conversation

@fagemx
Copy link
Owner

@fagemx fagemx commented Mar 16, 2026

Summary

  • add schema v11 index for snapshot hot path: decide_snapshots(village_id, decision_type, created_at DESC)
  • optimize query_snapshots with fixed SQL paths, preserve LIMIT/OFFSET, and add hot-path latency warning logs
  • rework /api/snapshots caching to per-village recent-100 (TTL 5 min), with in-memory filter/pagination and new regression tests

Closes #319

fagemx and others added 6 commits March 15, 2026 14:33
…313)

5 instances in bg_scan.rs and issue_proposal.rs used .unwrap() on
path.parent() which could panic on root paths. Replaced with
.context()? for graceful error propagation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add composite indexes for hot path queries:
  - idx_decisions_active_domain_branch on (is_active, domain, branch)
  - idx_decisions_active_domain on (is_active, domain)
- Add LIMIT parameter to active_decisions to prevent full table scans
- Add tracing for query latency monitoring
- Add benchmark test verifying queries complete in < 1ms
- Fix pre-existing bug in migrate_v1_to_v2 (scope column not yet exists)

Benchmark results: avg_all=0.34ms, avg_domain=0.30ms (requirement: < 100ms)

Closes #319
@fagemx
Copy link
Owner Author

fagemx commented Mar 16, 2026

Code Review: PR #322

Thanks for the implementation work — I reviewed the full diff against issue #319 scope.

Summary

This PR contains the intended hot-path snapshot optimizations, but it also includes unrelated files and a committed secret, which are blocking issues. The scoped changes in crates/edda-ledger/src/sqlite_store.rs and crates/edda-serve/src/lib.rs look directionally correct and include relevant tests.

Findings

Blockers

  • .env:1 includes a real API key (T8STAR_API_KEY=...), which is a credential leak and must not be present in the PR.
  • Scope is violated: PR perf(query): optimize snapshot decision hot path (<100ms) #322 includes unrelated files outside perf(query): optimize decision query for hot path (< 100ms) #319 (crates/edda-ask/src/lib.rs, crates/edda-bridge-claude/src/bg_detect.rs, crates/edda-bridge-claude/src/bg_scan.rs, crates/edda-bridge-claude/src/issue_proposal.rs, crates/edda-ledger/Cargo.toml, crates/edda-ledger/src/ledger.rs, opencode.json, plus .env), while the task scope was only crates/edda-ledger/src/sqlite_store.rs and crates/edda-serve/src/lib.rs.

Suggestions

  • None.

Four-Point Check

Check Status Notes
Scope PR contains multiple out-of-scope files unrelated to GH-319 implementation contract.
Reality The introduced APIs and fields in scoped files appear consistent with existing code paths.
Testing Added/updated tests cover decision_type+offset behavior, cache-window behavior, and perf guard in the hot path.
YAGNI Scoped changes are targeted to the stated perf/query requirements without obvious over-engineering.

Verdict

Changes Requested


Reviewed by edda AI

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.

perf(query): optimize decision query for hot path (< 100ms)

1 participant