opencode-self-improvement 0.14.25 → 0.14.26
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/README.md +1 -1
- package/package.json +1 -1
- package/src/gates.ts +2 -3
- package/src/hits.ts +3 -0
- package/src/index.ts +49 -30
- package/src/lock.ts +8 -6
- package/src/logfmt.ts +6 -9
- package/src/memory.ts +13 -7
- package/src/prune.ts +16 -4
- package/src/tombstones.ts +3 -4
- package/src/viewer/mutate.ts +10 -5
package/README.md
CHANGED
|
@@ -319,7 +319,7 @@ Use Bun **1.4.4** for development checks, matching CI. `bun run test` and `bun r
|
|
|
319
319
|
| `memory_remember` says blocked | A gate rejected the write: a stale code reference, a cited path that doesn't exist in the repo, overlap with a superseded memory, or an ambiguous claim. The reason is in `memory_evidence`; rephrase against current code and retry. |
|
|
320
320
|
| `invalid arguments to memory_*` | The call didn't match the tool's input schema; nothing was done and the message names the offending fields. Gate blocks look different (`blocked at GATE (…)`). |
|
|
321
321
|
| STORE shows `N malformed` | A daily file has a `ts=` that is not a valid ISO instant (typically a hand-edit). Every reader skips those rows; fix the `ts=` or restore the file with `memory_undo`. |
|
|
322
|
-
| `memory store is busy` |
|
|
322
|
+
| `memory store is busy` | A store write exhausted its 5s lock-wait budget. Appends, rewrites, and restores refuse that mutation rather than proceed unlocked and risk losing another writer's rows. Retry after contention clears. An operation spanning several files or steps may have completed earlier steps; refusal is not a rollback of those steps. If the reply reports `PARTIAL`, inspect the named rows and `memory_evidence` / `memory_undo` before retrying. A lock left by a killed process is taken over after 10s. |
|
|
323
323
|
| Stray `*.logfmt.lock` or `*.tmp` in the store | Write bookkeeping; safe to delete while nothing is writing. |
|
|
324
324
|
| `/repo-init` missing from the command list | The self-install couldn't write to `~/.config/opencode/commands/`. Create it and restart, or ask the model to "init memory for this repo" — the same tool. |
|
|
325
325
|
| Init says `Graph: unavailable` | `codebase-memory-mcp` couldn't start. Install pinned `0.11.0` or point `OPENCODE_CBM_BIN` at the binary. Scripts are still remembered without it. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.26",
|
|
4
4
|
"description": "Durable memory for opencode: remember facts, decisions, and commands across sessions, plus a one-command per-repo setup (/repo-init).",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"exports": {
|
package/src/gates.ts
CHANGED
|
@@ -444,11 +444,10 @@ export async function runWriteGate(
|
|
|
444
444
|
});
|
|
445
445
|
}
|
|
446
446
|
if (driftPlan.length > 0) {
|
|
447
|
-
const { marked } = await markManySupersededReport(driftPlan.map((p) => ({ ts: p.s.memory.ts, fields: p.fields })));
|
|
447
|
+
const { marked } = await markManySupersededReport(driftPlan.map((p) => ({ ts: p.s.memory.ts, fields: p.fields })), ctx.durable);
|
|
448
448
|
if (marked.length > 0) {
|
|
449
449
|
// Ledger BEFORE the audit lines: what is on disk now stays on disk no
|
|
450
450
|
// matter what the record loop below does (round-3 probe 3).
|
|
451
|
-
ctx.durable?.push(...marked);
|
|
452
451
|
for (const p of driftPlan) {
|
|
453
452
|
supersededTs = p.s.memory.ts;
|
|
454
453
|
await rec("superseded_by", {
|
|
@@ -497,10 +496,10 @@ export async function runWriteGate(
|
|
|
497
496
|
ts: p.ts,
|
|
498
497
|
fields: { superseded_by: target, reason: "canonical", entity: canon.entry.entity, from: p.from, to: canon.entry.value },
|
|
499
498
|
})),
|
|
499
|
+
ctx.durable,
|
|
500
500
|
);
|
|
501
501
|
if (canonMarked.length > 0) {
|
|
502
502
|
// Same ledger discipline as the drift batch above.
|
|
503
|
-
ctx.durable?.push(...canonMarked);
|
|
504
503
|
for (const p of canonPlan) {
|
|
505
504
|
if (!supersededTs) supersededTs = p.ts;
|
|
506
505
|
await rec("superseded_by", {
|
package/src/hits.ts
CHANGED
|
@@ -127,6 +127,9 @@ export async function recordHits(
|
|
|
127
127
|
);
|
|
128
128
|
return true;
|
|
129
129
|
} catch {
|
|
130
|
+
// Fail-closed lock contention can drop this use observation. Decay and
|
|
131
|
+
// consolidation therefore see a best-effort ledger, not proof of non-use;
|
|
132
|
+
// retrieval remains available even when its telemetry cannot be persisted.
|
|
130
133
|
return false; // telemetry never breaks retrieval
|
|
131
134
|
}
|
|
132
135
|
}
|
package/src/index.ts
CHANGED
|
@@ -794,7 +794,7 @@ const impl = {
|
|
|
794
794
|
symbol: target.ts,
|
|
795
795
|
from: target.ts,
|
|
796
796
|
to: survivorTs,
|
|
797
|
-
});
|
|
797
|
+
}, gateDurable);
|
|
798
798
|
if (done) {
|
|
799
799
|
return {
|
|
800
800
|
content:
|
|
@@ -854,8 +854,8 @@ const impl = {
|
|
|
854
854
|
? `memory_update PARTIAL: a step after the durable write failed: ${msg}. ` +
|
|
855
855
|
"Re-running this update reports the duplicate; inspect with memory_evidence."
|
|
856
856
|
: gateDurable.length > 0
|
|
857
|
-
? `memory_update
|
|
858
|
-
`${gateDurable.length}
|
|
857
|
+
? `memory_update PARTIAL: ${msg} No replacement was written, but this call had ALREADY retired ` +
|
|
858
|
+
`${gateDurable.length} row(s) (${gateDurable.join(", ")}): those retirements ARE on ` +
|
|
859
859
|
"disk and their audit lines may not all have landed. Re-running this update will not undo " +
|
|
860
860
|
"them — reconcile with memory_evidence / memory_undo before retrying."
|
|
861
861
|
: `memory_update blocked: ${msg} Nothing was written.`,
|
|
@@ -872,6 +872,7 @@ const impl = {
|
|
|
872
872
|
async execute(args, context): Promise<{ content: string }> {
|
|
873
873
|
const { sid } = toolIds(context);
|
|
874
874
|
const res = await pruneMemory(args.scope, args.type, args.reason, sid);
|
|
875
|
+
if (res.error) return { content: `memory_forget PARTIAL: deleted row(s) ${res.deleted.map((d) => d.memory.ts).join(", ")}; stopped: ${res.error}. Rejection tombstones or audit lines may be incomplete. Inspect memory_evidence / memory_undo before retrying.` };
|
|
875
876
|
if (!res.deleted.length) return { content: `No memories found for ${args.type} in ${args.scope}` };
|
|
876
877
|
return { content: `Deleted ${res.deleted.length} ${args.type} memory(s) from ${args.scope}. Audit: ${res.audit}` };
|
|
877
878
|
},
|
|
@@ -985,7 +986,7 @@ const impl = {
|
|
|
985
986
|
editor.add(validated(MergeReviewArgs, {
|
|
986
987
|
name: "memory_merge_review",
|
|
987
988
|
description:
|
|
988
|
-
"Resolve an open merge/review gate non-destructively: mark the loser as superseded_by the survivor, and clear any supersession the survivor itself carries so the canonical row stays recallable. Both rows stay active data (the loser is recoverable via memory_undo); nothing is deleted. A session may merge exactly the rows it may read: global rows are mergeable from anywhere, but a row belonging to another repository is refused in either seat.
|
|
989
|
+
"Resolve an open merge/review gate non-destructively: mark the loser as superseded_by the survivor, and clear any supersession the survivor itself carries so the canonical row stays recallable. Both rows stay active data (the loser is recoverable via memory_undo); nothing is deleted. A session may merge exactly the rows it may read: global rows are mergeable from anywhere, but a row belonging to another repository is refused in either seat. Refuses before writing when the reason or the survivor id is missing, the survivor id names no row in the store, the loser is already superseded or is the survivor itself, or either seat names a foreign repository's row. Later lock or I/O failures can leave partial changes; the reply names the completed retirement and failure.",
|
|
989
990
|
options: direct,
|
|
990
991
|
async execute(args, context): Promise<{ content: string }> {
|
|
991
992
|
const { sid } = toolIds(context);
|
|
@@ -1008,11 +1009,9 @@ const impl = {
|
|
|
1008
1009
|
// this cannot deadlock against a plain writer; on timeout it fails
|
|
1009
1010
|
// closed with nothing written.
|
|
1010
1011
|
const reader = readerFromSid(sid);
|
|
1011
|
-
//
|
|
1012
|
-
//
|
|
1013
|
-
|
|
1014
|
-
// claiming "nothing was done" is a lie (review probe 5).
|
|
1015
|
-
let mutated = false;
|
|
1012
|
+
// A batch may publish the loser then refuse a later file. The sink
|
|
1013
|
+
// records that publish before the overall promise settles (#197).
|
|
1014
|
+
const mergeDurable: string[] = [];
|
|
1016
1015
|
try {
|
|
1017
1016
|
return await withStoreLock(
|
|
1018
1017
|
join(memoryRoot(), "update-order"),
|
|
@@ -1047,11 +1046,10 @@ const impl = {
|
|
|
1047
1046
|
symbol: args.loser,
|
|
1048
1047
|
from: args.loser,
|
|
1049
1048
|
to: args.survivor,
|
|
1050
|
-
});
|
|
1049
|
+
}, mergeDurable);
|
|
1051
1050
|
if (!ok) {
|
|
1052
1051
|
return { content: "merge_review: loser not found or already superseded — nothing to resolve. No evidence written." };
|
|
1053
1052
|
}
|
|
1054
|
-
mutated = true;
|
|
1055
1053
|
// The survivor may itself have been superseded earlier (e.g. by
|
|
1056
1054
|
// a row this very call just made the loser). Declaring it
|
|
1057
1055
|
// canonical has to make it recallable, so clear its own marker.
|
|
@@ -1089,19 +1087,19 @@ const impl = {
|
|
|
1089
1087
|
);
|
|
1090
1088
|
} catch (err) {
|
|
1091
1089
|
// Before mutation this is the fail-closed lock contract: nothing
|
|
1092
|
-
// written.
|
|
1090
|
+
// written. Once a file published, the loser IS retired —
|
|
1093
1091
|
// the honest report names the completed mutation and the failed
|
|
1094
1092
|
// follow-up (evidence/revive), not a blanket "nothing was done".
|
|
1095
|
-
|
|
1093
|
+
const why = err instanceof Error ? err.message : String(err);
|
|
1094
|
+
if (mergeDurable.length === 0) {
|
|
1096
1095
|
return {
|
|
1097
|
-
content:
|
|
1096
|
+
content: `merge_review blocked: ${why} — nothing was done. Retry.`,
|
|
1098
1097
|
};
|
|
1099
1098
|
}
|
|
1100
|
-
const why = err instanceof Error ? err.message : String(err);
|
|
1101
1099
|
return {
|
|
1102
1100
|
content:
|
|
1103
1101
|
`merge_review PARTIAL: ${args.loser} IS retired on disk (superseded_by ${args.survivor}; ` +
|
|
1104
|
-
`recoverable via memory_undo) but
|
|
1102
|
+
`recoverable via memory_undo) but the remaining operation failed: ${why}. ` +
|
|
1105
1103
|
`The evidence line may be missing; re-running reports the loser already superseded.`,
|
|
1106
1104
|
};
|
|
1107
1105
|
}
|
|
@@ -1211,15 +1209,24 @@ const impl = {
|
|
|
1211
1209
|
// One lock/read/snapshot/publish per file for the whole decay run (#61):
|
|
1212
1210
|
// N retired rows are one undo point, not N. Idempotent (a no-op on rows
|
|
1213
1211
|
// already superseded, out-of-band ones skipped under the lock).
|
|
1214
|
-
const
|
|
1215
|
-
|
|
1216
|
-
|
|
1212
|
+
const durable: string[] = [];
|
|
1213
|
+
let retired: number;
|
|
1214
|
+
try {
|
|
1215
|
+
retired = await markManySuperseded(
|
|
1216
|
+
stale.map((m) => ({ ts: m.ts, fields: { superseded_by: "decay", reason: "decay" } })), durable,
|
|
1217
|
+
);
|
|
1218
|
+
} catch (err) {
|
|
1219
|
+
if (durable.length === 0) throw err;
|
|
1220
|
+
let why = err instanceof Error ? err.message : String(err);
|
|
1221
|
+
await record("decay_applied", { days, retired: durable.length, mem: durable.join(","), snapshot: snapshot.join(","), partial: true, error: why }, false).catch((audit) => { why += `; audit failed: ${String(audit)}`; });
|
|
1222
|
+
return { content: `memory_decay PARTIAL: retired row(s) ${durable.join(", ")}; stopped: ${why}. Recover with memory_undo; inspect memory_evidence before retrying.` };
|
|
1223
|
+
}
|
|
1217
1224
|
await record(
|
|
1218
1225
|
"decay_applied",
|
|
1219
1226
|
{
|
|
1220
1227
|
days,
|
|
1221
1228
|
retired,
|
|
1222
|
-
mem:
|
|
1229
|
+
mem: durable.join(",") || "-",
|
|
1223
1230
|
snapshot: snapshot.join(",") || "-",
|
|
1224
1231
|
},
|
|
1225
1232
|
false,
|
|
@@ -1557,16 +1564,28 @@ const impl = {
|
|
|
1557
1564
|
const text = typeof out === "string" ? out : out?.text ?? "";
|
|
1558
1565
|
const candidates = parseCandidates(text, captureMax);
|
|
1559
1566
|
for (const c of candidates) {
|
|
1560
|
-
const
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1567
|
+
const durable: string[] = [];
|
|
1568
|
+
let outcome: Awaited<ReturnType<typeof runWriteGate>>;
|
|
1569
|
+
try {
|
|
1570
|
+
outcome = await runWriteGate(
|
|
1571
|
+
{
|
|
1572
|
+
...c,
|
|
1573
|
+
tags:
|
|
1574
|
+
trigger === "compaction"
|
|
1575
|
+
? ["auto-capture", CAPTURE_COMPACT_TAG]
|
|
1576
|
+
: ["auto-capture"],
|
|
1577
|
+
},
|
|
1578
|
+
{ ...captureGate, durable },
|
|
1579
|
+
);
|
|
1580
|
+
} catch (err) {
|
|
1581
|
+
// A refused write must not disappear into the hook's fail-soft
|
|
1582
|
+
// wrapper. Preserve any earlier gate retirements in the receipt.
|
|
1583
|
+
await record(durable.length ? "auto_capture_partial" : "auto_capture_refused", {
|
|
1584
|
+
session: sid, trigger, type: c.type, scope: redactSecrets(c.scope),
|
|
1585
|
+
reason: String(err), retired: durable.join(",") || undefined,
|
|
1586
|
+
}, false, sid);
|
|
1587
|
+
continue;
|
|
1588
|
+
}
|
|
1570
1589
|
await record(
|
|
1571
1590
|
trigger === "compaction"
|
|
1572
1591
|
? `auto_capture_compaction_${outcome.action}`
|
package/src/lock.ts
CHANGED
|
@@ -48,18 +48,20 @@ export interface LockOptions {
|
|
|
48
48
|
/**
|
|
49
49
|
* What waiting past `timeoutMs` means. "fail" refuses the mutation (for
|
|
50
50
|
* callers where proceeding unlocked could destroy more than it saves, e.g.
|
|
51
|
-
* snapshot restore). "proceed" runs it
|
|
52
|
-
*
|
|
51
|
+
* snapshot restore). The legacy default, "proceed", runs it unlocked and
|
|
52
|
+
* can lose acknowledged writes when another caller rewrites the same file.
|
|
53
|
+
* Store writers must use LOCK_WRITE (or an explicit fail-closed policy).
|
|
53
54
|
*/
|
|
54
55
|
onTimeout?: "proceed" | "fail";
|
|
55
56
|
onEvent?: (event: LockEvent, waitedMs: number) => void;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
59
|
+
// Every writer of a shared store file must respect exclusion, INCLUDING
|
|
60
|
+
// appenders: an unlocked append inside a holder's read-modify-write window is
|
|
61
|
+
// overwritten by its publish. Refuse at the deadline so the caller can retry;
|
|
62
|
+
// never acknowledge a mutation performed outside the holder's lock (#196).
|
|
62
63
|
export const LOCK_WRITE: LockOptions = {
|
|
64
|
+
onTimeout: "fail",
|
|
63
65
|
onEvent: (event, waitedMs) => {
|
|
64
66
|
void record("store_lock", { event, waited_ms: waitedMs, op: "write" });
|
|
65
67
|
},
|
package/src/logfmt.ts
CHANGED
|
@@ -124,13 +124,10 @@ let tmpSeq = 0;
|
|
|
124
124
|
|
|
125
125
|
export async function writeAtomic(file: string, content: string, since?: string): Promise<void> {
|
|
126
126
|
await ensureDir(dirname(file));
|
|
127
|
-
// Unique PER CALL, not per process:
|
|
128
|
-
//
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
// very temp the anchored publish's ≤2s retry keeps renaming, and the retry
|
|
132
|
-
// would publish THOSE bytes under our success report. One extra leftover
|
|
133
|
-
// per failed attempt is the (unlinkable) price of that safety.
|
|
127
|
+
// Unique PER CALL, not per process: shared store writers now fail closed on
|
|
128
|
+
// lock timeout, but direct/legacy callers can still overlap. A pid-stable
|
|
129
|
+
// name would let one call replace the bytes another call's anchored publish
|
|
130
|
+
// is retrying. Keep separate temps even when the caller holds a lock.
|
|
134
131
|
const tmp = `${file}.${process.pid}.${++tmpSeq}.tmp`;
|
|
135
132
|
try {
|
|
136
133
|
await Bun.write(tmp, content);
|
|
@@ -147,8 +144,8 @@ export async function writeAtomic(file: string, content: string, since?: string)
|
|
|
147
144
|
// while that handle lives. Readers of a small store file cycle their handle on
|
|
148
145
|
// a microsecond scale, so that failure is usually transient and worth a retry
|
|
149
146
|
// window (~2s, well inside the 5s lock budget) — but a retry alone is not safe
|
|
150
|
-
// here. If an
|
|
151
|
-
//
|
|
147
|
+
// here. If an out-of-band or legacy unlocked writer appends into the
|
|
148
|
+
// destination DURING the window, the
|
|
152
149
|
// retried rename publishes our now-stale copy over that row — a slower way to
|
|
153
150
|
// lose exactly what the immediate failure preserved. So the retry runs only
|
|
154
151
|
// while the destination still matches `since`, the identity from before the
|
package/src/memory.ts
CHANGED
|
@@ -399,8 +399,8 @@ async function stampRow(
|
|
|
399
399
|
|
|
400
400
|
// Mark an existing memory as superseded IN PLACE (entry retained, recoverable).
|
|
401
401
|
// Idempotent: a second call is a no-op, so no double `superseded_by`.
|
|
402
|
-
export async function markSuperseded(ts: string, fields: SupersedeFields): Promise<boolean> {
|
|
403
|
-
return (await markManySupersededReport([{ ts, fields }])).marked.length > 0;
|
|
402
|
+
export async function markSuperseded(ts: string, fields: SupersedeFields, durable?: string[]): Promise<boolean> {
|
|
403
|
+
return (await markManySupersededReport([{ ts, fields }], durable)).marked.length > 0;
|
|
404
404
|
}
|
|
405
405
|
|
|
406
406
|
// Batch supersession (#61): one lock acquisition, one read, one snapshot and
|
|
@@ -412,8 +412,8 @@ export async function markSuperseded(ts: string, fields: SupersedeFields): Promi
|
|
|
412
412
|
// so a repeat run marks nothing and writes nothing. Duplicate ts entries in
|
|
413
413
|
// one batch: the FIRST entry's fields win (mirrors row-by-row first-call-wins).
|
|
414
414
|
// Returns the number of rows actually marked.
|
|
415
|
-
export async function markManySuperseded(entries: { ts: string; fields: SupersedeFields }[]): Promise<number> {
|
|
416
|
-
return (await markManySupersededReport(entries)).marked.length;
|
|
415
|
+
export async function markManySuperseded(entries: { ts: string; fields: SupersedeFields }[], durable?: string[]): Promise<number> {
|
|
416
|
+
return (await markManySupersededReport(entries, durable)).marked.length;
|
|
417
417
|
}
|
|
418
418
|
|
|
419
419
|
// Same operation, reporting WHICH rows retired rather than how many (#158
|
|
@@ -424,6 +424,9 @@ export async function markManySuperseded(entries: { ts: string; fields: Supersed
|
|
|
424
424
|
// this call did not perform.
|
|
425
425
|
export async function markManySupersededReport(
|
|
426
426
|
entries: { ts: string; fields: SupersedeFields }[],
|
|
427
|
+
// Updated immediately after EACH publish, even if a later file refuses its
|
|
428
|
+
// lock or lock cleanup throws. A rejected promise is not a rollback.
|
|
429
|
+
durable?: string[],
|
|
427
430
|
): Promise<{ marked: string[] }> {
|
|
428
431
|
if (entries.length === 0) return { marked: [] };
|
|
429
432
|
const wanted = new Map<string, SupersedeFields>();
|
|
@@ -464,6 +467,7 @@ export async function markManySupersededReport(
|
|
|
464
467
|
if (ids.length === 0) return [];
|
|
465
468
|
await snapshotBefore(file);
|
|
466
469
|
await writeAtomic(file, lines.join("\n") + "\n", since);
|
|
470
|
+
durable?.push(...ids);
|
|
467
471
|
return ids;
|
|
468
472
|
},
|
|
469
473
|
LOCK_WRITE,
|
|
@@ -623,9 +627,9 @@ export async function prune(
|
|
|
623
627
|
type: string,
|
|
624
628
|
reason: string,
|
|
625
629
|
reader: Reader = readerForAmbient(),
|
|
630
|
+
durable: PruneResult = { deleted: [], snapshot: [] },
|
|
626
631
|
): Promise<PruneResult> {
|
|
627
|
-
const deleted
|
|
628
|
-
const snapshot: string[] = [];
|
|
632
|
+
const { deleted, snapshot } = durable;
|
|
629
633
|
for (const file of await memoryFiles()) {
|
|
630
634
|
await withStoreLock(
|
|
631
635
|
file,
|
|
@@ -633,6 +637,7 @@ export async function prune(
|
|
|
633
637
|
const since = await fileIdentity(file);
|
|
634
638
|
const lines = await readLines(file);
|
|
635
639
|
const kept: string[] = [];
|
|
640
|
+
const fileDeleted: DeletedMemory[] = [];
|
|
636
641
|
let changed = false;
|
|
637
642
|
for (const line of lines) {
|
|
638
643
|
const parsed = parseLine(line);
|
|
@@ -641,7 +646,7 @@ export async function prune(
|
|
|
641
646
|
// another repo's row for scope X — same basename collisions are real
|
|
642
647
|
// (a fork next to its upstream).
|
|
643
648
|
if (m && m.scope === scope && m.type === type && isVisibleTo(m, reader)) {
|
|
644
|
-
|
|
649
|
+
fileDeleted.push({ memory: m, reason });
|
|
645
650
|
await logDeletion(m, reason);
|
|
646
651
|
changed = true;
|
|
647
652
|
continue;
|
|
@@ -651,6 +656,7 @@ export async function prune(
|
|
|
651
656
|
if (!changed) return;
|
|
652
657
|
snapshot.push(...(await snapshotFiles([file])));
|
|
653
658
|
await writeAtomic(file, kept.join("\n") + (kept.length ? "\n" : ""), since);
|
|
659
|
+
deleted.push(...fileDeleted);
|
|
654
660
|
},
|
|
655
661
|
LOCK_WRITE,
|
|
656
662
|
);
|
package/src/prune.ts
CHANGED
|
@@ -13,8 +13,15 @@ export async function pruneMemory(
|
|
|
13
13
|
// CALLER's identity, captured at tool entry, not the ambient current the
|
|
14
14
|
// locked file walk may outlive. "?" / undefined keep ambient semantics.
|
|
15
15
|
sid?: string,
|
|
16
|
-
): Promise<PruneResult & { audit: string }> {
|
|
17
|
-
const res =
|
|
16
|
+
): Promise<PruneResult & { audit: string; error?: string }> {
|
|
17
|
+
const res: PruneResult = { deleted: [], snapshot: [] };
|
|
18
|
+
let error: string | undefined;
|
|
19
|
+
try {
|
|
20
|
+
await prune(scope, type, reason, readerFromSid(sid), res);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
if (res.deleted.length === 0) throw err;
|
|
23
|
+
error = err instanceof Error ? err.message : String(err);
|
|
24
|
+
}
|
|
18
25
|
const memTs = res.deleted.map((d) => d.memory.ts).join(",") || "-";
|
|
19
26
|
await record(
|
|
20
27
|
"prune",
|
|
@@ -24,9 +31,14 @@ export async function pruneMemory(
|
|
|
24
31
|
snapshot: res.snapshot[0] ?? "-",
|
|
25
32
|
audit: deletionsFile(),
|
|
26
33
|
tool: "memory_forget",
|
|
34
|
+
partial: error ? true : undefined,
|
|
35
|
+
error,
|
|
27
36
|
},
|
|
28
37
|
true,
|
|
29
38
|
sid,
|
|
30
|
-
)
|
|
31
|
-
|
|
39
|
+
).catch((audit) => {
|
|
40
|
+
if (!error) throw audit;
|
|
41
|
+
error += `; audit failed: ${String(audit)}`;
|
|
42
|
+
});
|
|
43
|
+
return { ...res, audit: deletionsFile(), ...(error ? { error } : {}) };
|
|
32
44
|
}
|
package/src/tombstones.ts
CHANGED
|
@@ -295,10 +295,9 @@ export async function tombstones(): Promise<Tombstone[]> {
|
|
|
295
295
|
* pair plus a full read per row, and `memory_forget` deletes by scope+type, so a
|
|
296
296
|
* bulk forget issued hundreds of lock cycles while other sessions were writing.
|
|
297
297
|
* The heavy concurrent scenario on the Windows runner failed 2/2 with that shape
|
|
298
|
-
* (run 41112466339)
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
* this commit's CI run answers; the cost it removes is real either way.
|
|
298
|
+
* (run 41112466339). At that time, lock-budget expiry let a writer proceed
|
|
299
|
+
* unlocked, losing rows behind a long read-modify-write. LOCK_WRITE now refuses
|
|
300
|
+
* on timeout (#196); batching still reduces lock contention and its I/O cost.
|
|
302
301
|
*
|
|
303
302
|
* Still idempotent by `ch`, and de-duplicated WITHIN the batch too, so a forget
|
|
304
303
|
* that removes fifty rows carrying the same content records one tombstone.
|
package/src/viewer/mutate.ts
CHANGED
|
@@ -90,10 +90,15 @@ export async function editMemory(input: EditInput): Promise<MutationResult> {
|
|
|
90
90
|
repo: target.repo ?? "global",
|
|
91
91
|
repoPath: target.repo ? target.repoPath : undefined,
|
|
92
92
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
const retired: string[] = [];
|
|
94
|
+
try {
|
|
95
|
+
await markSuperseded(input.ts, {
|
|
96
|
+
superseded_by: newTs,
|
|
97
|
+
reason: "human_edit",
|
|
98
|
+
}, retired);
|
|
99
|
+
} catch (err) {
|
|
100
|
+
throw new Error(`viewer edit PARTIAL: replacement ${newTs} IS on disk; original ${input.ts} ${retired.includes(input.ts) ? "IS retired" : "was NOT retired by this edit"}. Stopped: ${String(err)}. Inspect the rows or use memory_undo before retrying.`);
|
|
101
|
+
}
|
|
97
102
|
await audit("edited", target, input.ts, newTs, input.reason);
|
|
98
103
|
await record("viewer_edit", {
|
|
99
104
|
chain,
|
|
@@ -228,4 +233,4 @@ export async function unrejectMemory(ch: string): Promise<boolean> {
|
|
|
228
233
|
return removeTombstone(ch);
|
|
229
234
|
}
|
|
230
235
|
|
|
231
|
-
export { addBlock, removeBlock };
|
|
236
|
+
export { addBlock, removeBlock };
|