hippo-memory 3.3.3 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/api/context/context-pools.js +2 -1
  2. package/dist/api/context/user-rule.js +2 -1
  3. package/dist/api/dashboard/detail.js +2 -1
  4. package/dist/api/dashboard/live.d.ts +0 -4
  5. package/dist/api/dashboard/live.js +0 -8
  6. package/dist/api/memories/conflicts.d.ts +2 -1
  7. package/dist/api/memories/conflicts.js +3 -8
  8. package/dist/api/memories/promote.js +6 -2
  9. package/dist/api/recall/compose.js +2 -1
  10. package/dist/api/recall/rank-stages.js +2 -1
  11. package/dist/api/recall/rows.js +2 -1
  12. package/dist/api/sleep/sleep-run.js +2 -1
  13. package/dist/api/summary-parents.js +2 -1
  14. package/dist/base/memory/ambient.js +2 -1
  15. package/dist/base/memory/entry.d.ts +4 -1
  16. package/dist/base/memory/entry.js +7 -1
  17. package/dist/base/memory/half-life-plan.js +6 -4
  18. package/dist/base/memory/keep-rules.js +2 -1
  19. package/dist/base/memory/liveness.d.ts +7 -0
  20. package/dist/base/memory/liveness.js +6 -0
  21. package/dist/base/memory/markdown.js +15 -5
  22. package/dist/base/memory/memory-audit.js +2 -1
  23. package/dist/base/memory/memory-facts.d.ts +0 -2
  24. package/dist/base/memory/memory-facts.js +0 -2
  25. package/dist/base/memory/merged-row.js +3 -2
  26. package/dist/base/memory/rule-replaces.js +2 -1
  27. package/dist/base/memory/stale-mark.d.ts +9 -0
  28. package/dist/base/memory/stale-mark.js +18 -0
  29. package/dist/base/ports/store/conflicts.d.ts +5 -1
  30. package/dist/base/ports/store/conflicts.js +2 -0
  31. package/dist/base/ports/store/consolidation.d.ts +51 -2
  32. package/dist/base/ports/store/consolidation.js +3 -0
  33. package/dist/base/ports/store/sessions.d.ts +8 -2
  34. package/dist/base/ports/store/sessions.js +6 -0
  35. package/dist/base/ports/store/store-effects.d.ts +3 -0
  36. package/dist/base/scope/live-memory.d.ts +7 -0
  37. package/dist/base/scope/live-memory.js +10 -0
  38. package/dist/base/scope/read-admission.js +2 -1
  39. package/dist/base/util/version.d.ts +1 -1
  40. package/dist/base/util/version.js +1 -1
  41. package/dist/db/continuity-tables.d.ts +4 -1
  42. package/dist/db/continuity-tables.js +21 -12
  43. package/dist/db/migrate.js +2 -2
  44. package/dist/db/migrations/index.d.ts +1 -1
  45. package/dist/db/migrations/index.js +3 -1
  46. package/dist/db/migrations/v61.js +3 -3
  47. package/dist/db/migrations/v62.d.ts +3 -0
  48. package/dist/db/migrations/v62.js +43 -0
  49. package/dist/db/required-objects.js +2 -1
  50. package/dist/db/sql-predicates.d.ts +22 -2
  51. package/dist/db/sql-predicates.js +27 -2
  52. package/dist/domain/agent-memories/apply.js +2 -1
  53. package/dist/domain/agent-memories/container-view.js +2 -1
  54. package/dist/domain/consolidate/conflicts.js +2 -1
  55. package/dist/domain/consolidate/dag-summary.d.ts +2 -0
  56. package/dist/domain/consolidate/dag.d.ts +3 -0
  57. package/dist/domain/consolidate/dag.js +53 -8
  58. package/dist/domain/consolidate/dedupe.js +2 -1
  59. package/dist/domain/consolidate/events.d.ts +2 -0
  60. package/dist/domain/consolidate/llm-passes.js +94 -20
  61. package/dist/domain/consolidate/merge.js +5 -4
  62. package/dist/domain/consolidate/retry-holds.d.ts +14 -0
  63. package/dist/domain/consolidate/retry-holds.js +26 -0
  64. package/dist/domain/consolidate/run.d.ts +8 -0
  65. package/dist/domain/consolidate/run.js +2 -0
  66. package/dist/domain/graph/recall.js +3 -2
  67. package/dist/domain/learn/churn-stale.js +2 -1
  68. package/dist/domain/learn/extract.d.ts +10 -0
  69. package/dist/domain/learn/extract.js +10 -5
  70. package/dist/domain/learn/invalidation.d.ts +1 -1
  71. package/dist/domain/learn/invalidation.js +4 -11
  72. package/dist/domain/objects/decisions.d.ts +2 -2
  73. package/dist/domain/objects/decisions.js +4 -9
  74. package/dist/domain/search/as-of.js +3 -2
  75. package/dist/store/sqlite/capture/compaction-rows.js +9 -2
  76. package/dist/store/sqlite/connectors/quarantine.js +13 -4
  77. package/dist/store/sqlite/consolidation/consolidation-summaries.d.ts +4 -5
  78. package/dist/store/sqlite/consolidation/consolidation-summaries.js +46 -26
  79. package/dist/store/sqlite/consolidation/consolidation.js +5 -0
  80. package/dist/store/sqlite/consolidation/empty-extractions.d.ts +14 -0
  81. package/dist/store/sqlite/consolidation/empty-extractions.js +57 -0
  82. package/dist/store/sqlite/consolidation/rebuild-holds.d.ts +21 -0
  83. package/dist/store/sqlite/consolidation/rebuild-holds.js +68 -0
  84. package/dist/store/sqlite/entries/entry-filter.js +2 -1
  85. package/dist/store/sqlite/entries/entry-reads.js +2 -1
  86. package/dist/store/sqlite/entries/entry-writes.js +6 -5
  87. package/dist/store/sqlite/maintenance/agent-import-steps.js +7 -2
  88. package/dist/store/sqlite/maintenance/project-tags.js +4 -3
  89. package/dist/store/sqlite/recall/candidates.js +10 -4
  90. package/dist/store/sqlite/recall/search-rows.js +4 -3
  91. package/dist/store/sqlite/reports/dashboard-lists.js +3 -2
  92. package/dist/store/sqlite/reports/dashboard-reads.js +5 -3
  93. package/dist/store/sqlite/reports/dashboard-sql.d.ts +0 -3
  94. package/dist/store/sqlite/reports/dashboard-sql.js +2 -9
  95. package/dist/store/sqlite/reports/reports.js +2 -1
  96. package/dist/store/sqlite/review/conflicts.js +7 -1
  97. package/dist/store/sqlite/runtime/rule-sql.js +2 -1
  98. package/dist/store/sqlite/runtime/status-transitions.d.ts +98 -0
  99. package/dist/store/sqlite/runtime/status-transitions.js +105 -0
  100. package/dist/store/sqlite/sessions/goals.js +11 -12
  101. package/dist/store/sqlite/sessions/sessions.d.ts +1 -1
  102. package/dist/store/sqlite/sessions/sessions.js +20 -8
  103. package/dist/surface/cli/conflicts.js +12 -1
  104. package/dist/surface/cli/continuity.js +4 -0
  105. package/dist/surface/cli/print.js +2 -1
  106. package/dist/surface/cli/verbs/objects.js +2 -2
  107. package/dist/surface/dashboard/dashboard-actions.js +1 -1
  108. package/dist/surface/render/sleep-events.js +2 -0
  109. package/dist-ui/assets/index-Cst0ubfs.js +1 -0
  110. package/dist-ui/index.html +1 -1
  111. package/extensions/openclaw-plugin/openclaw.plugin.json +1 -1
  112. package/extensions/openclaw-plugin/package.json +1 -1
  113. package/openclaw.plugin.json +1 -1
  114. package/package.json +1 -1
  115. package/dist-ui/assets/index-Q9SY-1Bj.js +0 -1
