hippo-memory 3.3.3 → 3.5.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/README.md +4 -4
- package/dist/api/callers.d.ts +4 -1
- package/dist/api/context/context-plan.js +3 -0
- package/dist/api/context/context-pools.js +4 -1
- package/dist/api/context/user-rule.js +2 -1
- package/dist/api/dashboard/detail.js +2 -1
- package/dist/api/dashboard/live.d.ts +0 -4
- package/dist/api/dashboard/live.js +0 -8
- package/dist/api/memories/conflicts.d.ts +2 -1
- package/dist/api/memories/conflicts.js +3 -8
- package/dist/api/memories/promote.js +6 -2
- package/dist/api/objects/object-kinds.d.ts +1 -4
- package/dist/api/objects/object-kinds.js +1 -5
- package/dist/api/recall/compose.js +2 -1
- package/dist/api/recall/rank-stages.js +2 -1
- package/dist/api/recall/rows.js +2 -1
- package/dist/api/session-end.d.ts +3 -2
- package/dist/api/session-end.js +8 -4
- package/dist/api/sharing.d.ts +4 -3
- package/dist/api/sharing.js +2 -2
- package/dist/api/sleep/auto-sleep.d.ts +3 -2
- package/dist/api/sleep/auto-sleep.js +16 -3
- package/dist/api/sleep/one-sleep.d.ts +23 -0
- package/dist/api/sleep/one-sleep.js +53 -0
- package/dist/api/sleep/sleep-run.js +2 -1
- package/dist/api/sleep/sleep.d.ts +5 -0
- package/dist/api/sleep/sleep.js +2 -1
- package/dist/api/summary-parents.js +2 -1
- package/dist/base/config/config-keys.js +1 -0
- package/dist/base/config/config.d.ts +2 -0
- package/dist/base/config/config.js +1 -0
- package/dist/base/embeddings/local.d.ts +1 -1
- package/dist/base/embeddings/local.js +2 -3
- package/dist/base/memory/ambient.js +2 -1
- package/dist/base/memory/entry.d.ts +4 -1
- package/dist/base/memory/entry.js +7 -1
- package/dist/base/memory/half-life-plan.js +6 -4
- package/dist/base/memory/keep-rules.js +2 -1
- package/dist/base/memory/liveness.d.ts +7 -0
- package/dist/base/memory/liveness.js +6 -0
- package/dist/base/memory/markdown.js +15 -5
- package/dist/base/memory/memory-audit.js +2 -1
- package/dist/base/memory/memory-facts.d.ts +0 -2
- package/dist/base/memory/memory-facts.js +0 -2
- package/dist/base/memory/merged-row.js +3 -2
- package/dist/base/memory/rule-replaces.js +2 -1
- package/dist/base/memory/stale-mark.d.ts +9 -0
- package/dist/base/memory/stale-mark.js +18 -0
- package/dist/base/ports/store/capture.d.ts +2 -0
- package/dist/base/ports/store/conflicts.d.ts +5 -1
- package/dist/base/ports/store/conflicts.js +2 -0
- package/dist/base/ports/store/consolidation.d.ts +66 -2
- package/dist/base/ports/store/consolidation.js +5 -0
- package/dist/base/ports/store/context-reads.d.ts +2 -0
- package/dist/base/ports/store/objects.d.ts +15 -4
- package/dist/base/ports/store/sessions.d.ts +8 -2
- package/dist/base/ports/store/sessions.js +6 -0
- package/dist/base/ports/store/store-effects.d.ts +5 -0
- package/dist/base/ports/store.d.ts +1 -1
- package/dist/base/scope/live-memory.d.ts +7 -0
- package/dist/base/scope/live-memory.js +10 -0
- package/dist/base/scope/read-admission.d.ts +2 -0
- package/dist/base/scope/read-admission.js +9 -2
- package/dist/base/util/version.d.ts +1 -1
- package/dist/base/util/version.js +1 -1
- package/dist/db/continuity-tables.d.ts +4 -1
- package/dist/db/continuity-tables.js +21 -12
- package/dist/db/migrate.js +2 -2
- package/dist/db/migrations/index.d.ts +1 -1
- package/dist/db/migrations/index.js +5 -1
- package/dist/db/migrations/v61.js +3 -3
- package/dist/db/migrations/v62.d.ts +3 -0
- package/dist/db/migrations/v62.js +43 -0
- package/dist/db/migrations/v63.d.ts +3 -0
- package/dist/db/migrations/v63.js +9 -0
- package/dist/db/required-objects.js +2 -1
- package/dist/db/sql-predicates.d.ts +22 -2
- package/dist/db/sql-predicates.js +27 -2
- package/dist/domain/agent-memories/apply.js +2 -1
- package/dist/domain/agent-memories/container-view.js +2 -1
- package/dist/domain/consolidate/conflicts.js +2 -1
- package/dist/domain/consolidate/dag-summary.d.ts +2 -0
- package/dist/domain/consolidate/dag.d.ts +3 -0
- package/dist/domain/consolidate/dag.js +53 -8
- package/dist/domain/consolidate/dedupe.js +2 -1
- package/dist/domain/consolidate/events.d.ts +2 -0
- package/dist/domain/consolidate/llm-passes.js +94 -20
- package/dist/domain/consolidate/merge.js +11 -10
- package/dist/domain/consolidate/retry-holds.d.ts +14 -0
- package/dist/domain/consolidate/retry-holds.js +26 -0
- package/dist/domain/consolidate/run.d.ts +8 -0
- package/dist/domain/consolidate/run.js +2 -0
- package/dist/domain/consolidate/tombstones.d.ts +3 -4
- package/dist/domain/consolidate/tombstones.js +3 -3
- package/dist/domain/graph/recall.js +3 -2
- package/dist/domain/learn/churn-stale.js +2 -1
- package/dist/domain/learn/extract.d.ts +10 -0
- package/dist/domain/learn/extract.js +10 -5
- package/dist/domain/learn/invalidation.d.ts +1 -1
- package/dist/domain/learn/invalidation.js +4 -11
- package/dist/domain/objects/decisions.d.ts +4 -7
- package/dist/domain/objects/decisions.js +1 -14
- package/dist/domain/objects/descriptor.d.ts +2 -0
- package/dist/domain/objects/lifecycle.js +8 -2
- package/dist/domain/search/as-of.js +3 -2
- package/dist/domain/sharing/share.d.ts +16 -4
- package/dist/domain/sharing/share.js +33 -17
- package/dist/entry/store-kit.js +2 -1
- package/dist/infra/local-embedder.js +14 -2
- package/dist/infra/spool-claims.d.ts +2 -2
- package/dist/infra/spool-claims.js +4 -3
- package/dist/infra/spool-import.js +1 -1
- package/dist/infra/spool-record.d.ts +3 -1
- package/dist/store/sqlite/capture/compaction-hooks.js +14 -6
- package/dist/store/sqlite/capture/compaction-rows.js +9 -2
- package/dist/store/sqlite/capture/spool-request-id.d.ts +3 -0
- package/dist/store/sqlite/capture/spool-request-id.js +12 -0
- package/dist/store/sqlite/connectors/quarantine.js +13 -4
- package/dist/store/sqlite/consolidation/consolidation-summaries.d.ts +4 -5
- package/dist/store/sqlite/consolidation/consolidation-summaries.js +46 -26
- package/dist/store/sqlite/consolidation/consolidation.js +7 -0
- package/dist/store/sqlite/consolidation/empty-extractions.d.ts +14 -0
- package/dist/store/sqlite/consolidation/empty-extractions.js +57 -0
- package/dist/store/sqlite/consolidation/rebuild-holds.d.ts +21 -0
- package/dist/store/sqlite/consolidation/rebuild-holds.js +68 -0
- package/dist/store/sqlite/consolidation/sleep-lock.d.ts +4 -0
- package/dist/store/sqlite/consolidation/sleep-lock.js +69 -0
- package/dist/store/sqlite/entries/entry-filter.js +3 -3
- package/dist/store/sqlite/entries/entry-reads.js +2 -1
- package/dist/store/sqlite/entries/entry-row.js +5 -1
- package/dist/store/sqlite/entries/entry-writes.js +9 -15
- package/dist/store/sqlite/entries/raw-archive.d.ts +2 -1
- package/dist/store/sqlite/entries/raw-archive.js +12 -3
- package/dist/store/sqlite/maintenance/agent-import-steps.js +7 -2
- package/dist/store/sqlite/maintenance/project-tags.js +4 -3
- package/dist/store/sqlite/recall/candidates.js +12 -11
- package/dist/store/sqlite/recall/search-rows.d.ts +3 -0
- package/dist/store/sqlite/recall/search-rows.js +26 -9
- package/dist/store/sqlite/records/object-rows.d.ts +2 -0
- package/dist/store/sqlite/records/object-rows.js +5 -1
- package/dist/store/sqlite/records/object-writes.d.ts +3 -0
- package/dist/store/sqlite/records/object-writes.js +43 -1
- package/dist/store/sqlite/reports/dashboard-lists.js +3 -2
- package/dist/store/sqlite/reports/dashboard-reads.js +5 -3
- package/dist/store/sqlite/reports/dashboard-sql.d.ts +0 -3
- package/dist/store/sqlite/reports/dashboard-sql.js +2 -9
- package/dist/store/sqlite/reports/reports.js +2 -1
- package/dist/store/sqlite/review/conflicts.js +10 -5
- package/dist/store/sqlite/runtime/rule-sql.d.ts +1 -0
- package/dist/store/sqlite/runtime/rule-sql.js +4 -1
- package/dist/store/sqlite/runtime/status-transitions.d.ts +98 -0
- package/dist/store/sqlite/runtime/status-transitions.js +105 -0
- package/dist/store/sqlite/sessions/goals.js +11 -12
- package/dist/store/sqlite/sessions/sessions.d.ts +1 -1
- package/dist/store/sqlite/sessions/sessions.js +20 -8
- package/dist/surface/capture/session-worker.d.ts +3 -2
- package/dist/surface/capture/session-worker.js +36 -10
- package/dist/surface/cli/api-context.js +2 -1
- package/dist/surface/cli/client.d.ts +6 -5
- package/dist/surface/cli/client.js +50 -19
- package/dist/surface/cli/conflicts.js +12 -1
- package/dist/surface/cli/continuity.js +4 -0
- package/dist/surface/cli/decisions.js +16 -17
- package/dist/surface/cli/hooks/session-end-worker.js +3 -2
- package/dist/surface/cli/install-steps.js +99 -13
- package/dist/surface/cli/memory-writes.js +3 -2
- package/dist/surface/cli/print.js +2 -1
- package/dist/surface/cli/sleep-render.js +7 -0
- package/dist/surface/cli/sleep.d.ts +3 -2
- package/dist/surface/cli/sleep.js +10 -4
- package/dist/surface/cli/transfer.js +6 -3
- package/dist/surface/cli/verbs/objects.js +2 -2
- package/dist/surface/dashboard/dashboard-actions.js +1 -1
- package/dist/surface/hooks-install/codex-wrapper.js +52 -11
- package/dist/surface/hooks-install/rules/hook-blocks.js +9 -2
- package/dist/surface/mcp/admin-tools.js +5 -2
- package/dist/surface/render/sleep-events.js +2 -0
- package/dist/surface/server/routes/decisions.js +2 -2
- package/dist/surface/server/sleep-child.js +5 -4
- package/dist/surface/server/sleep-offload.js +36 -25
- package/dist-ui/assets/index-Cst0ubfs.js +1 -0
- package/dist-ui/index.html +1 -1
- package/extensions/openclaw-plugin/openclaw.plugin.json +1 -1
- package/extensions/openclaw-plugin/package.json +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/dist-ui/assets/index-Q9SY-1Bj.js +0 -1
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ Every measurement we have ever published is indexed in [`docs/evals/`](docs/eval
|
|
|
56
56
|
pre-registrations kept next to their results, including the runs that failed and the one
|
|
57
57
|
claim we retracted.
|
|
58
58
|
|
|
59
|
-
- **Z0 round
|
|
59
|
+
- **Correct your agent once, and with hippo it repeats that mistake about half as often. Z0 round 3, real Claude Code sessions on 29 repositories, hippo against built-in memory alone: 11 repeats in 100 against 21, 2 to 4 tasks after the correction, at no extra cost (ratio 1.006 [0.964, 1.049]).** With no memory the agent repeats it 83 times in 100. Over every first chance to repeat, the pre-registered read is 14.9 points fewer [5.5, 24.3], adjusted p 0.006, against a full-win line of 15. The gain is the same with lesson capture switched off, so round 4 tests how much of it the stored lessons carry. ([result](docs/evals/2026-11-08-z0-round3-result.md); [round 2](docs/evals/2026-11-01-z0-round2-result.md), on 16 repositories, was inconclusive at -8.9 points)
|
|
60
60
|
- **Sequential Learning Benchmark.** [benchmarks/sequential-learning/](benchmarks/sequential-learning/). 50 tasks, 10 buried traps. Measures whether agents learn from past mistakes, not just retrieve text. v0.11.0 informal magnitude RETRACTED v1.7.9; mechanism remains shipped. See [CHANGELOG.md](./CHANGELOG.md) v1.7.9 entry.
|
|
61
61
|
- **LongMemEval oracle split, all 500 questions in one pooled store, BM25 only, no embeddings, v0.11: R@5 = 74.0%** ([benchmarks/README.md](benchmarks/README.md), scripts in [benchmarks/longmemeval/](benchmarks/longmemeval/)). A different setup from the per-haystack results under [Benchmarks](#benchmarks), so the two are not a before and after.
|
|
62
62
|
- **On a private 300-query developer store, R@1 0.41 to 0.62 with `hippo recall "<query>" --reranker jev`**, the free local cross-encoder against Jev ([full eval](docs/evals/2026-09-19-jev-reranker.md)). The opt-in [TypeSafe Jev](https://typesafe.ai) reranker, off by default, about 0.0004 USD a recall. 2000-draw paired bootstrap; the margin held in 20 of 20 seeds and a permutation null reached it in 0 of 200 runs. Ranking only: three graded tests on one 150-question LongMemEval set did **not** show a better answer rate than the free local cross-encoder, and that negative result is in the same doc. What it buys today is a shorter context: on that set, 2 memories ranked by Jev answered as well as 5 ranked by the cross-encoder.
|
|
@@ -847,7 +847,7 @@ The block asks for nothing a hook already does, because each extra tool call re-
|
|
|
847
847
|
For Claude Code, it also adds 7 hook entries to `~/.claude/settings.json`:
|
|
848
848
|
- a `SessionEnd` hook that runs `hippo sleep` and then `hippo capture` when the session exits. Capture matches the last 20 user and 10 assistant messages of the transcript against word patterns for decisions, rules, errors and preferences. It uses no model unless you turn on `capture.followUpRules` (see Conversation Capture) and does not read earlier turns, so a correction older than that window needs a `hippo remember` by hand.
|
|
849
849
|
- a `SessionStart` hook that prints the previous session's consolidation log on stderr, where `claude --debug` shows it. When the last sleep failed or a compaction summary was set aside, it shows you one line that points to `hippo doctor`.
|
|
850
|
-
- a `UserPromptSubmit` hook that runs `hippo context --pinned-only --include-recent 5 --format additional-context` every turn. It re-injects pinned memories (`hippo remember <text> --pin`) plus up to 5 memories that share words with your prompt. When nothing matches, it adds only the pinned ones. Since 1.55.0 this replaces the 5 newest memories, which cut the median block from 847 to 533 tokens in our eval. `{"pinnedInject":{"promptRecall":false}}` brings back the 5 newest, so fresh same-session lessons appear on the next prompt whatever you ask. The block is rendered without live strength percentages, so it stays byte-identical while its memories do not change, and it is sent only when it changed since the session's last prompt: an unchanged block is skipped, resent every 10 skips (`pinnedInject.refreshTurns`, `0` never resends) and resent after compaction. The prompt-matched memories go in a separate block that is never skipped, so they are sent on every prompt they match. `{"pinnedInject":{"skipUnchanged":false}}` sends the pinned block every turn as before. Opt out entirely with `{"pinnedInject":{"enabled":false}}` in `.hippo/config.json`.
|
|
850
|
+
- a `UserPromptSubmit` hook that runs `hippo context --pinned-only --include-recent 5 --format additional-context` every turn. It re-injects pinned memories (`hippo remember <text> --pin`) plus up to 5 memories that share words with your prompt. When nothing matches, it adds only the pinned ones. Since 1.55.0 this replaces the 5 newest memories, which cut the median block from 847 to 533 tokens in our eval. `{"pinnedInject":{"promptRecall":false}}` brings back the 5 newest, so fresh same-session lessons appear on the next prompt whatever you ask. The block is rendered without live strength percentages, so it stays byte-identical while its memories do not change, and it is sent only when it changed since the session's last prompt: an unchanged block is skipped, resent every 10 skips (`pinnedInject.refreshTurns`, `0` never resends) and resent after compaction. The prompt-matched memories go in a separate block that is never skipped, so they are sent on every prompt they match. `{"pinnedInject":{"skipUnchanged":false}}` sends the pinned block every turn as before. `{"pinnedInject":{"excludeTags":["session-digest"]}}` leaves out every memory that carries a listed tag, whether it is pinned, recent or matched to the prompt; the list is empty by default. Opt out entirely with `{"pinnedInject":{"enabled":false}}` in `.hippo/config.json`.
|
|
851
851
|
- a `PreCompact` hook that runs `hippo pre-compact` before the transcript gets summarized. It records the compaction in the store, saves a working-state snapshot (task/summary/next step) so mid-session compaction can't drop it, and asks the summariser to end its summary with a "Memories for hippo" list: the lessons, decisions and corrections from the session that should outlive it. The `SessionEnd` hook still owns extracting durable memories from the transcript.
|
|
852
852
|
- a second `SessionStart` hook (matcher `compact`) that runs `hippo compact-resume`, printing that snapshot back into context right after compaction, if it is under 15 minutes old.
|
|
853
853
|
- a `PostCompact` hook that runs `hippo post-compact`. It keeps the summary in the store with secrets scrubbed, and saves each item of that list as a memory that sleep never deletes: at most 10 per compaction, skipping an item an earlier compaction already saved and any item that looks like a secret. An item over 500 characters stays in the compaction's record only. It then prints one line, such as "Hippo saved 3 memories from this compaction and restored your task snapshot." If the store is busy, the summary waits in the store's `compactions-spool/` folder and `hippo sleep` finishes the save; `hippo doctor` names any compaction left unfinished for over 10 minutes. It also counts spool files that are waiting, stale (left by a replay that stopped) or set aside as `.bad`. The session that compacted does not have those memories injected back into its own prompts, since it just read them in the summary; `hippo recall` still finds them. The hook prints nothing when there is no store to save to.
|
|
@@ -1155,11 +1155,11 @@ Nothing. Hippo is MIT-licensed and needs no account or API key. Optional feature
|
|
|
1155
1155
|
|
|
1156
1156
|
### Is it production-ready?
|
|
1157
1157
|
|
|
1158
|
-
Judge it by what is tested. 3,500+ tests run against a real database, with no module mocks and no mocked store, and a negative test checks that one tenant cannot read another's memories. It is MIT-licensed and has zero runtime dependencies.
|
|
1158
|
+
Judge it by what is tested. 3,500+ tests run against a real database, with no module mocks and no mocked store, and a negative test checks that one tenant cannot read another's memories. It is MIT-licensed and has zero runtime dependencies. For what it does to an agent's work, see the next question.
|
|
1159
1159
|
|
|
1160
1160
|
### Has hippo been shown to make agents better at their work?
|
|
1161
1161
|
|
|
1162
|
-
|
|
1162
|
+
On repeat mistakes, yes. Z0 round 3 ran real Claude Code sessions on 29 repositories, with hippo and with Claude Code's built-in memory alone. An agent corrected once repeated that mistake about half as often with hippo installed: 11 times in 100 against 21, 2 to 4 tasks after the correction, at the same cost. Over every first chance to repeat, the pre-registered read is 14.9 points fewer [5.5, 24.3] ([result](https://github.com/kitfunso/hippo-memory/blob/master/docs/evals/2026-11-08-z0-round3-result.md)). On tasks with no lesson to apply, hippo changed neither the cost nor the share solved. The gain was the same with lesson capture switched off, so round 4 tests how much of it the stored lessons carry. The other published numbers measure retrieval. Every measurement, including failed runs and one retracted claim, is indexed in [docs/evals](https://github.com/kitfunso/hippo-memory/blob/master/docs/evals/README.md).
|
|
1163
1163
|
|
|
1164
1164
|
---
|
|
1165
1165
|
|
package/dist/api/callers.d.ts
CHANGED
|
@@ -11,9 +11,12 @@ export interface AutoSleepHost {
|
|
|
11
11
|
/** The rows `tenantId` wrote since the store's last sleep, counted on the store of the call
|
|
12
12
|
* that wrote, so a write's count opens no second connection. */
|
|
13
13
|
readonly newSince: (tenantId: string, now: Date) => Promise<number>;
|
|
14
|
-
/**
|
|
14
|
+
/** `held` is set while a sleep is counted or run, so two writes landing together start one.
|
|
15
|
+
* `notBefore` is the epoch ms before which no write retries, set after a sleep another process
|
|
16
|
+
* made this host skip. */
|
|
15
17
|
readonly latch: {
|
|
16
18
|
held: boolean;
|
|
19
|
+
notBefore?: number;
|
|
17
20
|
};
|
|
18
21
|
}
|
|
19
22
|
export type AutoSleepStart = Omit<AutoSleepHost, 'latch'>;
|
|
@@ -129,6 +129,8 @@ export function planContext(ctx, opts, local) {
|
|
|
129
129
|
/** The prompt-recall candidate request the ambient loads carry, when the prompt has any terms. */
|
|
130
130
|
export function promptRecallRequest(opts, plan) {
|
|
131
131
|
const { pinnedInject } = plan.config;
|
|
132
|
+
// Optional: a config built in code before this key existed has none, and reads as no list.
|
|
133
|
+
const excludeTags = pinnedInject.excludeTags ?? [];
|
|
132
134
|
const promptRecallTerms = plan.promptRecallPending && pinnedInject.enabled ? promptSearchTerms(opts.prompt ?? '') : [];
|
|
133
135
|
return promptRecallTerms.length > 0
|
|
134
136
|
? {
|
|
@@ -138,6 +140,7 @@ export function promptRecallRequest(opts, plan) {
|
|
|
138
140
|
min: 1,
|
|
139
141
|
})),
|
|
140
142
|
ownScope: plan.ownScope,
|
|
143
|
+
...(excludeTags.length > 0 && { excludeTags }),
|
|
141
144
|
}
|
|
142
145
|
: undefined;
|
|
143
146
|
}
|
|
@@ -4,6 +4,7 @@ import { DEFAULT_SEARCH_CANDIDATE_LIMIT } from '../../base/rank/search-types.js'
|
|
|
4
4
|
import { projectNames } from '../../base/scope/project-identity.js';
|
|
5
5
|
import { ambientAdmits, ambientEnvelopeAdmits, } from '../../base/scope/read-admission.js';
|
|
6
6
|
import { NO_QUERY, globalSource } from './context-plan.js';
|
|
7
|
+
import { isSuperseded } from '../../base/memory/liveness.js';
|
|
7
8
|
/** Most rows per store a no-query context reads; past it, ranking sees the strongest by decay. */
|
|
8
9
|
const CONTEXT_CANDIDATE_CAP = 2000;
|
|
9
10
|
/** The page is sized from the rows the budget can pay for: a memory under this many tokens is
|
|
@@ -67,11 +68,13 @@ export function ambientAdmission(opts, plan, digestHandoff) {
|
|
|
67
68
|
// Inside admit, not after the load, so the loader's window widens past a session's own items.
|
|
68
69
|
ownSessionId: opts.currentSessionId || undefined,
|
|
69
70
|
handoffSessionId: digestHandoff?.evidence?.derivedFrom === 'transcript' ? digestHandoff.sessionId : undefined,
|
|
71
|
+
// Only the hook block's pinned-only reads drop tags; a search or plain context read keeps them.
|
|
72
|
+
excludeTags: plan.pinnedOnly ? plan.config.pinnedInject.excludeTags : undefined,
|
|
70
73
|
};
|
|
71
74
|
const admit = (e) => ambientAdmits(e, rule);
|
|
72
75
|
// The two-store search has always ranked a session's own compaction items; only the local search
|
|
73
76
|
// drops them.
|
|
74
|
-
const bothStoresAdmit = (e) => !e
|
|
77
|
+
const bothStoresAdmit = (e) => !isSuperseded(e) && ambientEnvelopeAdmits(e, rule);
|
|
75
78
|
return { rule, admit, bothStoresAdmit };
|
|
76
79
|
}
|
|
77
80
|
/**
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
// cannot pass for one.
|
|
3
3
|
import { USER_RULE_TAG } from '../../base/memory/entry.js';
|
|
4
4
|
import { projectId, projectNames } from '../../base/scope/project-identity.js';
|
|
5
|
+
import { isSuperseded } from '../../base/memory/liveness.js';
|
|
5
6
|
export { USER_RULE_TAG };
|
|
6
7
|
export function isUserRule(e, viewer) {
|
|
7
8
|
const own = e.pinned &&
|
|
8
9
|
e.source === 'capture' &&
|
|
9
10
|
e.confidence === 'observed' &&
|
|
10
11
|
e.tags.includes(USER_RULE_TAG) &&
|
|
11
|
-
e
|
|
12
|
+
!isSuperseded(e) &&
|
|
12
13
|
e.scope === null &&
|
|
13
14
|
e.tenantId === viewer.tenantId;
|
|
14
15
|
if (!own)
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// The dashboard drawer's detail of one memory, read fresh through the api and stamped with the id
|
|
2
2
|
// the client holds.
|
|
3
3
|
import { calculateStrength } from '../../base/memory/strength.js';
|
|
4
|
+
import { isLiveMemory } from '../../base/scope/live-memory.js';
|
|
4
5
|
import { memoryFacts } from '../../base/memory/memory-facts.js';
|
|
5
6
|
import { round1 } from '../../base/util/format.js';
|
|
6
7
|
import { memoryGet } from '../memories/memories.js';
|
|
7
8
|
import { strengthOf } from '../types.js';
|
|
8
|
-
import { BANDS,
|
|
9
|
+
import { BANDS, LAYERS, projectIdentity, round3 } from './live.js';
|
|
9
10
|
async function openConflictsOf(store, { reads, tenantId, entry, at }) {
|
|
10
11
|
const conflicts = (await reads.openConflictsOf(tenantId, entry.id)).map((row) => row.conflict);
|
|
11
12
|
const otherId = (c) => c.memoryAId === entry.id ? c.memoryBId : c.memoryAId;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import type { MemoryEntry } from '../../base/memory/entry.js';
|
|
2
1
|
import type { DashboardChip, Origin } from '../../base/ports/store/dashboard-reads.js';
|
|
3
2
|
import type { Band, Layer, ProjectKind } from './types.js';
|
|
4
3
|
export declare const LAYERS: readonly Layer[];
|
|
5
4
|
export declare const BANDS: readonly Band[];
|
|
6
5
|
export type Chip = DashboardChip;
|
|
7
|
-
/** The one predicate for "shown on the dashboard": not superseded, not archived, not
|
|
8
|
-
* quarantined. */
|
|
9
|
-
export declare function isLiveMemory(entry: Pick<MemoryEntry, 'supersededBy' | 'kind' | 'scope'>): boolean;
|
|
10
6
|
/** Wire key, display name and kind of a project. */
|
|
11
7
|
export interface ProjectIdentity {
|
|
12
8
|
key: string;
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import { isQuarantineScope } from '../../domain/trust/quarantine.js';
|
|
2
1
|
export const LAYERS = ['buffer', 'episodic', 'semantic', 'trace'];
|
|
3
2
|
// Wire order of `Band`, and the order the mockup sorts bands in.
|
|
4
3
|
export const BANDS = ['pinned', 'strong', 'fading', 'atRisk'];
|
|
5
|
-
/** The one predicate for "shown on the dashboard": not superseded, not archived, not
|
|
6
|
-
* quarantined. */
|
|
7
|
-
export function isLiveMemory(entry) {
|
|
8
|
-
return (!entry.supersededBy &&
|
|
9
|
-
(entry.kind === 'raw' || entry.kind === 'distilled') &&
|
|
10
|
-
!isQuarantineScope(entry.scope));
|
|
11
|
-
}
|
|
12
4
|
/** Wire key, display name and kind for an `origin_project` value. */
|
|
13
5
|
export function projectIdentity(origin) {
|
|
14
6
|
if (origin === '')
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { MemoryConflict } from '../../base/ports/store/conflicts.js';
|
|
2
|
+
import type { ConflictStatus } from '../../base/ports/store/conflicts.js';
|
|
2
3
|
import type { CallerProject } from '../prompt-hook.js';
|
|
3
4
|
import type { KeysetPosition } from '../../base/util/keyset.js';
|
|
4
5
|
import { type ContextWith } from '../types.js';
|
|
@@ -44,7 +45,7 @@ export declare function conflictListOpen(ctx: ContextWith<'conflicts'>, opts?: C
|
|
|
44
45
|
}): Promise<ConflictPage>;
|
|
45
46
|
/** One page of conflicts with `status` ('*' for any) in reach, with no scope filter: the host's
|
|
46
47
|
* own view, so the host admin only. */
|
|
47
|
-
export declare function conflictList(ctx: ContextWith<'conflicts'>, status:
|
|
48
|
+
export declare function conflictList(ctx: ContextWith<'conflicts'>, status: ConflictStatus | '*', reach?: TenantReach, opts?: ConflictPageOptions): Promise<ConflictPage>;
|
|
48
49
|
/** Each page a paged list answers from `start`, the largest page at a time, for the verbs that
|
|
49
50
|
* print every conflict. */
|
|
50
51
|
export declare function conflictPages(read: (page: ConflictPageOptions) => Promise<ConflictPage>, start?: KeysetPosition): AsyncGenerator<ConflictPage>;
|
|
@@ -4,17 +4,11 @@ import { BadRequestError, ConflictError, NotFoundError } from '../../base/errors
|
|
|
4
4
|
import { assertWriteRight, canReadScope, passesScopeFilterForRecall, personalScopeOf, scopeReaderOf, } from '../../base/scope/recall-scope.js';
|
|
5
5
|
import { conflictLoserFate } from '../../domain/consolidate/conflicts.js';
|
|
6
6
|
import { classifyOriginProject } from '../../base/scope/project-identity.js';
|
|
7
|
-
import {
|
|
7
|
+
import { isLiveMemory } from '../../base/scope/live-memory.js';
|
|
8
8
|
import { MAX_LIST_LIMIT } from '../../base/util/limits.js';
|
|
9
9
|
import { keysetPages, pageLimit } from '../pages.js';
|
|
10
10
|
import { ALL_TENANTS } from '../../base/util/tenant.js';
|
|
11
11
|
import { requireHostAdmin } from '../types.js';
|
|
12
|
-
function isLive(member) {
|
|
13
|
-
return (member !== null &&
|
|
14
|
-
!member.supersededBy &&
|
|
15
|
-
(member.kind === 'raw' || member.kind === 'distilled') &&
|
|
16
|
-
!isQuarantineScope(member.scope));
|
|
17
|
-
}
|
|
18
12
|
/** A row the caller could not read hides its whole pair. */
|
|
19
13
|
function touchable(actor, row) {
|
|
20
14
|
return [row.a, row.b].every((member) => member !== null && canReadScope(actor, member.scope));
|
|
@@ -41,7 +35,8 @@ export async function conflictResolve(ctx, conflictId, opts) {
|
|
|
41
35
|
throw new ConflictError(`conflict ${conflictId} is already resolved`);
|
|
42
36
|
}
|
|
43
37
|
const { keep, loser } = sidesOf(row, opts.keepId);
|
|
44
|
-
|
|
38
|
+
const { a, b } = row;
|
|
39
|
+
if (!(a !== null && isLiveMemory(a) && b !== null && isLiveMemory(b))) {
|
|
45
40
|
throw new NotFoundError(`conflict ${conflictId} names a memory that is superseded, archived or quarantined`);
|
|
46
41
|
}
|
|
47
42
|
const reason = opts.reason ?? `resolveConflict ${conflictId}: kept ${keep.id}`;
|
|
@@ -7,6 +7,7 @@ import { globalTargetOf } from '../infra.js';
|
|
|
7
7
|
import { withDetached } from '../detached.js';
|
|
8
8
|
import { sharedStoreOf } from '../types.js';
|
|
9
9
|
import { assertWriteRight, canReadScope, isPersonalScope, isQuarantineScope, scopeReaderOf, } from '../../base/scope/recall-scope.js';
|
|
10
|
+
import { isSuperseded } from '../../base/memory/liveness.js';
|
|
10
11
|
export async function promote(ctx, id) {
|
|
11
12
|
// Another tenant's row and a row out of the caller's reach read alike, so the reply says nothing
|
|
12
13
|
// of either.
|
|
@@ -88,8 +89,11 @@ function assertSupersedable(ctx, oldId, old) {
|
|
|
88
89
|
assertWriteRight(scopeReaderOf(ctx.actor), row, oldId, `Memory not found: ${oldId}`);
|
|
89
90
|
// The CAS UPDATE closes the race; this check only gives a clearer error in the common
|
|
90
91
|
// single-writer case.
|
|
91
|
-
if (row
|
|
92
|
-
|
|
92
|
+
if (isSuperseded(row)) {
|
|
93
|
+
const by = row.supersededBy;
|
|
94
|
+
throw new ConflictError(by === ''
|
|
95
|
+
? `Memory ${oldId} is already superseded.`
|
|
96
|
+
: `Memory ${oldId} is already superseded by ${by}. Supersede that one instead.`);
|
|
93
97
|
}
|
|
94
98
|
return row;
|
|
95
99
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { MemoryEntry } from '../../base/memory/entry.js';
|
|
2
1
|
import type { Incident, Policy, ProjectBrief } from '../../base/records/object-types.js';
|
|
3
2
|
import { type SaveIncidentOptions } from '../../domain/objects/incidents.js';
|
|
4
3
|
import { type BriefDigest } from '../../domain/objects/project-briefs.js';
|
|
5
|
-
import type {
|
|
4
|
+
import type { ContextWith } from '../types.js';
|
|
6
5
|
import { type WriteOrigin } from './objects.js';
|
|
7
6
|
export type { BriefDigest } from '../../domain/objects/project-briefs.js';
|
|
8
7
|
export type { SaveIncidentOptions } from '../../domain/objects/incidents.js';
|
|
@@ -39,6 +38,4 @@ export declare function briefRefresh(ctx: ContextWith<'objects'>, repo: string):
|
|
|
39
38
|
/** The active decision whose mirror is `memoryId`, or null: what the CLI's `--supersedes
|
|
40
39
|
* <memory-id>` names. */
|
|
41
40
|
export declare function decisionIdByMemory(ctx: ContextWith<'objects'>, memoryId: string): Promise<number | null>;
|
|
42
|
-
/** Weakens the memory a new decision replaces, once that decision has saved. */
|
|
43
|
-
export declare function decisionMemoryWeaken(ctx: Context, entry: MemoryEntry): Promise<void>;
|
|
44
41
|
//# sourceMappingURL=object-kinds.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MAX_CUSTOMER_LEN, MAX_NOTE_LEN } from '../../domain/objects/customer-notes.js';
|
|
2
2
|
import { MAX_SHORT_FIELD_LEN } from '../../base/util/limits.js';
|
|
3
|
-
import { resolveActiveDecisionIdByMemory
|
|
3
|
+
import { resolveActiveDecisionIdByMemory } from '../../domain/objects/decisions.js';
|
|
4
4
|
import { openIncident, resolveOpenIncident, } from '../../domain/objects/incidents.js';
|
|
5
5
|
import { policiesAsOf } from '../../domain/objects/policies.js';
|
|
6
6
|
import { MAX_PROCESS_STEP_LEN, MAX_PROCESS_STEPS } from '../../domain/objects/processes.js';
|
|
@@ -70,8 +70,4 @@ export function briefRefresh(ctx, repo) {
|
|
|
70
70
|
export function decisionIdByMemory(ctx, memoryId) {
|
|
71
71
|
return resolveActiveDecisionIdByMemory(ctx.store.objects, ctx.tenantId, memoryId);
|
|
72
72
|
}
|
|
73
|
-
/** Weakens the memory a new decision replaces, once that decision has saved. */
|
|
74
|
-
export function decisionMemoryWeaken(ctx, entry) {
|
|
75
|
-
return weakenSupersededMemory(ctx.store.entryWrites, entry, ctx.actor.subject);
|
|
76
|
-
}
|
|
77
73
|
//# sourceMappingURL=object-kinds.js.map
|
|
@@ -10,6 +10,7 @@ import { passesScopeFilterForRecall } from '../../base/scope/recall-scope.js';
|
|
|
10
10
|
import { anchoringRows, availabilityRows, callerOf, recallAuditMetadata, recallAuditRow, } from './finish.js';
|
|
11
11
|
import { biasHintEnabled, detectAnchoring, hashQueryText, } from './anchoring.js';
|
|
12
12
|
import { rankBands, overflowGroups } from './bands.js';
|
|
13
|
+
import { isSuperseded } from '../../base/memory/liveness.js';
|
|
13
14
|
const DEFAULT_RECALL_LIMIT = 10;
|
|
14
15
|
export function recallOrigin(opts) {
|
|
15
16
|
const project = opts.filter?.project;
|
|
@@ -97,7 +98,7 @@ function recallResult(options, bands, continuity, suppressedByInterference) {
|
|
|
97
98
|
// The SQL load already applied tenant and scope; a recall candidate loader must go through
|
|
98
99
|
// store.searchRecallEntries.
|
|
99
100
|
function admitCandidates(opts, all, limit, personalScope) {
|
|
100
|
-
const current = all.filter((e) => !e
|
|
101
|
+
const current = all.filter((e) => !isSuperseded(e));
|
|
101
102
|
const scope = opts.filter?.scope;
|
|
102
103
|
let entries;
|
|
103
104
|
if (scope !== undefined && scope !== '') {
|
|
@@ -9,6 +9,7 @@ import { CONFLICT_PEER_MULTIPLIER, SALIENCE_MIN_MULTIPLIER, UTILITY_LENGTH_PENAL
|
|
|
9
9
|
import { isJsonNumber } from '../../base/util/json.js';
|
|
10
10
|
import { indexTokenize, textOverlap, tokenize as tokenizeQuery } from '../../base/util/tokenize.js';
|
|
11
11
|
import { poolScope } from './rank-search.js';
|
|
12
|
+
import { isSuperseded } from '../../base/memory/liveness.js';
|
|
12
13
|
/** The stages after the search, in order: graph expansion, re-rank, goal boost, salience, then
|
|
13
14
|
* the outcome and layer filters. */
|
|
14
15
|
export async function rankStages(ctx, opts, state, profile) {
|
|
@@ -114,7 +115,7 @@ function reorderResults(opts, state) {
|
|
|
114
115
|
state.results = newestOnTopicFirst(opts.query, state.results);
|
|
115
116
|
}
|
|
116
117
|
if (opts.filterConflicts) {
|
|
117
|
-
dropUnless(state, (r) => !r.entry
|
|
118
|
+
dropUnless(state, (r) => !isSuperseded(r.entry));
|
|
118
119
|
demoteConflictPeers(opts, state);
|
|
119
120
|
}
|
|
120
121
|
if (opts.valueAware && state.results.length >= 1)
|
package/dist/api/recall/rows.js
CHANGED
|
@@ -10,6 +10,7 @@ import { fitBudget } from '../../domain/search/finalize.js';
|
|
|
10
10
|
import { estimateTokens } from '../../base/util/token-text.js';
|
|
11
11
|
import { passesCliRecallScopeFilter, passesScopeFilterForRecall, } from '../../base/scope/recall-scope.js';
|
|
12
12
|
import { CONTINUITY_EVENT_LIMIT } from '../continuity/continuity.js';
|
|
13
|
+
import { isSuperseded } from '../../base/memory/liveness.js';
|
|
13
14
|
export { DEFAULT_MAX_NEIGHBORS, MAX_HOPS } from '../../domain/graph/recall.js';
|
|
14
15
|
/** Which stores a recall reads under `ctx`, with `activeScope` (an explicit scope merged with
|
|
15
16
|
* the detected one), which only boosts. */
|
|
@@ -97,7 +98,7 @@ export function recallJsonRow({ r, query, showWhy, isGlobal, now, }) {
|
|
|
97
98
|
if (r.entry.layer === Layer.Trace) {
|
|
98
99
|
base.trace_outcome = r.entry.traceOutcome;
|
|
99
100
|
}
|
|
100
|
-
if (r.entry
|
|
101
|
+
if (isSuperseded(r.entry)) {
|
|
101
102
|
base.superseded = true;
|
|
102
103
|
base.superseded_by = r.entry.supersededBy;
|
|
103
104
|
}
|
|
@@ -51,8 +51,9 @@ export interface SessionEndWork<Turn, Scan extends {
|
|
|
51
51
|
}) => void;
|
|
52
52
|
/** Where the re-read count's lines wait for sleep. */
|
|
53
53
|
held: HeldLog;
|
|
54
|
-
/** Sleeps the folder's own store; reports its own failure.
|
|
55
|
-
|
|
54
|
+
/** Sleeps the folder's own store; reports its own failure. True when another sleep held the
|
|
55
|
+
* store's claim, so this one consolidated nothing. */
|
|
56
|
+
sleep: () => Promise<boolean | void>;
|
|
56
57
|
/** Imports the session's agent notes into the global store, for a folder that does not sleep
|
|
57
58
|
* here. */
|
|
58
59
|
importAgentNotes: () => Promise<void>;
|
package/dist/api/session-end.js
CHANGED
|
@@ -173,8 +173,10 @@ async function sleepStep(ctx, w) {
|
|
|
173
173
|
await w.importAgentNotes();
|
|
174
174
|
return;
|
|
175
175
|
}
|
|
176
|
-
if (w.mode !== 'turn' || !w.sessionId)
|
|
177
|
-
|
|
176
|
+
if (w.mode !== 'turn' || !w.sessionId) {
|
|
177
|
+
await w.sleep();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
178
180
|
// Each line starts the log afresh, as a sleep does.
|
|
179
181
|
const prefix = `turn close, session ${w.sessionId}`;
|
|
180
182
|
try {
|
|
@@ -184,8 +186,10 @@ async function sleepStep(ctx, w) {
|
|
|
184
186
|
w.log(`${prefix}: skip sleep, ${why}`, { startFresh: true });
|
|
185
187
|
return;
|
|
186
188
|
}
|
|
187
|
-
await w.sleep();
|
|
188
|
-
w.log(
|
|
189
|
+
const refused = await w.sleep();
|
|
190
|
+
w.log(refused
|
|
191
|
+
? `${prefix}: skip sleep, a sleep is already running`
|
|
192
|
+
: `${prefix}: ran sleep at ${count} new memories (threshold ${threshold})`);
|
|
189
193
|
}
|
|
190
194
|
catch (err) {
|
|
191
195
|
w.log(`${prefix}: sleep check failed: ${errorMessage(err)}`, {
|
package/dist/api/sharing.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { MemoryEntry } from '../base/memory/entry.js';
|
|
2
|
+
import { type ShareOutcome } from '../domain/sharing/share.js';
|
|
2
3
|
import { type Context, type ContextWith } from './types.js';
|
|
3
4
|
export { AUTO_SHARE_MIN_SCORE, transferScore } from '../domain/sharing/share.js';
|
|
4
5
|
/** One project's rows in the global store. */
|
|
@@ -7,11 +8,11 @@ export interface SharePeer {
|
|
|
7
8
|
readonly count: number;
|
|
8
9
|
readonly latest: string;
|
|
9
10
|
}
|
|
10
|
-
/** Copies one of the caller's memories to the global store
|
|
11
|
-
*
|
|
11
|
+
/** Copies one of the caller's memories to the global store unless its transfer score is too low
|
|
12
|
+
* and `force` is off, or the caller's global rows already hold its text. */
|
|
12
13
|
export declare function shareToGlobal(ctx: ContextWith<'folderFiles'>, id: string, opts: {
|
|
13
14
|
readonly force: boolean;
|
|
14
|
-
}): Promise<
|
|
15
|
+
}): Promise<ShareOutcome>;
|
|
15
16
|
/** The caller's memories whose transfer score reaches `minScore`, copied to the global store
|
|
16
17
|
* unless `dryRun`. */
|
|
17
18
|
export declare function autoShareToGlobal(ctx: ContextWith<'sharing' | 'folderFiles'>, opts: {
|
package/dist/api/sharing.js
CHANGED
|
@@ -17,8 +17,8 @@ function requireGlobalTarget(ctx, action) {
|
|
|
17
17
|
}
|
|
18
18
|
return target;
|
|
19
19
|
}
|
|
20
|
-
/** Copies one of the caller's memories to the global store
|
|
21
|
-
*
|
|
20
|
+
/** Copies one of the caller's memories to the global store unless its transfer score is too low
|
|
21
|
+
* and `force` is off, or the caller's global rows already hold its text. */
|
|
22
22
|
export async function shareToGlobal(ctx, id, opts) {
|
|
23
23
|
const target = requireGlobalTarget(ctx, 'share');
|
|
24
24
|
const options = { force: opts.force, tenantId: ctx.tenantId, embed: ctx.infra };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { HippoConfig } from '../../base/config/config.js';
|
|
2
2
|
import { type ConsolidationResult } from '../../domain/consolidate/run.js';
|
|
3
3
|
import { type Context, type ContextWith } from '../types.js';
|
|
4
|
+
import { type AutoSleepRefused } from './one-sleep.js';
|
|
4
5
|
/**
|
|
5
6
|
* Runs one auto-sleep consolidation of the folder its host was built for: the HTTP server passes
|
|
6
7
|
* one that runs it off its event loop, in a child process; stdio passes one that runs it in its
|
|
7
8
|
* own.
|
|
8
9
|
*/
|
|
9
|
-
export type AutoSleepRunner = () => Promise<void>;
|
|
10
|
+
export type AutoSleepRunner = () => Promise<void | AutoSleepRefused>;
|
|
10
11
|
export interface AutoSleepDue {
|
|
11
12
|
enabled: boolean;
|
|
12
13
|
count: number;
|
|
@@ -23,5 +24,5 @@ export declare function autoSleepDue(newSince: (tenantId: string, now: Date) =>
|
|
|
23
24
|
export declare function autoSleepAfterWrite(ctx: Pick<Context, 'tenantId' | 'config' | 'callers' | 'infra' | 'detached'>): Promise<void>;
|
|
24
25
|
/** What one auto-sleep runs: the consolidation alone, its skipped passes logged by the process
|
|
25
26
|
* that ran it. */
|
|
26
|
-
export declare function autoSleepConsolidate(ctx: Pick<ContextWith<'consolidation' | 'learning' | 'lessonWrites' | 'auditMaintenance' | 'vectors'>, 'store' | 'config' | 'tenantId' | 'infra'>): Promise<ConsolidationResult>;
|
|
27
|
+
export declare function autoSleepConsolidate(ctx: Pick<ContextWith<'consolidation' | 'learning' | 'lessonWrites' | 'auditMaintenance' | 'vectors'>, 'store' | 'config' | 'tenantId' | 'infra'>): Promise<ConsolidationResult | AutoSleepRefused>;
|
|
27
28
|
//# sourceMappingURL=auto-sleep.d.ts.map
|
|
@@ -5,6 +5,10 @@ import { logPhaseFailures } from '../../domain/consolidate/run.js';
|
|
|
5
5
|
import { runConsolidation } from '../../domain/consolidate/sleep.js';
|
|
6
6
|
import { strengthOf } from '../types.js';
|
|
7
7
|
import { withDetached } from '../detached.js';
|
|
8
|
+
import { oneSleepPerStore, refusedAutoSleep, sleepWasRefused, } from './one-sleep.js';
|
|
9
|
+
// Long enough that a host skips the minutes another process spends on its sleep, short enough that
|
|
10
|
+
// the next due write after it ends is not left waiting.
|
|
11
|
+
const REFUSED_BACKOFF_MS = 60_000;
|
|
8
12
|
/** Counts only when enabled: the count reads the store. */
|
|
9
13
|
export async function autoSleepDue(newSince, tenantId, config, now) {
|
|
10
14
|
const { enabled, threshold } = config;
|
|
@@ -21,7 +25,7 @@ export async function autoSleepAfterWrite(ctx) {
|
|
|
21
25
|
const { tenantId, config } = ctx;
|
|
22
26
|
if (host === undefined || !config.autoSleep.enabled || tenantId !== host.hostTenantId)
|
|
23
27
|
return;
|
|
24
|
-
if (host.latch.held)
|
|
28
|
+
if (host.latch.held || ctx.infra.clock().getTime() < (host.latch.notBefore ?? 0))
|
|
25
29
|
return;
|
|
26
30
|
// Held from the count on, so two writes landing together never both start a sleep.
|
|
27
31
|
host.latch.held = true;
|
|
@@ -42,6 +46,11 @@ export async function autoSleepAfterWrite(ctx) {
|
|
|
42
46
|
// it. A failure is logged here once, with the tenant.
|
|
43
47
|
const sleep = host
|
|
44
48
|
.run()
|
|
49
|
+
.then((outcome) => {
|
|
50
|
+
if (sleepWasRefused(outcome)) {
|
|
51
|
+
host.latch.notBefore = ctx.infra.clock().getTime() + REFUSED_BACKOFF_MS;
|
|
52
|
+
}
|
|
53
|
+
})
|
|
45
54
|
.catch((err) => {
|
|
46
55
|
log.error(`auto-sleep consolidate failed (tenant ${tenantId}): ${errorMessage(err)}`, errorFields(err));
|
|
47
56
|
})
|
|
@@ -54,13 +63,17 @@ export async function autoSleepAfterWrite(ctx) {
|
|
|
54
63
|
* that ran it. */
|
|
55
64
|
export async function autoSleepConsolidate(ctx) {
|
|
56
65
|
const { store, config, tenantId, infra } = ctx;
|
|
57
|
-
const result = await runConsolidation(store, {
|
|
66
|
+
const result = await oneSleepPerStore(store, false, () => runConsolidation(store, {
|
|
58
67
|
config,
|
|
59
68
|
tenantId,
|
|
60
69
|
llm: infra.llm,
|
|
61
70
|
now: infra.clock(),
|
|
62
71
|
strength: strengthOf(ctx),
|
|
63
|
-
});
|
|
72
|
+
}), refusedAutoSleep);
|
|
73
|
+
if (sleepWasRefused(result)) {
|
|
74
|
+
log.info(`auto-sleep: skipped, a sleep is already running (since ${result.alreadyRunning.since})`);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
64
77
|
logPhaseFailures(result);
|
|
65
78
|
return result;
|
|
66
79
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Consolidation } from '../../base/ports/store/consolidation.js';
|
|
2
|
+
import type { ConsolidationResult } from '../../domain/consolidate/run.js';
|
|
3
|
+
import type { SleepResult } from './sleep.js';
|
|
4
|
+
/** What an auto-sleep answers when another sleep held the store; non-null, as the sleep child's
|
|
5
|
+
* reply check rejects a null result. */
|
|
6
|
+
export interface AutoSleepRefused {
|
|
7
|
+
readonly alreadyRunning: {
|
|
8
|
+
readonly since: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** A sleep that did nothing: its 0 counts mean "nothing was done", not "the store is empty". */
|
|
12
|
+
export declare function refusedSleep(since: string): SleepResult;
|
|
13
|
+
export declare function refusedAutoSleep(since: string): AutoSleepRefused;
|
|
14
|
+
/** What a sleep entry point answers: its result, an auto-sleep's consolidation, a refusal, or nothing. */
|
|
15
|
+
export type SleepAnswer = SleepResult | ConsolidationResult | AutoSleepRefused | void;
|
|
16
|
+
/** True for an answer a held claim produced: the one test every reader of a sleep's answer uses. */
|
|
17
|
+
export declare function sleepWasRefused(result: SleepAnswer): result is AutoSleepRefused;
|
|
18
|
+
/** Runs `run` holding the store's claim; a held claim gives `refused(since)` and runs nothing. A dry
|
|
19
|
+
* run consolidates nothing, so it takes no claim, and a store without claim methods runs unguarded. */
|
|
20
|
+
export declare function oneSleepPerStore<R, F>({ consolidation }: {
|
|
21
|
+
readonly consolidation: Consolidation;
|
|
22
|
+
}, dryRun: boolean, run: () => Promise<R>, refused: (since: string) => F): Promise<R | F>;
|
|
23
|
+
//# sourceMappingURL=one-sleep.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { errorFields, errorMessage, log } from '../../base/util/log.js';
|
|
2
|
+
/** A sleep that did nothing: its 0 counts mean "nothing was done", not "the store is empty". */
|
|
3
|
+
export function refusedSleep(since) {
|
|
4
|
+
return {
|
|
5
|
+
active: 0,
|
|
6
|
+
removed: 0,
|
|
7
|
+
mergedEpisodic: 0,
|
|
8
|
+
newSemantic: 0,
|
|
9
|
+
dryRun: false,
|
|
10
|
+
alreadyRunning: { since },
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function refusedAutoSleep(since) {
|
|
14
|
+
return { alreadyRunning: { since } };
|
|
15
|
+
}
|
|
16
|
+
/** True for an answer a held claim produced: the one test every reader of a sleep's answer uses. */
|
|
17
|
+
export function sleepWasRefused(result) {
|
|
18
|
+
return (typeof result === 'object' &&
|
|
19
|
+
result !== null &&
|
|
20
|
+
'alreadyRunning' in result &&
|
|
21
|
+
result.alreadyRunning !== undefined);
|
|
22
|
+
}
|
|
23
|
+
/** Runs `run` holding the store's claim; a held claim gives `refused(since)` and runs nothing. A dry
|
|
24
|
+
* run consolidates nothing, so it takes no claim, and a store without claim methods runs unguarded. */
|
|
25
|
+
export async function oneSleepPerStore({ consolidation }, dryRun, run, refused) {
|
|
26
|
+
if (dryRun || consolidation.claimSleep === undefined)
|
|
27
|
+
return run();
|
|
28
|
+
const claim = await consolidation.claimSleep();
|
|
29
|
+
if (claim.kind === 'held')
|
|
30
|
+
return refused(claim.since);
|
|
31
|
+
try {
|
|
32
|
+
return await run();
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
await giveBack(consolidation);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// A failed release must not replace the sleep's own result or error; one retry, since a claim kept by a
|
|
39
|
+
// long-running host would refuse every later sleep until it restarts.
|
|
40
|
+
async function giveBack(consolidation) {
|
|
41
|
+
if (consolidation.releaseSleep === undefined)
|
|
42
|
+
return;
|
|
43
|
+
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
44
|
+
try {
|
|
45
|
+
await consolidation.releaseSleep();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
log.warn(`the sleep claim was not given back (attempt ${attempt} of 2): ${errorMessage(err)}`, errorFields(err));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=one-sleep.js.map
|
|
@@ -15,6 +15,7 @@ import { errorFields, errorMessage, log } from '../../base/util/log.js';
|
|
|
15
15
|
import { ALL_TENANTS } from '../../base/util/tenant.js';
|
|
16
16
|
import { failedUnitOf } from '../../base/errors/failed-unit.js';
|
|
17
17
|
import { reportAuditWriteFailure } from '../../base/records/audit-report.js';
|
|
18
|
+
import { isSuperseded } from '../../base/memory/liveness.js';
|
|
18
19
|
const DEFAULT_SLEEP_PHASES = {
|
|
19
20
|
consolidate: runConsolidation,
|
|
20
21
|
deduplicateStore,
|
|
@@ -220,7 +221,7 @@ async function summarizeAmbient(ctx, phases, result, pages) {
|
|
|
220
221
|
const rules = strengthOf(ctx);
|
|
221
222
|
const tallies = tallyAmbientEntries([], now, rules);
|
|
222
223
|
for await (const page of pages()) {
|
|
223
|
-
foldAmbientRows(tallies, page.filter((e) => !e
|
|
224
|
+
foldAmbientRows(tallies, page.filter((e) => !isSuperseded(e)), now, rules);
|
|
224
225
|
}
|
|
225
226
|
if (tallies.total === 0)
|
|
226
227
|
return 0;
|
|
@@ -50,6 +50,11 @@ export interface SleepResult {
|
|
|
50
50
|
};
|
|
51
51
|
/** What the sleep did, in order. */
|
|
52
52
|
events?: SleepEvent[];
|
|
53
|
+
/** Set when another sleep held the store's claim since that ISO time, so this one did nothing and
|
|
54
|
+
* its 0 counts mean "nothing was done", not "the store is empty". */
|
|
55
|
+
alreadyRunning?: {
|
|
56
|
+
since: string;
|
|
57
|
+
};
|
|
53
58
|
}
|
|
54
59
|
/** Sleeps the WHOLE store, every tenant, so /v1/sleep stays loopback-only; never auto-deletes
|
|
55
60
|
* pinned, raw, kept or object-backing rows. */
|
package/dist/api/sleep/sleep.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// The sleep cycle: decay, consolidation, dedupe, graph extraction and the other maintenance passes.
|
|
2
2
|
import { runSleep } from './sleep-run.js';
|
|
3
|
+
import { oneSleepPerStore, refusedSleep } from './one-sleep.js';
|
|
3
4
|
/** Sleeps the WHOLE store, every tenant, so /v1/sleep stays loopback-only; never auto-deletes
|
|
4
5
|
* pinned, raw, kept or object-backing rows. */
|
|
5
6
|
export async function sleepWholeStore(ctx, opts = {}) {
|
|
6
|
-
return runSleep(ctx, opts);
|
|
7
|
+
return oneSleepPerStore(ctx.store, opts.dryRun === true, () => runSleep(ctx, opts), refusedSleep);
|
|
7
8
|
}
|
|
8
9
|
//# sourceMappingURL=sleep.js.map
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { DAG_LEVEL } from '../base/memory/entry.js';
|
|
2
2
|
import { passesScopeFilterForRecall } from '../base/scope/recall-scope.js';
|
|
3
3
|
import { classifyOriginProject } from '../base/scope/project-identity.js';
|
|
4
|
+
import { isSuperseded } from '../base/memory/liveness.js';
|
|
4
5
|
/** The level-2 summaries that may stand in for their children: live, in the caller's scope and
|
|
5
6
|
* in its project. */
|
|
6
7
|
export function eligibleSummaryParents(parents, scope, own, project) {
|
|
7
8
|
return parents.filter((p) => (p.dagLevel ?? 0) === DAG_LEVEL.topic &&
|
|
8
|
-
!p
|
|
9
|
+
!isSuperseded(p) &&
|
|
9
10
|
passesScopeFilterForRecall(p.scope ?? null, scope, own) &&
|
|
10
11
|
(!project || classifyOriginProject(p.originProject, project) !== 'cross-project'));
|
|
11
12
|
}
|
|
@@ -50,6 +50,7 @@ function pinnedInjectFields(read) {
|
|
|
50
50
|
promptRecallMinShared: read('promptRecallMinShared', count(P.promptRecallMinShared)),
|
|
51
51
|
promptRecallMaxItems: read('promptRecallMaxItems', count(P.promptRecallMaxItems)),
|
|
52
52
|
promptRecallCandidates: read('promptRecallCandidates', count(P.promptRecallCandidates)),
|
|
53
|
+
excludeTags: read('excludeTags', textList([])),
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
// Every top-level key loadConfig reads. A bad value warns once, in one wording, and reads as the
|