Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/persistence/src/model_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ impl PostgresModelCallRepository {
// compaction result frontier while retaining only the unsummarized
// source suffix. Read those bounded pieces directly; independently
// assembled frontiers retain the exact complete-membership comparison.
// Calls no newer than the latest compaction cannot win the final call-ID
// ordering, so discard them before the exact summary-membership probe.
let row = sqlx::query(
"WITH RECURSIVE latest_compaction AS MATERIALIZED (
SELECT compaction.context_compaction_id,
Expand Down Expand Up @@ -673,6 +675,11 @@ impl PostgresModelCallRepository {
AND model_call.resolved_provider_model_identity_id = $2
AND model_call.state_kind = 'terminal'
AND model_call.usage_input_tokens IS NOT NULL
AND NOT EXISTS (
SELECT 1
FROM latest_compaction AS latest
WHERE model_call.model_call_id <= latest.model_call_id
)
AND NOT EXISTS (
SELECT 1
FROM latest_compaction AS latest
Expand Down
Loading