huskies: merge 1009

This commit is contained in:
dave
2026-05-13 22:50:13 +00:00
parent a5cd3a2152
commit 4e007bb770
56 changed files with 453 additions and 384 deletions
+30 -21
View File
@@ -11,7 +11,7 @@ use serde_json::json;
use super::super::state::{apply_and_persist, emit_event, get_crdt, rebuild_index};
use super::super::types::CrdtEvent;
use crate::io::story_metadata::QaMode;
use crate::pipeline_state::{Stage, stage_dir_name};
use crate::pipeline_state::{AgentClaim, Stage, stage_dir_name};
/// Set the typed `depends_on` CRDT register for a pipeline item.
///
@@ -221,7 +221,6 @@ pub fn set_qa_mode(story_id: &str, mode: Option<QaMode>) -> bool {
///
/// `stage` is the typed pipeline state; it is serialised to the canonical
/// clean wire form (story 934) via [`stage_dir_name`] at the CRDT boundary.
#[allow(clippy::too_many_arguments)]
pub fn write_item(
story_id: &str,
stage: &Stage,
@@ -229,11 +228,14 @@ pub fn write_item(
agent: Option<&str>,
retry_count: Option<i64>,
depends_on: Option<&str>,
claimed_by: Option<&str>,
claimed_at: Option<f64>,
merged_at: Option<f64>,
) {
let stage_str = stage_dir_name(stage);
let claim: Option<&AgentClaim> = match stage {
Stage::Coding { claim } => claim.as_ref(),
Stage::Merge { claim, .. } => claim.as_ref(),
_ => None,
};
let Some(state_mutex) = get_crdt() else {
return;
};
@@ -291,14 +293,19 @@ pub fn write_item(
s.crdt.doc.items[idx].depends_on.set(d.to_string())
});
}
if let Some(cb) = claimed_by {
apply_and_persist(&mut state, |s| {
s.crdt.doc.items[idx].claimed_by.set(cb.to_string())
});
}
if let Some(ca) = claimed_at {
apply_and_persist(&mut state, |s| s.crdt.doc.items[idx].claimed_at.set(ca));
}
let (claim_agent_str, claim_ts_val) = match claim {
Some(c) => (
c.agent.0.as_str().to_string(),
c.claimed_at.timestamp() as f64,
),
None => (String::new(), 0.0),
};
apply_and_persist(&mut state, |s| {
s.crdt.doc.items[idx].claim_agent.set(claim_agent_str)
});
apply_and_persist(&mut state, |s| {
s.crdt.doc.items[idx].claim_ts.set(claim_ts_val)
});
if let Some(ma) = merged_at {
apply_and_persist(&mut state, |s| s.crdt.doc.items[idx].merged_at.set(ma));
}
@@ -322,6 +329,13 @@ pub fn write_item(
}
} else {
// Insert new item.
let (insert_claim_agent, insert_claim_ts) = match claim {
Some(c) => (
c.agent.0.as_str().to_string(),
c.claimed_at.timestamp() as f64,
),
None => (String::new(), 0.0),
};
let item_json: JsonValue = json!({
"story_id": story_id,
"stage": stage_str,
@@ -329,8 +343,8 @@ pub fn write_item(
"agent": agent.unwrap_or(""),
"retry_count": retry_count.unwrap_or(0) as f64,
"depends_on": depends_on.unwrap_or(""),
"claimed_by": claimed_by.unwrap_or(""),
"claimed_at": claimed_at.unwrap_or(0.0),
"claim_agent": insert_claim_agent,
"claim_ts": insert_claim_ts,
"merged_at": merged_at.unwrap_or(0.0),
"qa_mode": "",
"item_type": "",
@@ -357,8 +371,8 @@ pub fn write_item(
item.agent.advance_seq(floor);
item.retry_count.advance_seq(floor);
item.depends_on.advance_seq(floor);
item.claimed_by.advance_seq(floor);
item.claimed_at.advance_seq(floor);
item.claim_agent.advance_seq(floor);
item.claim_ts.advance_seq(floor);
item.merged_at.advance_seq(floor);
item.qa_mode.advance_seq(floor);
item.item_type.advance_seq(floor);
@@ -384,7 +398,6 @@ pub fn write_item(
/// Stages are normalised through [`Stage::from_dir`]: unknown strings cause
/// the write to be skipped (with a log line).
#[cfg(test)]
#[allow(clippy::too_many_arguments)]
pub fn write_item_str(
story_id: &str,
stage: &str,
@@ -392,8 +405,6 @@ pub fn write_item_str(
agent: Option<&str>,
retry_count: Option<i64>,
depends_on: Option<&str>,
claimed_by: Option<&str>,
claimed_at: Option<f64>,
merged_at: Option<f64>,
) {
// Normalise pre-934 directory-style strings to clean wire form so
@@ -423,8 +434,6 @@ pub fn write_item_str(
agent,
retry_count,
depends_on,
claimed_by,
claimed_at,
merged_at,
);
}