Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(cache): close gaps left by merging main into #7512 (#7838)
teoa28981558bd5
diff --git a/Cargo.lock b/Cargo.lockindex 7f843cc58f..418bf15989 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3460,7 +3460,7 @@ dependencies = [[[package]]name = "cache-wasm"-version = "0.6.44"+version = "0.6.45"dependencies = ["async-lock","cache-core",diff --git a/apps/web/src/lib/graphql-cache/exchange/mutation-queue-runner.ts b/apps/web/src/lib/graphql-cache/exchange/mutation-queue-runner.tsindex ffb4ae0c34..5f8a6f700b 100644--- a/apps/web/src/lib/graphql-cache/exchange/mutation-queue-runner.ts+++ b/apps/web/src/lib/graphql-cache/exchange/mutation-queue-runner.ts@@ -563,16 +563,16 @@ export function createMutationQueueRunner(hasNext: false,};await recordAttemptResult(attempt, result, false);- // Known gap: unlike every other settlement step, this rollback and the- // bookkeeping after it do not recheck the token. A storage reset during- // the recovery hook lets this stale attempt roll back a replacement- // queue head that reuses its transaction id and lease generation.+ // A storage reset during the recovery hook or rollback retires this+ // attempt; a replacement head may reuse its transaction id and lease.+ if (!isCurrent(attempt)) return;await host.rollbackOptimisticWrite(claimed.transactionId,claimOf(attempt),failure.message,'LOCAL_RECOVERY_FAILED');+ if (!isCurrent(attempt)) return;liveQueuedOps.delete(claimed.transactionId);live?.resolveRoute(withOptimisticMutationDisposition(result, {diff --git a/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.test.ts b/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.test.tsindex 06323aa59a..a814f48dd3 100644--- a/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.test.ts+++ b/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.test.ts@@ -3786,11 +3786,9 @@ describe('normalizedCacheExchange', () => {]);});- // Known gap kept by the queue runner extraction: a recovery failure- // rolls back without rechecking its attempt token. The replacement- // queue reuses transaction id txn-1 and lease generation 1, so the- // stale attempt discards the new head. Change to `it` once fenced.- it.fails('fences a recovery-failure rollback after storage resets', async () => {+ // The replacement queue reuses transaction id txn-1 and lease+ // generation 1, so an unfenced stale attempt would discard the new head.+ it('fences a recovery-failure rollback after storage resets', async () => {const recording = deferred<void>();let admissions = 0;const { ops, forwarded } = controlledQueryHarness(host, {diff --git a/crates/client/cache-turso/src/storage.rs b/crates/client/cache-turso/src/storage.rsindex 34d4e52163..434db449af 100644--- a/crates/client/cache-turso/src/storage.rs+++ b/crates/client/cache-turso/src/storage.rs@@ -1492,7 +1492,7 @@ impl Storage for TursoStorage {)?;self.fault_after(TestFaultSite::Put, index)?;}- write_search_documents(&connection, &entries)?;+ write_derived_rows(&connection, &entries)?;write_projection_mutations(&connection, projections)})})();diff --git a/crates/client/cache-turso/tests/shared_conformance/calendar_points.rs b/crates/client/cache-turso/tests/shared_conformance/calendar_points.rsindex 23fda10dfe..e61cfd7071 100644--- a/crates/client/cache-turso/tests/shared_conformance/calendar_points.rs+++ b/crates/client/cache-turso/tests/shared_conformance/calendar_points.rs@@ -182,3 +182,48 @@ fn in_memory_points_follow_the_calendar_storage_contract() {fn turso_points_follow_the_calendar_storage_contract() {block_on(point_contract::<TursoFactory>());}++/// An identity reset rewrites the cache from one response, so the records it+/// restores need the same derived calendar rows as an ordinary write.+async fn reset_contract<F: BackendFactory>() {+ let (mut factory, mut storage) = F::create();+ let point_key = |name: &str| key(&format!("GraphqlCalendarOccurrence:points:{name}"));+ storage+ .put_batch(vec![(+ point_key("previous"),+ timed_record(START_MS, START_MS),+ )])+ .await+ .unwrap();+ storage+ .reset_with_records(+ vec![(+ point_key("restored"),+ timed_record(START_MS + 500, START_MS + 500),+ )],+ Vec::new(),+ )+ .await+ .unwrap();+ let storage = factory.reopen(storage);+ let snapshot = storage.query_calendar_ranges(&point_range()).await.unwrap();+ assert_eq!(+ snapshot+ .rows+ .iter()+ .map(|row| row.record_key.clone())+ .collect::<Vec<_>>(),+ [point_key("restored")]+ );+ factory.finish(storage);+}++#[test]+fn in_memory_reset_writes_calendar_rows_for_restored_records() {+ block_on(reset_contract::<InMemoryFactory>());+}++#[test]+fn turso_reset_writes_calendar_rows_for_restored_records() {+ block_on(reset_contract::<TursoFactory>());+}diff --git a/crates/client/cache-wasm/Cargo.toml b/crates/client/cache-wasm/Cargo.tomlindex 038131ba6f..6cd59a8c56 100644--- a/crates/client/cache-wasm/Cargo.toml+++ b/crates/client/cache-wasm/Cargo.toml@@ -2,8 +2,8 @@edition = "2024"name = "cache-wasm"publish = false-# Rebuild live queries and optimistic transactions on runtime-loaded GraphQL SDL.-version = "0.6.44"+# Rebuild to check watch patch values for unsafe integers.+version = "0.6.45"[features]default = []diff --git a/crates/client/cache-wasm/src/shell.rs b/crates/client/cache-wasm/src/shell.rsindex 55f127fe6d..68d5da4474 100644--- a/crates/client/cache-wasm/src/shell.rs+++ b/crates/client/cache-wasm/src/shell.rs@@ -1097,6 +1097,19 @@ fn read_response_to_js<'a, T: Serialize>(js_sys::JSON::parse(&json)}+/// JSON values a watch update sends to JS. Patch values cross the boundary+/// the same way as a hit's data, so they need the same integer check.+fn query_update_values(+ update: &cache_core::engine::watch_query::QueryUpdate,+) -> Vec<&serde_json::Value> {+ use cache_core::engine::watch_query::QueryUpdate;+ match update {+ QueryUpdate::Hit { data, .. } => vec![data],+ QueryUpdate::Patch { patches, .. } => patches.iter().map(|patch| &patch.value).collect(),+ QueryUpdate::Miss { .. } => Vec::new(),+ }+}+fn has_unsafe_json_integer(value: &serde_json::Value) -> bool {const MAX_SAFE_INTEGER: i64 = 9_007_199_254_740_991;match value {@@ -1380,11 +1393,7 @@ impl CacheEngine {).await;let result = state.engine_result(result)?;- let data = match &result {- cache_core::engine::watch_query::QueryUpdate::Hit { data, .. } => Some(data),- _ => None,- };- read_response_to_js(&result, data)+ read_response_to_js(&result, query_update_values(&result))})}diff --git a/crates/client/cache-wasm/src/shell/test.rs b/crates/client/cache-wasm/src/shell/test.rsindex 5c5a89f7bc..c73205615d 100644--- a/crates/client/cache-wasm/src/shell/test.rs+++ b/crates/client/cache-wasm/src/shell/test.rs@@ -84,6 +84,32 @@ fn read_response_conversion_preserves_unsafe_integer_errors() {}}+#[wasm_bindgen_test]+fn watch_patches_reject_unsafe_integers_like_hits() {+ use cache_core::engine::live_query::{LiveFieldPatch, ResponsePathSegment};+ use cache_core::engine::watch_query::QueryUpdate;+ let value = serde_json::json!({"nested": [{"value": 9_007_199_254_740_992_u64}]});+ let hit = QueryUpdate::Hit {+ data: value.clone(),+ revision: "1".into(),+ };+ let patch = QueryUpdate::Patch {+ patches: vec![LiveFieldPatch {+ path: vec![ResponsePathSegment::Field("payload".into())],+ value,+ }],+ revision: "2".into(),+ };+ for update in [&hit, &patch] {+ assert_eq!(+ read_response_to_js(update, query_update_values(update))+ .unwrap_err()+ .as_string(),+ to_js(update).unwrap_err().as_string()+ );+ }+}+#[wasm_bindgen_test]fn build_info_reports_compiled_versions_without_opening_storage() {let info: serde_json::Value =