Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
dfb4908
Document configurable PostgreSQL storage design
mmpg-x86 Oct 14, 2026
953c8d2
Initialize pseudoterminals in display tests
mmpg-x86 Oct 15, 2026
ebb23b6
Parse opt-in PostgreSQL storage modes
mmpg-x86 Oct 15, 2026
8cc1137
Add PostgreSQL catalog migration foundation
mmpg-x86 Oct 15, 2026
282da5e
Support PostgreSQL for daemon storage
mmpg-x86 Oct 15, 2026
5ff2a61
Synchronize shared bug catalogs through PostgreSQL
mmpg-x86 Oct 15, 2026
0d7e948
Keep catalog merge bases until local changes are acknowledged
mmpg-x86 Oct 15, 2026
f0ab873
Keep imported discovery links scoped to their producer
mmpg-x86 Oct 15, 2026
1b9ef39
Honor the selected storage backend in database clients
mmpg-x86 Oct 15, 2026
dec5920
Provide OpenSSL dependencies for Linux Nix builds
mmpg-x86 Oct 15, 2026
9d63568
Run PostgreSQL integration coverage in CI
mmpg-x86 Oct 15, 2026
f74127a
Preserve ASCII subsystem scope matching on both backends
mmpg-x86 Oct 15, 2026
1256de8
Redact foreign duplicate history in scoped bug views
mmpg-x86 Oct 15, 2026
0a1ddeb
Bound pending catalog lookups to the requested bug views
mmpg-x86 Oct 15, 2026
67b4b3d
Preserve shared duplicate relationships during concurrent triage
mmpg-x86 Oct 15, 2026
b67bc94
Preserve analysis outcomes across shared catalog outages
mmpg-x86 Oct 15, 2026
44b0051
Recover ordinary PostgreSQL sessions after connection loss
mmpg-x86 Oct 15, 2026
ba8ef01
Keep the libSQL covering index for review statistics
mmpg-x86 Oct 15, 2026
3d64a2d
Exercise PostgreSQL adapter boundaries with deterministic fixtures
mmpg-x86 Oct 15, 2026
4447f1f
Describe PostgreSQL deployment and execution boundaries
mmpg-x86 Oct 15, 2026
56b079b
Keep shared publication scoped to the configured project
mmpg-x86 Oct 15, 2026
f5f686c
Scope PostgreSQL coordination locks to the configured schema
mmpg-x86 Oct 15, 2026
592d15d
Version shared mirror tracking and exclude local bookkeeping
mmpg-x86 Oct 15, 2026
44eb292
Reuse the shared catalog connection and TLS configuration
mmpg-x86 Oct 15, 2026
35b5c79
Discard PostgreSQL sessions after interrupted operations
mmpg-x86 Oct 15, 2026
672dbce
Classify transient catalog failures before refunding attempts
mmpg-x86 Oct 15, 2026
085e67a
Preserve legacy bug identifiers in project catalog namespaces
mmpg-x86 Oct 15, 2026
e875af3
Bound shared catalog synchronization with durable scheduling
mmpg-x86 Oct 15, 2026
490c9dc
Preserve original metadata when importing shared bug history
mmpg-x86 Oct 15, 2026
13fd37c
Match libSQL bug triage behavior on PostgreSQL
mmpg-x86 Oct 15, 2026
66e32d9
Verify the shared catalog readiness contract
mmpg-x86 Oct 15, 2026
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
Prev Previous commit
Next Next commit
Preserve shared duplicate relationships during concurrent triage
Check duplicate chains while holding the catalog write lock. Defer
references to unpublished targets and reject reciprocal decisions
that would remove every canonical bug in a cycle. Retain the catalog
triage and record the rejected proposal in conflict history.

Import a newly selected target before acknowledging a dirty local
record. Exercise both acknowledgement and reciprocal triage races
against the live PostgreSQL catalog.

Signed-off-by: Maciej Grochowski <maciej.grochowski@protonmail.com>
  • Loading branch information
