Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: tombstone system prevents deleted pipes from auto-restoring + preset ghost fix

Louis Beaumontf46314ed6f85
diff --git a/apps/screenpipe-app-tauri/components/settings/ai-presets.tsx b/apps/screenpipe-app-tauri/components/settings/ai-presets.tsx
index eb788abae..95fde69a5 100644
--- a/apps/screenpipe-app-tauri/components/settings/ai-presets.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/ai-presets.tsx
@@ -188,6 +188,7 @@ const AISection = ({
piAvailable?: boolean;
}) => {
const { settings, updateSettings } = useSettings();
+ const isEnterprise = useIsEnterpriseBuild();
const [settingsPreset, setSettingsPreset] = useState<
Partial<AIPreset> | undefined
>(preset);
@@ -201,16 +202,22 @@ const AISection = ({
const [chatgptLoggedIn, setChatgptLoggedIn] = useState(false);
const [chatgptLoading, setChatgptLoading] = useState(false);
+ // Filter presets the same way the UI does so hidden presets don't block creation
+ const visiblePresets = useMemo(
+ () => settings.aiPresets.filter((p) => !isEnterprise || p.provider !== "pi"),
+ [settings.aiPresets, isEnterprise]
+ );
+
// Optimized validation with debouncing
const debouncedValidatePreset = useMemo(
() => debounce((presetData: Partial<AIPreset>) => {
const errors: Record<string, string> = {};
-
+
// Validate name
if (presetData.id) {
const nameValidation = validatePresetName(
- presetData.id,
- settings.aiPresets,
+ presetData.id,
+ visiblePresets,
preset?.id
);
if (!nameValidation.isValid && nameValidation.error) {
@@ -338,8 +345,14 @@ const AISection = ({
defaultPreset: false,
} as AIPreset;
+ // Remove any hidden preset with the same name (e.g. filtered Pi preset
+ // in enterprise builds) so it doesn't ghost-block future operations
+ const cleanedPresets = settings.aiPresets.filter(
+ (p) => p.id.toLowerCase() !== newPreset.id.toLowerCase()
+ );
+
await updateSettings({
- aiPresets: [...settings.aiPresets, newPreset],
+ aiPresets: [...cleanedPresets, newPreset],
});
toast({
@@ -1038,7 +1051,7 @@ const AISection = ({
label="Preset Name"
value={settingsPreset?.id || ""}
onChange={(value, isValid) => updateSettingsPreset({ id: value })}
- validation={(value) => validatePresetName(value, settings.aiPresets, preset?.id)}
+ validation={(value) => validatePresetName(value, visiblePresets, preset?.id)}
placeholder="Enter preset name"
required={true}
disabled={!!preset && !isDuplicating && preset.id !== undefined}
diff --git a/apps/screenpipe-app-tauri/lib/utils/validation.ts b/apps/screenpipe-app-tauri/lib/utils/validation.ts
index 74b8a584e..3255a546f 100644
--- a/apps/screenpipe-app-tauri/lib/utils/validation.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/validation.ts
@@ -232,27 +232,29 @@ export const getFieldHelperText = (field: keyof SettingsStore, settings: any) =>
};
// Preset validation
-export const validatePresetName = (name: string, existingPresets: AIPreset[], currentId?: string): FieldValidationResult => {
+// `visiblePresets` should be the filtered list the user actually sees,
+// so hidden presets (e.g. Pi presets in enterprise builds) don't block creation.
+export const validatePresetName = (name: string, visiblePresets: AIPreset[], currentId?: string): FieldValidationResult => {
if (!name.trim()) {
return { isValid: false, error: "Preset name is required" };
}
-
+
if (name.trim().toLowerCase().endsWith("copy")) {
return { isValid: false, error: "Preset name cannot end with 'copy'" };
}
-
- const exists = existingPresets.some(
+
+ const exists = visiblePresets.some(
preset => preset.id.toLowerCase() === name.toLowerCase() && preset.id !== currentId
);
-
+
if (exists) {
return { isValid: false, error: "A preset with this name already exists" };
}
-
+
if (!/^[a-zA-Z0-9\s\-_]+$/.test(name)) {
return { isValid: false, error: "Only letters, numbers, spaces, hyphens, and underscores are allowed" };
}
-
+
return { isValid: true };
};
diff --git a/crates/screenpipe-core/src/pipes/mod.rs b/crates/screenpipe-core/src/pipes/mod.rs
index 8e61c27bb..92bba5541 100644
--- a/crates/screenpipe-core/src/pipes/mod.rs
+++ b/crates/screenpipe-core/src/pipes/mod.rs
@@ -224,6 +224,70 @@ fn simple_hash(content: &str) -> String {
format!("{:016x}", hash)
}
+// ---------------------------------------------------------------------------
+// Tombstone tracking — prevents deleted pipes from being restored by
+// builtin installation or cloud sync.
+// ---------------------------------------------------------------------------
+
+/// A single tombstone entry for a deleted pipe.
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct TombstoneEntry {
+ /// When the pipe was deleted (UTC ISO 8601).
+ pub deleted_at: String,
+ /// FNV-1a hash of the pipe.md content at the time of deletion.
+ /// Used by `install_builtin_pipes` to detect updated builtins.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub content_hash: Option<String>,
+}
+
+/// File name for the tombstone registry inside the pipes directory.
+const TOMBSTONES_FILE: &str = ".tombstones.json";
+
+/// Read the tombstone file from a pipes directory.
+/// Returns an empty map on any error (missing file, corrupt JSON).
+pub fn read_tombstones(pipes_dir: &Path) -> HashMap<String, TombstoneEntry> {
+ let path = pipes_dir.join(TOMBSTONES_FILE);
+ match std::fs::read_to_string(&path) {
+ Ok(content) => serde_json::from_str(&content).unwrap_or_else(|e| {
+ warn!("tombstones file corrupt, ignoring: {}", e);
+ HashMap::new()
+ }),
+ Err(_) => HashMap::new(),
+ }
+}
+
+/// Write the tombstone file atomically (write to temp, then rename).
+fn write_tombstones(pipes_dir: &Path, tombstones: &HashMap<String, TombstoneEntry>) -> Result<()> {
+ let path = pipes_dir.join(TOMBSTONES_FILE);
+ let tmp_path = pipes_dir.join(".tombstones.json.tmp");
+ let json = serde_json::to_string_pretty(tombstones)?;
+ std::fs::write(&tmp_path, &json)?;
+ std::fs::rename(&tmp_path, &path)?;
+ Ok(())
+}
+
+/// Add a tombstone for a deleted pipe.
+fn add_tombstone(pipes_dir: &Path, name: &str, content_hash: Option<String>) -> Result<()> {
+ let mut tombstones = read_tombstones(pipes_dir);
+ tombstones.insert(
+ name.to_string(),
+ TombstoneEntry {
+ deleted_at: Utc::now().to_rfc3339(),
+ content_hash,
+ },
+ );
+ write_tombstones(pipes_dir, &tombstones)
+}
+
+/// Remove a tombstone (e.g. when a pipe is re-installed explicitly).
+fn remove_tombstone(pipes_dir: &Path, name: &str) -> Result<()> {
+ let mut tombstones = read_tombstones(pipes_dir);
+ if tombstones.remove(name).is_some() {
+ write_tombstones(pipes_dir, &tombstones)?;
+ }
+ Ok(())
+}
+
/// Result of a single pipe run.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PipeRunLog {
@@ -2020,6 +2084,8 @@ impl PipeManager {
std::fs::copy(source_path, &dest_file)?;
}
self.load_pipes().await?;
+ // Clear any tombstone — user is explicitly re-installing
+ let _ = remove_tombstone(&self.pipes_dir, &name);
info!("installed pipe '{}' from local file", name);
return Ok(name);
} else if source_path.is_dir() {
@@ -2038,6 +2104,7 @@ impl PipeManager {
copy_dir_recursive(source_path, &dest_dir)?;
}
self.load_pipes().await?;
+ let _ = remove_tombstone(&self.pipes_dir, &name);
info!("installed pipe '{}' from local dir", name);
return Ok(name);
}
@@ -2059,6 +2126,7 @@ impl PipeManager {
let content = response.text().await?;
std::fs::write(dest_dir.join("pipe.md"), &content)?;
self.load_pipes().await?;
+ let _ = remove_tombstone(&self.pipes_dir, &name);
info!("installed pipe '{}' from URL", name);
return Ok(name);
}
@@ -2097,6 +2165,7 @@ impl PipeManager {
std::fs::write(dest_dir.join("pipe.md"), &content)?;
self.load_pipes().await?;
+ let _ = remove_tombstone(&self.pipes_dir, &name);
info!("installed pipe '{}' from store (v{})", name, version);
Ok(name)
}
@@ -2138,6 +2207,8 @@ impl PipeManager {
}
/// Delete a pipe and its folder.
+ /// Writes a tombstone so the pipe is not restored by builtin installation
+ /// or cloud sync.
pub async fn delete_pipe(&self, name: &str) -> Result<()> {
let dir = self.pipes_dir.join(name);
if !dir.exists() {
@@ -2160,8 +2231,18 @@ impl PipeManager {
}
}
+ // Compute content hash before deleting (for builtin upgrade detection)
+ let content_hash = std::fs::read_to_string(dir.join("pipe.md"))
+ .ok()
+ .map(|c| simple_hash(&c));
+
std::fs::remove_dir_all(&dir)?;
+ // Write tombstone so builtin install and cloud sync don't restore it
+ if let Err(e) = add_tombstone(&self.pipes_dir, name, content_hash) {
+ warn!("failed to write tombstone for '{}': {}", name, e);
+ }
+
let mut pipes = self.pipes.lock().await;
pipes.remove(name);
@@ -2772,10 +2853,33 @@ impl PipeManager {
),
];
+ let tombstones = read_tombstones(&self.pipes_dir);
+
for (name, content) in builtins {
let dir = self.pipes_dir.join(name);
let pipe_md = dir.join("pipe.md");
if !pipe_md.exists() {
+ // Check tombstone — user may have intentionally deleted this pipe
+ if let Some(entry) = tombstones.get(name) {
+ let new_hash = simple_hash(content);
+ if entry.content_hash.as_deref() == Some(&new_hash) {
+ // Same content as when deleted — respect user's deletion
+ debug!(
+ "skipping tombstoned builtin pipe '{}' (content unchanged)",
+ name
+ );
+ continue;
+ }
+ // Content changed (new app version) — install updated version
+ // and clear the tombstone so user gets the improvement
+ info!(
+ "builtin pipe '{}' updated since deletion, re-installing",
+ name
+ );
+ if let Err(e) = remove_tombstone(&self.pipes_dir, name) {
+ warn!("failed to remove tombstone for '{}': {}", name, e);
+ }
+ }
std::fs::create_dir_all(&dir)?;
std::fs::write(&pipe_md, content)?;
info!("installed built-in pipe: {}", name);
diff --git a/crates/screenpipe-core/src/pipes/sync.rs b/crates/screenpipe-core/src/pipes/sync.rs
index 9361345a2..d1dbbb944 100644
--- a/crates/screenpipe-core/src/pipes/sync.rs
+++ b/crates/screenpipe-core/src/pipes/sync.rs
@@ -15,7 +15,7 @@ use std::collections::HashMap;
use std::path::Path;
use tracing::{info, warn};
-use super::parse_frontmatter;
+use super::{parse_frontmatter, read_tombstones};
/// Current schema version for the sync manifest.
pub const PIPE_SYNC_SCHEMA: u32 = 1;
@@ -146,6 +146,16 @@ pub fn build_local_manifest(pipes_dir: &Path, machine_id: &str) -> PipeSyncManif
);
}
+ // Load local tombstones so cloud sync doesn't re-import deleted pipes
+ let tombstones = read_tombstones(pipes_dir);
+ for (name, entry) in &tombstones {
+ if !manifest.pipes.contains_key(name) {
+ manifest
+ .tombstones
+ .insert(name.clone(), entry.deleted_at.clone());
+ }
+ }
+
manifest
}