Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(task-sources): stop tracking board card ids in the ingest ledger

Steven Enamakel1d267f749f74
diff --git a/crates/openhuman-core/src/integrations/task_sources/ops.rs b/crates/openhuman-core/src/integrations/task_sources/ops.rs
index 702679646c..5867a0d7ae 100644
--- a/crates/openhuman-core/src/integrations/task_sources/ops.rs
+++ b/crates/openhuman-core/src/integrations/task_sources/ops.rs
@@ -86,9 +86,6 @@ pub async fn remove(config: &Config, id: &str) -> Result<RpcOutcome<Value>, Stri
let ingested = store::list_ingested_refs(config, id).map_err(|e| e.to_string())?;
let mut pruned = 0usize;
for item in ingested {
- if let Some(card_id) = item.card_id.as_deref().filter(|id| !id.trim().is_empty()) {
- route::remove_card(config, card_id).await?;
- }
if store::remove_ingested(config, id, &item.external_id).map_err(|e| e.to_string())? {
pruned += 1;
}
diff --git a/crates/openhuman-core/src/integrations/task_sources/pipeline.rs b/crates/openhuman-core/src/integrations/task_sources/pipeline.rs
index ba697042e4..2b5909fcc5 100644
--- a/crates/openhuman-core/src/integrations/task_sources/pipeline.rs
+++ b/crates/openhuman-core/src/integrations/task_sources/pipeline.rs
@@ -162,20 +162,18 @@ async fn run_inner(
continue;
}
- // Look up the stale card id (if any) before enrichment so we can
- // remove the old board card when re-routing an edited upstream task.
- let stale_card_id = store::get_card_id(config, &source.id, &task.external_id)
- .map_err(|e| format!("get_card_id failed: {e}"))?;
+ let edited = store::is_ingested(config, &source.id, &task.external_id)
+ .map_err(|e| format!("is_ingested failed: {e}"))?;
tracing::debug!(
source_id = %source.id,
provider = %source.provider.as_str(),
external_id = %task.external_id,
content_hash = %hash,
- edited = stale_card_id.is_some(),
+ edited,
"[task_sources:dedup] route — not a dupe for this source ({})",
- if stale_card_id.is_some() {
- "content changed since last ingest → re-route, replace stale card"
+ if edited {
+ "content changed since last ingest → re-route"
} else {
"new external_id for this source"
}
@@ -186,27 +184,17 @@ async fn run_inner(
// Route first; only mark ingested on success so a routing
// failure retries on the next pass instead of being silently
// dropped.
- let new_card_id = match route::route_enriched(
- config,
- source,
- &enriched,
- stale_card_id.as_deref(),
- )
- .await
- {
- Ok(id) => id,
- Err(e) => {
- tracing::warn!(
- source_id = %source.id,
- external_id = %enriched.task.external_id,
- error = %e,
- "[task_sources:pipeline] routing failed (will retry next pass)"
- );
- continue;
- }
- };
+ if let Err(e) = route::route_enriched(config, source, &enriched).await {
+ tracing::warn!(
+ source_id = %source.id,
+ external_id = %enriched.task.external_id,
+ error = %e,
+ "[task_sources:pipeline] routing failed (will retry next pass)"
+ );
+ continue;
+ }
- store::mark_ingested(config, &source.id, &enriched.task, &new_card_id)
+ store::mark_ingested(config, &source.id, &enriched.task)
.map_err(|e| format!("mark_ingested failed: {e}"))?;
BUS.publish(DomainEvent::TaskSourceTaskIngested {
source_id: source.id.clone(),
@@ -273,15 +261,6 @@ async fn reconcile_missing_tasks(
continue;
}
- if let Some(card_id) = item.card_id.as_deref().filter(|id| !id.trim().is_empty()) {
- route::remove_card(config, card_id).await.map_err(|e| {
- format!(
- "remove stale card '{}' for source '{}' external task '{}': {e}",
- card_id, source.id, item.external_id
- )
- })?;
- }
-
if store::remove_ingested(config, &source.id, &item.external_id)
.map_err(|e| format!("remove_ingested failed: {e}"))?
{
diff --git a/crates/openhuman-core/src/integrations/task_sources/store.rs b/crates/openhuman-core/src/integrations/task_sources/store.rs
index 7f06a73122..72797f073f 100644
--- a/crates/openhuman-core/src/integrations/task_sources/store.rs
+++ b/crates/openhuman-core/src/integrations/task_sources/store.rs
@@ -267,64 +267,55 @@ pub fn is_ingested(
/// Record a routed task in the dedup ledger (idempotent upsert).
///
-/// `card_id` is the board card UUID returned by `route::add_card`; it is
-/// persisted so that a later edit of the same upstream task can remove the
-/// stale card before creating a fresh one (preventing duplicate board cards).
-pub fn mark_ingested(
- config: &Config,
- source_id: &str,
- task: &NormalizedTask,
- card_id: &str,
-) -> Result<()> {
+/// The `card_id` column is left `NULL`: tasks are no longer mirrored onto a
+/// todo board, the ledger row itself is the record. The column stays so
+/// older databases open unchanged.
+pub fn mark_ingested(config: &Config, source_id: &str, task: &NormalizedTask) -> Result<()> {
let hash = content_hash(task);
let payload = serde_json::to_string(task).context("serialize ingested task payload")?;
let now = Utc::now().to_rfc3339();
with_connection(config, |conn| {
conn.execute(
"INSERT INTO ingested_tasks (source_id, external_id, content_hash, title, payload, ingested_at, card_id)
- VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)
+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, NULL)
ON CONFLICT(source_id, external_id) DO UPDATE SET
content_hash = excluded.content_hash,
title = excluded.title,
payload = excluded.payload,
ingested_at = excluded.ingested_at,
- card_id = excluded.card_id",
- params![source_id, task.external_id, hash, task.title, payload, now, card_id],
+ card_id = NULL",
+ params![source_id, task.external_id, hash, task.title, payload, now],
)
.context("Failed to mark task ingested")?;
Ok(())
})
}
-/// Return the board card id previously stored for `(source_id, external_id)`,
-/// if any. Used by the pipeline to remove stale board cards when an upstream
-/// task is edited and re-ingested.
-pub fn get_card_id(config: &Config, source_id: &str, external_id: &str) -> Result<Option<String>> {
+/// Whether `(source_id, external_id)` has been ingested before under any
+/// content hash. The pipeline uses it to tell an edited upstream task from a
+/// brand-new one in its logs.
+pub fn is_ingested(config: &Config, source_id: &str, external_id: &str) -> Result<bool> {
with_connection(config, |conn| {
let mut stmt = conn.prepare(
- "SELECT card_id FROM ingested_tasks WHERE source_id = ?1 AND external_id = ?2",
+ "SELECT 1 FROM ingested_tasks WHERE source_id = ?1 AND external_id = ?2",
)?;
let mut rows = stmt.query(params![source_id, external_id])?;
- match rows.next()? {
- Some(row) => Ok(row.get(0)?),
- None => Ok(None),
- }
+ Ok(rows.next()?.is_some())
})
}
-/// Return ingested task ids/card ids for one source. Used by reconciliation
-/// to prune board cards that no longer match the upstream source/filter.
+/// Return ingested task ids for one source. Used by reconciliation to prune
+/// ledger rows that no longer match the upstream source/filter.
pub fn list_ingested_refs(config: &Config, source_id: &str) -> Result<Vec<IngestedTaskRef>> {
with_connection(config, |conn| {
let mut stmt = conn.prepare(
- "SELECT external_id, card_id FROM ingested_tasks
+ "SELECT external_id FROM ingested_tasks
WHERE source_id = ?1
ORDER BY ingested_at ASC, external_id ASC",
)?;
let rows = stmt.query_map(params![source_id], |row| {
Ok(IngestedTaskRef {
external_id: row.get(0)?,
- card_id: row.get(1)?,
})
})?;
let mut out = Vec::new();