Skip to content

Commit d40cfd1

Browse files
committed
fix(core): preserve agent source through note materialization
Signed-off-by: phernandez <paul@basicmachines.co>
1 parent 2643912 commit d40cfd1

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/basic_memory/runtime/note_object_metadata.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@
4545
# extraction or ingestion-run note through the canonical note mutation path.
4646
# wiki_projector = the deterministic OKF projector accepting generated index
4747
# and log notes through that same path before materializing them as Markdown.
48+
# agent_runtime = a managed agent accepting a note through the canonical write
49+
# path; preserving it through materialization prevents recursive agent dispatch.
4850
VALID_NOTE_OBJECT_SOURCES: frozenset[RuntimeNoteChangeSource] = frozenset(
4951
{
52+
"agent_runtime",
5053
"api",
5154
"collaboration_relay",
5255
"document_ingestion",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Agent provenance must survive the queue and object-storage boundaries."""
2+
3+
from basic_memory.runtime.job_payloads import RuntimeNoteMaterializationJobPayload
4+
from basic_memory.runtime.note_content import RuntimeNoteMaterializationJobRequest
5+
from basic_memory.runtime.note_object_metadata import (
6+
RuntimeNoteObjectMetadata,
7+
RuntimeNoteObjectProvenance,
8+
)
9+
10+
11+
def test_agent_source_survives_materialization_payload_and_storage_metadata() -> None:
12+
request = RuntimeNoteMaterializationJobRequest(
13+
project_id=1,
14+
entity_id=2,
15+
db_version=3,
16+
db_checksum="abc123",
17+
actor_kind="system",
18+
actor_name="Preview Agent",
19+
source="agent_runtime",
20+
)
21+
payload = RuntimeNoteMaterializationJobPayload.from_runtime_request(request)
22+
restored = RuntimeNoteMaterializationJobPayload.model_validate_json(
23+
payload.model_dump_json()
24+
).to_runtime_request()
25+
assert restored == request
26+
metadata = RuntimeNoteObjectMetadata(
27+
entity_id=restored.entity_id,
28+
db_version=restored.db_version,
29+
db_checksum=restored.db_checksum,
30+
actor_kind=restored.actor_kind,
31+
actor_name=restored.actor_name,
32+
source=restored.source,
33+
).to_storage_metadata()
34+
provenance = RuntimeNoteObjectProvenance.from_object_metadata(metadata)
35+
assert provenance.source == "agent_runtime"
36+
assert provenance.actor_kind == "system"
37+
assert provenance.actor_name == "Preview Agent"

0 commit comments

Comments
 (0)