Repository navigation
refactor(python): one row-value walk for Record.data()/to_dict() and result_graph (LABS-1474) - #247
Conversation
|
Rust review: no rust-relevant changes (no Rust files modified). ✅ |
|
Security review (security-review skill) Reviewed the three-file Python refactor that unifies the row-value walk behind a new No issues found. Security review: ✅ no issues found |
|
|
||
| A ``Node``, ``Relationship`` or ``Path`` is replaced by | ||
| ``on_graph_value(value)`` (the callback decides whether to descend into | ||
| it); a ``Mapping`` becomes a ``dict``, a list, tuple, set or frozenset a |
There was a problem hiding this comment.
[High] structure (flag-logic-wrong-layer): The new shared walk is generic row-value conversion, but it lives in the graph-extraction feature module: record.py — home of the public Record row type — now imports relate.result_graph for it,
Suggested fix: Extract map_row_value and _SEQUENCE_TYPES into a neutral row-value module (or into record.py, with result_graph importing from it) so the dependency points result_graph → record, not the reverse; leave result_graph.py owning only ResultGraph/collect_graph_entities and update its modu
finding F-1-1
| walk(item) | ||
| collect(entity) | ||
| else: | ||
| raise TypeError(f"not a graph value: {type(value).__name__}") |
There was a problem hiding this comment.
[Medium] branching (std-2): This branch is unreachable: map_row_value invokes the callback only under isinstance(value, (Node, Relationship, Path)), and the recursive calls feed it value.nodes / value.relationships, whic
Suggested fix: Delete the else; the walk owns the vocabulary test, so collect should be only the two store branches plus the Path flatten. If the sink's precondition must be defended, assert it once at the collect_graph_entities boundary instead of adding a branch the sole caller cannot reach.
finding F-1-2
| for row in rows: | ||
| for value in row.values(): | ||
| walk(value) | ||
| map_row_value(value, collect) |
There was a problem hiding this comment.
[Medium] boundaries (std-4): map_row_value is a mapper — it rebuilds every nested Mapping and sequence — and the collector drops its result, so cursor.graph() / viz.to_visualization_graph now allocate a full converted cop
Suggested fix: Keep the leaf vocabulary ((Node, Relationship, Path)) and _SEQUENCE_TYPES shared, but give the collector an in-place visitor beside the mapper (visit_row_value(value, on_graph_value)) instead of routing it through map_row_value; a sink must not build a copy it discards.
finding F-1-3
| collect(entity) | ||
| else: | ||
| raise TypeError(f"not a graph value: {type(value).__name__}") | ||
| return value |
There was a problem hiding this comment.
[Medium] boundaries (std-5): The walk only invokes the callback for Node, Relationship or Path, so this branch can never fire — a dead raise beside the walk's own handled pass-through (the no-panic-beside-a-handled-form rul
Suggested fix: Type the callback over the graph-value union with no return value, delete the unreachable raise, and derive the vocabulary (walk + callback) from one central definition so a new entity type is an edit in a single place.
finding F-1-4
|
Stellar review (stellar-review skill) Round 4 · head Still open from earlier rounds
Stellar review: |
5cb4d0a to
86583f3
Compare
| return list(value) | ||
| return None | ||
|
|
||
|
|
There was a problem hiding this comment.
[Medium] boundaries (std-5): The Optional return makes a shared vocabulary helper carry a leaf sentinel that its two callers must interpret with different idioms: map_row_value branches on children is None, while `iter_graph_
Suggested fix: Drop the Optional. Either return the container's own iterable view (value.values() / value) and let each walk's isinstance branches decide leaf-ness (map needs to know container-vs-leaf to rebuild []; iter does not), or delete _children and put the two isinstance arms beside `_GRAPH_VALU
finding F-2-1
| return list(value) | ||
| return None | ||
|
|
||
|
|
There was a problem hiding this comment.
[Medium] boundaries (std-4): _children copies every container's children into a fresh list, so iter_graph_values — documented as the walk that builds nothing, and split from map_row_value precisely so the read path stops re
Suggested fix: Return the container's existing iterable (value.values() for a Mapping, value itself for a sequence) instead of list(...); both call sites only iterate, and map_row_value's comprehensions build the new container anyway. Keep the vocabulary constants as the single source of which types are wa
finding F-2-2
| items = value.values() if isinstance(value, Mapping) else value | ||
| for item in items: | ||
| walk(item) | ||
| collect(entity) |
There was a problem hiding this comment.
[Medium] boundaries (q-abstraction): The graph walk's path shape knowledge is split from the rest of the vocabulary: row_values._GRAPH_VALUES declares Path a leaf and iter_graph_values therefore yields paths unexpanded, while this
Suggested fix: Give the entity stream one contract: have the row-values walk flatten a Path into its nodes and relationships (or add iter_graph_entities beside it that does) so Path's internal shape lives with the rest of the vocabulary. collect then becomes a flat classify-and-dedup loop over the yielded
finding F-2-3
Spec-harness coverage — 🟡
Rerun |
|
Loadtest baselines comparison
Loadtest baseline comparisonFrozen baselines vs current reports; bands match the Status: warning Pairs: fraud-loadtest: compared · identity-loadtest: compared (failing rows) fraud-loadtest
Per-use-case p99 latency
identity-loadtest
Per-use-case p99 latency
|
|
Memory shape
Memory shapeStatus: ok All memory shapes held. 🟢 baseGiven: an empty relate serve, 1 integer properties on every node, text indexes 0, point indexes 0, range indexes 0, and a 32.00 MB logical ceiling. When: the base shape is loaded to 0 nodes and 0 relationships, then checkpointed. The child RSS is sampled. Then: the database holds those counts. The load finishes under the ceiling. Logical bytes, disk, attributed RSS, and the ratio stay inside the frozen boundaries. Baseline: logical 0.00 MB – 0.00 MB, disk 0.00 MB – 0.00 MB, attributed RSS 0.00 MB – 0.00 MB, ratio 0.000x–0.000x. A reading may sit 5% outside the ratio, and 15% or 1.00 MB outside the sizes. Validated: logical 0.00 MB, disk 0.00 MB, attributed RSS 0.00 MB, ratio 0.000x. Report: logical, disk, attributed RSS, and the ratio held. flatGiven: an empty relate serve, 1 integer properties on every node, text indexes 0, point indexes 0, range indexes 0, and a 32.00 MB logical ceiling. When: the flat shape is loaded to 120000 nodes and 0 relationships, then checkpointed. The child RSS is sampled. Then: the database holds those counts. The load finishes under the ceiling. Logical bytes, disk, attributed RSS, and the ratio stay inside the frozen boundaries. Baseline: logical 26.02 MB – 26.02 MB, disk 1.95 MB – 1.95 MB, attributed RSS 36.49 MB – 36.93 MB, ratio 1.402x–1.419x. A reading may sit 5% outside the ratio, and 15% or 1.00 MB outside the sizes. Validated: logical 26.02 MB, disk 1.26 MB, attributed RSS 37.65 MB, ratio 1.447x. Report: logical, disk, attributed RSS, and the ratio held. fanoutGiven: an empty relate serve, 1 integer properties on every node, text indexes 0, point indexes 0, range indexes 0, and a 32.00 MB logical ceiling. When: the fanout shape is loaded to 52016 nodes and 52000 relationships, then checkpointed. The child RSS is sampled. Then: the database holds those counts. The load finishes under the ceiling. Logical bytes, disk, attributed RSS, and the ratio stay inside the frozen boundaries. Baseline: logical 28.62 MB – 28.62 MB, disk 1.75 MB – 1.75 MB, attributed RSS 34.93 MB – 36.61 MB, ratio 1.220x–1.279x. A reading may sit 5% outside the ratio, and 15% or 1.00 MB outside the sizes. Validated: logical 27.43 MB, disk 1.10 MB, attributed RSS 36.01 MB, ratio 1.313x. Report: logical, disk, attributed RSS, and the ratio held. ringGiven: an empty relate serve, 1 integer properties on every node, text indexes 0, point indexes 0, range indexes 0, and a 32.00 MB logical ceiling. When: the ring shape is loaded to 46000 nodes and 46000 relationships, then checkpointed. The child RSS is sampled. Then: the database holds those counts. The load finishes under the ceiling. Logical bytes, disk, attributed RSS, and the ratio stay inside the frozen boundaries. Baseline: logical 29.99 MB – 29.99 MB, disk 1.77 MB – 1.77 MB, attributed RSS 35.30 MB – 35.89 MB, ratio 1.177x–1.197x. A reading may sit 5% outside the ratio, and 15% or 1.00 MB outside the sizes. Validated: logical 29.99 MB, disk 1.20 MB, attributed RSS 35.86 MB, ratio 1.196x. Report: logical, disk, attributed RSS, and the ratio held. dense ringGiven: an empty relate serve, 1 integer properties on every node, text indexes 0, point indexes 0, range indexes 0, and a 32.00 MB logical ceiling. When: the dense ring shape is loaded to 5000 nodes and 100000 relationships, then checkpointed. The child RSS is sampled. Then: the database holds those counts. The load finishes under the ceiling. Logical bytes, disk, attributed RSS, and the ratio stay inside the frozen boundaries. Baseline: logical 31.41 MB – 31.41 MB, disk 1.62 MB – 1.62 MB, attributed RSS 31.27 MB – 32.46 MB, ratio 0.996x–1.034x. A reading may sit 5% outside the ratio, and 15% or 1.00 MB outside the sizes. Validated: logical 31.11 MB, disk 0.73 MB, attributed RSS 31.95 MB, ratio 1.027x. Report: logical, disk, attributed RSS, and the ratio held. |
|
Memory controls and workspace memory calibration
(comparison document unavailable) |
…result_graph (LABS-1474) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
86583f3 to
10cf1a5
Compare
Oplane Security ReviewOplane reviewed this PR and did not identify any security requirements that need attention. Review the generated threat model. Change comment settings · Set up Oplane in your agent · Workflow guidance |
Summary
Refactor (python surface).
record.py::_convertwas a second hand-rolled walk over the row-value vocabulary besideresult_graph.collect_graph_entities. Both now call one helper,result_graph.map_row_value, so the container set (Mapping, list, tuple, set, frozenset) lives in one place.relate/row_values.pyowns the vocabulary:map_row_valuerebuilds a value (used byRecord.data()/to_dict()),iter_graph_valuesyields graph values without copying (used bycollect_graph_entities); both dispatch through one_childrenhelper.record._convertandresult_graph._CONTAINER_TYPESremoved.User-facing impact:
Record.data()/to_dict()now also convert graph values inside sets and non-dict Mappings (previously left as is). Otherwise unchanged.Verification
python/testsagainst a maturin-built wheel: 338 passed, 8 skippedcargo fmt --all --checkclean; full local stellar round: one medium (fixed) plus nits (pass-through and explicit Path branch fixed)enters_arithmetic_searchdead code), unrelated; this change touches no RustLABS-1474
🤖 Generated with Claude Code