Repository navigation
fix(cli): novelty-aware encoded-binding resolution in the table renderer, and never Debug-print a binding - #1693
Conversation
…rint
The table fast path resolved `Binding::EncodedSid` through
`gv.store().resolve_subject_iri` — the base-store resolver, which only
consults persisted subject_forward_packs. A subject first seen after the
index snapshot lives in DictNovelty, so that lookup fails, and all six
encoded-binding arms then fell back to `format!("{b:?}")`: the internal
struct's Debug repr, printed into a user-facing table cell.
Two changes. The subject arm now calls the novelty-aware
`BinaryGraphView::resolve_subject_iri`, which is what the API formatters
already reach through `format::materialize`. And every fallback renders
an explicit `<unresolved>` placeholder instead of a Debug repr, so a
failed resolve degrades to something legible rather than leaking
internals.
The predicate arm keeps `store().resolve_predicate_iri`: predicate IDs
come from the index root's inline dict and have no novelty layer, which
is why `BinaryGraphView` exposes no predicate resolver of its own. Every
other formatter in the tree resolves predicates the same way.
Guards: a renderer-level test builds an indexed ledger, commits a
novelty-only subject on top, and asserts the cell renders the IRI —
asserting first that the base-store resolver genuinely cannot see that
ID, so the test can't pass vacuously against a fixture that stopped
being novelty-only. A second pins `<unresolved>` for every encoded arm
with and without a graph view, and an end-to-end integration test walks
the reported repro through insert/index/insert/`query --format table`.
`merge preview`'s conflict listing Debug-printed `Option<Sid>`, so a
line read `s=ex:a p=ex:b g=Some("http://ex/g")` while `s` and `p` beside
it rendered plain IRIs. Same class as the table-cell fix: a Rust
container repr reaching stdout. A key with no graph is in the default
graph, so it now says `<default>`.
Found by the audit sweep for Debug formatting in user-facing output.
bplatz
left a comment
There was a problem hiding this comment.
Approving — the resolver swap is right, the audit table is genuinely useful, and the non-vacuity assert inside encoded_sid_from_novelty_renders_iri_not_debug_repr is load-bearing (I reverted the resolver line and it reddens with got "<unresolved>").
Two things I'd want looked at before merge, both inline. Neither is a correctness objection to the change itself.
Also worth a one-line wording fix while you're in here: the body says predicates "have no novelty layer at all" as the reason for keeping store().resolve_predicate_iri. Keeping it is correct — I inserted a brand-new predicate on a novelty-only subject after an index and it renders fine — but there is an ephemeral predicate layer (EphemeralPredicateMap, binary_scan.rs:2577, routed by DictOverlay::resolve_predicate_iri at dict_overlay.rs:293). Right decision, wrong reason, and the stated reason is the kind of thing someone builds on later.
| /// Placeholder rendered when an encoded binding cannot be resolved to a | ||
| /// user-facing value (missing graph view, or an ID the dictionaries don't | ||
| /// know). Internal `Debug` representations must never reach user output. | ||
| const UNRESOLVED_CELL: &str = "<unresolved>"; |
There was a problem hiding this comment.
The placeholder discards the one datum you'd need if this ever fires.
Every unresolvable binding collapses to identical text, so two distinct broken rows look the same — where the Debug repr at least carried the id. And <unresolved> in RDF-facing output reads like a relative IRI; a user can reasonably parse that cell as a subject named unresolved.
There's precedent for the better shape at fluree-db-query/src/materializer.rs:666, which fabricates _:unknown_p_{p_id} and tracing::warn!s. Something like (unresolved s_id=…) plus a warn costs nothing and keeps the cell diagnosable. The EncodedPid arm is fully silent today — Option, no logging anywhere beneath it.
This matters more, not less, given the second comment: if the arm is cold, the day it fires is the day you most want the id.
| /// pipeline (insert, index, insert, `query --format table`) so a regression | ||
| /// anywhere along it — not just in the resolver — is caught. | ||
| #[test] | ||
| fn table_output_renders_novelty_only_subject_after_index() { |
There was a problem hiding this comment.
This test doesn't reach the code the PR fixes, and the doc comment above claims it does ("pins the whole pipeline … so a regression anywhere along it — not just in the resolver — is caught").
I reverted the resolver line and ran it: passes. Instrumenting sparql_table_cell to log its binding variant, this query yields 12 Sid + 6 EncodedLit cells and zero EncodedSid — it would pass with the whole EncodedSid arm deleted.
I tried six more shapes on the same fixture (?s ?p ?o, a <urn:Probe>, join-through-literal, SELECT *, …) and couldn't produce an EncodedSid in any of them; subjects always arrive already materialized as Sid. That's probably why #1466 stopped reproducing.
Not asking you to drop the test — it's still a net against a future re-route. But either soften the comment to say it's currently non-reddening, or use the shape that does emit EncodedSid (you mention confirming the fused path engaged via debug markers — engaging the fused path isn't the same as emitting EncodedSid to the formatter; if you have that shape, it belongs here). Worth deciding on Fixes #1466 too: if nothing live covers it, closing leaves no guard if the symptom returns.
An encoded binding the renderer can't resolve used to collapse to a bare
`<unresolved>`. Two distinct broken rows rendered identically, so the cell
carried nothing to debug from — and in RDF-facing output `<unresolved>`
reads like a relative IRI, i.e. a subject actually named `unresolved`.
The fallback now renders `(unresolved s_id=…)` / `(unresolved p_id=…)` /
`(unresolved o_kind=… o_key=… p_id=…)` and logs a `tracing::warn!` naming
the ID and why the resolve failed. That matches how the rest of the tree
signals the same failure: the API formatters hard-error with the ID in the
message (fluree-db-api/src/format/materialize.rs:63) and the materializer
fabricates `_:unknown_p_{p_id}` alongside a warn
(fluree-db-query/src/materializer.rs:669-673). The EncodedPid arm had no
logging at all beneath it before this.
Also records why the predicate arm resolves store-only. It is not that
predicates have no novelty layer — `EphemeralPredicateMap`
(binary_scan.rs:2577) is exactly that, routed by
`DictOverlay::resolve_predicate_iri` (dict_overlay.rs:291). The reason is
reachability: `Binding::EncodedPid` has one engine construction site
(binary_scan.rs:1486), gated on `late_materialize`, which requires
`overlay.epoch() == 0` (binary_scan.rs:1366). Ephemeral p_ids are minted
only during overlay translation, and under an overlay that same scan takes
the eager branch (binary_scan.rs:1488) and emits a resolved `Binding::Sid`.
So an ephemeral p_id can never reach this formatter as an `EncodedPid`.
Adds a renderer test that drives the encoded-subject arm from a real query
rather than a hand-built binding, and asserts before rendering that the
engine put an `EncodedSid` in the batch whose ID the base store cannot
resolve — the two conditions that together make the store-only resolver
wrong — so the guard cannot go quietly vacuous.
The end-to-end test moves to that same shape. Joining the novelty subject
in through a literal — the reported repro's shape — never reaches the arm:
subjects arrive already materialized as `Binding::Sid`, so that version of
the test passed with the whole `EncodedSid` arm deleted. A reference-edge
join against a typed object keeps `?s` late-materialized. Reverting the
resolver line now reddens both tests, the table showing
`(unresolved s_id=3659174697238532)` where `urn:m9` belongs.
`status["status"].as_str()` is an `Option<&str>`, so Debug-printing it in
the catch-all rendered `unexpected remote import status: Some("weird")` —
the Rust container rather than the value the server actually returned.
Same class as the merge-preview conflict listing.
Falls back to the raw JSON when the field is absent or isn't a string
(`null`, a number, an object), so the message still names what arrived.
|
Thanks @bplatz — all three landed, and the third one turned out to be more important than either of us thought. Leading with the correction, because it changes the framing of the whole PR. You're right that the integration test didn't reach the arm — I reverted the resolver and it passed, exactly as you found. But chasing a shape that does emit A reference-edge join emits an unresolved I verified by instrumentation rather than debug markers, per your caution — a temporary probe recording the binding variant per output variable across ~20 shapes, plus a per- The integration test now uses that shape, and there's a new On the placeholder — agreed, and the On the predicate wording — you're right, and thank you for catching that the decision was right for the wrong reason, which is the version that gets built on. The body claimed predicates have no novelty layer; Also folded in Since the framing section changed materially, the body is worth a re-skim — it now says the symptom is live rather than incidentally fixed. |
Fixes #1466
Where the reported symptom actually stands
#1466 reported
EncodedSid { s_id: .., t: None, op: None }turning up in a--format tablecell. The query shape in that report no longer reproduces — I ran it at47e96b7b6and the novelty-only subject renders as its IRI every time. For a while I thought that meant the bug had been fixed incidentally somewhere in the engine emit-path work since v4.1.2. It hasn't. The symptom is live onmain; it just needs a different join shape, and I did reproduce it verbatim.Indexed ledger, one commit on top that isn't indexed, then a query that joins through a reference edge rather than a literal:
The difference is which bindings survive to the formatter. I instrumented
sparql_table_cellto record the binding variant per output variable across ~20 shapes on an indexed-plus-novelty fixture. Under the reporter's literal join,?mand?kindarrive asBinding::Sidand?contentasEncodedLit— zeroEncodedSid, so that shape would render correctly even with the entireEncodedSidarm deleted. Under a reference-edge join against a typed object,?sstays late-materialized and reaches the formatter asEncodedSid; for a novelty-only subject that's ans_idthe persisted store cannot resolve. Same forOPTIONAL { ?s <knows> ?o }, a two-hop?a <knows> ?b . ?b <knows> ?c, and a three-predicate star.On the
Fixesline: the issue was rescoped in a comment to "cli: table renderer should use novelty-aware encoded-binding resolution and never Debug-print bindings", which is exactly what this PR does. It also fixes the original symptom under the shape that still produces it, so the closure holds against the issue as it reads now and as it was first reported.The gap
fluree-db-cli/src/output.rs:188resolvedBinding::EncodedSidthroughgv.store().resolve_subject_iri— the base-store resolver, which consults only the persistedsubject_forward_packs(fluree-db-binary-index/src/read/binary_index_store.rs:1302). A subject first seen after the index snapshot lives inDictNovelty, so that lookup fails. All six encoded-binding arms then fell back toformat!("{b:?}")— the internal struct'sDebugrepr — straight into a table cell.The novelty-aware resolver already exists one level up.
BinaryGraphView::resolve_subject_iri(binary_index_store.rs:2436) triesdict_noveltyfirst, then the store, then the novelty subject dict as a fallback. It's what every API formatter reaches throughfluree-db-api/src/format/materialize.rs:52-57, whoseEncodedSidarm is explicitly commented "Novelty-aware: subjects first seen after the index snapshot resolve from DictNovelty". The CLI table fast path reads raw batches and bypasses that materialization pass, so it was the one remaining formatter in the tree using the store-only resolver behind aDebugfallback.That's the same class as the newtype-
Displayfootgun we've hit before: an internal repr with a plausible-looking string form leaking into something a user reads.What changed
The resolver swap (
output.rs:227).Binding::EncodedSidnow goes throughgv.resolve_subject_iri, matching the API formatters. Two lines, and it's the whole correctness fix.All six
{b:?}fallbacks become a placeholder that carries the ID (output.rs:182). A failed resolve now renders(unresolved s_id=3659174697238532)/(unresolved p_id=…)/(unresolved o_kind=… o_key=… p_id=…)and emits atracing::warn!naming the ID and whether the failure was a missing graph view or a resolver miss. Even with the resolver fixed, the fallback is the actual guarantee — it's what makes the class impossible rather than merely unlikely.Two things drove that shape. A bare marker throws away the one datum worth having: every unresolvable binding would collapse to identical text, so two distinct broken rows look alike, and for an arm this cold the day it fires is the day you want the ID. And something like
<unresolved>in RDF-facing output reads like a relative IRI — a user can reasonably parse that cell as a subject actually namedunresolved. The parenthesised form can't be mistaken for one. This follows what the rest of the tree already does with the same failure: the API formatters hard-error with the ID in the message (fluree-db-api/src/format/materialize.rs:63), and the materializer fabricates_:unknown_p_{p_id}alongside atracing::warn!(fluree-db-query/src/materializer.rs:669-673). TheEncodedPidarm had no logging beneath it at all before this — it's anOption, and aNonejust vanished. (CLI logs are off by default;--verbosesurfaces them.)The predicate arm deliberately keeps
gv.store().resolve_predicate_iri, andoutput.rs:232-251now records why. The reason is not that predicates have no novelty layer — they do have one:EphemeralPredicateMap(fluree-db-query/src/binary_scan.rs:2577), routed byDictOverlay::resolve_predicate_iri(dict_overlay.rs:291). The reason is reachability. The engine has exactly one construction site forBinding::EncodedPid(binary_scan.rs:1486), and it's gated onlate_materialize, which requiresoverlay.epoch() == 0(binary_scan.rs:1366) — no novelty overlay at all. Ephemeral p_ids are minted only during overlay translation, i.e. only when an overlay exists, and under an overlay that same scan takes the eager branch (binary_scan.rs:1488) and emits an already-resolvedBinding::Sid. So an ephemeral p_id can't coexist with the path that puts anEncodedPidin front of this formatter, and the index root's inline predicate dict is complete for every p_id that can. Every other formatter in the tree resolves predicates the same way (fluree-db-api/src/format/sparql_xml.rs:302,fluree-db-api/src/lib.rs:4580,fluree-db-query/src/sort.rs:93). Only the fallback changed there.commands/branch.rs:1248— one more from the audit sweep.merge preview's conflict listing Debug-printed anOption<Sid>, so a line reads=ex:a p=ex:b g=Some("http://ex/g")whilesandpright beside it rendered plain IRIs. A key with no graph is in the default graph, so it says<default>now.commands/create.rs:265— same class again.status["status"].as_str()is anOption<&str>, and the catch-all Debug-printed it, so an unrecognised status rendered asunexpected remote import status: Some("weird"). It now prints the value the server actually sent, falling back to the raw JSON when the field is absent or isn't a string (null, a number, an object), so the message still names what arrived.The audit — what I looked at and what I left alone
I swept the CLI crate for
{:?}reaching user output. Beyond the eight sites fixed above, everything else is deliberate or harmless, and I'd rather name each than silently leave them:commands/create.rs:685{phase:?}goes into a JSON crash-breadcrumb file. Leave.commands/create.rs:1122,1164(EdgePolicy),commands/server.rs:1156(server_role),commands/track.rs:118(RemoteEndpoint),commands/multi_query.rs:271(OutputFormat),commands/materialize.rs:149(MaterializeVerify)Displayimpl.{:?}prints a bare variant name — no struct guts, nothing that can leak an ID. Cosmetic casing at worst (Quickvsquick). Scoped out.commands/load.rs:266{s:?}is deliberately quoting user input in an error message so an invisible character is visible. Correct as-is.commands/materialize.rs:356{:?}onCheckOutcomein the verify parity report — this one does print struct guts, but it's a developer-facing diagnostic where the payload is the content. I don't think it belongs in this PR, but I'm flagging it in case you disagree.remote_client.rs,context.rs,mcp/ide.rs, …)I also checked the rest of the tree for the same store-vs-view mistake. After this change,
grepforstore().resolve_subject_irioutside tests turns up onlyfluree-db-query/src/dict_overlay.rs:220,241— and that one does its own watermark routing (dict_overlay.rs:212-250), so it's already novelty-aware by construction.output.rswas genuinely the only novelty-blind site, and there are none left.Tests
Four renderer-level guards in
output.rs, plus one end-to-end intests/integration.rs:novelty_only_encoded_sid_from_a_real_query_renders_its_iri— the one that proves the arm is on a live path. It runs the reference-edge join through the real query engine, then, before rendering anything, asserts that the engine actually put anEncodedSidin the batch and thatgv.store().resolve_subject_irican't resolve its ID. Those two conditions together are exactly what makes the store-only resolver wrong; asserting them means the guard can't quietly go vacuous if plan selection changes or the fixture stops being novelty-only. It then renders throughformat_sparql_table_from_resultand asserts the IRI appears and noEncoded*or placeholder does.encoded_sid_from_novelty_renders_iri_not_debug_repr— the same property at the single-cell level, on a hand-built binding, with the same store-can't-see-this non-vacuity assert.unresolvable_encoded_bindings_render_placeholder— an unresolvableEncodedSid/EncodedPid/EncodedLit, with and without a graph view, all six paths. Asserts the placeholder shape, that it carries the ID, that it contains noEncoded*, and that it doesn't start with<(i.e. can't be read as an IRI).unresolvable_binding_inside_list_renders_placeholder— the Cypher list/map arms recurse through the same cell function, so the placeholder and its ID have to hold there too.table_output_renders_novelty_only_subject_after_index— the repro end to end through the real binary:insert→index→insert→query --format table. This used to use the reporter's literal-join shape, which as noted above never reaches theEncodedSidarm; it now uses the reference-edge shape that does.Checked these aren't vacuous by reverting the two-line resolver change and re-running. Both
EncodedSidtests and the end-to-end test fail, and the rendered table shows the placeholder in place of the subject:Reverting the fallback as well as the resolver puts the original
EncodedSid { .. }back in that cell, which is the repro quoted at the top.Gates
cargo test -p fluree-db-cli— 346 passed, 0 failedcargo clippy -p fluree-db-cli --all-targets --no-deps— cleancargo fmt --all— clean (run last)