feat: expose graph edge metadata (caused_by, leads_to, timestamp) in memory_search - #301
feat: expose graph edge metadata (caused_by, leads_to, timestamp) in memory_search#301xDarkicex wants to merge 3 commits into
Conversation
Surface causal graph edges (why_ids → caused_by, how_ids → leads_to) and timestamps from record metadata in both legacy and structured search result paths. This enables agents to traverse the event DAG for causal reasoning without new RPCs — the data was already flowing through metadataJson, just not surfaced in tool output. Also exposes memory_kind and memory_signals in structured results for consistency with the legacy path.
📝 WalkthroughWalkthrough
ChangesMemory Search Result Metadata Enrichment
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/memory-runtime.ts`:
- Around line 351-359: The metaTimestamp function can call
Date.prototype.toISOString() on a Date that is invalid or out-of-range which may
throw; update metaTimestamp to validate the constructed Date (e.g., const d =
new Date(ts); check Number.isFinite(d.getTime()) and d.getTime() >
-Infinity/…/not NaN) and/or wrap the toISOString() call in a try/catch and
return undefined on failure so a single bad metadata.ts does not throw; apply
this change to the metaTimestamp function to ensure numeric and parsed string
timestamps are converted safely and invalid/out-of-range dates are treated as
“no timestamp.”
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/memory-tools.ts (1)
199-205: ⚡ Quick winKeep the local result type aligned with the documented fields.
This description now advertises
kind,signals,caused_by,leads_to, andtimestamp, butMemorySearchResulton Lines 34-42 still only models the old fields. Updating the type here will keep the tool contract self-consistent and prevent future code in this file from accidentally ignoring the new metadata.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/memory-tools.ts` around lines 199 - 205, Update the MemorySearchResult type to include the newly documented metadata fields so the local type matches the tool contract: add optional properties kind (string), signals (number or appropriate enum/bitmask type used elsewhere), caused_by (string[]), leads_to (string[]), and timestamp (string, ISO 8601) to the MemorySearchResult interface/type definition; ensure any references to MemorySearchResult (e.g., functions that deserialize search results) accept and preserve these fields and adjust imports/types if a shared enum/type (for signals) exists.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/memory-tools.ts`:
- Around line 202-203: The doc text incorrectly instructs callers to pass event
IDs from caused_by/leads_to into memory_get; memory_get expects a path produced
by memory_search, not raw event IDs. Update the wording around the caused_by and
leads_to descriptions to either (a) tell callers to call memory_search with
those event IDs to obtain a path and then pass that path to memory_get, or (b)
say to use memory_get only with paths returned by memory_search and to use
memory_get/memory_search together to walk the causal chain; reference symbols:
caused_by, leads_to, memory_get, memory_search.
---
Nitpick comments:
In `@src/memory-tools.ts`:
- Around line 199-205: Update the MemorySearchResult type to include the newly
documented metadata fields so the local type matches the tool contract: add
optional properties kind (string), signals (number or appropriate enum/bitmask
type used elsewhere), caused_by (string[]), leads_to (string[]), and timestamp
(string, ISO 8601) to the MemorySearchResult interface/type definition; ensure
any references to MemorySearchResult (e.g., functions that deserialize search
results) accept and preserve these fields and adjust imports/types if a shared
enum/type (for signals) exists.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 827d3335-04fc-4a71-9638-4865ea29c0b0
📒 Files selected for processing (2)
src/memory-runtime.tssrc/memory-tools.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/memory-runtime.ts
| "- caused_by: array of upstream causal event IDs (why this happened). Use memory_get with these IDs to walk backward through the causal chain.\n" + | ||
| "- leads_to: array of downstream procedural event IDs (what this caused). Use memory_get with these IDs to walk forward through the event DAG.\n" + |
There was a problem hiding this comment.
Don't tell callers to pass graph IDs into memory_get.
Lines 202-203 describe caused_by/leads_to as event IDs, but memory_get only accepts a path returned by memory_search (see Lines 107-125 and Lines 265-266). This guidance sends the model down an unsupported call path.
Suggested wording
- "- caused_by: array of upstream causal event IDs (why this happened). Use memory_get with these IDs to walk backward through the causal chain.\n" +
- "- leads_to: array of downstream procedural event IDs (what this caused). Use memory_get with these IDs to walk forward through the event DAG.\n" +
+ "- caused_by: array of upstream causal event IDs (why this happened). Use these IDs to correlate related memories or issue a targeted memory_search to walk backward through the causal chain.\n" +
+ "- leads_to: array of downstream procedural event IDs (what this caused). Use these IDs to correlate related memories or issue a targeted memory_search to walk forward through the event DAG.\n" +📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "- caused_by: array of upstream causal event IDs (why this happened). Use memory_get with these IDs to walk backward through the causal chain.\n" + | |
| "- leads_to: array of downstream procedural event IDs (what this caused). Use memory_get with these IDs to walk forward through the event DAG.\n" + | |
| "- caused_by: array of upstream causal event IDs (why this happened). Use these IDs to correlate related memories or issue a targeted memory_search to walk backward through the causal chain.\n" + | |
| "- leads_to: array of downstream procedural event IDs (what this caused). Use these IDs to correlate related memories or issue a targeted memory_search to walk forward through the event DAG.\n" + |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/memory-tools.ts` around lines 202 - 203, The doc text incorrectly
instructs callers to pass event IDs from caused_by/leads_to into memory_get;
memory_get expects a path produced by memory_search, not raw event IDs. Update
the wording around the caused_by and leads_to descriptions to either (a) tell
callers to call memory_search with those event IDs to obtain a path and then
pass that path to memory_get, or (b) say to use memory_get only with paths
returned by memory_search and to use memory_get/memory_search together to walk
the causal chain; reference symbols: caused_by, leads_to, memory_get,
memory_search.
Vale ReviewVerdict: not merge-ready. The runtime enrichment idea is sound, but this branch currently conflicts with Findings
GitHub reports the PR as The conflict matters: current
The PR replaces that description with the new result-field docs. When rebasing, keep both pieces: the anti-loop guidance from
In
That is wrong for the actual tool contract. Fix direction: either expose resolvable paths alongside the graph IDs, or describe these IDs as correlation/search keys, not direct
In const signals = meta.memory_signals as string[] | undefined;Then the code checks Use the same defensive pattern as
This PR changes both legacy and structured result paths, but adds no tests. I would want focused tests for:
Positive notesThe actual enrichment in CI / verification stateI found no GitHub Actions runs for head |
Summary
metadataJsoninmemory_searchresultswhy_ids→caused_by(upstream causal parents — "from")how_ids→leads_to(downstream procedural children — "to")ts→timestamp(ISO 8601, human-readable)memory_kindandmemory_signalsin structured result path (was only in legacy path)No daemon changes required — data already flows through
metadataJson, just wasn't surfaced in tool output.Test plan
memory_searchreturnscaused_by/leads_toarrays on records with graph edgesmemory_searchreturnstimestampon records withtsmetadatamemory_kindandmemory_signalsappear in structured resultsSummary by CodeRabbit