dsh-layers-hippocampus 1.10.0 → 1.10.1
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.
- package/CHANGELOG.md +40 -0
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/index/indexManager.js +11 -1
- package/src/log/identityLedger.js +18 -0
- package/src/memory.js +49 -14
- package/src/pendingDelete.js +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,46 @@ All notable changes to `dsh-layers-hippocampus` are documented here.
|
|
|
4
4
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
5
5
|
and the project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [1.10.1] — 2026-12-02
|
|
8
|
+
|
|
9
|
+
**批次 2(前四条):删除队列、附件指针、幂等账本、模板解析。**
|
|
10
|
+
|
|
11
|
+
### 1. `pending_delete` 会自我堵死(P0-8)
|
|
12
|
+
|
|
13
|
+
`request()` 的注释写着"幂等",实现每次 `push`。重复 `forget` 于是排了两条同样的请求:
|
|
14
|
+
第一条 purge 成功后,第二条找不到 event 抛 `NOT_FOUND`,而促销循环外层只有一个
|
|
15
|
+
`try/catch` —— 整轮中止,失败项永不移除,此后**队列里所有到期删除都不再执行**。
|
|
16
|
+
|
|
17
|
+
- `request()` 真正幂等:同 `mode` + 同 id 集合直接返回已有条目;
|
|
18
|
+
- `maintain()` 的促销改为**逐条** try/catch:失败项记录进 `report.pendingDeletes.failed`
|
|
19
|
+
并留在队列里等下一轮,健康项照常推进。
|
|
20
|
+
|
|
21
|
+
### 2. `media_url` 校验完就被丢掉(P0-3)
|
|
22
|
+
|
|
23
|
+
`validateMedia()` 返回 `{url,type}`,`buildEpisode()` 只持久化
|
|
24
|
+
`content/salience/tags/meta` —— 于是附件指针永久消失,而调用方看到 `appended`。
|
|
25
|
+
|
|
26
|
+
修法:指针落进 `meta.media`(`meta` 本来就持久化且是自由结构,无需 schema 迁移)。
|
|
27
|
+
没有选择"直接拒绝":拒绝会让"帮我记一下这张图"彻底做不到,而内容是存在的,丢的只是指针。
|
|
28
|
+
|
|
29
|
+
### 3. 幂等账本的幽灵 event_id(P0-5)
|
|
30
|
+
|
|
31
|
+
`ledger.register()` 在 `append` **之前**(stage 期注册是必要的:并发相同写入不能都放行)。
|
|
32
|
+
一旦 append 失败,这个 payload 之后永远返回"已存在"的幽灵 id,直到重启。
|
|
33
|
+
|
|
34
|
+
修法:`IdentityLedger.release(key, eventId)` + `commitMany()` 的 append 失败路径逐个释放
|
|
35
|
+
(只释放自己注册的那个 event id,新注册者优先)。
|
|
36
|
+
|
|
37
|
+
### 4. 重建后的索引不解析模板(P0-7)
|
|
38
|
+
|
|
39
|
+
`dedupeTemplates()` 把重复长文本压成 `content: ''` + `contentRef`;磁盘加载路径会
|
|
40
|
+
`resolveTemplates`,而 `IndexManager._swap()` 直接把 build 结果挂上去 —— **跑过一次维护
|
|
41
|
+
之后**,这些事件召回正文变空串、词法分恒 0。现在在 `_swap` 里统一解析,所有生产者都覆盖。
|
|
42
|
+
|
|
43
|
+
### Tests
|
|
44
|
+
|
|
45
|
+
`test/v2020.batch2.test.js`(5 例)先红后绿;全套 **786/786**。
|
|
46
|
+
|
|
7
47
|
## [1.10.0] — 2026-12-02
|
|
8
48
|
|
|
9
49
|
**批次 1「止血」:两条 P0 + 两条不变量;schema 3 → 4。**
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-layers-hippocampus",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Layered long-term memory for DeepSeek Harness: append-only event log, rebuildable tag index, day diaries, independent semantic layer, L2.5 trend quarantine, offline knowledge graph and a Web UI panel.",
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
import { buildIndex } from './buildIndex.js';
|
|
24
|
+
import { resolveTemplates } from './templates.js';
|
|
24
25
|
import { MemoryError, ErrorCodes } from '../errors.js';
|
|
25
26
|
|
|
26
27
|
const MAX_CATCHUP_PASSES = 3;
|
|
@@ -267,8 +268,17 @@ export class IndexManager {
|
|
|
267
268
|
}
|
|
268
269
|
|
|
269
270
|
_swap(view) {
|
|
271
|
+
// v1.10.1 (audit P0-7): `dedupeTemplates()` replaces repeated long bodies with a
|
|
272
|
+
// `contentRef` + `content: ''` to save disk. The disk loader resolves those refs
|
|
273
|
+
// (indexStore calls resolveTemplates); the in-memory rebuild path did not, so after
|
|
274
|
+
// ONE maintenance pass those events recalled as empty strings with a zero lexical
|
|
275
|
+
// score. Resolve HERE, on the read model, so every producer is covered.
|
|
276
|
+
const published =
|
|
277
|
+
view && view.templates && Array.isArray(view.events)
|
|
278
|
+
? { ...view, events: resolveTemplates(view.events, view.templates) }
|
|
279
|
+
: view;
|
|
270
280
|
// ONE assignment: the read path resolves `_active` once per query.
|
|
271
|
-
this._active =
|
|
281
|
+
this._active = published;
|
|
272
282
|
this._standby = null;
|
|
273
283
|
this._swaps += 1;
|
|
274
284
|
}
|
|
@@ -85,6 +85,24 @@ export class IdentityLedger {
|
|
|
85
85
|
this._dirty = true;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* v1.10.1 (audit P0-5): undo a `register()` whose append never landed.
|
|
90
|
+
*
|
|
91
|
+
* Registration happens while STAGING (so two concurrent identical writes cannot both
|
|
92
|
+
* be admitted), which means a failed append leaves a ghost entry: from then on every
|
|
93
|
+
* retry is answered `duplicate` for a memory that does not exist, until restart.
|
|
94
|
+
* Releases only the exact event id it registered — a newer registration wins.
|
|
95
|
+
*/
|
|
96
|
+
release(key, eventId) {
|
|
97
|
+
if (!key) return false;
|
|
98
|
+
const current = this._idempotency.get(key);
|
|
99
|
+
if (current === undefined) return false;
|
|
100
|
+
if (eventId !== undefined && current !== eventId) return false;
|
|
101
|
+
this._idempotency.delete(key);
|
|
102
|
+
this._dirty = true;
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
|
|
88
106
|
/**
|
|
89
107
|
* Persist for fast startup. The log stays the truth source, so this is a cache:
|
|
90
108
|
* the hot path only SCHEDULES it (one O(n) write per interval, not per append) —
|
package/src/memory.js
CHANGED
|
@@ -22,7 +22,7 @@ import fs from 'node:fs';
|
|
|
22
22
|
import path from 'node:path';
|
|
23
23
|
import { assertClock, SystemClock } from './clock.js';
|
|
24
24
|
import { DeletePipeline } from './deletePipeline.js';
|
|
25
|
-
import { MemoryError, ErrorCodes, invalidInput } from './errors.js';
|
|
25
|
+
import { MemoryError, ErrorCodes, asMemoryError, invalidInput } from './errors.js';
|
|
26
26
|
import { buildAliasMap, hashPolicy, normaliseTagToken, resolvePolicy } from './policy.js';
|
|
27
27
|
import { controlIdFor } from './identity.js';
|
|
28
28
|
import { makeForget, makeReinforce, makeRestore } from './log/records.js';
|
|
@@ -873,6 +873,16 @@ export class Memory {
|
|
|
873
873
|
event_time: eventTime ?? happenedAt,
|
|
874
874
|
...(media ? { media } : {}),
|
|
875
875
|
};
|
|
876
|
+
// v1.10.1 (audit P0-3): `media` was validated and then dropped — buildEpisode only
|
|
877
|
+
// persists content/salience/tags/meta, so the attachment pointer vanished while the
|
|
878
|
+
// caller was told `appended`. meta is already durable and free-form, so the pointer
|
|
879
|
+
// lives there; no schema change, and a re-read can still find the file.
|
|
880
|
+
if (media) {
|
|
881
|
+
payload.meta = {
|
|
882
|
+
...(payload.meta && typeof payload.meta === 'object' ? payload.meta : {}),
|
|
883
|
+
media: { url: media.url, type: media.type },
|
|
884
|
+
};
|
|
885
|
+
}
|
|
876
886
|
const plan = ingestEpisode({
|
|
877
887
|
payload,
|
|
878
888
|
clock: this.clock,
|
|
@@ -960,7 +970,17 @@ export class Memory {
|
|
|
960
970
|
if (ready.length === 0) return results;
|
|
961
971
|
|
|
962
972
|
const records = ready.map((entry) => entry.plan.record);
|
|
963
|
-
|
|
973
|
+
try {
|
|
974
|
+
await this.logStore.append(records);
|
|
975
|
+
} catch (error) {
|
|
976
|
+
// v1.10.1 (audit P0-5): the ledger registered these keys during STAGE, before the
|
|
977
|
+
// append. Without this release a failed write leaves a ghost idempotency entry and
|
|
978
|
+
// every retry is answered `duplicate` for a memory that was never written.
|
|
979
|
+
for (const { plan } of ready) {
|
|
980
|
+
if (plan.dedupeKey) this.ledger.release(plan.dedupeKey, plan.eventId);
|
|
981
|
+
}
|
|
982
|
+
throw error;
|
|
983
|
+
}
|
|
964
984
|
this.ledger.schedulePersist();
|
|
965
985
|
await this.indexManager.applyRecords(records);
|
|
966
986
|
this._markBriefingDirty();
|
|
@@ -2828,20 +2848,35 @@ export class Memory {
|
|
|
2828
2848
|
try {
|
|
2829
2849
|
const due = this.pendingDeletes.due(this.clock.now());
|
|
2830
2850
|
const promoted = [];
|
|
2851
|
+
const failed = [];
|
|
2852
|
+
// v1.10.1 (audit P0-8): PER ITEM isolation. The loop used to be wrapped in one
|
|
2853
|
+
// try/catch, so a single NOT_FOUND (the usual symptom of a duplicate request
|
|
2854
|
+
// already purged) aborted every earlier AND later item: the failed entry was
|
|
2855
|
+
// never removed, stayed due forever and silently blocked deletions from then on.
|
|
2831
2856
|
for (const item of due) {
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2857
|
+
try {
|
|
2858
|
+
const snapshot = await this.logStore.snapshot();
|
|
2859
|
+
const hashes = item.eventIds
|
|
2860
|
+
.map((id) => sha256(snapshot.records.find((record) => record.event_id === id)?.content ?? ''))
|
|
2861
|
+
.filter(Boolean);
|
|
2862
|
+
await this.deletePipeline.request({ eventIds: item.eventIds, mode: item.mode, reason: item.reason });
|
|
2863
|
+
if (item.mode === 'purge') {
|
|
2864
|
+
const turnIds = await this.raw.turnIdsForHashes(hashes);
|
|
2865
|
+
await this.raw.tombstone({ hashes, turnIds, at: this.clock.now() });
|
|
2866
|
+
}
|
|
2867
|
+
this.pendingDeletes.remove(item.id);
|
|
2868
|
+
promoted.push({ id: item.id, events: item.eventIds.length });
|
|
2869
|
+
} catch (error) {
|
|
2870
|
+
// Stays queued: a later pass retries it, and the report names the reason.
|
|
2871
|
+
failed.push({
|
|
2872
|
+
id: item.id,
|
|
2873
|
+
events: item.eventIds.length,
|
|
2874
|
+
error: error?.code ?? asMemoryError(error).code,
|
|
2875
|
+
message: String(error?.message ?? error).slice(0, 200),
|
|
2876
|
+
});
|
|
2877
|
+
}
|
|
2843
2878
|
}
|
|
2844
|
-
report.pendingDeletes = { promoted };
|
|
2879
|
+
report.pendingDeletes = { promoted, failed };
|
|
2845
2880
|
if (promoted.length > 0) {
|
|
2846
2881
|
// Purge rewrites the log, so the index must be rebuilt before anything
|
|
2847
2882
|
// else in this maintenance pass reads it.
|
package/src/pendingDelete.js
CHANGED
|
@@ -42,6 +42,18 @@ export class PendingDeletes {
|
|
|
42
42
|
const now = this.clock.now();
|
|
43
43
|
const ids = [...new Set(eventIds)].sort();
|
|
44
44
|
const state = this.load();
|
|
45
|
+
// v1.10.1 (audit P0-8): the docstring said idempotent, the code always pushed. A
|
|
46
|
+
// repeated `forget` therefore queued a SECOND entry for the same ids; when the
|
|
47
|
+
// first purge landed, the second threw NOT_FOUND and (before the per-item fix in
|
|
48
|
+
// Memory#maintain) stalled the whole queue.
|
|
49
|
+
const existing = state.items.find(
|
|
50
|
+
(item) =>
|
|
51
|
+
item.mode === mode &&
|
|
52
|
+
Array.isArray(item.eventIds) &&
|
|
53
|
+
item.eventIds.length === ids.length &&
|
|
54
|
+
item.eventIds.every((id, index) => id === ids[index]),
|
|
55
|
+
);
|
|
56
|
+
if (existing) return existing;
|
|
45
57
|
const id = sha256(`pending|${ids.join(',')}|${now}`).slice(0, 24);
|
|
46
58
|
const record = {
|
|
47
59
|
id,
|