huskies: merge 1095 bug Shadow drift: set_name writes CRDT name register without updating pipeline_items.name
This commit is contained in:
@@ -198,6 +198,40 @@ pub fn delete_item(story_id: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sync the shadow table's `name` column after a CRDT name-register write.
|
||||
///
|
||||
/// Reads the current item from the CRDT (which already holds the new name after
|
||||
/// `apply_and_persist`) and sends a `PipelineWriteMsg` so the SQLite mirror
|
||||
/// stays in sync. All other columns (stage, agent, retry_count, depends_on)
|
||||
/// are preserved from the live CRDT view; `content` is left as `None` so the
|
||||
/// UPSERT's `COALESCE` keeps the existing value.
|
||||
///
|
||||
/// No-ops if the DB is not initialised or the item is not in the CRDT.
|
||||
pub fn sync_item_name(story_id: &str) {
|
||||
let Some(db) = PIPELINE_DB.get() else { return };
|
||||
let Some(view) = crate::crdt_state::read_item(story_id) else {
|
||||
return;
|
||||
};
|
||||
let depends_on = {
|
||||
let d = view.depends_on();
|
||||
if d.is_empty() {
|
||||
None
|
||||
} else {
|
||||
serde_json::to_string(d).ok()
|
||||
}
|
||||
};
|
||||
let msg = PipelineWriteMsg {
|
||||
story_id: story_id.to_string(),
|
||||
stage: view.stage().dir_name().to_string(),
|
||||
name: Some(view.name().to_string()),
|
||||
agent: view.agent().map(|a| a.to_string()),
|
||||
retry_count: Some(view.retry_count() as i64),
|
||||
depends_on,
|
||||
content: None,
|
||||
};
|
||||
let _ = db.tx.send(msg);
|
||||
}
|
||||
|
||||
/// Get the next available item number by scanning the CRDT state, the
|
||||
/// in-memory content store, AND the tombstone set for the highest existing
|
||||
/// number.
|
||||
|
||||
Reference in New Issue
Block a user