Skip to content

fix(ingestor): bound neighbor-edges builder scan to retention window#1331

Open
efiten wants to merge 1 commit into
Kpa-clawbot:masterfrom
efiten:fix/neighbor-builder-unbounded-scan
Open

fix(ingestor): bound neighbor-edges builder scan to retention window#1331
efiten wants to merge 1 commit into
Kpa-clawbot:masterfrom
efiten:fix/neighbor-builder-unbounded-scan

Conversation

@efiten
Copy link
Copy Markdown
Contributor

@efiten efiten commented May 23, 2026

Summary

Fix

Add lookbackSecs int64 parameter to StartNeighborEdgesBuilder and buildAndPersistNeighborEdges. The query now filters:

WHERE o.timestamp > strftime('%s', 'now') - ?

The lookback is derived from NeighborEdgesDaysOrDefault() (default 5 days), matching the existing edge retention window. The idx_observations_timestamp index (already present) makes this efficient regardless of DB size.

Historical edges already in neighbor_edges are preserved by the ON CONFLICT DO UPDATE upsert — only the incremental scan window shrinks.

Test plan

  • TestNeighborEdgesBuilderUpsertsFromObservations updated: observation seeded with time.Now().Unix() so it falls inside the lookback window; lookback arg 7*86400 passed explicitly
  • Full ingestor test suite passes (go test ./...)
  • Verify on live: [neighbor-build] log line now includes lookback=5d; MQTT watchdog stops firing

🤖 Generated with Claude Code

buildAndPersistNeighborEdges() was doing a full unbounded JOIN across
observations+transmissions every 60s. On a 9.7GB live DB this query
runs for several minutes, serialising the ingestor's SQLite write path
and starving MQTT ingestion — triggering the watchdog every ~60–90s.

Add a lookbackSecs parameter (derived from NeighborEdgesDaysOrDefault,
default 5 days) and filter `WHERE o.timestamp > strftime('%s','now') - ?`.
The existing idx_observations_timestamp index makes this efficient.
Historical edges already in neighbor_edges are preserved by the ON
CONFLICT upsert; only the incremental scan window shrinks.

Fix test: seed observation with time.Now().Unix() so it falls inside
the lookback window, and pass 7*86400 as the lookback argument.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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