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(live-view): stop the cadence write silently doing nothing (#6134)

Louis Beaumontf9f2445b949a
diff --git a/apps/screenpipe-app-tauri/components/settings/__tests__/brain-overview.test.tsx b/apps/screenpipe-app-tauri/components/settings/__tests__/brain-overview.test.tsx
index e1d103160..4e70f39ec 100644
--- a/apps/screenpipe-app-tauri/components/settings/__tests__/brain-overview.test.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/__tests__/brain-overview.test.tsx
@@ -1178,18 +1178,31 @@ describe("BrainOverview", () => {
// Enabling alone is not enough: a `manual` schedule leaves the scheduler
// with nothing to fire, so the block would freeze again after this refresh.
+ //
+ // The fields go at the top level. `POST /pipes/:id/config` flattens the
+ // request body into its update map, so a `config` envelope arrives as one
+ // unrecognized key, gets filed under free-form user config, and still
+ // answers `{"success": true}` with the schedule untouched. This assertion
+ // used to accept the envelope, which is how the write shipped applying
+ // nothing at all while every refresh reported success.
await waitFor(() =>
expect(
calls.some((call) => {
- const config = (call.body as { config?: Record<string, unknown> })?.config;
+ const body = call.body as Record<string, unknown> | null;
return (
call.path === "/pipes/daily-summary/config" &&
- config?.schedule === "every 1h" &&
- config?.enabled === true
+ body?.schedule === "every 1h" &&
+ body?.enabled === true
);
}),
).toBe(true),
);
+ // No envelope: a nested `config` key would be silently ignored by the API.
+ expect(
+ calls.every(
+ (call) => !(call.body as { config?: unknown } | null)?.config,
+ ),
+ ).toBe(true);
const configIndex = calls.findIndex((call) => call.path.endsWith("/config"));
const runIndex = calls.findIndex((call) => call.path.endsWith("/run"));
expect(configIndex).toBeGreaterThanOrEqual(0);
diff --git a/apps/screenpipe-app-tauri/components/settings/brain-overview.tsx b/apps/screenpipe-app-tauri/components/settings/brain-overview.tsx
index b80e9fa6f..6ea06e07a 100644
--- a/apps/screenpipe-app-tauri/components/settings/brain-overview.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/brain-overview.tsx
@@ -105,7 +105,10 @@ import {
getLiveViewTimeRangeOption,
} from "@/lib/live-views/time-range";
import { summarizeLiveViewFreshness } from "@/lib/live-views/freshness";
-import { planSourceCadence } from "@/lib/live-views/source-cadence";
+import {
+ planSourceCadence,
+ sourceCadenceConfigBody,
+} from "@/lib/live-views/source-cadence";
import {
liveViewSourceStatus,
parsePipeScheduleSnapshots,
@@ -1131,26 +1134,41 @@ export function BrainOverview({
pipeSchedulesRef.current,
);
if (cadencePlans.length > 0) {
+ const cadenceFailures: string[] = [];
await Promise.all(
cadencePlans.map(async (plan) => {
+ // Shape pinned by `sourceCadenceConfigBody`: top-level fields, no
+ // `config` envelope. An envelope still answers `{"success": true}`
+ // while changing nothing, so the dashboard would silently freeze
+ // again with a refresh that looked like it worked.
+ const update = sourceCadenceConfigBody(plan);
try {
- const config: Record<string, unknown> = {};
- if (plan.schedule) config.schedule = plan.schedule;
- if (plan.enable) config.enabled = true;
- await localFetch(`/pipes/${encodeURIComponent(plan.pipeName)}/config`, {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ config }),
- });
+ const response = await localFetch(
+ `/pipes/${encodeURIComponent(plan.pipeName)}/config`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(update),
+ },
+ );
+ if (!response.ok) cadenceFailures.push(plan.pipeName);
} catch {
- // Non-fatal: the run below still refreshes the Block once.
+ cadenceFailures.push(plan.pipeName);
}
}),
);
+ if (cadenceFailures.length > 0) {
+ console.warn(
+ `live view: could not set a cadence for ${cadenceFailures.join(", ")}; these blocks stay refresh-only`,
+ );
+ }
posthog.capture("live_view_source_cadence_applied", {
...analyticsProperties,
scheduled_pipe_count: cadencePlans.filter((plan) => plan.schedule).length,
resumed_pipe_count: cadencePlans.filter((plan) => plan.enable).length,
+ // Non-zero means the cadence write silently failed and the dashboard
+ // is still frozen despite a refresh that reported success.
+ failed_pipe_count: cadenceFailures.length,
});
try {
const response = await localFetch("/pipes");
diff --git a/apps/screenpipe-app-tauri/lib/live-views/__tests__/source-cadence.test.ts b/apps/screenpipe-app-tauri/lib/live-views/__tests__/source-cadence.test.ts
index 2f5a38dc7..212afa8c1 100644
--- a/apps/screenpipe-app-tauri/lib/live-views/__tests__/source-cadence.test.ts
+++ b/apps/screenpipe-app-tauri/lib/live-views/__tests__/source-cadence.test.ts
@@ -6,6 +6,7 @@ import { describe, expect, it } from "vitest";
import {
liveViewCadenceFor,
planSourceCadence,
+ sourceCadenceConfigBody,
} from "@/lib/live-views/source-cadence";
import { parsePipeScheduleSnapshots } from "@/lib/live-views/source-status";
import type { BrainViewSlot, BrainViewTimeRange } from "@/lib/utils/tauri";
@@ -100,3 +101,31 @@ describe("planSourceCadence", () => {
).toEqual([]);
});
});
+
+describe("sourceCadenceConfigBody", () => {
+ // POST /pipes/:id/config flattens the request body into its update map. A
+ // `config` envelope therefore arrives as one unrecognized key, is filed under
+ // free-form user config, and still returns `{"success": true}` while the
+ // schedule stays untouched: the dashboard freezes and the refresh looks fine.
+ it("puts fields at the top level, with no config envelope", () => {
+ const body = sourceCadenceConfigBody({
+ pipeName: "time-breakdown",
+ schedule: "every 1h",
+ enable: true,
+ });
+ expect(body).toEqual({ schedule: "every 1h", enabled: true });
+ expect(body).not.toHaveProperty("config");
+ });
+
+ it("omits a schedule the task already has", () => {
+ expect(
+ sourceCadenceConfigBody({ pipeName: "day-recap", schedule: null, enable: true }),
+ ).toEqual({ enabled: true });
+ });
+
+ it("omits enabled for a task that is already on", () => {
+ expect(
+ sourceCadenceConfigBody({ pipeName: "day-recap", schedule: "every 6h", enable: false }),
+ ).toEqual({ schedule: "every 6h" });
+ });
+});
diff --git a/apps/screenpipe-app-tauri/lib/live-views/source-cadence.ts b/apps/screenpipe-app-tauri/lib/live-views/source-cadence.ts
index d33d8e815..7bf715270 100644
--- a/apps/screenpipe-app-tauri/lib/live-views/source-cadence.ts
+++ b/apps/screenpipe-app-tauri/lib/live-views/source-cadence.ts
@@ -50,6 +50,25 @@ export type SourceCadencePlan = {
* needs, so the shortest period still updates.
* - A task needing no change is omitted, so callers issue no request at all.
*/
+/**
+ * Body for `POST /pipes/:id/config` that applies a plan.
+ *
+ * The fields go at the top level. The handler flattens the request body into
+ * its update map, so wrapping them in a `config` envelope arrives as a single
+ * unrecognized key, gets filed under free-form user config, and still answers
+ * `{"success": true}` while the schedule stays exactly as it was. That failure
+ * is invisible from the response, so the shape is pinned by a test here rather
+ * than left inline at the call site.
+ */
+export function sourceCadenceConfigBody(
+ plan: SourceCadencePlan,
+): Record<string, unknown> {
+ const body: Record<string, unknown> = {};
+ if (plan.schedule) body.schedule = plan.schedule;
+ if (plan.enable) body.enabled = true;
+ return body;
+}
+
export function planSourceCadence(
bound: readonly { slots: readonly BrainViewSlot[]; timeRange: BrainViewTimeRange }[],
snapshots: readonly PipeScheduleSnapshot[],
diff --git a/crates/screenpipe-core/src/pipes/mod.rs b/crates/screenpipe-core/src/pipes/mod.rs
index 3846347d9..1db407ebf 100644
--- a/crates/screenpipe-core/src/pipes/mod.rs
+++ b/crates/screenpipe-core/src/pipes/mod.rs
@@ -659,6 +659,54 @@ fn content_is_enterprise_managed(content: &str) -> bool {
.any(|line| line.trim() == "enterprise_managed: true")
})
}
+/// Front-matter fields `PipeManager::update_config` applies. Every other key is
+/// free-form user config, so an unrecognized key cannot simply be rejected.
+const KNOWN_CONFIG_UPDATE_KEYS: &[&str] = &[
+ "raw_content",
+ "prompt_body",
+ "schedule",
+ "enabled",
+ "agent",
+ "model",
+ "provider",
+ "preset",
+ "connections",
+ "timeout",
+ "history",
+ "trigger",
+ "schedule_config",
+];
+
+/// Spot a `POST /pipes/:id/config` body that wrapped its fields in a `config`
+/// envelope, returning the recognized fields it meant to set.
+///
+/// The handler's request type is `#[serde(flatten)]`, so the update map *is* the
+/// request body: `{"schedule": "every 1h"}`. An envelope still deserializes —
+/// it just arrives as a single unrecognized key, which the catch-all arm files
+/// under free-form user config. The write then succeeds and the caller is told
+/// `{"success": true}` while nothing it asked for changed.
+///
+/// Matching only when *every* nested key is a real field keeps a user setting
+/// that happens to be named `config` working.
+fn nested_config_envelope(updates: &HashMap<String, serde_json::Value>) -> Option<Vec<String>> {
+ if updates.len() != 1 {
+ return None;
+ }
+ let inner = updates.get("config")?.as_object()?;
+ if inner.is_empty() {
+ return None;
+ }
+ if !inner
+ .keys()
+ .all(|key| KNOWN_CONFIG_UPDATE_KEYS.contains(&key.as_str()))
+ {
+ return None;
+ }
+ let mut fields: Vec<String> = inner.keys().cloned().collect();
+ fields.sort();
+ Some(fields)
+}
+
/// Simple FNV-1a 64-bit hash, sufficient for change detection.
fn simple_hash(content: &str) -> String {
let mut hash: u64 = 0xcbf29ce484222325;
@@ -4561,6 +4609,19 @@ impl PipeManager {
));
}
+ // A caller that wraps its fields in a `config` envelope would otherwise
+ // land in the catch-all arm below, be filed under free-form user config,
+ // and get `{"success": true}` back with not one requested field applied.
+ // Silence is the worst answer here, so say what went wrong instead.
+ if let Some(fields) = nested_config_envelope(&updates) {
+ return Err(anyhow!(
+ "config update for '{}' wraps its fields in a `config` envelope; \
+ send them at the top level instead: {}",
+ name,
+ fields.join(", ")
+ ));
+ }
+
// If raw_content is provided, write the full file directly and re-parse
if let Some(raw) = updates.get("raw_content").and_then(|v| v.as_str()) {
// Validate it parses correctly
@@ -11029,6 +11090,50 @@ mod tests {
parse_frontmatter(&serialized).expect("round-trip parse failed after extras cleanup");
}
+ #[test]
+ fn test_nested_config_envelope_is_detected() {
+ // The exact body the Live View cadence write used to send. It reached
+ // the catch-all arm, so the schedule never changed and the caller still
+ // got `{"success": true}`.
+ let mut updates = HashMap::new();
+ updates.insert(
+ "config".to_string(),
+ serde_json::json!({"schedule": "every 1h", "enabled": true}),
+ );
+ let fields = nested_config_envelope(&updates).expect("envelope should be rejected");
+ assert_eq!(fields, vec!["enabled".to_string(), "schedule".to_string()]);
+ }
+
+ #[test]
+ fn test_flat_config_body_is_not_treated_as_an_envelope() {
+ // What every correct caller sends.
+ let mut updates = HashMap::new();
+ updates.insert("schedule".to_string(), serde_json::json!("every 1h"));
+ updates.insert("enabled".to_string(), serde_json::json!(true));
+ assert!(nested_config_envelope(&updates).is_none());
+ }
+
+ #[test]
+ fn test_user_config_named_config_still_allowed() {
+ // A free-form user setting that happens to be named `config` must keep
+ // working, so the guard only fires when every nested key is a real
+ // front-matter field.
+ let mut updates = HashMap::new();
+ updates.insert(
+ "config".to_string(),
+ serde_json::json!({"api_url": "https://example.com", "retries": 3}),
+ );
+ assert!(nested_config_envelope(&updates).is_none());
+
+ // Mixed: one real field, one arbitrary key. Ambiguous, so leave it be.
+ let mut mixed = HashMap::new();
+ mixed.insert(
+ "config".to_string(),
+ serde_json::json!({"schedule": "every 1h", "api_url": "https://example.com"}),
+ );
+ assert!(nested_config_envelope(&mixed).is_none());
+ }
+
#[test]
fn test_update_config_trigger_does_not_leak_to_extras() {
// Simulate what update_config does when receiving a trigger update