mmpg-x86 committed Oct 15, 2026
commit 67b4b3d6dd1366af3c56abf947f1ff5a2e5d9b98
99 changes: 81 additions & 18 deletions src/db/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,60 @@ struct MergeConflict {
shared: Option<serde_json::Value>,
}

enum DuplicateChain {
Valid,
Unpublished,
Cycle,
}

async fn shared_duplicate_chain(
conn: &crate::storage::Connection,
project: &str,
record: &Record,
) -> Result<DuplicateChain> {
let mut target = record.triage.duplicate_of.clone();
let mut visited = BTreeSet::from([record.bugid.clone()]);
while let Some(bugid) = target {
if !visited.insert(bugid.clone()) {
return Ok(DuplicateChain::Cycle);
}
let mut rows = conn
.query(
"SELECT payload::jsonb #>> '{triage,duplicate_of}'
FROM shared_bug_records WHERE project=? AND bugid=?",
libsql::params![project, bugid],
)
.await?;
let Some(row) = rows.next().await? else {
return Ok(DuplicateChain::Unpublished);
};
target = row.get(0)?;
}
Ok(DuplicateChain::Valid)
}

impl Record {
fn add_conflict(&mut self, conflict: MergeConflict, version: i64, instance: &str) {
let field = conflict.field;
let key = format!("conflict:{instance}:{}:{version}:{field}", self.bugid);
self.events.entry(key).or_insert_with(|| Event {
kind: "sync_conflict".into(),
tool: "shared_catalog".into(),
model: None,
author: Some("system".into()),
created_at: chrono::Utc::now().timestamp(),
content: Some(format!(
"Concurrent changes to {field}; kept the shared catalog value"
)),
data_json: Some(json!({"field":field,"local_version":version,"proposed":conflict.local,"kept":conflict.shared})),
tokens_in: None,
tokens_out: None,
tokens_cached: None,
logs: None,
});
}
}