@@ -1,6 +1,12 @@
1
1
  import type { JsonValue, JsonObject } from '../../util/json.js';
2
2
  import type { HandoffEvidence, HandoffOutcome, SessionHandoff } from '../../session/handoff.js';
3
3
  import type { ContinuityKey } from './types.js';
4
+ /** The statuses a task snapshot takes when it leaves `active` without a successor. */
5
+ export declare const SNAPSHOT_CLOSE_STATUSES: readonly ["cleared", "done", "session-ended"];
6
+ /** One of `SNAPSHOT_CLOSE_STATUSES`. */
7
+ export type SnapshotCloseStatus = (typeof SNAPSHOT_CLOSE_STATUSES)[number];
8
+ /** True when `status` is one of the close statuses a snapshot clear may set. */
9
+ export declare function isSnapshotCloseStatus(status: string): status is SnapshotCloseStatus;
4
10
  export interface TaskSnapshot {
5
11
  id: number;
6
12
  task: string;
@@ -142,13 +148,13 @@ export interface Sessions {
142
148
  readonly limit?: number;
143
149
  }): Promise<WorkingMemoryItem[]>;
144
150
  /** Closes with `status` the key's active snapshots the session saved, never a newer session's;
145
- * rows closed. */
151
+ * rows closed. `status` is cleared, done or session-ended. */
146
152
  clear(tenantId: string, kind: 'snapshot', close: {
147
153
  readonly status: string;
148
154
  readonly sessionId: string;
149
155
  }, key: ContinuityKey | null): Promise<number>;
150
156
  /** Closes with `status` the tenant's newest active snapshot, whoever saved it, and drops its
151
- * mirror; a shared store refuses. Rows closed. */
157
+ * mirror; a shared store refuses. Rows closed. `status` is cleared, done or session-ended. */
152
158
  clear(tenantId: string, kind: 'snapshot', close: {
153
159
  readonly status: string;
154
160
  }): Promise<number>;
@@ -1,3 +1,9 @@
1
+ /** The statuses a task snapshot takes when it leaves `active` without a successor. */
2
+ export const SNAPSHOT_CLOSE_STATUSES = ['cleared', 'done', 'session-ended'];
3
+ /** True when `status` is one of the close statuses a snapshot clear may set. */
4
+ export function isSnapshotCloseStatus(status) {
5
+ return SNAPSHOT_CLOSE_STATUSES.some((close) => close === status);
6
+ }
1
7
  /** What each Sessions method does to the store; every adapter honours it. */
