Skip to content

Bound history index scans by the causal trigger timestamp - #222

Merged
iamwavecut merged 1 commit into
mainfrom
fix/history-causal-index-bound
Oct 10, 2026
Merged

iamwavecut merged 1 commit into
mainfrom
fix/history-causal-index-bound

Conversation

@iamwavecut

Copy link
Copy Markdown
Owner

Recent dialog history can spend tens of seconds reading newer rows before applying its causal trigger filter. Production inspection observed a 40-second DataFileRead wait, and the query plan placed the upper timestamp only in Filter, outside the index range.

Add the equivalent occurred_at <= trigger_timestamp condition to both chat and thread tail queries. PostgreSQL can now seek within the causal timestamp range. The existing strict timestamp/message-ID boundary, ordering, topic resets, UTC partition bounds, and result limits are unchanged. No migration or persisted-data change.

Validation: cargo fmt --all; git diff --check; workspace/all-target tests (2456 passed, 10 ignored); workspace/all-target Clippy with -D warnings. Actual Postgres 17 + pgvector checks passed in a disposable database: outbox compatibility and the history round-trip, including UTC offsets, topic/reset exclusions, same-timestamp message IDs, and JSON query-plan assertions that both index scans include the causal upper timestamp. A read-only plan on the production schema also places the upper bound in Index Cond. Latency improvement still requires the next deployed observation window.

@github-actions

Copy link
Copy Markdown
Messages
📖 Danger checked 1 changed file(s).

Generated by 🚫 dangerJS against cc718ed

@iamwavecut
iamwavecut merged commit efad397 into main Oct 10, 2026
12 checks passed
@iamwavecut
iamwavecut deleted the fix/history-causal-index-bound branch October 10, 2026 11:45
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