Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -266,26 +266,24 @@ fn sessions_unfinished_lists_workflow_state_evidence() {
.await
.expect("session fixture write")
);
assert!(
runtime
.upsert_session_message_for_test(
HostAdmissionScope::Project,
&MessageRecordBuilder::new(
"claude",
"message-1",
"session-1",
"assistant",
1,
"Blocked: waiting on missing deploy credentials",
"message",
)
.with_source(Some("/tmp/project/transcript.jsonl"), Some(1))
.with_metadata(Some(r#"{"task_id":"task-7"}"#))
.build(),
runtime
.upsert_session_message_for_test(
HostAdmissionScope::Project,
&MessageRecordBuilder::new(
"claude",
"message-1",
"session-1",
"assistant",
1,
"Blocked: waiting on missing deploy credentials",
"message",
)
.await
.expect("session message fixture write")
);
.with_source(Some("/tmp/project/transcript.jsonl"), Some(1))
.with_metadata(Some(r#"{"task_id":"task-7"}"#))
.build(),
)
.await
.expect("session message fixture write");
// The daemon started below opens this database as a separate process.
// Checkpoint and release the writer here so it sees the fixture rows
// and can take the single-writer authority, the same discipline the
Expand Down
1 change: 0 additions & 1 deletion crates/tracedecay-global-db/src/api_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use tracedecay_runtime_core::storage::{ProjectStorageLocation, classify_registry

pub use tracedecay_sessions::runtime::{
SessionActivityRow, SessionIngestHealth, SessionProviderCoverage, SessionProviderCoverageState,
TranscriptBatch,
};

/// Total savings + call count for a project (or all projects when `project` is None).
Expand Down
60 changes: 4 additions & 56 deletions crates/tracedecay-global-db/src/git_correlation_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,8 @@ impl GitCorrelationSessionStore for RegisteredGlobalDb {
#[cfg(test)]
mod tests {
use super::GlobalDbGitCorrelationStore;
use crate::{
ParseOffset, TranscriptPersistenceError,
tests::harness::{RegisteredGlobalDbHarness, RegisteredGlobalDbTestRuntime},
};
use crate::tests::harness::{RegisteredGlobalDbHarness, RegisteredGlobalDbTestRuntime};
use tracedecay_domain::ProjectId;
use tracedecay_sessions::runtime::SessionRecord;
use tracedecay_sessions::runtime::git_correlation::{
CommitRelationFilter, GitCorrelationError, GitRefFilter, GitScopeFilter, SessionsForQuery,
SpanObservation, SpanSource, SystemGit,
Expand Down Expand Up @@ -479,58 +475,10 @@ mod tests {
if message.contains("ProjectSessions")
));

let session = SessionRecord {
provider: "codex".to_owned(),
session_id: "profile-git-evidence".to_owned(),
project_key: "user".to_owned(),
project_path: "user".to_owned(),
title: None,
started_at: Some(1),
ended_at: Some(1),
transcript_path: None,
metadata_json: None,
parent_session_id: None,
is_subagent: false,
agent_id: None,
parent_tool_use_id: None,
};
let error = harness
.registered
.persist_transcript_batch_with_git_evidence_result(
&session,
&[],
"profile-git-evidence.jsonl",
ParseOffset::default(),
ParseOffset::default(),
tracedecay_sessions::runtime::TranscriptGitEvidence::new(
&[],
&[SpanObservation {
provider: "codex".to_owned(),
session_id: session.session_id.clone(),
thread_id: None,
branch: Some("main".to_owned()),
worktree: "/repo".to_owned(),
ts: 1,
source: SpanSource::Ingest,
}],
),
)
.await
.expect_err("profile transcript authority must reject project Git evidence");
assert!(matches!(
error,
TranscriptPersistenceError::Storage { operation, source }
if operation == "record transcript git evidence"
&& source.to_string().contains("ProjectSessions")
store.record_span_observation(&span_observation(10), 5).await,
Err(GitCorrelationError::Db(message))
if message.contains("ProjectSessions")
));
assert_eq!(
harness
.registered
.get_session("codex", "profile-git-evidence")
.await
.expect("load profile session"),
None,
"scope rejection must happen before transcript rows commit"
);
}
}
2 changes: 1 addition & 1 deletion crates/tracedecay-global-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub use api_types::{
ProjectStoreContext, ProjectStoreResolution, RegisteredProjectRootInventoryV1, SavingsDay,
SavingsTotal, SessionActivityRow, SessionIngestHealth, SessionProviderCoverage,
SessionProviderCoverageState, StoreArtifactRecord, StoreArtifactUpsert, StoreInstanceRecord,
StoreInstanceUpsert, TranscriptBatch, registry_context_candidate_roots,
StoreInstanceUpsert, registry_context_candidate_roots,
};
pub use support::{
AccountingMode, env_flag, env_value_truthy, global_accounting_enabled, global_accounting_mode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1430,9 +1430,9 @@ fn reconcile_metadata(
}
}
}
// Host ingest keeps the first annotation (`merge_session_metadata`).
// A later observation's source, cwd, or hook label is not a different
// session. Session identity stays on provider and session id.
// The first annotation wins: a later observation's source, cwd, or
// hook label is not a different session. Session identity stays on
// provider and session id.
Some(_) => {}
}
}
Expand Down
35 changes: 0 additions & 35 deletions crates/tracedecay-global-db/src/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,41 +749,6 @@ impl HostAdmissionTestRuntimeV1 {
.await)
}

pub async fn upsert_session_message_for_test(
&self,
scope: HostAdmissionScope,
message: &tracedecay_sessions::runtime::SessionMessageRecord,
) -> tracedecay_domain::errors::Result<bool> {
let database = self.session_database_for_test(scope)?;
let session = database
.get_session(&message.provider, &message.session_id)
.await
.map_err(
|error| tracedecay_domain::errors::TraceDecayError::Database {
operation: "seed registered session message fixture".to_owned(),
message: error.to_string(),
},
)?
.ok_or_else(|| tracedecay_domain::errors::TraceDecayError::Database {
operation: "seed registered session message fixture".to_owned(),
message: format!(
"session {}/{} is unavailable",
message.provider, message.session_id
),
})?;
Ok(database
.upsert_transcript_batch(
&session,
std::slice::from_ref(message),
&format!(
"global-db-test-message:{}:{}",
message.provider, message.message_id
),
crate::ParseOffset::default(),
)
.await)
}

pub async fn session_for_test(
&self,
scope: HostAdmissionScope,
Expand Down
63 changes: 1 addition & 62 deletions crates/tracedecay-global-db/src/transcript.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{ParseOffset, RegisteredGlobalDb};
use tracedecay_sessions::runtime::{
SessionMessageRecord, SessionRecord, SessionStoreAccess, TranscriptGitEvidence,
TranscriptPersistenceError,
};
use tracedecay_sessions::runtime::{SessionRecord, SessionStoreAccess, TranscriptPersistenceError};

pub(super) use tracedecay_sessions::runtime::store_access::{
require_expected_offset, set_parse_offset,
Expand All @@ -25,64 +22,6 @@ impl RegisteredGlobalDb {
.await
}

#[hotpath::measure(future = true, label = "global_db.transcript.upsert_batch")]
pub async fn upsert_transcript_batch(
&self,
session: &SessionRecord,
messages: &[SessionMessageRecord],
parse_offset_path: &str,
parse_offset: ParseOffset,
) -> bool {
SessionStoreAccess::new(self)
.upsert_transcript_batch(session, messages, parse_offset_path, parse_offset)
.await
}

#[hotpath::measure(future = true, label = "global_db.transcript.persist_batch")]
pub async fn persist_transcript_batch_result(
&self,
session: &SessionRecord,
messages: &[SessionMessageRecord],
parse_offset_path: &str,
expected_offset: ParseOffset,
parse_offset: ParseOffset,
) -> Result<(), TranscriptPersistenceError> {
SessionStoreAccess::new(self)
.persist_transcript_batch_result(
session,
messages,
parse_offset_path,
expected_offset,
parse_offset,
)
.await
}

#[hotpath::measure(
future = true,
label = "global_db.transcript.persist_batch_with_git_evidence"
)]
pub async fn persist_transcript_batch_with_git_evidence_result(
&self,
session: &SessionRecord,
messages: &[SessionMessageRecord],
parse_offset_path: &str,
expected_offset: ParseOffset,
parse_offset: ParseOffset,
git_evidence: TranscriptGitEvidence<'_>,
) -> Result<(), TranscriptPersistenceError> {
SessionStoreAccess::new(self)
.persist_transcript_batch_with_git_evidence_result(
session,
messages,
parse_offset_path,
expected_offset,
parse_offset,
git_evidence,
)
.await
}

#[hotpath::measure(future = true, label = "global_db.transcript.persist_offset")]
pub async fn persist_transcript_offset_result(
&self,
Expand Down
51 changes: 21 additions & 30 deletions crates/tracedecay-project/src/test_support/host_admission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,39 +557,27 @@ impl HostAdmissionTestRuntimeV1 {
.await)
}

/// Seeds one raw LCM message into its already-registered session.
#[doc(hidden)]
#[hotpath::skip]
pub async fn upsert_session_message_for_test(
&self,
scope: HostAdmissionScope,
message: &tracedecay_sessions::runtime::SessionMessageRecord,
) -> Result<bool> {
let database = self.session_database_for_test(scope)?;
let session = database
.get_session(&message.provider, &message.session_id)
.await
.map_err(|error| TraceDecayError::Database {
operation: "seed registered session message fixture".to_owned(),
message: error.to_string(),
})?
) -> Result<()> {
let session = self
.session_for_test(scope, &message.provider, &message.session_id)
.await?
.ok_or_else(|| TraceDecayError::Database {
operation: "seed registered session message fixture".to_owned(),
message: format!(
"session {}/{} is unavailable",
message.provider, message.session_id
),
})?;
Ok(database
.upsert_transcript_batch(
&session,
std::slice::from_ref(message),
&format!(
"host-admission-test-message:{}:{}",
message.provider, message.message_id
),
tracedecay_global_db::ParseOffset::default(),
)
.await)
self.seed_session_messages_for_test(scope, &session, std::slice::from_ref(message))
.await
.map(|_| ())
}

#[doc(hidden)]
Expand Down Expand Up @@ -622,28 +610,31 @@ impl HostAdmissionTestRuntimeV1 {
.await
}

/// Seeds one session row and its raw LCM messages, returning each
/// message's raw store id in input order.
#[doc(hidden)]
#[hotpath::skip]
pub async fn upsert_transcript_batch_for_test(
pub async fn seed_session_messages_for_test(
&self,
scope: HostAdmissionScope,
session: &tracedecay_sessions::runtime::SessionRecord,
messages: &[tracedecay_sessions::runtime::SessionMessageRecord],
source: &str,
offset: tracedecay_global_db::ParseOffset,
) -> Result<Vec<i64>> {
let database = self.session_database_for_test(scope)?;
if !database
.upsert_transcript_batch(session, messages, source, offset)
.await
{
if !self.upsert_session_for_test(scope, session).await? {
return Err(TraceDecayError::Database {
operation: "seed registered transcript batch fixture".to_owned(),
message: "registered transcript batch write failed".to_owned(),
operation: "seed registered session fixture".to_owned(),
message: "registered session write failed".to_owned(),
});
}
let database = self.session_database_for_test(scope)?;
let mut store_ids = Vec::with_capacity(messages.len());
for message in messages {
self.lcm_ingest_raw_message_for_test(scope, message)
.await
.map_err(|error| TraceDecayError::Database {
operation: "seed registered session message fixture".to_owned(),
message: error.to_string(),
})?;
let store_id = database
.lcm_raw_message_store_id(&message.provider, &message.message_id)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,33 +129,6 @@ impl HostAdmissionTestRuntimeV1 {
)
}

#[doc(hidden)]
pub async fn set_parse_offset_insert_failure_for_test(
&self,
scope: HostAdmissionScope,
enabled: bool,
) -> tracedecay_domain::errors::Result<()> {
let statement = if enabled {
"CREATE TRIGGER fail_parse_offset_insert
BEFORE INSERT ON parse_offsets
BEGIN
SELECT RAISE(ABORT, 'late parse offset failure');
END;"
} else {
"DROP TRIGGER IF EXISTS fail_parse_offset_insert;"
};
self.session_database_for_test(scope)?
.writer_connection()?
.execute_batch(statement)
.await
.map_err(
|error| tracedecay_domain::errors::TraceDecayError::Database {
operation: "configure registered parse-offset failure".to_owned(),
message: error.to_string(),
},
)
}

#[doc(hidden)]
pub async fn set_project_parse_offset_for_test(
&self,
Expand Down
Loading
Loading