Repository navigation
Canonicalize every object in a catalog's canonical document - #727
Draft
dajiaohuang wants to merge 1 commit into
Draft
dajiaohuang wants to merge 1 commit into
dajiaohuang wants to merge 1 commit into
Conversation
Catalog#to_yaml writes a canonical document whose digest is how a catalog is compared, and docs/framework/evaluations.md says object key order does not change that digest. Only a scenario's extension fields were sorted, though, so the same catalog written with any other object's keys in another order hashed differently. A catalog document lives in a JSON column, which hands keys back in its own order -- jsonb sorts them -- so a document the dashboard exported and re-imported could preview as a change and write a new digest. Route the catalog's, a product's and a set's extension fields, their criteria, pass bars and judge, and a scenario's params and expect through the same canonicalizing step the scenario extensions already used.
This branch has not been deployed
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.
A catalog's digest depends on its object key order
Catalog#digestis how two copies of a scenario catalog are compared withoutdiffing them, and
docs/framework/evaluations.mdstates the contract thedigest is meant to hold:
Only a scenario's extension fields were actually canonicalized. Every other
object the canonical document carries went into the YAML in whatever order it
arrived in, so the same catalog hashed differently depending on key order.
Path and wrong result
A catalog document is stored in a JSON column (
jsonbon PostgreSQL, whichsorts object keys;
jsonelsewhere).ScenarioCatalogImportwrites it withparse(document).digest(actionagent/app/services/action_agent/scenario_catalog_import.rb:55)and
ScenarioCatalog#refresh_document!rewrites it from the records(
scenario_catalog.rb:97). Because the digest was order-sensitive for theseobjects, a document the dashboard exported and re-imported could compare
unequal and preview as a change, writing a new digest for a catalog whose
content never changed.
Affected objects, each proven below: the catalog's, a product's and a set's
extension fields, a product's
criteriaandpass, a set'scriteria,passandjudge, and a scenario'sparams. A scenario's extension fieldswere already sorted, and its
expectblock is written from theScenariostruct in a fixed shape, so those two were already stable.
Proof
The failing case, against pristine
9e802e7, using only the publicActiveAgent::Evals::CatalogAPI:Before, on base
9e802e7:After:
The regression test is the discriminating check, run on both sides with the
same command and the same file:
9e802e7, library reverted, test unchanged:1 failures(
catalog metadata keys in another order must read as the same catalog, twodifferent 64-hex digests),
9 runs, 41 assertions9 runs, 51 assertions, 0 failures, 0 errors, 0 skipsThe fix
lib/active_agent/evals/catalog.rb: the canonical-document writer passed thecatalog's, a product's and a set's extension fields, their
criteria,passand
judge, and a scenario'sparamsstraight through, whilecanonical_metadatasorted only a scenario's extensions. Those call sites nowgo through that same step, renamed
canonicalsince it is no longer aboutmetadata alone. Nothing else changes: the sort was left as
keys.sort(everyobject reaching it has already been deep-stringified by
Catalog#initialize),Catalog#to_his unchanged, and a document already written in canonical orderkeeps its digest byte for byte.
What I validated
test/evals/catalog_metadata_test.rb,catalog_test.rb,standalone_load_test.rb,suite_test.rb,pass_thresholds_test.rb,scenario_parser_test.rb,report_test.rb,test/cli/cli_test.rb—230+ runs green on the final head.
actionagent/test/'sscenario_catalog_test.rb,catalog_scenario_metadata_test.rb,catalog_pass_bars_test.rb,catalog_product_criteria_test.rb,scenario_catalog_entries_api_test.rb,scenario_catalogs_api_test.rb—green. A wider 269-run sweep of the catalog, evals and CLI files was green
too.
What I did not do
bin/testsuite to completion on the final head. Iran it once on the pristine base (before the change) and it reported 12
failures, all of which I traced to this checkout's line endings
(
core.autocrlfhad rewritten the generator templates to CRLF and converteda binary PDF fixture); after re-checking out with LF, the two affected files
passed, so I recorded them as environmental rather than related to this
change.
rubocop: it is not in therails8.gemfilebundle in thischeckout (
can't find executable rubocop for gem rubocop), so lint isunverified here and will be checked by CI's
lintjob.jsonbdirectly. Thejsonbkey-sortingbehaviour is the motivation for the fix, not something this change relies
on: the test proves order-independence with plain Ruby hashes, which is the
stronger statement.
Unreleased → Fixed, because the docs already described the behaviour this PR
restores.