impl Event {
fn new_enrichment(&self) -> NewBugEnrichment {
NewBugEnrichment {
Expand Down Expand Up @@ -277,7 +331,30 @@ impl Database {
.transpose()?
.map(|s| serde_json::from_str(&s))
.transpose()?;
let merged = merge_record(base.as_ref(), &local, prior.as_ref(), version, &instance)?;
let mut merged =
merge_record(base.as_ref(), &local, prior.as_ref(), version, &instance)?;
// Validate relations under the catalog write lock. Independent
// local decisions can otherwise form a cross-instance cycle.
match shared_duplicate_chain(&tx, &project, &merged).await? {
DuplicateChain::Valid => {}
DuplicateChain::Unpublished => {
tx.rollback().await?;
continue;
}
DuplicateChain::Cycle => {
let prior = prior
.as_ref()
.context("shared duplicate cycle without a prior record")?;
let conflict = MergeConflict {
field: "triage".into(),
local: Some(serde_json::to_value(&merged.triage)?),
shared: Some(serde_json::to_value(&prior.triage)?),
};
merged.triage = prior.triage.clone();
merged.analysis = prior.analysis.clone();
merged.add_conflict(conflict, version, &instance);
}
}
if prior.as_ref() != Some(&merged) {
tx.execute(
"INSERT INTO shared_bug_records (project,bugid,payload) VALUES (?,?,?)
Expand All @@ -292,6 +369,8 @@ impl Database {
.await?;
}
tx.commit().await?;
self.shared_import_targets(&remote, &merged, &project, &instance)
.await?;
self.shared_accept(&merged, Some(version), &instance)
.await?;
}
Expand Down Expand Up @@ -675,23 +754,7 @@ fn merge_record(
result.created_at = local.created_at.min(remote.created_at);
result.updated_at = local.updated_at.max(remote.updated_at);
for conflict in conflicts {
let field = conflict.field;
let key = format!("conflict:{instance}:{}:{version}:{field}", local.bugid);
result.events.entry(key).or_insert_with(|| Event {
kind: "sync_conflict".into(),
tool: "shared_catalog".into(),
model: None,
author: Some("system".into()),
created_at: chrono::Utc::now().timestamp(),
content: Some(format!(
"Concurrent changes to {field}; kept the shared catalog value"
)),
data_json: Some(json!({"field":field,"local_version":version,"proposed":conflict.local,"kept":conflict.shared})),
tokens_in: None,
tokens_out: None,
tokens_cached: None,
logs: None,
});
result.add_conflict(conflict, version, instance);
}
Ok(result)
}
Expand Down
89 changes: 89 additions & 0 deletions tests/integration/postgres_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,5 +381,94 @@ async fn exercise_shared(
resumed.sync_shared_bugs().await?;
second.sync_shared_bugs().await?;
assert!(second.get_bug_by_bugid(&pending.bugid).await?.is_some());
exercise_shared_duplicate_races(first, second).await?;
Ok(())
}

async fn shared_report(db: &Database, title: &str) -> Result<(i64, String)> {
let bugid = format!("sashiko-{}", uuid::Uuid::new_v4());
let bug: NewBug = serde_json::from_value(json!({
"bugid": bugid, "title": title,
"pipeline_state": "succeeded", "lifecycle_status": "open"
}))?;
Ok((db.create_bug(&bug).await?, bugid))
}

async fn exercise_shared_duplicate_races(first: &Database, second: &Database) -> Result<()> {
let (source, source_public) = shared_report(first, "acknowledgement source").await?;
first.sync_shared_bugs().await?;
second.sync_shared_bugs().await?;
let source_mirror = second.get_bug_by_bugid(&source_public).await?.unwrap();
let (target, target_public) = shared_report(second, "new remote target").await?;
second.sync_shared_bugs().await?;
second
.mark_bug_as_duplicate(sashiko::db::MarkDuplicateBugParams {
ephemeral_id: source_mirror.id,
canonical_id: target,
reasoning: "new shared target",
..Default::default()
})
.await?;
second.sync_shared_bugs().await?;
first
.add_bug_enrichment(
source,
&NewBugEnrichment {
kind: "comment".into(),
content: Some("concurrent source comment".into()),
..Default::default()
},
)
.await?;
// Publishing the dirty source merges a target this mirror has not pulled.
first.sync_shared_bugs().await?;
let imported_target = first.get_bug_by_bugid(&target_public).await?.unwrap();
let loaded = first.get_bug(source).await?.unwrap();
assert_eq!(loaded.duplicate_of_id, Some(imported_target.id));
assert!(
loaded
.enrichments
.iter()
.any(|e| e.content.as_deref() == Some("concurrent source comment"))
);

let (left, left_public) = shared_report(first, "left concurrent decision").await?;
let (right, right_public) = shared_report(first, "right concurrent decision").await?;
first.sync_shared_bugs().await?;
second.sync_shared_bugs().await?;
let mirror_left = second.get_bug_by_bugid(&left_public).await?.unwrap();
let mirror_right = second.get_bug_by_bugid(&right_public).await?.unwrap();
first
.mark_bug_as_duplicate(sashiko::db::MarkDuplicateBugParams {
ephemeral_id: left,
canonical_id: right,
reasoning: "first decision",
..Default::default()
})
.await?;
second
.mark_bug_as_duplicate(sashiko::db::MarkDuplicateBugParams {
ephemeral_id: mirror_right.id,
canonical_id: mirror_left.id,
reasoning: "reciprocal decision",
..Default::default()
})
.await?;
first.sync_shared_bugs().await?;
second.sync_shared_bugs().await?;
first.sync_shared_bugs().await?;
for db in [first, second] {
let left = db.get_bug_by_bugid(&left_public).await?.unwrap();
let right = db.get_bug_by_bugid(&right_public).await?.unwrap();
assert_eq!(left.duplicate_of_id, Some(right.id));
assert_eq!(right.lifecycle_status, BugLifecycleStatus::Open);
assert!(right.duplicate_of_id.is_none());
assert!(
right
.enrichments
.iter()
.any(|event| event.kind == "sync_conflict")
);
}
Ok(())
}