Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(bootstrap): resume only a contiguous prefix of completed chunks (#635)

AkitaOnRailsbcdfd44e3f0a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f5d45460..7f6bcf6c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
+- `bootstrap --resume` recovers an interrupted run from durable per-chunk
+ progress instead of re-paying for every LLM call (#621). Each chunk's pages
+ are recorded (keyed by a fingerprint of the pruned sources + chunk budget, so
+ a re-run after new commits re-chunks and starts fresh) and `--resume` seeds
+ them and skips those chunks; the wiki write stays atomic (nothing lands until
+ the whole run completes) and progress is cleared on success. It adopts only
+ the **contiguous** prefix of completed chunks and re-runs from the first gap
+ or unreadable row (#635), so a resumed run can never diverge from a clean one
+ by seeding a later chunk with context an earlier, still-missing chunk never
+ produced. Complements the transient-retry from 2.0.3 (#617): retry reduces
+ how often you need resume; resume covers the crash / restart case.
- Added first-party OpenCode 2.0 beta (`opencode2`) support.
`install-mcp --client opencode2` merges the V2 `mcp.servers` remote entry
(no `enabled` field, `oauth: false` for header credentials);
diff --git a/crates/ai-memory-consolidate/src/bootstrap.rs b/crates/ai-memory-consolidate/src/bootstrap.rs
index 548d446a..49e90ac5 100644
--- a/crates/ai-memory-consolidate/src/bootstrap.rs
+++ b/crates/ai-memory-consolidate/src/bootstrap.rs
@@ -461,16 +461,27 @@ impl Bootstrap {
.writer
.load_bootstrap_progress(fingerprint.clone())
.await?;
- for record in recorded {
+ // Adopt only the CONTIGUOUS prefix of completed chunks (0, 1, 2, …).
+ // Each chunk's output depends on the pages the earlier chunks wrote,
+ // in order (`prior` below), so reusing a later chunk while an earlier
+ // one is missing — a gap left by a crash, or an unreadable row —
+ // would seed it with context a clean run never had, and a resumed run
+ // must not diverge from a fresh one (#635). Records arrive ordered by
+ // chunk_index; stop at the first gap or unreadable row and re-run
+ // everything from there (the re-run overwrites the stale later rows).
+ for (expected, record) in recorded.into_iter().enumerate() {
+ if record.chunk_index as usize != expected {
+ break;
+ }
let pages: Vec<BootstrapPage> = match serde_json::from_str(&record.pages_json) {
Ok(pages) => pages,
Err(e) => {
warn!(
chunk = record.chunk_index,
error = %e,
- "skipping unreadable bootstrap progress row; will re-run this chunk"
+ "unreadable bootstrap progress row; re-running from this chunk on"
);
- continue;
+ break;
}
};
for page in pages {
@@ -2205,4 +2216,97 @@ mod tests {
.unwrap();
assert!(cleared.is_empty(), "a completed run clears its progress");
}
+
+ /// Three sources sized so `plan_bootstrap_chunks` splits them into exactly
+ /// three chunks under the same small budget as `two_chunk_sources`.
+ fn three_chunk_sources() -> Vec<BootstrapSource> {
+ (0..3u8)
+ .map(|i| BootstrapSource {
+ kind: SourceKind::GitCommit,
+ label: format!("git: {i}"),
+ text: ((b'a' + i) as char).to_string().repeat(2_000),
+ })
+ .collect()
+ }
+
+ fn one_page_json(path: &str) -> String {
+ serde_json::to_string(&vec![BootstrapPage {
+ path: path.into(),
+ title: path.into(),
+ body_markdown: "body".into(),
+ tags: vec![],
+ }])
+ .unwrap()
+ }
+
+ /// #635: a NON-CONTIGUOUS recorded set — chunk 0 and chunk 2 durable, chunk
+ /// 1 missing (the crash case this feature exists for) — must adopt only the
+ /// contiguous prefix `{0}` and re-run chunks 1 AND 2, so each sees the same
+ /// prior context a clean run would. The stale chunk-2 pages must NOT be
+ /// adopted; they are re-produced by the re-run.
+ #[tokio::test]
+ async fn resume_ignores_a_non_contiguous_gap_and_reruns_from_it() {
+ let tmp = tempfile::tempdir().unwrap();
+ let sources = three_chunk_sources();
+ let chunk_budget = effective_chunk_budget(800, 100_000);
+ let planned = plan_bootstrap_chunks(sources.clone(), chunk_budget);
+ assert_eq!(planned.len(), 3, "fixture must produce three chunks");
+
+ // Re-run scripts chunk 1 -> b.md, chunk 2 -> c.md (the fresh chunk-2
+ // page, distinct from the stale one seeded below).
+ let llm = Arc::new(SequencedLlm {
+ calls: AtomicUsize::new(0),
+ responses: vec![
+ page_response("concepts/b.md", "chunk1"),
+ page_response("concepts/c.md", "chunk2"),
+ ],
+ fail_at: None,
+ });
+ let (store, bootstrap, ws, proj) = bootstrap_fixture(tmp.path(), llm.clone()).await;
+ let fingerprint = bootstrap_fingerprint(ws, proj, chunk_budget, &planned);
+
+ // Seed a GAP: chunk 0 (kept) and chunk 2 (stale, must be discarded);
+ // chunk 1 deliberately absent.
+ store
+ .writer
+ .record_bootstrap_chunk(
+ fingerprint.clone(),
+ 0,
+ one_page_json("concepts/a.md"),
+ "c0".into(),
+ )
+ .await
+ .unwrap();
+ store
+ .writer
+ .record_bootstrap_chunk(
+ fingerprint.clone(),
+ 2,
+ one_page_json("concepts/stale.md"),
+ "c2-stale".into(),
+ )
+ .await
+ .unwrap();
+
+ let outcome = bootstrap
+ .process_sources(&resume_test_config(ws, proj, true), sources)
+ .await
+ .expect("resume completes");
+
+ // Only chunk 0 was contiguous → chunks 1 and 2 were both re-run.
+ assert_eq!(
+ llm.calls.load(Ordering::SeqCst),
+ 2,
+ "chunk 2 must be re-run (not adopted across the gap), so both 1 and 2 call the LLM"
+ );
+ assert!(outcome.pages_written.contains(&"concepts/a.md".to_string()));
+ assert!(outcome.pages_written.contains(&"concepts/b.md".to_string()));
+ assert!(outcome.pages_written.contains(&"concepts/c.md".to_string()));
+ assert!(
+ !outcome
+ .pages_written
+ .contains(&"concepts/stale.md".to_string()),
+ "the stale chunk-2 page across the gap must not be adopted"
+ );
+ }
}