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
Keep imported discovery links scoped to their producer
Identify foreign evidence through stable shared event identities.
Retain its raw input for inspection while resolving patch and review
links only from evidence produced by the local instance.

Cover local link preservation and imported link suppression in a
regression test, and document the treatment of original payloads.

Signed-off-by: Maciej Grochowski <maciej.grochowski@protonmail.com>
  • Loading branch information
mmpg-x86 committed Oct 15, 2026
commit f0ab8739094caf923aed14c46e174678db72400a
5 changes: 3 additions & 2 deletions designs/DESIGN_POSTGRESQL_STORAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ transaction for operations that currently depend on SQLite atomicity.

PostgreSQL owns the shared catalog; each libSQL daemon keeps a local bug mirror
alongside its reviews and patchsets. A stable instance UUID and public bug IDs
identify synchronization records. Local row IDs never cross the catalog
boundary. Discovery commit references remain part of the shared evidence.
identify synchronization records. Catalog relations use public bug IDs. Original evidence retains its raw
payload, but imported discoveries never resolve producer-local patch or review
IDs against the mirror database. Discovery commits remain shared evidence.

SQLite triggers maintain a coalescing outbox in the bug mutation's transaction.
The synchronizer publishes a typed snapshot with stable event identities, then
Expand Down
5 changes: 3 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ instances change the same triage decision, the catalog decision is retained
and a conflict event is recorded in the bug's audit history. The originating
instance runs the bug's analysis; other instances can view and triage it.

Public bug IDs identify shared records. Local patch and review IDs stay in
their originating database. All instances sharing a catalog must trust the
Public bug IDs identify shared records. Patch and review relations remain
local. Original evidence can contain producer-local IDs; imported discoveries
do not turn them into links in another database. All instances sharing a catalog must trust the
same subsystem attribution and permission policy. A shared catalog may hold
multiple projects, with synchronization scoped by the instance's project.
Use the API for catalog changes so audit history and synchronization remain
Expand Down
8 changes: 6 additions & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3211,6 +3211,7 @@ impl Database {
// Interaction logs are deliberately not loaded with the family, so ask
// the table which records carry one before assembling the events.
let family_ids: Vec<i64> = family.iter().map(|b| b.id).collect();
let foreign_events = self.foreign_shared_events(&family_ids).await?;
let mut logged_records = std::collections::HashSet::<i64>::new();
if !family_ids.is_empty() {
let mut rows = self
Expand Down Expand Up @@ -3272,12 +3273,15 @@ impl Database {
tools.insert(t.clone());
}

let patchset_id = record
// Raw inputs retain their original payload. Only references
// produced by this instance can link to its patch database.
let local_record = record.filter(|e| !foreign_events.contains(&e.id));
let patchset_id = local_record
.and_then(|e| e.data_json.as_ref())
.and_then(|d| d.get("patchset_id"))
.and_then(|v| v.as_i64())
.or(bug.discovered_in_patchset_id);
let patch_id = record
let patch_id = local_record
.and_then(|e| e.data_json.as_ref())
.and_then(|d| d.get("patch_id"))
.and_then(|v| v.as_i64())
Expand Down
78 changes: 78 additions & 0 deletions src/db/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,24 @@ impl Database {
Ok(ids)
}

/// Producer-local IDs in foreign evidence cannot identify mirror reviews.
pub(super) async fn foreign_shared_events(&self, bug_ids: &[i64]) -> Result<BTreeSet<i64>> {
if self.shared.is_none() || bug_ids.is_empty() {
return Ok(BTreeSet::new());
}
let prefix = format!("{}:%", self.shared_meta("shared_instance").await?);
let mut rows = self.conn.query(
"SELECT e.id FROM bug_enrichments e JOIN shared_bug_events s ON s.enrichment_id=e.id
WHERE e.bug_id IN (SELECT value FROM json_each(?)) AND s.event_key NOT LIKE ?",
libsql::params![serde_json::to_string(bug_ids)?, prefix],
).await?;
let mut foreign = BTreeSet::new();
while let Some(row) = rows.next().await? {
foreign.insert(row.get(0)?);
}
Ok(foreign)
}

/// Publish local mutations and import catalog updates. Retries are idempotent.
pub async fn sync_shared_bugs(&self) -> Result<()> {
let Some(shared) = &self.shared else {
Expand Down Expand Up @@ -722,6 +740,66 @@ fn merge_value(
mod tests {
use super::*;

#[tokio::test]
async fn imported_evidence_keeps_raw_input_without_foreign_review_links() -> Result<()> {
let mut db = Database::new(&crate::settings::DatabaseSettings {
url: ":memory:".into(),
token: String::new(),
})
.await?;
db.shared = Some(Arc::new(SharedCatalog {
settings: Default::default(),
lock: tokio::sync::Mutex::new(()),
}));
db.migrate().await?;
db.ensure_project_stamp(crate::project::ProjectId::Sashiko)
.await?;
let instance = db.shared_meta("shared_instance").await?;
let bug: NewBug = serde_json::from_value(json!({
"bugid": format!("sashiko-{}", uuid::Uuid::new_v4()), "title": "local discovery"
}))?;
let payload = json!({"patchset_id": 123, "patch_id": 456, "review_id": 789, "reasoning": "original evidence"});
let id = db
.create_bug_with_enrichment(
&bug,
Some(&NewBugEnrichment {
kind: "candidate".into(),
data_json: Some(payload.clone()),
..Default::default()
}),
)
.await?;
let (mut record, _, _) = db.shared_snapshot(id, &instance).await?;
let local = db.get_bug(id).await?.context("local discovery")?;
let evidence = db.bug_evidence(&[local]).await?;
assert_eq!(evidence["discoveries"][0]["patchset_id"], 123);
assert_eq!(evidence["discoveries"][0]["patch_id"], 456);
record.bugid = format!("sashiko-{}", uuid::Uuid::new_v4());
record.origin = uuid::Uuid::new_v4().to_string();
record.events = record
.events
.into_iter()
.map(|(key, event)| (key.replacen(&instance, &record.origin, 1), event))
.collect();
db.shared_accept(&record, None, &instance).await?;
let imported = db
.get_bug_by_bugid(&record.bugid)
.await?
.context("imported discovery")?;
assert_eq!(
imported
.enrichments
.iter()
.find(|e| e.kind == "candidate")
.and_then(|e| e.data_json.as_ref()),
Some(&payload)
);
let evidence = db.bug_evidence(&[imported]).await?;
assert!(evidence["discoveries"][0]["patchset_id"].is_null());
assert!(evidence["discoveries"][0]["patch_id"].is_null());
Ok(())
}

#[tokio::test]
async fn acknowledgement_keeps_merge_base_after_concurrent_local_edit() -> Result<()> {
let mut db = Database::new(&crate::settings::DatabaseSettings {
Expand Down