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
Version shared mirror tracking and exclude local bookkeeping
Track the opt-in mirror schema independently of primary migrations.
Gate its triggers on the selected mode, and requeue local edits when
shared storage is enabled again after a period in libSQL mode.

Queue bug updates only when shared payload fields change. Lease renewal
and fix-check housekeeping no longer resend complete histories.

Cover mode transitions, unsupported mirror versions, housekeeping and
origin ownership across fix-check claims and lease recovery.

Signed-off-by: Maciej Grochowski <maciej.grochowski@protonmail.com>
  • Loading branch information
mmpg-x86 committed Oct 15, 2026
commit 592d15d77553c00862a83edc6a3de9b943ca5419
3 changes: 3 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ In shared catalog mode, each local database has a stable instance identity
and a local bug mirror. Changes enter a durable outbox in the same transaction
as the bug update. A background task publishes and imports changes every five
seconds; PostgreSQL outages leave changes queued and visible as **Sync pending**.
Lease renewals and housekeeping timestamps do not queue whole reports. Mirror
migrations have their own version in metadata. Selecting `libsql` disables change
tracking; re-enabling the shared catalog reconciles edits made while it was off.
Analysis waits for the catalog before making shared deduplication decisions.
An outage during that check requeues the analysis without consuming an attempt.
If an outcome is already committed locally, publication retries from the outbox
Expand Down
14 changes: 14 additions & 0 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,20 @@ impl Database {

if self.shared.is_some() {
self.initialize_shared_catalog().await?;
} else {
let mut rows = self
.conn
.query(
"SELECT 1 FROM sqlite_master WHERE type='table' AND name='shared_bug_sync'",
(),
)
.await?;
let installed = rows.next().await?.is_some();
drop(rows);
if installed {
self.execute("UPDATE meta SET value='0' WHERE key='shared_enabled'", ())
.await?;
}
}
info!("Database schema is up to date at version 13.");

Expand Down
166 changes: 163 additions & 3 deletions src/db/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,35 @@ impl Database {

pub(super) async fn initialize_shared_catalog(&self) -> Result<()> {
let tx = self.begin_transaction().await?;
tx.execute_batch(include_str!("../migrations/014_shared_bug_mirror.sql"))
let (version, was_enabled) = {
let mut rows = tx.query(
"SELECT key,value FROM meta WHERE key IN ('shared_schema_version','shared_enabled')", (),
).await?;
let mut version = 0u32;
let mut enabled = false;
while let Some(row) = rows.next().await? {
match row.get::<String>(0)?.as_str() {
"shared_schema_version" => version = row.get::<String>(1)?.parse()?,
"shared_enabled" => enabled = row.get::<String>(1)? == "1",
_ => {}
}
}
(version, enabled)
};
anyhow::ensure!(
version <= 1,
"Unsupported shared mirror schema version {version}"
);
if version == 0 {
tx.execute_batch(include_str!("../migrations/shared_catalog/001_mirror.sql"))
.await?;
tx.execute(
"INSERT INTO meta (key,value) VALUES ('shared_schema_version','1')
ON CONFLICT(key) DO UPDATE SET value=excluded.value",
(),
)
.await?;
}
tx.execute(
"INSERT INTO meta (key,value) VALUES ('shared_instance',?) ON CONFLICT(key) DO NOTHING",
[uuid::Uuid::new_v4().to_string()],
Expand All @@ -240,9 +267,20 @@ impl Database {
(),
)
.await?;
tx.execute("INSERT INTO shared_bug_sync (bug_id, origin, local_version, dirty)
tx.execute(
"INSERT INTO meta (key,value) VALUES ('shared_enabled','1')
ON CONFLICT(key) DO UPDATE SET value=excluded.value",
(),
)
.await?;
let conflict = if was_enabled {
"DO NOTHING"
} else {
"DO UPDATE SET local_version=local_version+1,dirty=1"
};
tx.execute(&format!("INSERT INTO shared_bug_sync (bug_id, origin, local_version, dirty)
SELECT id, (SELECT value FROM meta WHERE key='shared_instance'), 1, 1 FROM bugs WHERE true
ON CONFLICT(bug_id) DO NOTHING", ()).await?;
ON CONFLICT(bug_id) {conflict}"), ()).await?;
tx.commit().await?;
Ok(())
}
Expand Down Expand Up @@ -880,6 +918,128 @@ mod tests {
Ok(db)
}

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

async fn acknowledge_local(db: &Database, id: i64) -> Result<()> {
let instance = db.shared_meta("shared_instance").await?;
let (record, _, version) = db.shared_snapshot(id, &instance).await?;
db.shared_accept(&record, Some(version), &instance).await
}

#[tokio::test]
async fn lease_and_housekeeping_updates_do_not_republish_reports() -> Result<()> {
let db = local_mirror().await?;
let id = local_report(&db, "bookkeeping").await?;
db.claim_pending_bug("owner", 300, 3)
.await?
.context("claim")?;
acknowledge_local(&db, id).await?;
assert!(db.shared_bug_pending_ids().await?.is_empty());
assert!(db.renew_bug_lease(id, "owner", 300).await?);
assert!(db.shared_bug_pending_ids().await?.is_empty());
db.execute("UPDATE bugs SET lifecycle_status='open',pipeline_state='succeeded',locked_by=NULL,lease_expires_at=NULL WHERE id=?", [id]).await?;
acknowledge_local(&db, id).await?;
assert_eq!(db.touch_open_bugs_fix_check_batch(&[id]).await?, 1);
assert!(db.shared_bug_pending_ids().await?.is_empty());
db.update_bug_title(id, "meaningful edit").await?;
assert!(db.shared_bug_pending_ids().await?.contains(&id));
Ok(())
}

#[tokio::test]
async fn disabling_and_reenabling_catalog_tracking_preserves_local_edits() -> Result<()> {
let mut db = local_mirror().await?;
let id = local_report(&db, "before disable").await?;
acknowledge_local(&db, id).await?;
let shared = db.shared.take().context("shared mode")?;
db.migrate().await?;
db.update_bug_title(id, "edited in libSQL mode").await?;
let mut rows = db
.conn
.query("SELECT dirty FROM shared_bug_sync WHERE bug_id=?", [id])
.await?;
assert_eq!(rows.next().await?.unwrap().get::<i64>(0)?, 0);
drop(rows);
db.shared = Some(shared);
db.migrate().await?;
assert!(db.shared_bug_pending_ids().await?.contains(&id));
assert_eq!(
db.get_bug(id).await?.unwrap().title,
"edited in libSQL mode"
);
assert_eq!(db.shared_meta("shared_schema_version").await?, "1");
db.execute(
"UPDATE meta SET value='999' WHERE key='shared_schema_version'",
(),
)
.await?;
assert!(db.migrate().await.is_err());
Ok(())
}

#[tokio::test]
async fn fix_checks_and_lease_recovery_skip_foreign_mirrors() -> Result<()> {
let db = local_mirror().await?;
let own = local_report(&db, "origin-owned analysis").await?;
db.execute("UPDATE bugs SET lifecycle_status='open',pipeline_state='succeeded',verified_on_sha='old' WHERE id=?", [own]).await?;
let instance = db.shared_meta("shared_instance").await?;
let (mut remote, _, _) = db.shared_snapshot(own, &instance).await?;
remote.bugid = format!("sashiko-{}", uuid::Uuid::new_v4());
remote.origin = uuid::Uuid::new_v4().to_string();
remote.events.clear();
db.shared_accept(&remote, None, &instance).await?;
let foreign = db
.get_bug_by_bugid(&remote.bugid)
.await?
.context("foreign mirror")?
.id;
let candidates = db.list_open_bugs_for_fix_check("new", None, 50).await?;
assert_eq!(
candidates.iter().map(|bug| bug.id).collect::<Vec<_>>(),
vec![own]
);
assert!(
db.claim_specific_open_bug_for_fix_check(foreign, "new", "owner", 300)
.await?
.is_none()
);
assert_eq!(
db.claim_open_bug_for_fix_check("new", "owner", 300)
.await?
.context("owned fix check")?
.id,
own
);
assert!(
db.claim_open_bug_for_fix_check("new", "owner", 300)
.await?
.is_none()
);
for id in [own, foreign] {
db.execute("UPDATE bugs SET pipeline_state='running',attempt_count=3,locked_by=NULL,lease_expires_at=NULL WHERE id=?", [id]).await?;
}
assert_eq!(db.recover_stale_running_bugs().await?, 1);
assert_eq!(
db.get_bug(foreign).await?.unwrap().pipeline_state,
BugPipelineState::Running
);
assert_eq!(db.abandon_exhausted_bugs(3).await?, 1);
assert_eq!(
db.get_bug(own).await?.unwrap().pipeline_state,
BugPipelineState::Abandoned
);
assert_eq!(
db.get_bug(foreign).await?.unwrap().pipeline_state,
BugPipelineState::Running
);
Ok(())
}

#[tokio::test]
async fn pending_state_is_limited_to_requested_bugs() -> Result<()> {
let db = local_mirror().await?;
Expand Down
102 changes: 0 additions & 102 deletions src/migrations/014_shared_bug_mirror.sql

This file was deleted.

Loading