Repository navigation
feat(kr-activation): bitemporal as-of route + durable tool-observation memory - #98
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9eb4ffc4b8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .map(|rec| SearchResult { | ||
| content: rec.value, | ||
| source: semantic_memory::SearchSource::Fact { | ||
| fact_id: rec.id, | ||
| namespace: scope.namespace.clone(), |
There was a problem hiding this comment.
Enforce scope before returning injected bitemporal records
When a runtime has injected records, querying another namespace or a narrower workspace/repository scope returns the same records: as_of receives only timestamps, and the mapping simply labels every returned record with the requested namespace. This bypasses the scope filtering performed by the projection adapter and can expose records outside the requested scope, even when projection-backed execution enforced that scope successfully. Associate injected records with their originating scope and filter them before returning results; do not relabel unscoped records as belonging to the caller's namespace. The crate's scoped guidance explicitly requires scope pushdown and disclosure of widening.
AGENTS.md reference: knowledge-runtime/AGENTS.md:L23-L25
Useful? React with 👍 / 👎.
| if !asof.is_empty() { | ||
| results = asof | ||
| .into_iter() | ||
| .map(|rec| SearchResult { |
There was a problem hiding this comment.
Apply query selection and result limits to the temporal source
Whenever any injected records are visible at the requested timestamps, this replaces the query pipeline's results with every visible record, regardless of the query text, resolved entity, or configured result limit. For example, a targeted temporal query with default_limit = 10 can return hundreds of unrelated records while discarding matching projection results. Integrate the temporal source into retrieval and merge rather than substituting a full snapshot after merging. This also violates the crate-specific requirement to preserve projection-backed retrieval as the supported substrate.
AGENTS.md reference: knowledge-runtime/AGENTS.md:L23-L24
Useful? React with 👍 / 👎.
| .map(|r| ToolObservationMemoryRecordV1 { | ||
| tool_name: String::new(), | ||
| invocation_id: String::new(), | ||
| session_id: None, | ||
| scope: scope.to_string(), |
There was a problem hiding this comment.
Restore observation fields from persisted metadata
Searching for a stored observation always replaces its tool name, invocation ID, status, session, timestamps, and receipt ID with empty values, despite persisting those fields in metadata. Consequently, even a successful store/search round trip cannot identify the invocation or dereference its receipt, unlike the existing in-memory implementation, which returns the original record. Resolve each matching fact and deserialize its stored observation metadata instead of constructing a summary-only placeholder.
Useful? React with 👍 / 👎.
| let namespaces = [scope]; | ||
| let results = self | ||
| .search(query, Some(limit), Some(&namespaces), None) | ||
| .await |
There was a problem hiding this comment.
Restrict observation searches to observation records
If the supplied MemoryStore also contains ordinary facts in the requested namespace, this unrestricted search returns those facts and then converts them into tool observations. The stored kind marker and OBSERVATION_SOURCE are never checked, so unrelated facts can both appear as fabricated observations and consume the result limit ahead of real observations. Filter by the observation source/kind before applying the observation limit.
Useful? React with 👍 / 👎.
| self.add_fact( | ||
| &record.scope, | ||
| &record.summary, | ||
| Some(OBSERVATION_SOURCE), | ||
| Some(metadata), |
There was a problem hiding this comment.
Preserve distinct invocations with identical summaries
When two invocations in the same scope produce the same summary, the second observation is silently discarded. MemoryStore::add_fact_with_trace deduplicates solely by namespace and content and returns the existing fact ID without updating metadata, so different invocation IDs, statuses, or receipt IDs do not make these writes distinct. Use observation identity in the persistence scheme rather than relying on summary-only fact insertion, otherwise repeated tool runs cannot be durably represented.
Useful? React with 👍 / 👎.
| if !asof.is_empty() { | ||
| results = asof |
There was a problem hiding this comment.
Preserve empty results from the configured temporal source
When injected records exist but none are visible at the requested valid/recorded coordinates, this condition discards the empty as-of answer and retains the earlier pipeline results. With no projection imports and non-strict temporal mode, that pipeline performs ordinary hybrid search, so querying before the first injected version can return current facts instead of the empty historical state. Distinguish an unconfigured source from a configured source with no visible records, and preserve the latter's empty answer rather than treating it as a reason to fall back. The scoped guidance specifically forbids substituting hybrid fact search for temporal behavior.
AGENTS.md reference: knowledge-runtime/AGENTS.md:L38-L39
Useful? React with 👍 / 👎.
Adds: (A) bitemporal as-of bridge + temporal-route consumption via KnowledgeRuntime::with_bitemporal_records; (B) durable ToolObservationMemory impl for MemoryStore + activated previously-orphaned semantic_memory module; tests for both. Cherry-picked onto main from the remediation line. Local: fmt clean, clippy -D warnings clean on touched crates, all touched-crate tests pass (knowledge-runtime 60+51+... , llm-tool-runtime).