Add C++ local-document ingest with immutable chunks - #126
Merged
Conversation
Local-Document-Adapter payloads now parse document metadata and UTF-8 chunks, reject secrets, hash-bind content_sha256, and upsert the chunks collection the same way as Go. Start/Heal still launch Go.
There was a problem hiding this comment.
🟡 Changes recommended
The new JSON parsing path silently accepts malformed numeric fields (e.g., non-number ocr_confidence/confidence) due to ignored parse failures, which breaks strict input validation guarantees.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the C++ cpp_memory_store ingestion protocol and MongoDB write path to support local-document ingestion (document + immutable chunks) in parity with the existing Go memory-store behavior, enabling idempotent chunk staging keyed by extractor identity and chunk index.
Changes:
- Added
document+chunksparsing/validation to the C++ stdin JSON protocol, including bounded chunk ranges and sensitive-content scanning. - Added MongoDB
chunksunique index and chunk upsert + immutability conflict checks during staging. - Exposed
sha256_hex()for documentcontent_sha256validation and documented the new “cut 11” capability.
File summaries
| File | Description |
|---|---|
| godbrain_core/cpp_memory_store/src/store.cpp | Adds unique index and staging logic for immutable per-source chunks tied to extractor identity. |
| godbrain_core/cpp_memory_store/src/protocol.cpp | Parses/validates document + chunks, including SHA-256 checks and secret scanning. |
| godbrain_core/cpp_memory_store/src/embedding.cpp | Makes sha256_hex() available outside the anonymous namespace. |
| godbrain_core/cpp_memory_store/README.md | Bumps to cut 11 and documents local-document ingest + immutable chunks. |
| godbrain_core/cpp_memory_store/include/godbrain/memory_store/protocol.hpp | Adds DocumentMetadata/SourceChunk structs and payload fields. |
| godbrain_core/cpp_memory_store/include/godbrain/memory_store/embedding.hpp | Exposes sha256_hex() in the public header. |
Review details
Suppressed comments (1)
godbrain_core/cpp_memory_store/src/protocol.cpp:1091
- json_number() return value is ignored for per-chunk confidence. If confidence is provided with a non-number type, the code marks has_confidence=true but leaves confidence at the default 0, silently accepting malformed payloads.
if (json_has(item, "confidence")) {
ch.has_confidence = true;
json_number(item, "confidence", &ch.confidence);
}
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1049
to
+1052
| if (json_has(*doc, "ocr_confidence")) { | ||
| route->ingest.document.has_ocr_confidence = true; | ||
| json_number(*doc, "ocr_confidence", &route->ingest.document.ocr_confidence); | ||
| } |
Comment on lines
1
to
5
| #include "godbrain/memory_store/protocol.hpp" | ||
| #include "godbrain/memory_store/embedding.hpp" | ||
| #include "godbrain/memory_store/json.hpp" | ||
| #include "godbrain/memory_store/state_machine.hpp" | ||
| #include "godbrain/memory_store/embedding.hpp" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
C++
memory-storestill rejecteddocument/chunks(Local-Document-Adapter). Go already stages immutable chunks and records adapter provenance on the run and source observation.What
Same gates as Go: metadata and chunks together,
content_sha256ofraw_transcript, contiguous UTF-8 byte ranges covering the transcript, forbidden-secret scan, uniquechunksindex,$setOnInsertso a retry isidempotent_noop.Verified
memory-store.exe --self-test(document-ok,document-chunks-required)godbrain_cpp_store_test: committed,chunks=1, second ingestidempotent_noop; db droppedNot in this PR