2
8
  export const SESSIONS_EFFECTS = {
3
9
  save: 'write',
@@ -220,6 +220,9 @@ export declare const STORE_EFFECTS: {
220
220
  readonly particlesByRecall: "read";
221
221
  readonly saveParticles: "write";
222
222
  readonly dirtySummaries: "read";
223
+ readonly noteRebuildFailures: "write";
224
+ readonly emptyExtractions: "read";
225
+ readonly noteEmptyExtractions: "write";
223
226
  readonly unprofiledTopicSummaries: "read";
224
227
  readonly settleSummary: "write";
225
228
  readonly commit: "write";
@@ -0,0 +1,7 @@
1
+ /** True for a live memory: not superseded, kind raw or distilled, and not in a quarantine scope. */
2
+ export declare function isLiveMemory(entry: {
3
+ readonly supersededBy?: string | null;
4
+ readonly kind: string;
5
+ readonly scope: string | null;
6
+ }): boolean;
7
+ //# sourceMappingURL=live-memory.d.ts.map
@@ -0,0 +1,10 @@
1
+ // Here, not in base/memory, since scope already imports memory and the quarantine test is scope's.
2
+ import { isSuperseded } from '../memory/liveness.js';
3
+ import { isQuarantineScope } from './recall-scope.js';
4
+ /** True for a live memory: not superseded, kind raw or distilled, and not in a quarantine scope. */
5
+ export function isLiveMemory(entry) {
6
+ return (!isSuperseded(entry) &&
7
+ (entry.kind === 'raw' || entry.kind === 'distilled') &&
8
+ !isQuarantineScope(entry.scope));
9
+ }
10
+ //# sourceMappingURL=live-memory.js.map
@@ -6,6 +6,7 @@ import { classifyOriginProject, projectNames } from './project-identity.js';
6
6
  import { passesScopeFilterForRecall } from './recall-scope.js';
7
7
  import { isSessionDigestRow } from '../session/session-digest-row.js';
8
8
  import { detectSecret } from '../util/secret-detect.js';
9
+ import { isSuperseded } from '../memory/liveness.js';
9
10
  /** The secret half of the ambient policy alone: a flagged row is admitted only inside its owning
10
11
  * project. */
11
12
  export function ambientSecretAdmit(e, currentProject) {
@@ -34,7 +35,7 @@ export function ambientEnvelopeAdmits(e, a) {
34
35
  }
35
36
  // Superseded rows go first because the envelope regex-scans content for secrets.
36
37
  export function ambientAdmits(e, a) {
37
- return !e.supersededBy && !isOwnCompactionItem(e, a.ownSessionId) && ambientEnvelopeAdmits(e, a);
38
+ return !isSuperseded(e) && !isOwnCompactionItem(e, a.ownSessionId) && ambientEnvelopeAdmits(e, a);
38
39
  }
39
40
  /** Why an ambient load leaves `e` out, or null when it keeps it. */
40
41
  export function ambientRefusal(e, a) {
@@ -2,7 +2,7 @@
2
2
  * Single source of truth for the package version, written by scripts/sync-version.mjs; never
3
3
  * edit by hand. Read by the db rollback guard, /health, MCP. A constant, not a runtime
4
4
  * package.json read: the published bundle may lack package.json on a path ESM can resolve. */
5
- export declare const PACKAGE_VERSION = "3.3.3";
5
+ export declare const PACKAGE_VERSION = "3.4.0";
6
6
  /** The floor a store takes on its first expiring key: the first release with schema v53, set by
7
7
  * hand in that release; scripts/checks/check-expiring-keys-floor.mjs gates it. */
8
8
  export declare const EXPIRING_KEYS_MIN_BINARY = "1.64.0";
@@ -2,7 +2,7 @@
2
2
  * Single source of truth for the package version, written by scripts/sync-version.mjs; never
3
3
  * edit by hand. Read by the db rollback guard, /health, MCP. A constant, not a runtime
4
4
  * package.json read: the published bundle may lack package.json on a path ESM can resolve. */
5
- export const PACKAGE_VERSION = '3.3.3';
5
+ export const PACKAGE_VERSION = '3.4.0';
6
6
  /** The floor a store takes on its first expiring key: the first release with schema v53, set by
7
7
  * hand in that release; scripts/checks/check-expiring-keys-floor.mjs gates it. */
8
8
  export const EXPIRING_KEYS_MIN_BINARY = '1.64.0';
@@ -5,8 +5,11 @@ export declare const HEALED_TABLES: readonly ["task_snapshots", "session_events"
5
5
  /** The indexes the chain puts on those tables and the two request indexes, by name: the open's
6
6
  * probe counts them, and a missing one is made again from the chain. */
7
7
  export declare const HEALED_INDEXES: readonly ["idx_task_snapshots_status_updated", "idx_task_snapshots_tenant_status", "idx_task_snapshots_tenant_scope", "idx_task_snapshots_owner", "idx_session_events_session_created", "idx_session_events_task_created", "idx_session_events_tenant_session", "idx_session_handoffs_session", "idx_session_handoffs_tenant_session", "idx_session_handoffs_tenant_outcome", "idx_session_handoffs_tenant_card", "idx_session_handoffs_owner", "idx_cards_tenant_status", "idx_card_deps_tenant_child", "idx_card_deps_tenant_parent", "idx_card_runs_tenant_card", "idx_card_comments_tenant_card", "idx_memory_quarantine_status", "idx_compactions_request", "idx_failure_log_request"];
8
+ /** The triggers the chain puts on those tables, by name: a dropped table takes its triggers with
9
+ * it, so the open's probe counts them and a missing one is made again from the chain. */
10
+ export declare const HEALED_TRIGGERS: readonly ["trg_task_snapshots_status_check_insert", "trg_task_snapshots_status_check_update"];
8
11
  /** The healed tables this store lacks; a read only, so an open can skip the write lock when none. */
9
12
  export declare function missingHealedTables(db: DatabaseSyncLike): Set<string>;
10
13
  export declare function ensureContinuityTables(db: DatabaseSyncLike): void;
11
- export declare function ensureContinuityIndexes(db: DatabaseSyncLike): void;
14
+ export declare function ensureContinuityObjects(db: DatabaseSyncLike): void;
12
15
  //# sourceMappingURL=continuity-tables.d.ts.map
@@ -40,6 +40,13 @@ export const HEALED_INDEXES = [
40
40
  'idx_compactions_request',
41
41
  'idx_failure_log_request',
42
42
  ];
43
+ /** The triggers the chain puts on those tables, by name: a dropped table takes its triggers with
44
+ * it, so the open's probe counts them and a missing one is made again from the chain. */
45
+ export const HEALED_TRIGGERS = [
46
+ 'trg_task_snapshots_status_check_insert',
47
+ 'trg_task_snapshots_status_check_update',
48
+ ];
49
+ const HEALED_OBJECTS = [...HEALED_INDEXES, ...HEALED_TRIGGERS];
43
50
  // The request indexes' tables: never healed, since a store that lost one still opens so its hooks
44
51
  // can log the step.
45
52
  const REQUEST_TABLES = ['compactions', 'failure_log'];
@@ -59,25 +66,26 @@ export function ensureContinuityTables(db) {
59
66
  if (missing.has(table))
60
67
  db.exec(sql);
61
68
  }
62
- // After the loop, when every column an index names exists; only a store missing one builds the
63
- // chain.
64
- export function ensureContinuityIndexes(db) {
69
+ // After the loop, when every column an index names exists; only a store missing an index or a
70
+ // trigger builds the chain.
71
+ export function ensureContinuityObjects(db) {
65
72
  // SAFETY: one TEXT column named name.
66
73
  const present = db
67
- .prepare(`SELECT name FROM sqlite_master WHERE type = 'index' AND name IN (${placeholders(HEALED_INDEXES.length)})`)
68
- .all(...HEALED_INDEXES);
69
- if (present.length === HEALED_INDEXES.length)
74
+ .prepare(`SELECT name FROM sqlite_master WHERE type IN ('index', 'trigger') ` +
75
+ `AND name IN (${placeholders(HEALED_OBJECTS.length)})`)
76
+ .all(...HEALED_OBJECTS);
77
+ if (present.length === HEALED_OBJECTS.length)
70
78
  return;
71
79
  const have = new Set(present.map(({ name }) => name));
72
80
  chainObjects ??= objectsFromChain();
73
- for (const name of HEALED_INDEXES) {
81
+ for (const name of HEALED_OBJECTS) {
74
82
  const made = chainObjects.get(name);
75
83
  if (!have.has(name) && made !== undefined && tableExists(db, made.table))
76
84
  db.exec(made.sql);
77
85
  }
78
86
  }
79
- /** Each healed table's CREATE TABLE, then every index on it and on the request tables, keyed by
80
- * object name, as the migration chain leaves them on an empty database. */
87
+ /** Each healed table's CREATE TABLE, then every index and trigger on it and on the request tables,
88
+ * keyed by object name, as the migration chain leaves them on an empty database. */
81
89
  function objectsFromChain() {
82
90
  const db = new DatabaseSync(':memory:');
83
91
  try {
@@ -89,8 +97,9 @@ function objectsFromChain() {
89
97
  // SAFETY: rows follow the selected columns, and the WHERE drops the autoindexes whose sql is
90
98
  // NULL.
91
99
  const rows = db
92
- .prepare(`SELECT name, tbl_name, sql FROM sqlite_master WHERE sql IS NOT NULL AND type IN ('table', 'index') ` +
93
- `AND tbl_name IN (${placeholders(tables.length)}) ORDER BY type DESC, name`)
100
+ .prepare(`SELECT name, tbl_name, sql FROM sqlite_master WHERE sql IS NOT NULL ` +
101
+ `AND type IN ('table', 'index', 'trigger') AND tbl_name IN (${placeholders(tables.length)}) ` +
102
+ `ORDER BY CASE type WHEN 'table' THEN 0 WHEN 'index' THEN 1 ELSE 2 END, name`)
94
103
  .all(...tables);
95
104
  return new Map(rows.map(({ name, tbl_name, sql }) => [name, { table: tbl_name, sql: ifNotExists(sql) }]));
96
105
  }
@@ -99,5 +108,5 @@ function objectsFromChain() {
99
108
  }
100
109
  }
101
110
  // sqlite_master keeps each CREATE without its IF NOT EXISTS.
102
- const ifNotExists = (sql) => sql.replace(/^CREATE (UNIQUE )?(TABLE|INDEX) /, 'CREATE $1$2 IF NOT EXISTS ');
111
+ const ifNotExists = (sql) => sql.replace(/^CREATE (UNIQUE )?(TABLE|INDEX|TRIGGER) /, 'CREATE $1$2 IF NOT EXISTS ');
103
112
  //# sourceMappingURL=continuity-tables.js.map
@@ -4,7 +4,7 @@ import { importLegacyEmbeddingIndex } from './vector-store.js';
4
4
  import { execWithBusyRetry, withWriteScope } from './busy.js';
5
5
  import { tableExists } from './tables.js';
6
6
  import { ensureMetaTable, getMeta, getSchemaVersion, setMeta, setSchemaVersion, META_KEY, } from './meta.js';
7
- import { ensureContinuityIndexes, ensureContinuityTables, missingHealedTables, } from './continuity-tables.js';
7
+ import { ensureContinuityObjects, ensureContinuityTables, missingHealedTables, } from './continuity-tables.js';
8
8
  import { MEMORIES_FTS_DDL, ensureTrigramIndex, isFtsMissing, rebuildTrigramIndex, } from './fts-index.js';
9
9
  import { REQUIRED_SCHEMA_OBJECTS } from './required-objects.js';
10
10
  import { CURRENT_SCHEMA_VERSION, MIGRATIONS } from './migrations/index.js';
@@ -137,7 +137,7 @@ function migrateAndHeal(db, hippoRoot, busyWaitMs) {
137
137
  currentVersion = applyMigration(db, migration, hippoRoot, busyWaitMs);
138
138
  }
139
139
  healUserVersion(db, currentVersion, busyWaitMs);
140
- ensureContinuityIndexes(db);
140
+ ensureContinuityObjects(db);
141
141
  ensureMetaDefaults(db);
142
142
  ensureOptionalFts(db);
143
143
  }
@@ -1,5 +1,5 @@
1
1
  import type { Migration } from './types.js';
2
- export declare const CURRENT_SCHEMA_VERSION = 61;
2
+ export declare const CURRENT_SCHEMA_VERSION = 62;
3
3
  /** Every schema migration in version order; runMigrations applies each one above the stored
4
4
  * version. */
5
5
  export declare const MIGRATIONS: Migration[];
@@ -59,7 +59,8 @@ import { v58 } from './v58.js';
59
59
  import { v59 } from './v59.js';
60
60
  import { v60 } from './v60.js';
61
61
  import { v61 } from './v61.js';
62
- export const CURRENT_SCHEMA_VERSION = 61;
62
+ import { v62 } from './v62.js';
63
+ export const CURRENT_SCHEMA_VERSION = 62;
63
64
  /** Every schema migration in version order; runMigrations applies each one above the stored
64
65
  * version. */
65
66
  export const MIGRATIONS = [
@@ -124,5 +125,6 @@ export const MIGRATIONS = [
124
125
  v59,
125
126
  v60,
126
127
  v61,
128
+ v62,
127
129
  ];
128
130
  //# sourceMappingURL=index.js.map
@@ -1,10 +1,10 @@
1
- import { CURRENT_DISTILLED, TEXT_OUTSIDE_TRIGRAMS } from '../sql-predicates.js';
1
+ import { DUPLICATE_HASH_INDEX_WHERE, TEXT_OUTSIDE_TRIGRAMS } from '../sql-predicates.js';
2
2
  import { ensureTrigramIndex, isFtsMissing } from '../fts-index.js';
3
3
  import { tableHasColumn } from '../tables.js';
4
4
  import { duplicateHash } from '../../base/util/same-text.js';
5
5
  import { errorMessage } from '../../base/util/log.js';
6
6
  const INDEXES = [
7
- `idx_memories_duplicate_hash ON memories(duplicate_hash) WHERE ${CURRENT_DISTILLED}`,
7
+ `idx_memories_duplicate_hash ON memories(duplicate_hash) WHERE ${DUPLICATE_HASH_INDEX_WHERE}`,
8
8
  'idx_audit_log_tenant_op_ts ON audit_log(tenant_id, op, ts DESC, id DESC)',
9
9
  'idx_memory_conflicts_updated ON memory_conflicts(updated_at)',
10
10
  `idx_memories_text_outside_trigrams ON memories(tenant_id) WHERE ${TEXT_OUTSIDE_TRIGRAMS}`,
@@ -25,7 +25,7 @@ function backfillDuplicateHashes(db) {
25
25
  // content is NOT NULL TEXT, so String() hands the hash the text as stored.
26
26
  db.function('hippo_duplicate_hash', { deterministic: true }, (content) => duplicateHash(String(content)));
27
27
  db.exec(`UPDATE memories SET duplicate_hash = hippo_duplicate_hash(content) ` +
28
- `WHERE duplicate_hash IS NULL AND ${CURRENT_DISTILLED}`);
28
+ `WHERE duplicate_hash IS NULL AND ${DUPLICATE_HASH_INDEX_WHERE}`);
29
29
  }
30
30
  export const v61 = {
31
31
  version: 61,
@@ -0,0 +1,3 @@
1
+ import type { Migration } from './types.js';
2
+ export declare const v62: Migration;
3
+ //# sourceMappingURL=v62.d.ts.map
@@ -0,0 +1,43 @@
1
+ const CREATE_TRIGGER_TASK_SNAPSHOTS_STATUS_CHECK_INSERT_SQL = `
2
+ CREATE TRIGGER IF NOT EXISTS trg_task_snapshots_status_check_insert
3
+ BEFORE INSERT ON task_snapshots
4
+ WHEN NEW.status NOT IN ('active','superseded','cleared','done','session-ended')
5
+ BEGIN
6
+ SELECT RAISE(ABORT, 'invalid task snapshot status: must be active|superseded|cleared|done|session-ended');
7
+ END
8
+ `;
9
+ const CREATE_TRIGGER_TASK_SNAPSHOTS_STATUS_CHECK_UPDATE_SQL = `
10
+ CREATE TRIGGER IF NOT EXISTS trg_task_snapshots_status_check_update
11
+ BEFORE UPDATE OF status ON task_snapshots
12
+ WHEN NEW.status NOT IN ('active','superseded','cleared','done','session-ended')
13
+ BEGIN
14
+ SELECT RAISE(ABORT, 'invalid task snapshot status: must be active|superseded|cleared|done|session-ended');
15
+ END
16
+ `;
17
+ const CREATE_TRIGGER_MEMORY_CONFLICTS_STATUS_CHECK_INSERT_SQL = `
18
+ CREATE TRIGGER IF NOT EXISTS trg_memory_conflicts_status_check_insert
19
+ BEFORE INSERT ON memory_conflicts
20
+ WHEN NEW.status NOT IN ('open','resolved')
21
+ BEGIN
22
+ SELECT RAISE(ABORT, 'invalid conflict status: must be open|resolved');
23
+ END
24
+ `;
25
+ const CREATE_TRIGGER_MEMORY_CONFLICTS_STATUS_CHECK_UPDATE_SQL = `
26
+ CREATE TRIGGER IF NOT EXISTS trg_memory_conflicts_status_check_update
27
+ BEFORE UPDATE OF status ON memory_conflicts
28
+ WHEN NEW.status NOT IN ('open','resolved')
29
+ BEGIN
30
+ SELECT RAISE(ABORT, 'invalid conflict status: must be open|resolved');
31
+ END
32
+ `;
33
+ export const v62 = {
34
+ version: 62,
35
+ up: (db) => {
36
+ // UPDATE OF status, not UPDATE: a stored row outside the list stays editable in its other columns.
37
+ db.exec(CREATE_TRIGGER_TASK_SNAPSHOTS_STATUS_CHECK_INSERT_SQL);
38
+ db.exec(CREATE_TRIGGER_TASK_SNAPSHOTS_STATUS_CHECK_UPDATE_SQL);
39
+ db.exec(CREATE_TRIGGER_MEMORY_CONFLICTS_STATUS_CHECK_INSERT_SQL);
40
+ db.exec(CREATE_TRIGGER_MEMORY_CONFLICTS_STATUS_CHECK_UPDATE_SQL);
41
+ },
42
+ };
43
+ //# sourceMappingURL=v62.js.map
@@ -1,5 +1,5 @@
1
1
  import { META_TABLE_DDL } from './meta.js';
2
- import { HEALED_INDEXES, HEALED_TABLES } from './continuity-tables.js';
2
+ import { HEALED_INDEXES, HEALED_TABLES, HEALED_TRIGGERS } from './continuity-tables.js';
3
3
  import { FTS_INDEX_DDL } from './fts-index.js';
4
4
  const CREATED_NAME = /CREATE\s+(?:VIRTUAL\s+|UNIQUE\s+)?(?:TABLE|INDEX|TRIGGER)\s+IF\s+NOT\s+EXISTS\s+(\w+)/gi;
5
5
  /** Names of every table, index and trigger a `CREATE ... IF NOT EXISTS` in `ddl` makes. */
@@ -12,6 +12,7 @@ export const REQUIRED_SCHEMA_OBJECTS = Object.freeze([
12
12
  ...createdObjectNames(META_TABLE_DDL),
13
13
  ...HEALED_TABLES,
14
14
  ...HEALED_INDEXES,
15
+ ...HEALED_TRIGGERS,
15
16
  ...FTS_INDEX_DDL.flatMap(createdObjectNames),
16
17
  ]);
17
18
  //# sourceMappingURL=required-objects.js.map
@@ -1,5 +1,25 @@
1
- /** The rows the duplicate read groups: current distilled ones. */
2
- export declare const CURRENT_DISTILLED = "COALESCE(kind, 'distilled') = 'distilled' AND COALESCE(superseded_by, '') = ''";
1
+ /** "Not superseded" for a column written in full; the text partial indexes match. */
2
+ export declare const notSupersededAt: (col: string) => string;
3
+ /** "Superseded" for a column written in full: any link, a blank one included. */
4
+ export declare const supersededAt: (col: string) => string;
5
+ /** "Not superseded" for `superseded_by` under table prefix `t` (`'m.'`, or none). */
6
+ export declare const notSupersededIn: (t?: string) => string;
7
+ /** "Superseded" for `superseded_by` under table prefix `t` (`'old.'`, or none). */
8
+ export declare const supersededIn: (t?: string) => string;
9
+ /** SQL twin of isQuarantineScope for `scope` under prefix `t`; substr compares bytes, as
10
+ * startsWith does, where LIKE would fold case. */
11
+ export declare const quarantinedIn: (t: string) => string;
12
+ /** The kind of a row under prefix `t`; a row with no kind reads as distilled. */
13
+ export declare const kindIn: (t: string) => string;
14
+ /** SQL twin of isLiveMemory for a row under prefix `t`. */
15
+ export declare const liveIn: (t: string) => string;
16
+ /** A row whose kind says superseded. */
17
+ export declare const supersededKindIn: (t: string) => string;
18
+ /** The WHERE of idx_memories_duplicate_hash (migration v61). Changing it changes the index new stores
19
+ * build, so it needs a migration. */
20
+ export declare const DUPLICATE_HASH_INDEX_WHERE = "COALESCE(kind, 'distilled') = 'distilled' AND COALESCE(superseded_by, '') = ''";
21
+ /** The rows the duplicate read groups: current distilled ones, plus the term that keeps the index. */
22
+ export declare const CURRENT_DISTILLED: string;
3
23
  export declare const TAGS_NOT_AS_WRITTEN = "instr(tags_json, '\\') > 0 OR tags_json GLOB '*[0-9{]*' OR instr(substr(tags_json, 2), '[') > 0";
4
24
  /** The rows whose text a trigram lookup may miss where JavaScript's lower-casing finds it: tags
5
25
  * not as written, and a dotted capital I, which FTS5 does not fold to `i`. Migration v61 indexes
@@ -1,5 +1,30 @@
1
- /** The rows the duplicate read groups: current distilled ones. */
2
- export const CURRENT_DISTILLED = "COALESCE(kind, 'distilled') = 'distilled' AND COALESCE(superseded_by, '') = ''";
1
+ import { QUARANTINE_SCOPE_PREFIX } from '../base/scope/recall-scope.js';
2
+ // The only place a `superseded_by` predicate is spelled: `IS NULL` is the text three partial indexes
3
+ // repeat, and a blank link counts as superseded, as isSuperseded reads it.
4
+ /** "Not superseded" for a column written in full; the text partial indexes match. */
5
+ export const notSupersededAt = (col) => `${col} IS NULL`;
6
+ /** "Superseded" for a column written in full: any link, a blank one included. */
7
+ export const supersededAt = (col) => `${col} IS NOT NULL`;
8
+ /** "Not superseded" for `superseded_by` under table prefix `t` (`'m.'`, or none). */
9
+ export const notSupersededIn = (t = '') => notSupersededAt(`${t}superseded_by`);
10
+ /** "Superseded" for `superseded_by` under table prefix `t` (`'old.'`, or none). */
11
+ export const supersededIn = (t = '') => supersededAt(`${t}superseded_by`);
12
+ /** SQL twin of isQuarantineScope for `scope` under prefix `t`; substr compares bytes, as
13
+ * startsWith does, where LIKE would fold case. */
14
+ export const quarantinedIn = (t) => `(${t}scope IS NOT NULL AND substr(${t}scope, 1, ${QUARANTINE_SCOPE_PREFIX.length}) = ` +
15
+ `'${QUARANTINE_SCOPE_PREFIX}')`;
16
+ /** The kind of a row under prefix `t`; a row with no kind reads as distilled. */
17
+ export const kindIn = (t) => `COALESCE(${t}kind, 'distilled')`;
18
+ /** SQL twin of isLiveMemory for a row under prefix `t`. */
19
+ export const liveIn = (t) => `${notSupersededIn(t)} AND ${kindIn(t)} IN ('raw', 'distilled') AND NOT ${quarantinedIn(t)}`;
20
+ // `hippo remember --kind superseded` saves this kind with no successor, so the field alone misses it.
21
+ /** A row whose kind says superseded. */
22
+ export const supersededKindIn = (t) => `${kindIn(t)} = 'superseded'`;
23
+ /** The WHERE of idx_memories_duplicate_hash (migration v61). Changing it changes the index new stores
24
+ * build, so it needs a migration. */
25
+ export const DUPLICATE_HASH_INDEX_WHERE = "COALESCE(kind, 'distilled') = 'distilled' AND COALESCE(superseded_by, '') = ''";
26
+ /** The rows the duplicate read groups: current distilled ones, plus the term that keeps the index. */
27
+ export const CURRENT_DISTILLED = `${DUPLICATE_HASH_INDEX_WHERE} AND ${notSupersededIn()}`;
3
28
  // A tag list with a `\`, a digit, an object or a nested list may not hold its tags' text as
4
29
  // written: an escape, or a value String() writes another way.
5
30
  export const TAGS_NOT_AS_WRITTEN = `instr(tags_json, '\\') > 0 OR tags_json GLOB '*[0-9{]*' \
@@ -7,6 +7,7 @@ import { itemHash } from './keys.js';
7
7
  import { planContainer, } from './plan.js';
8
8
  import { emptyTally } from '../../base/memory/agent-memory-report.js';
9
9
  import { MIN_ITEM_CHARS, splitSource, storedText } from './source.js';
10
+ import { isSuperseded } from '../../base/memory/liveness.js';
10
11
  /** Null when the rows changed under both plans; throws a busy error when another writer held the
11
12
  * store too long. */
12
13
  export async function syncContainer(s, work) {
@@ -120,7 +121,7 @@ async function dormantSnapshots(s, w, view, { liveKeys, refusals, }) {
120
121
  tenantId: s.tenantId,
121
122
  sourcePrefix: w.prefix,
122
123
  });
123
- return [...under, ...view.movedDormant].filter((snap) => !snap.entry.supersededBy);
124
+ return [...under, ...view.movedDormant].filter((snap) => !isSuperseded(snap.entry));
124
125
  }
125
126
  /** The plan asks which notes another path already stores only for the rows it would write; those
126
127
  * texts are read in one call, and the same items are asked again with the answers. */
@@ -1,5 +1,6 @@
1
1
  import { READ_PAGE_ROWS, readAll } from '../../base/util/pages.js';
2
2
  import { itemSource } from './source.js';
3
+ import { isSuperseded } from '../../base/memory/liveness.js';
3
4
  /** The tenant's live rows whose source starts with `prefix`, oldest first. */
4
5
  export async function liveUnder(store, tenantId, prefix) {
5
6
  const under = { tenantId, sourcePrefix: prefix, live: true };
@@ -49,7 +50,7 @@ async function standingLegacy(s, rows) {
49
50
  const from = new Map(rows.map((row) => [row.id, row.source]));
50
51
  const out = new Map();
51
52
  for (const row of await s.store.entriesByIds([...from.keys()], s.tenantId)) {
52
- if (!row.supersededBy && row.source === from.get(row.id))
53
+ if (!isSuperseded(row) && row.source === from.get(row.id))
53
54
  out.set(row.id, row);
54
55
  }
55
56
  return out;
@@ -7,6 +7,7 @@ import { CONFLICT_STOPWORDS } from '../../base/util/stopwords.js';
7
7
  import { jaccardSets, tokenizeMin } from '../../base/util/tokenize.js';
8
8
  import { DECAY_THRESHOLD } from './decay.js';
9
9
  import { BadRequestError } from '../../base/errors/api-errors.js';
10
+ import { isSuperseded } from '../../base/memory/liveness.js';
10
11
  // Gate contradictions on content overlap, not shared tags (`feedback`/`policy` are too coarse). The
11
12
  // Jaccard threshold on stopword-filtered tokens only applies after a polarity signal, so it filters
12
13
  // drive-by topic similarity, not semantic drift.
@@ -56,7 +57,7 @@ function conflictRow(place, e) {
56
57
  place,
57
58
  id: e.id,
58
59
  trace: e.layer === Layer.Trace,
59
- superseded: Boolean(e.supersededBy),
60
+ superseded: isSuperseded(e),
60
61
  restated: e.tags.includes(EXTRACTED_TAG) || e.tags.includes('session-digest'),
61
62
  scope: e.scope,
62
63
  tenantId: e.tenantId,
@@ -2,6 +2,8 @@ import { type Llm, type LlmFailure } from '../../base/ports/llm.js';
2
2
  export interface DagSummaryOptions {
3
3
  llm: Llm;
4
4
  model?: string;
5
+ /** Called once per failed attempt. `failure` is set if and only if the model call itself failed;
6
+ * a refused reply carries only the message, and a too short one is not reported. */
5
7
  onError?: (msg: string, failure?: LlmFailure) => void;
6
8
  }
7
9
  export declare function generateDagSummary(label: string, factContents: string[], opts: DagSummaryOptions): Promise<string | null>;
@@ -30,6 +30,9 @@ export interface DagRebuildResult {
30
30
  zeroChildSkipped: number;
31
31
  failed: number;
32
32
  capped: boolean;
33
+ /** Dirty summaries left out of this pass because their hold had not ended; none of them was
34
+ * attempted, so none is in `attempted` or `failed`. */
35
+ held: number;
33
36
  }
34
37
  /** Sleep-cycle phase draining the dirty L2 summary queue; one throwing rebuild does not abort
35
38
  * the rest. A concurrent sleep's second writer gets changed=false (UPDATE requires
@@ -1,6 +1,7 @@
1
1
  import { createMemory, DAG_LEVEL, EXTRACTED_TAG, Layer, } from '../../base/memory/entry.js';
2
2
  import { RejectedValueError } from '../../base/errors/api-errors.js';
3
3
  import { generateDagSummary } from './dag-summary.js';
4
+ import { rebuildRetryAfter } from './retry-holds.js';
4
5
  import { overlapPartners } from './overlap-index.js';
5
6
  import { derivationScope, derivationPartitionKey } from '../../base/scope/recall-scope.js';
6
7
  import { neverAutoShareTags } from '../sharing/share.js';
@@ -133,7 +134,7 @@ export async function buildDag(store, facts, opts) {
133
134
  return result;
134
135
  }
135
136
  async function rebuildOneSummary(options) {
136
- const { store, summary, opts, result, preloaded, rebuiltContent } = options;
137
+ const { store, summary, opts, result, preloaded, rebuiltContent, counted } = options;
137
138
  // A child rebuilt earlier in this drain was loaded before its rebuild, so it takes the content
138
139
  // that rebuild wrote.
139
140
  const children = preloaded.map((c) => {
@@ -144,10 +145,13 @@ async function rebuildOneSummary(options) {
144
145
  await clearZeroChildSummary(store, summary, result, opts.now);
145
146
  return;
146
147
  }
147
- const newContent = await generateDagSummary(summaryLabel(summary), children.map((c) => c.content), opts);
148
+ const { text: newContent, providerFailed } = await regenerate(summary, children, opts);
148
149
  if (!newContent) {
149
- // LLM null / fetch error → leave dirty for next cycle
150
+ // Left dirty for the next cycle. A provider failure says nothing about this summary, so only
151
+ // a content failure counts toward its hold.
150
152
  result.failed++;
153
+ if (!providerFailed)
154
+ counted.push(nextFailure(options));
151
155
  return;
152
156
  }
153
157
  const childCreatedAts = children.map((c) => c.created).sort();
@@ -170,6 +174,29 @@ async function rebuildOneSummary(options) {
170
174
  }
171
175
  // changed=false (refused also false) → race lost; not failure, not success, silently skip
172
176
  }
177
+ /** The model's new text for a summary, and whether the model call itself failed. */
178
+ async function regenerate(summary, children, opts) {
179
+ let providerFailed = false;
180
+ const text = await generateDagSummary(summaryLabel(summary), children.map((c) => c.content), {
181
+ ...opts,
182
+ onError: (msg, failure) => {
183
+ if (failure)
184
+ providerFailed = true;
185
+ opts.onError?.(msg, failure);
186
+ },
187
+ });
188
+ return { text, providerFailed };
189
+ }
190
+ /** The summary's failure count after one more content failure, with the hold that count earns. */
191
+ function nextFailure({ summary, failures, opts }) {
192
+ return {
193
+ id: summary.id,
194
+ tenantId: summary.tenantId,
195
+ priorFailures: failures,
196
+ failures: failures + 1,
197
+ retryAfter: rebuildRetryAfter(failures + 1, opts.now),
198
+ };
199
+ }
173
200
  /** Zero-child case: clear dirty + zero counts, no LLM call, no rebuild_count bump. */
174
201
  async function clearZeroChildSummary(store, summary, result, now) {
175
202
  const { changed } = await applyRebuild(store, summary, {
@@ -199,7 +226,7 @@ function summaryLabel(summary) {
199
226
  * summary_dirty=1) and is skipped silently; a tombstone hit counts as `refused`. */
200
227
  export async function rebuildDirtySummaries(store, opts) {
201
228
  const cap = opts.cap ?? DEFAULT_REBUILD_CAP;
202
- const { summaries: queue, more } = await store.consolidation.dirtySummaries(cap);
229
+ const { summaries: queue, more, held, } = await store.consolidation.dirtySummaries(cap, opts.now.toISOString());
203
230
  const result = {
204
231
  attempted: queue.length,
205
232
  rebuilt: 0,
@@ -207,9 +234,11 @@ export async function rebuildDirtySummaries(store, opts) {
207
234
  zeroChildSkipped: 0,
208
235
  failed: 0,
209
236
  capped: more,
237
+ held: held ?? 0,
210
238
  };
211
239
  const rebuiltContent = new Map();
212
- for (const [index, { summary, children }] of queue.entries()) {
240
+ const counted = [];
241
+ for (const [index, { summary, children, failures }] of queue.entries()) {
213
242
  // Yield the macrotask queue every 25 summaries: each iteration is synchronous store work, so a
214
243
  // batch of up to 1000 would starve timers and IPC (server keep-alives, Vitest's birpc
215
244
  // heartbeat).
@@ -223,19 +252,35 @@ export async function rebuildDirtySummaries(store, opts) {
223
252
  result,
224
253
  preloaded: children,
225
254
  rebuiltContent,
255
+ failures: failures ?? 0,
256
+ counted,
226
257
  });
227
258
  }
259
+ await noteFailedRebuilds(store, counted);
228
260
  return result;
229
261
  }
262
+ /** Stores the pass's counted failures in one call. A store without the method keeps no holds,
263
+ * and a note that fails only leaves them uncounted: the next failure counts. */
264
+ async function noteFailedRebuilds(store, counted) {
265
+ if (counted.length === 0)
266
+ return;
267
+ try {
268
+ await store.consolidation.noteRebuildFailures?.(counted);
269
+ }
270
+ catch (err) {
271
+ log.warn(`rebuildDirtySummaries: noting ${counted.length} failed rebuilds failed: ${errorMessage(err)}`, errorFields(err));
272
+ }
273
+ }
230
274
  async function rebuildIsolated(options) {
231
- const { summary, result } = options;
275
+ const { summary, result, counted } = options;
232
276
  try {
233
277
  await rebuildOneSummary(options);
234
278
  }
235
279
  catch (err) {
236
- // One throw doesn't abort the queue; log enough to triage an exotic failure (store I/O,
237
- // prepare), since audit() already catches its own.
280
+ // A throw counts toward the hold: it mostly follows a paid model call, and one that repeats on
281
+ // this row would otherwise cost a call every sleep.
238
282
  result.failed++;
283
+ counted.push(nextFailure(options));
239
284
  log.error(`rebuildDirtySummaries: summary ${summary.id} (tenant ${summary.tenantId}) failed: ${errorMessage(err)}`, errorFields(err));
240
285
  }
241
286
  }
@@ -10,6 +10,7 @@ import { canAutoDelete } from '../../base/memory/keep-rules.js';
10
10
  import { derivationPartitionKey } from '../../base/scope/recall-scope.js';
11
11
  import { duplicateKey } from '../../base/util/same-text.js';
12
12
  import { CLI_ACTOR } from '../../base/scope/actor.js';
13
+ import { isSuperseded } from '../../base/memory/liveness.js';
13
14
  /**
14
15
  * Quantization step for strength-tie comparisons: the 0.01 epsilon applied by rounding instead of
15
16
  * an abs-diff threshold, so the tiebreak is transitive.
@@ -84,7 +85,7 @@ function partitionPairs(groups, backing) {
84
85
  .flatMap((group) => group.losers.sort(survivorOrder).map((loser) => dedupPair(group.survivor, loser)));
85
86
  }
86
87
  /** The rows duplicateCandidates selects, picked from pages of every row. */
87
- const isCurrentDistilled = (e) => (e.kind ?? 'distilled') === 'distilled' && !e.supersededBy;
88
+ const isCurrentDistilled = (e) => (e.kind ?? 'distilled') === 'distilled' && !isSuperseded(e);
88
89
  /** Groups rows fed a page at a time; between pages only each group's survivor and losers are
89
90
  * held. Map order is first appearance, so partitions keep the order the pages gave them. */
90
91
  async function partitionRows(pages) {
@@ -40,6 +40,8 @@ export type ConsolidateEvent = {
40
40
  refused: number;
41
41
  zeroChildSkipped: number;
42
42
  failed: number;
43
+ /** Dirty summaries left out because their hold had not ended. */
44
+ held: number;
43
45
  /** The rebuild cap when it stopped the pass, else null. */
44
46
  cappedAt: number | null;
45
47
  } | {