aKode: rimossa la memoria nativa di Codex e le funzioni senza codice; meno chiamate al modello
Memoria nativa (memories) rimossa del tutto: - features: memories, memory_tool, external_agent_memory_import, chronicle (alias telepathy) diventano Removed; le chiavi restano accettate e memories/memory_tool/[memories] producono un solo avviso senza link («La sezione [memories] e la chiave memory_tool non sono più usate da aKode: la memoria a lungo termine è il plugin memoria di imeAI.»). - Tolti i crate memories/read, memories/write ed ext/memories, l'avvio della pipeline a ogni turno (app-server), l'estensione, /memories e la richiesta di attivazione nella TUI, `akode debug clear-memories`, l'importazione delle memorie da altri agenti (memory_import.rs, detect/memory.rs; il resto di /import resta). - core: niente più MemoriesConfig, citazioni delle memorie, metriche e marcatura «polluted» dei thread; [memories] (MemoriesToml) resta solo come sezione accettata e ignorata. - state: memories_1.sqlite e memories_v2_1.sqlite non vengono più aperti né cancellati; la colonna threads.memory_mode resta, nessuna migrazione. - Protocollo app-server invariato per compatibilità col daemon: memory/reset risponde «non supportato» senza cancellare nulla, memory/status non è mai pronto, thread/memory/read non ha riassunto. Altre rimozioni: - I 14 flag dell'app desktop di OpenAI senza codice (tool_suggest, in_app_*, browser_use*, computer_use, bedrock_setup_wizard, workspace_dependencies) e analytics_plan_history: Removed, chiavi accettate; analytics_plan_history esce da /experimental. - Skill: tolto l'esperimento «shadow selection» e i selettori collegati. Meno chiamate al modello non richieste: - Titoli dei thread: il primo messaggio dell'utente su una riga, troncato a 36 caratteri; `[tui] auto_title = true` riattiva i titoli generati. - `[tui] auto_recap` predefinito false; `goals` spento di default. Privacy: installation_id e gli id di sessione/thread/finestra (e il blocco dei metadati del turno che li ripete) vanno in client_metadata e negli header di compatibilità solo ai provider locali (loopback, IP privati 10/8, 172.16/12, 192.168/16, host .local/.lan). Domini OpenAI: tolti i link visibili (avviso dei flag deprecati, profili, bubblewrap), l'attribuzione Codex nei commit (sempre spenta), la riscrittura dell'URL della documentazione OpenAI via MCP e la registrazione remota dell'exec-server verso host OpenAI (ora solo loopback); il riconoscimento delle destinazioni OpenAI confronta i domini etichetta per etichetta. Il binario non contiene più «openai.com» né «chatgpt.com». Test adattati (sicurezza compresa: guardian, ruolo ostile, exec-server ora più restrittivo); rimossi solo quelli del codice tolto. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,6 @@ codex_rust_crate(
|
||||
compile_data = glob([
|
||||
"goals_migrations/**",
|
||||
"logs_migrations/**",
|
||||
"memory_migrations/**",
|
||||
"migrations/**",
|
||||
"queue_migrations/**",
|
||||
"thread_history_migrations/**",
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
CREATE TABLE stage1_outputs (
|
||||
thread_id TEXT PRIMARY KEY,
|
||||
source_updated_at INTEGER NOT NULL,
|
||||
raw_memory TEXT NOT NULL,
|
||||
rollout_summary TEXT NOT NULL,
|
||||
rollout_slug TEXT,
|
||||
generated_at INTEGER NOT NULL,
|
||||
usage_count INTEGER,
|
||||
last_usage INTEGER,
|
||||
selected_for_phase2 INTEGER NOT NULL DEFAULT 0,
|
||||
selected_for_phase2_source_updated_at INTEGER
|
||||
);
|
||||
|
||||
CREATE INDEX idx_stage1_outputs_source_updated_at
|
||||
ON stage1_outputs(source_updated_at DESC, thread_id DESC);
|
||||
|
||||
CREATE TABLE jobs (
|
||||
kind TEXT NOT NULL,
|
||||
job_key TEXT NOT NULL,
|
||||
status TEXT NOT NULL,
|
||||
worker_id TEXT,
|
||||
ownership_token TEXT,
|
||||
started_at INTEGER,
|
||||
finished_at INTEGER,
|
||||
lease_until INTEGER,
|
||||
retry_at INTEGER,
|
||||
retry_remaining INTEGER NOT NULL,
|
||||
last_error TEXT,
|
||||
input_watermark INTEGER,
|
||||
last_success_watermark INTEGER,
|
||||
PRIMARY KEY (kind, job_key)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_jobs_kind_status_retry_lease
|
||||
ON jobs(kind, status, retry_at, lease_until);
|
||||
@@ -1,6 +0,0 @@
|
||||
-- A successful consolidation is the readiness boundary for the version experiment.
|
||||
CREATE TABLE consolidation_progress (
|
||||
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
||||
max_thread_count INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
INSERT INTO consolidation_progress (singleton) VALUES (1);
|
||||
@@ -26,7 +26,6 @@ pub use model::CreatedProject;
|
||||
pub use model::LogEntry;
|
||||
pub use model::LogQuery;
|
||||
pub use model::LogRow;
|
||||
pub use model::Phase2JobClaimOutcome;
|
||||
pub use model::Project;
|
||||
pub use model::ProjectRoot;
|
||||
pub use model::ProjectSortKey;
|
||||
@@ -68,10 +67,6 @@ pub use model::ExtractionOutcome;
|
||||
pub use model::RemoveThreadAttachmentOutcome;
|
||||
pub use model::SortDirection;
|
||||
pub use model::SortKey;
|
||||
pub use model::Stage1JobClaim;
|
||||
pub use model::Stage1JobClaimOutcome;
|
||||
pub use model::Stage1Output;
|
||||
pub use model::Stage1StartupClaimParams;
|
||||
pub use model::ThreadAttachment;
|
||||
pub use model::ThreadAttachmentArchiveFilter;
|
||||
pub use model::ThreadAttachmentOwner;
|
||||
@@ -94,7 +89,6 @@ pub use runtime::GoalAccountingMode;
|
||||
pub use runtime::GoalAccountingOutcome;
|
||||
pub use runtime::GoalStore;
|
||||
pub use runtime::GoalUpdate;
|
||||
pub use runtime::MemoryStore;
|
||||
pub use runtime::ReadStateOperation;
|
||||
pub use runtime::ReadStateUpdate;
|
||||
pub use runtime::RemoteControlEnrollmentRecord;
|
||||
|
||||
@@ -7,7 +7,6 @@ use sqlx_sqlite::SqlitePool;
|
||||
pub(crate) static STATE_MIGRATOR: Migrator = sqlx_macros::migrate!("./migrations");
|
||||
pub(crate) static LOGS_MIGRATOR: Migrator = sqlx_macros::migrate!("./logs_migrations");
|
||||
pub(crate) static GOALS_MIGRATOR: Migrator = sqlx_macros::migrate!("./goals_migrations");
|
||||
pub(crate) static MEMORIES_MIGRATOR: Migrator = sqlx_macros::migrate!("./memory_migrations");
|
||||
pub(crate) static QUEUE_MIGRATOR: Migrator = sqlx_macros::migrate!("./queue_migrations");
|
||||
pub(crate) static THREAD_HISTORY_MIGRATOR: Migrator =
|
||||
sqlx_macros::migrate!("./thread_history_migrations");
|
||||
@@ -41,10 +40,6 @@ pub(crate) fn runtime_goals_migrator() -> Migrator {
|
||||
runtime_migrator(&GOALS_MIGRATOR)
|
||||
}
|
||||
|
||||
pub(crate) fn runtime_memories_migrator() -> Migrator {
|
||||
runtime_migrator(&MEMORIES_MIGRATOR)
|
||||
}
|
||||
|
||||
pub(crate) fn runtime_queue_migrator() -> Migrator {
|
||||
runtime_migrator(&QUEUE_MIGRATOR)
|
||||
}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
use akode_protocol::ThreadId;
|
||||
use chrono::DateTime;
|
||||
use chrono::Utc;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::ThreadMetadata;
|
||||
|
||||
/// Stored stage-1 memory extraction output for a single thread.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Stage1Output {
|
||||
pub thread_id: ThreadId,
|
||||
pub rollout_path: PathBuf,
|
||||
pub source_updated_at: DateTime<Utc>,
|
||||
pub raw_memory: String,
|
||||
pub rollout_summary: String,
|
||||
pub rollout_slug: Option<String>,
|
||||
pub cwd: PathBuf,
|
||||
pub git_branch: Option<String>,
|
||||
pub generated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
/// Result of trying to claim a stage-1 memory extraction job.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Stage1JobClaimOutcome {
|
||||
/// The caller owns the job and should continue with extraction.
|
||||
Claimed { ownership_token: String },
|
||||
/// Existing output is already newer than or equal to the source rollout.
|
||||
SkippedUpToDate,
|
||||
/// Another worker currently owns a fresh lease for this job.
|
||||
SkippedRunning,
|
||||
/// The job is in backoff and should not be retried yet.
|
||||
SkippedRetryBackoff,
|
||||
/// The job has exhausted retries and should not be retried automatically.
|
||||
SkippedRetryExhausted,
|
||||
}
|
||||
|
||||
/// Claimed stage-1 job with thread metadata.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Stage1JobClaim {
|
||||
pub thread: ThreadMetadata,
|
||||
pub ownership_token: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Stage1StartupClaimParams<'a> {
|
||||
pub scan_limit: usize,
|
||||
pub max_claimed: usize,
|
||||
pub max_age_days: i64,
|
||||
pub min_rollout_idle_hours: i64,
|
||||
pub allowed_sources: &'a [String],
|
||||
pub lease_seconds: i64,
|
||||
}
|
||||
|
||||
/// Result of trying to claim a phase-2 consolidation job.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Phase2JobClaimOutcome {
|
||||
/// The caller owns the global lock and may inspect the memory workspace.
|
||||
Claimed {
|
||||
ownership_token: String,
|
||||
/// Snapshot of `input_watermark` at claim time.
|
||||
input_watermark: i64,
|
||||
},
|
||||
/// The global job is in retry backoff.
|
||||
SkippedRetryUnavailable,
|
||||
/// The global job completed recently enough that consolidation is cooling down.
|
||||
SkippedCooldown,
|
||||
/// Another worker currently owns a fresh global consolidation lease.
|
||||
SkippedRunning,
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
mod backfill_state;
|
||||
mod graph;
|
||||
mod log;
|
||||
mod memories;
|
||||
mod project;
|
||||
mod queued_item;
|
||||
mod rollout_migration_state;
|
||||
@@ -15,11 +14,6 @@ pub use graph::DirectionalThreadSpawnEdgeStatus;
|
||||
pub use log::LogEntry;
|
||||
pub use log::LogQuery;
|
||||
pub use log::LogRow;
|
||||
pub use memories::Phase2JobClaimOutcome;
|
||||
pub use memories::Stage1JobClaim;
|
||||
pub use memories::Stage1JobClaimOutcome;
|
||||
pub use memories::Stage1Output;
|
||||
pub use memories::Stage1StartupClaimParams;
|
||||
pub use project::CreatedProject;
|
||||
pub use project::Project;
|
||||
pub use project::ProjectRoot;
|
||||
|
||||
@@ -9,7 +9,6 @@ use crate::ThreadsPage;
|
||||
use crate::apply_rollout_item;
|
||||
use crate::migrations::runtime_goals_migrator;
|
||||
use crate::migrations::runtime_logs_migrator;
|
||||
use crate::migrations::runtime_memories_migrator;
|
||||
use crate::migrations::runtime_queue_migrator;
|
||||
use crate::migrations::runtime_state_migrator;
|
||||
use crate::migrations::runtime_thread_history_migrator;
|
||||
@@ -46,8 +45,6 @@ mod goals;
|
||||
mod guardian_feedback;
|
||||
mod logs;
|
||||
mod logs_maintenance;
|
||||
mod memories;
|
||||
mod memory_versions;
|
||||
mod projects;
|
||||
mod queued_items;
|
||||
pub(crate) mod reclamation;
|
||||
@@ -75,7 +72,6 @@ pub use guardian_feedback::GuardianReviewRecord;
|
||||
pub use guardian_feedback::MAX_GUARDIAN_REVIEW_BYTES;
|
||||
pub use guardian_feedback::MAX_GUARDIAN_REVIEW_RECORDS;
|
||||
pub use guardian_feedback::MAX_GUARDIAN_REVIEW_RECORDS_PER_THREAD;
|
||||
pub use memories::MemoryStore;
|
||||
pub use queued_items::SqliteQueueStore;
|
||||
pub use recovery::backup_runtime_db_for_fresh_start;
|
||||
pub use recovery::collect_runtime_db_backups;
|
||||
@@ -104,8 +100,6 @@ pub struct StateRuntime {
|
||||
pool: Arc<sqlx::SqlitePool>,
|
||||
logs_pool: Arc<sqlx::SqlitePool>,
|
||||
thread_goals: GoalStore,
|
||||
memories: MemoryStore,
|
||||
memories_v2: Arc<tokio::sync::OnceCell<MemoryStore>>,
|
||||
thread_queue: SqliteQueueStore,
|
||||
thread_updated_at_millis: Arc<AtomicI64>,
|
||||
thread_recency_at_millis: Arc<AtomicI64>,
|
||||
@@ -141,12 +135,10 @@ impl StateRuntime {
|
||||
let state_migrator = runtime_state_migrator();
|
||||
let logs_migrator = runtime_logs_migrator();
|
||||
let goals_migrator = runtime_goals_migrator();
|
||||
let memories_migrator = runtime_memories_migrator();
|
||||
let queue_migrator = runtime_queue_migrator();
|
||||
let state_path = sqlite.state_db_path();
|
||||
let logs_path = sqlite.logs_db_path();
|
||||
let goals_path = sqlite.goals_db_path();
|
||||
let memories_path = sqlite.memories_db_path();
|
||||
let queue_path = sqlite.queue_db_path();
|
||||
let pool = match sqlite
|
||||
.open_state_db(&state_migrator, telemetry_override)
|
||||
@@ -158,7 +150,6 @@ impl StateRuntime {
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
let has_memories_v2 = tokio::fs::try_exists(sqlite.memories_v2_db_path()).await?;
|
||||
let logs_pool = match sqlite
|
||||
.open_logs_db(&logs_migrator, telemetry_override)
|
||||
.await
|
||||
@@ -181,20 +172,6 @@ impl StateRuntime {
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
let memories_pool = match sqlite
|
||||
.open_memories_db(&memories_migrator, telemetry_override)
|
||||
.await
|
||||
{
|
||||
Ok(db) => Arc::new(db),
|
||||
Err(err) => {
|
||||
warn!(
|
||||
"failed to open memories db at {}: {err}",
|
||||
memories_path.display()
|
||||
);
|
||||
close_sqlite_pools(&[pool.as_ref(), logs_pool.as_ref(), goals_pool.as_ref()]).await;
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
let queue_pool = match sqlite
|
||||
.open_queue_db(&queue_migrator, telemetry_override)
|
||||
.await
|
||||
@@ -206,7 +183,6 @@ impl StateRuntime {
|
||||
pool.as_ref(),
|
||||
logs_pool.as_ref(),
|
||||
goals_pool.as_ref(),
|
||||
memories_pool.as_ref(),
|
||||
])
|
||||
.await;
|
||||
return Err(err);
|
||||
@@ -226,7 +202,6 @@ impl StateRuntime {
|
||||
pool.as_ref(),
|
||||
logs_pool.as_ref(),
|
||||
goals_pool.as_ref(),
|
||||
memories_pool.as_ref(),
|
||||
queue_pool.as_ref(),
|
||||
])
|
||||
.await;
|
||||
@@ -255,8 +230,7 @@ impl StateRuntime {
|
||||
pool.as_ref(),
|
||||
logs_pool.as_ref(),
|
||||
goals_pool.as_ref(),
|
||||
memories_pool.as_ref(),
|
||||
queue_pool.as_ref(),
|
||||
queue_pool.as_ref(),
|
||||
])
|
||||
.await;
|
||||
return Err(err);
|
||||
@@ -267,8 +241,6 @@ impl StateRuntime {
|
||||
let runtime = Arc::new(Self {
|
||||
reclamation: reclamation::SqliteReclamationWorker::spawn(sqlite.clone()),
|
||||
thread_goals: GoalStore::new(Arc::clone(&goals_pool)),
|
||||
memories: MemoryStore::new(Arc::clone(&memories_pool), Arc::clone(&pool)),
|
||||
memories_v2: Arc::new(tokio::sync::OnceCell::new()),
|
||||
thread_queue: SqliteQueueStore::new(queue_pool),
|
||||
pool,
|
||||
logs_pool,
|
||||
@@ -277,16 +249,6 @@ impl StateRuntime {
|
||||
thread_updated_at_millis: Arc::new(AtomicI64::new(thread_updated_at_millis)),
|
||||
thread_recency_at_millis: Arc::new(AtomicI64::new(thread_recency_at_millis)),
|
||||
});
|
||||
// Existing v2 state must participate in startup corruption recovery.
|
||||
// Keep creation lazy for users who have never used v2.
|
||||
if has_memories_v2
|
||||
&& let Err(err) = runtime
|
||||
.memories_for_version(akode_protocol::MemoryVersion::V2)
|
||||
.await
|
||||
{
|
||||
runtime.close().await;
|
||||
return Err(err);
|
||||
}
|
||||
runtime.start_periodic_logs_maintenance(std::time::Duration::from_secs(30 * 60));
|
||||
Ok(runtime)
|
||||
}
|
||||
@@ -300,10 +262,6 @@ impl StateRuntime {
|
||||
&self.thread_goals
|
||||
}
|
||||
|
||||
pub fn memories(&self) -> &MemoryStore {
|
||||
&self.memories
|
||||
}
|
||||
|
||||
/// Return the durable, SQLite-backed user-message queue.
|
||||
pub fn thread_queue(&self) -> &SqliteQueueStore {
|
||||
&self.thread_queue
|
||||
@@ -313,46 +271,10 @@ impl StateRuntime {
|
||||
pub async fn close(&self) {
|
||||
self.reclamation.close().await;
|
||||
self.thread_queue.close().await;
|
||||
self.memories.close().await;
|
||||
if let Some(memories) = self.memories_v2.get() {
|
||||
memories.close().await;
|
||||
}
|
||||
self.thread_goals.close().await;
|
||||
self.logs_pool.close().await;
|
||||
self.pool.close().await;
|
||||
}
|
||||
|
||||
pub async fn clear_memory_data_in_sqlite_home(sqlite: &SqliteConfig) -> anyhow::Result<bool> {
|
||||
let mut cleared = false;
|
||||
for version in [
|
||||
akode_protocol::MemoryVersion::V1,
|
||||
akode_protocol::MemoryVersion::V2,
|
||||
] {
|
||||
let path = match version {
|
||||
akode_protocol::MemoryVersion::V1 => sqlite.memories_db_path(),
|
||||
akode_protocol::MemoryVersion::V2 => sqlite.memories_v2_db_path(),
|
||||
};
|
||||
if !tokio::fs::try_exists(path).await? {
|
||||
continue;
|
||||
}
|
||||
let pool = match version {
|
||||
akode_protocol::MemoryVersion::V1 => {
|
||||
sqlite
|
||||
.open_memories_db(
|
||||
&runtime_memories_migrator(),
|
||||
/*telemetry_override*/ None,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
akode_protocol::MemoryVersion::V2 => sqlite.open_memories_v2_db().await?,
|
||||
};
|
||||
let result = memories::clear_memory_data_in_pool(&pool).await;
|
||||
pool.close().await;
|
||||
result?;
|
||||
cleared = true;
|
||||
}
|
||||
Ok(cleared)
|
||||
}
|
||||
}
|
||||
|
||||
async fn close_sqlite_pools(pools: &[&SqlitePool]) {
|
||||
@@ -707,8 +629,6 @@ mod tests {
|
||||
"migrate_logs",
|
||||
"open_goals",
|
||||
"migrate_goals",
|
||||
"open_memories",
|
||||
"migrate_memories",
|
||||
"open_queue",
|
||||
"migrate_queue",
|
||||
"ensure_backfill_state",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,16 +0,0 @@
|
||||
//! Consolidation progress used to select a warmed memory pipeline.
|
||||
|
||||
use super::MemoryStore;
|
||||
|
||||
impl MemoryStore {
|
||||
/// Largest number of distinct source threads included in a successful consolidation.
|
||||
/// Kept across ordinary pruning, and cleared by an explicit memory reset.
|
||||
pub async fn max_consolidated_thread_count(&self) -> anyhow::Result<u32> {
|
||||
let count: i64 = sqlx::query_scalar(
|
||||
"SELECT max_thread_count FROM consolidation_progress WHERE singleton = 1",
|
||||
)
|
||||
.fetch_one(self.pool.as_ref())
|
||||
.await?;
|
||||
Ok(u32::try_from(count)?)
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
//! Creates isolated v2 memory state on demand while sharing the source thread catalog.
|
||||
//! Reset and thread deletion always cover every existing version.
|
||||
|
||||
use super::MemoryStore;
|
||||
use super::StateRuntime;
|
||||
use akode_protocol::MemoryVersion;
|
||||
use akode_protocol::ThreadId;
|
||||
use std::sync::Arc;
|
||||
|
||||
impl StateRuntime {
|
||||
pub async fn memories_for_version(
|
||||
&self,
|
||||
version: MemoryVersion,
|
||||
) -> anyhow::Result<MemoryStore> {
|
||||
match version {
|
||||
MemoryVersion::V1 => Ok(self.memories.clone()),
|
||||
MemoryVersion::V2 => self
|
||||
.memories_v2
|
||||
.get_or_try_init(|| async {
|
||||
let pool = self.sqlite.open_memories_v2_db().await?;
|
||||
Ok(MemoryStore::new(Arc::new(pool), Arc::clone(&self.pool)))
|
||||
})
|
||||
.await
|
||||
.cloned(),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn clear_all_memory_data(&self) -> anyhow::Result<()> {
|
||||
self.memories.clear_memory_data().await?;
|
||||
if tokio::fs::try_exists(self.sqlite.memories_v2_db_path()).await? {
|
||||
self.memories_for_version(MemoryVersion::V2)
|
||||
.await?
|
||||
.clear_memory_data()
|
||||
.await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) async fn delete_versioned_thread_memory(
|
||||
&self,
|
||||
thread_id: ThreadId,
|
||||
) -> anyhow::Result<()> {
|
||||
self.memories.delete_thread_memory(thread_id).await?;
|
||||
if tokio::fs::try_exists(self.sqlite.memories_v2_db_path()).await? {
|
||||
self.memories_for_version(MemoryVersion::V2)
|
||||
.await?
|
||||
.delete_thread_memory(thread_id)
|
||||
.await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "memory_versions_tests.rs"]
|
||||
mod tests;
|
||||
@@ -1,113 +0,0 @@
|
||||
use super::*;
|
||||
use crate::SqliteConfig;
|
||||
use crate::Stage1JobClaimOutcome;
|
||||
use crate::runtime::test_support::test_thread_metadata;
|
||||
use akode_utils_absolute_path::test_support::PathExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
async fn versions_isolate_jobs_outputs_and_reset_without_losing_threads() -> anyhow::Result<()> {
|
||||
let home = crate::runtime::test_support::unique_temp_dir();
|
||||
let sqlite = SqliteConfig::new_for_testing(home.as_path().abs());
|
||||
let db = StateRuntime::init(sqlite.clone(), "test-provider".to_string()).await?;
|
||||
assert!(!sqlite.memories_v2_db_path().exists());
|
||||
let thread_id = ThreadId::new();
|
||||
let metadata = test_thread_metadata(home.as_path(), thread_id, home.as_path().join("project"));
|
||||
db.upsert_thread(&metadata).await?;
|
||||
|
||||
for version in [MemoryVersion::V1, MemoryVersion::V2] {
|
||||
let store = db.memories_for_version(version).await?;
|
||||
let Stage1JobClaimOutcome::Claimed { ownership_token } = store
|
||||
.try_claim_stage1_job(
|
||||
thread_id,
|
||||
thread_id,
|
||||
metadata.updated_at.timestamp(),
|
||||
/*lease_seconds*/ 60,
|
||||
/*max_running_jobs*/ 1,
|
||||
)
|
||||
.await?
|
||||
else {
|
||||
panic!("each version must independently claim the same source")
|
||||
};
|
||||
assert!(
|
||||
store
|
||||
.mark_stage1_job_succeeded(
|
||||
thread_id,
|
||||
&ownership_token,
|
||||
metadata.updated_at.timestamp(),
|
||||
"raw",
|
||||
version.directory_name(),
|
||||
/*rollout_slug*/ None
|
||||
)
|
||||
.await?
|
||||
);
|
||||
}
|
||||
for version in [MemoryVersion::V1, MemoryVersion::V2] {
|
||||
let outputs = db
|
||||
.memories_for_version(version)
|
||||
.await?
|
||||
.list_stage1_outputs_for_global(/*n*/ 10)
|
||||
.await?;
|
||||
assert_eq!(
|
||||
outputs
|
||||
.iter()
|
||||
.map(|output| output.rollout_summary.as_str())
|
||||
.collect::<Vec<_>>(),
|
||||
vec![version.directory_name()]
|
||||
);
|
||||
}
|
||||
// Reopening under v1 must still clear existing v2 state.
|
||||
db.close().await;
|
||||
let db = StateRuntime::init(sqlite.clone(), "test-provider".to_string()).await?;
|
||||
db.delete_thread(thread_id).await?;
|
||||
for version in [MemoryVersion::V1, MemoryVersion::V2] {
|
||||
assert!(
|
||||
db.memories_for_version(version)
|
||||
.await?
|
||||
.list_stage1_outputs_for_global(/*n*/ 10)
|
||||
.await?
|
||||
.is_empty()
|
||||
);
|
||||
}
|
||||
db.upsert_thread(&metadata).await?;
|
||||
for version in [MemoryVersion::V1, MemoryVersion::V2] {
|
||||
let store = db.memories_for_version(version).await?;
|
||||
let Stage1JobClaimOutcome::Claimed { ownership_token } = store
|
||||
.try_claim_stage1_job(
|
||||
thread_id,
|
||||
thread_id,
|
||||
metadata.updated_at.timestamp(),
|
||||
/*lease_seconds*/ 60,
|
||||
/*max_running_jobs*/ 1,
|
||||
)
|
||||
.await?
|
||||
else {
|
||||
panic!("deletion must clear the job watermark")
|
||||
};
|
||||
store
|
||||
.mark_stage1_job_succeeded(
|
||||
thread_id,
|
||||
&ownership_token,
|
||||
metadata.updated_at.timestamp(),
|
||||
"raw",
|
||||
"summary",
|
||||
/*rollout_slug*/ None,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
db.clear_all_memory_data().await?;
|
||||
for version in [MemoryVersion::V1, MemoryVersion::V2] {
|
||||
assert!(
|
||||
db.memories_for_version(version)
|
||||
.await?
|
||||
.list_stage1_outputs_for_global(/*n*/ 10)
|
||||
.await?
|
||||
.is_empty()
|
||||
);
|
||||
}
|
||||
assert!(db.get_thread(thread_id).await?.is_some());
|
||||
db.close().await;
|
||||
assert!(StateRuntime::clear_memory_data_in_sqlite_home(&sqlite).await?);
|
||||
tokio::fs::remove_dir_all(home).await?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -1249,7 +1249,6 @@ ON CONFLICT(id) DO UPDATE SET
|
||||
.execute_with_busy_retry(self.logs_pool.as_ref())
|
||||
.await?;
|
||||
self.thread_queue.delete_thread_queue(*thread_id).await?;
|
||||
self.delete_versioned_thread_memory(*thread_id).await?;
|
||||
self.thread_goals.delete_thread_goal(*thread_id).await?;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ const DEFAULT_BUSY_TIMEOUT: Duration = Duration::from_secs(5);
|
||||
|
||||
const LOGS_DB_FILENAME: &str = "logs_2.sqlite";
|
||||
const GOALS_DB_FILENAME: &str = "goals_1.sqlite";
|
||||
const MEMORIES_DB_FILENAME: &str = "memories_1.sqlite";
|
||||
const QUEUE_DB_FILENAME: &str = "queue_1.sqlite";
|
||||
const STATE_DB_FILENAME: &str = "state_5.sqlite";
|
||||
const THREAD_HISTORY_DB_FILENAME: &str = "thread_history_1.sqlite";
|
||||
@@ -114,23 +113,6 @@ const GOALS_DB: RuntimeDbSpec = RuntimeDbSpec {
|
||||
recovery: RecoveryMode::BackupAndRebuild,
|
||||
};
|
||||
|
||||
const MEMORIES_DB: RuntimeDbSpec = RuntimeDbSpec {
|
||||
label: "memories DB",
|
||||
filename: MEMORIES_DB_FILENAME,
|
||||
kind: DbKind::Memories,
|
||||
open_phase: "open_memories",
|
||||
migrate_phase: "migrate_memories",
|
||||
background_reclamation: false,
|
||||
recovery: RecoveryMode::BackupAndRebuild,
|
||||
};
|
||||
|
||||
const MEMORIES_V2_DB: RuntimeDbSpec = RuntimeDbSpec {
|
||||
label: "memories v2 DB",
|
||||
filename: "memories_v2_1.sqlite",
|
||||
background_reclamation: false,
|
||||
..MEMORIES_DB
|
||||
};
|
||||
|
||||
const QUEUE_DB: RuntimeDbSpec = RuntimeDbSpec {
|
||||
label: "queue DB",
|
||||
filename: QUEUE_DB_FILENAME,
|
||||
@@ -151,12 +133,10 @@ const THREAD_HISTORY_DB: RuntimeDbSpec = RuntimeDbSpec {
|
||||
recovery: RecoveryMode::Unavailable,
|
||||
};
|
||||
|
||||
const RUNTIME_DBS: [RuntimeDbSpec; 7] = [
|
||||
const RUNTIME_DBS: [RuntimeDbSpec; 5] = [
|
||||
STATE_DB,
|
||||
LOGS_DB,
|
||||
GOALS_DB,
|
||||
MEMORIES_DB,
|
||||
MEMORIES_V2_DB,
|
||||
QUEUE_DB,
|
||||
THREAD_HISTORY_DB,
|
||||
];
|
||||
@@ -279,24 +259,6 @@ impl SqliteConfig {
|
||||
GOALS_DB.path(self)
|
||||
}
|
||||
|
||||
/// Return the path to the memories database.
|
||||
pub fn memories_db_path(&self) -> PathBuf {
|
||||
MEMORIES_DB.path(self)
|
||||
}
|
||||
|
||||
pub(crate) fn memories_v2_db_path(&self) -> PathBuf {
|
||||
MEMORIES_V2_DB.path(self)
|
||||
}
|
||||
|
||||
pub(crate) async fn open_memories_v2_db(&self) -> anyhow::Result<SqlitePool> {
|
||||
self.open_runtime_db(
|
||||
MEMORIES_V2_DB,
|
||||
&crate::migrations::runtime_memories_migrator(),
|
||||
/*telemetry_override*/ None,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Return the path to the durable user-message queue database.
|
||||
pub fn queue_db_path(&self) -> PathBuf {
|
||||
QUEUE_DB.path(self)
|
||||
@@ -361,15 +323,6 @@ impl SqliteConfig {
|
||||
.await
|
||||
}
|
||||
|
||||
pub(super) async fn open_memories_db(
|
||||
&self,
|
||||
migrator: &Migrator,
|
||||
telemetry_override: Option<&dyn DbTelemetry>,
|
||||
) -> anyhow::Result<SqlitePool> {
|
||||
self.open_runtime_db(MEMORIES_DB, migrator, telemetry_override)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(super) async fn open_queue_db(
|
||||
&self,
|
||||
migrator: &Migrator,
|
||||
|
||||
@@ -508,7 +508,6 @@ async fn required_nfs_migration_preserves_runtime_data_and_backups_after_restart
|
||||
runtime.checkpoint_backfill("before-migration").await?;
|
||||
let before = runtime.get_backfill_state().await?;
|
||||
runtime.close().await;
|
||||
original.open_memories_v2_db().await?.close().await;
|
||||
crate::open_thread_history_db(&original)
|
||||
.await?
|
||||
.close()
|
||||
@@ -555,7 +554,7 @@ async fn required_nfs_migration_preserves_runtime_data_and_backups_after_restart
|
||||
assert!(!crate::NfsDbMigration::needs_migration(&state_path).await?);
|
||||
|
||||
// Simulate a crash after moving the original but before reinstalling a lazy database.
|
||||
let lazy = sqlite.memories_v2_db_path();
|
||||
let lazy = sqlite.thread_history_db_path();
|
||||
let name = lazy.file_name().unwrap().to_str().unwrap();
|
||||
std::fs::rename(
|
||||
&lazy,
|
||||
|
||||
@@ -51,7 +51,6 @@ pub(crate) enum DbKind {
|
||||
State,
|
||||
Logs,
|
||||
Goals,
|
||||
Memories,
|
||||
Queue,
|
||||
ThreadHistory,
|
||||
}
|
||||
@@ -62,7 +61,6 @@ impl DbKind {
|
||||
Self::State => "state",
|
||||
Self::Logs => "logs",
|
||||
Self::Goals => "goals",
|
||||
Self::Memories => "memories",
|
||||
Self::Queue => "queue",
|
||||
Self::ThreadHistory => "thread_history",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user