You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/sim/lib/memory/README.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ A journal belongs to one execution, workflow, block, node, and execution-order i
20
20
21
21
Recorded terminal tool outcomes are reused. Calls with no recorded outcome may run again with their original Sim invocation ID, so continuation provides at-least-once execution, not exactly-once external effects. An external service must support the supplied idempotency key to deduplicate an uncertain effect. A new execution or loop iteration has a separate journal.
22
22
23
-
New durability failures degrade execution to its in-memory path. They must never cause a version-2 conversation to resume legacy-array writes. A missing result payload remains a terminal outcome, with an unavailable-detail notice and its recorded success status and cost. A missing or invalid step in a reference checkpoint, or oversized saved ciphertext, prevents continuation instead of starting the invocation again. Generic database availability failures retain the existing in-memory degradation behavior. API and ordinary memory behavior keep their existing error contract. Deleting a conversation takes the conversation lock and cascades item, journal, and artifact ownership rows. Active turns retain the original memory ID, so a later conversation with the same key cannot accept their stale checkpoint writes.
23
+
New durability failures degrade execution to its in-memory path. They must never cause a version-2 conversation to resume legacy-array writes. A missing result payload remains a terminal outcome, with an unavailable-detail notice and its recorded success status and cost. Any nonempty saved checkpoint must decrypt, match its original identity and memory owner, and contain a valid state before continuation. Damaged ciphertext, invalid bindings or state, a missing step payload, and oversized saved ciphertext stop continuation instead of starting the invocation again. Database availability failures before a checkpoint is obtained retain the existing in-memory degradation behavior. API and ordinary memory behavior keep their existing error contract. Deleting a conversation takes the conversation lock and cascades item, journal, and artifact ownership rows. Active turns retain the original memory ID, so a later conversation with the same key cannot accept their stale checkpoint writes.
24
24
25
25
Large-result artifacts have conversation ownership separate from run-log retention. The cleanup predicate retains owned artifacts and their dependencies while the conversation remains active; deleting the conversation releases this ownership.
26
26
@@ -42,15 +42,19 @@ The shared context policy uses an explicit memory token window when configured a
42
42
43
43
`agent_memory_read` is supplied only with the trusted original memory owner. It searches retained history, including a safely projectable legacy prefix, or reads a referenced result in bounded pages. Legacy-prefix data and provenance must fit the 1 MiB retrieval admission limit. Each call returns at most 6,000 UTF-8 text bytes and scans at most 10 history items; a continuation cursor may be returned even when no match appears in a page. Cursors bind to the owner and search. Artifact reads use opaque IDs and canonical conversation ownership, and return only safely projected model content. Journal envelopes, provider continuations, raw replay fields, and unrelated conversation artifacts cannot be retrieved through this tool. At most two retrievals run concurrently per execution context. Read pages sequentially and follow `nextCursor` when more detail is needed.
44
44
45
-
Before a generation omits older optional groups, a bound compactor can summarize both earlier conversation records and older completed exchanges from the active invocation. The current prompt and newest tool exchange remain required. A summary has priority within the same optional history budget as recent raw groups. Refreshes require additional history equal to at least half the configured history target, with a 1,024-token minimum, so every tool response does not trigger another summary call. A refreshed note can include the preceding note and newly eligible older records. The summary request has no tools, reads at most 8,000 estimated source tokens, and requests at most 1,024 output tokens, further constrained by the actual available summary budget. Its token/cost totals are recorded as `contextUsage`, without adding an execution step or a public conversation message. The latest summary is an encrypted derived cache on the original `memory` owner: at most 6,000 characters and 64 KiB of ciphertext, reused only for an exact versioned source hash. Cache replacement does not change the immutable transcript or its provenance, and generation runs outside database locks. Cache reads have a SQL byte guard and ordinary memory reads exclude the cache column. Failed summary generation or cache access falls back to bounded history selection.
45
+
Before a generation omits older optional groups, a bound compactor can summarize earlier available conversation records and older completed exchanges from the active invocation. The current prompt and newest tool exchange remain required. A summary has priority within the same optional history budget as recent raw groups. Once the eligible backlog is covered, refreshes require additional history equal to at least half the configured history target, with a 1,024-token minimum, so every tool response does not trigger another summary call.
46
+
47
+
Compaction processes at most three source batches per pressure event, in chronological order. Each batch combines the preceding note with the next contiguous older records, admits at most 8,000 estimated source tokens, and requests at most 1,024 output tokens, further constrained by the actual available summary budget. An individually large group may contribute a bounded excerpt with its call identities and artifact IDs. The coverage cursor advances only through a successfully summarized prefix; a failed or unusable response cannot mark skipped records as covered. Remaining backlog can continue at the next pressure event. Summary calls have no tools, and their token/cost totals are recorded as `contextUsage` without adding an execution step or a public conversation message. Original records remain authoritative; a derived note may omit details and never authorizes tool replay.
48
+
49
+
The latest summary is an encrypted version-2 cache on the original `memory` owner, bounded to 6,000 characters and 64 KiB of ciphertext. Reuse requires validated cache metadata: its original-message count and source hash must exactly match an eligible canonical history prefix under the current summary policy. The source hash follows original records, independent of intermediate generated wording. Cache replacement does not change the immutable transcript or its provenance, and generation runs outside database locks. Cache reads have a SQL byte guard and ordinary memory reads exclude the cache column. Failed summary generation or cache access preserves any earlier usable note and falls back to bounded history selection.
46
50
47
51
The public [Agent block documentation](../../../docs/content/docs/workflows/blocks/agent.mdx) describes these user-visible limits.
48
52
49
53
## Verification
50
54
51
55
The optional five-family live contract suite is `providers/conversation-smoke.test.ts`. It is skipped unless `RUN_AGENT_MEMORY_PROVIDER_SMOKE=true` and `AGENT_MEMORY_PROVIDER_SMOKE_CASES` supplies an array of `{protocol, providerId, model, apiKey?, azureEndpoint?, azureApiVersion?, bedrockAccessKeyId?, bedrockSecretKey?, bedrockRegion?}` entries. Supply one entry for each protocol from `history-adapters.ts`. It executes a mocked, side-effect-free echo tool and then sends the captured native history through a second live request. These calls use provider credits; credentials remain in the environment and must not be committed. The implementation verification did not enable this paid suite.
52
56
53
-
`conversation-store.postgres.test.ts` creates a disposable schema in a local database selected by `MEMORY_PROVENANCE_TEST_DATABASE_URL`. It applies migration 0368 and checks legacy-prefix preservation, public projections, CAS conflicts and rollback, append deduplication, pair-safe history windows, deletion/recreation, artifact retention, and oversized-checkpoint admission. `summary-store.postgres.test.ts` verifies exact hash reuse, scope binding, concurrent replacement/deletion, encrypted cache bounds, and exclusion from public projections and SQL reads. That suite requires the isolated local database at `127.0.0.1:5433/sim_durable_memory_e2e`. `message-provenance.postgres.test.ts` also applies this migration and verifies legacy provenance through a 17,000-message conversation and concurrent native/tool appends. All three suites drop their disposable schemas afterward.
57
+
`conversation-store.postgres.test.ts` creates a disposable schema in a local database selected by `MEMORY_PROVENANCE_TEST_DATABASE_URL`. It applies migration 0368 and checks legacy-prefix preservation, public projections, CAS conflicts and rollback, append deduplication, pair-safe history windows, deletion/recreation, artifact retention, and oversized-checkpoint admission. `summary-store.postgres.test.ts` verifies exact hash reuse, scope binding, concurrent replacement/deletion, encrypted cache bounds, and exclusion from public projections and SQL reads. It uses the same explicitly configured local database and a disposable schema. `message-provenance.postgres.test.ts` also applies this migration and verifies legacy provenance through a 17,000-message conversation and concurrent native/tool appends. All three suites drop their disposable schemas afterward.
54
58
55
59
The journal/session fixtures cover terminal sibling replay, missing artifacts, legacy snapshot migration, byte signatures, provenance, and context usage. The growth regression records 50 steps/results and checks that each payload is uploaded once while the encrypted manifest stays below 120 KiB. Run the focused suites from `apps/sim`:
0 commit comments