Repository navigation
docs(common): render_criterion's docstring must name the separators it passes - #997
Merged
NandhaKishorM merged 2 commits intoOct 7, 2026
Conversation
…t passes
The docstring promised structured criterion values "become compact JSON". Compact JSON is
separators=(",", ":"); the implementation at laya/common.py:109 passes
separators=(", ", ": "), the default spelling, so a two-member dict renders as
`{"a": 1, "b": 2}` and a list as `["a", "b", "c"]`. tests/test_criteria.py:50 and
tests/test_batch.py:331 already assert the space-padded bytes, so the docstring was the only
surface claiming the opposite.
Reworded to state both halves of what the code really does -- a single-line JSON document with
the default separators -- leaving behaviour untouched. Added a gate to tests/test_criteria.py:
AST-reads render_criterion's docstring, bans "compact" in it at all, requires it to spell both
`", "` and `": "` and to keep the single-line promise, reads the separators tuple out of the
json.dumps call in the same AST rather than retyping it, and live-checks the bytes for a dict
and a list, including that they differ from a genuinely compact dump.
Suite 198 -> 208 (+10 checks; baseline measured in a detached a4a8921 worktree); mutation
harness laya-bench/mutate_render_criterion_separators.py catches 4/4 mutants: the pre-fix
docstring, "compact" reintroduced beside the separators, the separator spelling dropped, and
the code switched to genuinely compact separators.
…the routing/language-detection step -- a native crash on the runner, not an assertion; the same commit is green on the other four matrices)
Owner
|
Merged in 0.3.29.
|
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.
What
Fixes
render_criterion's docstring inlaya/common.pyand adds a gate intests/test_criteria.pythat holds it to the separators the implementation actually passes.Why
The docstring said:
laya/common.py:109is:Compact JSON is
separators=(",", ":").(", ", ": ")is the default, space-padded spelling --the opposite of what the docstring promises. Two existing tests already assert the space-padded
bytes, so the code is right and the docstring was the only stale surface:
tests/test_criteria.py:50—check("criterion/list -> json", render_criterion(["a", "b"]), '["a", "b"]')tests/test_batch.py:331—("dict level", [{"a": 1}], {"0": '{"a": 1}'}), ("list level", [[1, 2]], {"0": "[1, 2]"})The word "compact" also reads as a promise about prompt bytes, which is the one thing a caller
cannot re-derive:
render_criterionoutput goes into the tokenized prompt, so whether a memberseparator costs a token is a question the maintainer will be asked. Naming the separators makes
the claim checkable.
How
Docstring now states both halves of what the code does, and behaviour is untouched:
The gate added at the bottom of
tests/test_criteria.py:render_criterion's docstring out oflaya/common.py(not a copy of the text);"compact"anywhere in it, case-insensitively;", "and": ", and to keep stating the property "compact" wasreaching for (
"single-line JSON");separators=tuple out of the samejson.dumpscall via AST and pins it to(", ", ": "), so the doc and the code are held to each other rather than to this test file;render_criterion({"a": 1, "b": 2}) == '{"a": 1, "b": 2}', that theresult differs from
json.dumps(..., separators=(",", ":")), that it stays on one line, andrender_criterion(["a", "b", "c"]) == '["a", "b", "c"]'.Verification
198 passed, 0 failed— measured in a separate detached worktree ata4a8921,removed after the run, so the number is the base commit's own count.
208 passed, 0 failed(+10 checks).ruff check laya/ --select=E9,F63,F7,F82,F401,F811 --line-length=120→ All checks passed; sameselection on
tests/test_criteria.py→ All checks passed.python -m compileall -q laya/ tests/→ silent.laya-bench/mutate_render_criterion_separators.py→ 4/4 CAUGHT, tree restored:"compact"reintroduced alongside the separator sentence ("compact single-line JSON", whichthe first draft's
"compact JSON"ban missed) → now caught by the case-insensitive ban;(",", ":")→ the AST separator pin fails, the live bytecheck fails, and the "dict is not compact" witness fails.
sk-…,ghp_…,AKIA…, PEM header,Bearer …,api_key=…): 0 matches.Deconfliction
gh pr list --repo NandhaKishorM/laya --state open --json files—laya/common.pyis touched byfeat(train): add early stopping, disjoint validation split, and budget-independent schedules (#963) #982, feat(encoder): add opt-in residual bottleneck adapters #921, fix: make choice criteria permutation-invariant#779 #783 and perf(agent): tokenize only the prefix of state a sequence holds, and make state_tokens opt-in #687; none of them edit
render_criterion. perf(agent): tokenize only the prefix of state a sequence holds, and make state_tokens opt-in #687 inserts a new functionabove it, so its hunk shows the
def render_criterionline as trailing context only; this PRedits lines inside the docstring, which are different lines from that insertion point.
tests/test_criteria.pyis touched by fix(agent): comprehensive input validation for questions, instructions, and state (#707) #716 at one hunk,@@ -339,6 +339,7 @@— this PR appendsafter the
truncate_leftblock near line 605, so the hunks are disjoint.the tree (
grep -rn compact docs/ README.md tests/ laya/→ only this PR's own new lines).Checklist
CONTRIBUTING.md/AGENTS.md.ruff,compileall, test suites) pass locally.