huskies: merge 852

This commit is contained in:
dave
2026-04-29 08:51:22 +00:00
parent 549a9defc4
commit dcd695ad0e
3 changed files with 70 additions and 15 deletions
+27 -15
View File
@@ -10,23 +10,17 @@ use super::time::{
};
impl AgentPool {
/// Start the merge pipeline as a background task.
/// Sweep all Running merge jobs in the CRDT and delete any that were left
/// behind by a previous server instance.
///
/// Returns immediately so the MCP tool call doesn't time out (the full
/// pipeline — squash merge + quality gates — takes well over 60 seconds,
/// exceeding Claude Code's MCP tool-call timeout).
/// A job is considered stale when its recorded `server_start` timestamp is
/// older than the current server's boot time, or when the `error` field
/// cannot be decoded (legacy / malformed entries).
///
/// The mergemaster agent should poll [`get_merge_status`](Self::get_merge_status)
/// until the job reaches a terminal state.
pub fn start_merge_agent_work(
self: &Arc<Self>,
project_root: &Path,
story_id: &str,
) -> Result<(), String> {
// Sweep stale Running entries left behind by dead processes before
// applying the double-start guard. This handles the case where the
// server crashed mid-merge: the next attempt finds a Running entry
// whose owning process is gone and clears it automatically.
/// Called at the top of [`start_merge_agent_work`] to unblock retries, and
/// also by the periodic background reaper in the tick loop so stale entries
/// are cleaned up even when no new merge is triggered.
pub(crate) fn reap_stale_merge_jobs(&self) {
if let Some(jobs) = crate::crdt_state::read_all_merge_jobs() {
let current_boot = server_start_time();
for job in jobs {
@@ -46,6 +40,24 @@ impl AgentPool {
}
}
}
}
/// Start the merge pipeline as a background task.
///
/// Returns immediately so the MCP tool call doesn't time out (the full
/// pipeline — squash merge + quality gates — takes well over 60 seconds,
/// exceeding Claude Code's MCP tool-call timeout).
///
/// The mergemaster agent should poll [`get_merge_status`](Self::get_merge_status)
/// until the job reaches a terminal state.
pub fn start_merge_agent_work(
self: &Arc<Self>,
project_root: &Path,
story_id: &str,
) -> Result<(), String> {
// Sweep stale Running entries left behind by dead processes before
// applying the double-start guard.
self.reap_stale_merge_jobs();
// Guard against double-starts; clear any completed/failed entry so the
// caller can retry without needing to call a separate cleanup step.