Skip to content

fix(transforms): join and sentence_repair treat a non-string var as absent - #405

Merged
znat merged 4 commits into
mainfrom
fix/envelope-non-string-vars
Nov 6, 2026
Merged

znat merged 4 commits into
mainfrom
fix/envelope-non-string-vars

Conversation

@znat

@znat znat commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

join and sentence_repair now treat a var that is not a string as absent. Before this, a user stage that published a number or true where they expect text made each script raise. The script caught it and gave up: join left the clip unjoined, and sentence_repair lost every rule and reported declined: failed: .... These are the two bugs mypy --strict found in #404. Their # type: ignore lines go. When the vars are strings, both scripts give the same output as before.

Review the two small hunks in join.py run() and sentence_repair.py written_by_vocabulary(). The rest is test cases.

What failed, and what it does now: same envelope, main against this branch

Each script is fed one invented envelope on stdin. Python 3.9.6 and 3.13.7 print the same.

Script Var main branch
join input.before = 7 i think you should. try this, applied: "" i think you should try this, applied: "stop at a pause"
join input.after = true, before a string the cache should be smaller., applied: "" The cache should be smaller., applied: "line start"
join both strings The cache should be smaller., line start same
sentence_repair vocabulary.protected = 7 Notes kept, declined: "failed: 'int' object has no attribute 'split'" notes, capitals: 1, declined: ""
sentence_repair vocabulary.protected = true declined: "failed: 'bool' object has no attribute 'split'" notes, capitals: 1, declined: ""
sentence_repair vocabulary.protected = "Notes" Notes kept same

Swift publishes both vars as strings, so the app does not reach either bug today. vocabulary is a reserved stage name, so only the input case can come from a user stage.

Tests: five new cases fail on main and pass here

Commits are ordered test first, then fix, for each script.

  • join/cases.yaml: three cases with before: 7, before: true with after: true, and a string before with after: 7. On main scripts/check-join.sh gives 46/49 ("right answer, wrong rule", nothing applied). Here it gives 49/49.
  • sentence_repair/cases.yaml: two cases with protected: 7 and protected: true. score.py reads the new protected: case key as the raw value the vocabulary stage published, in place of written:. On main score.py stops with AttributeError: 'int' object has no attribute 'split'. Here it gives 48/48. Both cases reuse inputs already in envelopes.json, so nothing is recorded again.

Old cases print the same lines as main in both scorers. The only diff is the new lines and the totals.

Why the output is the same when the vars are strings, and why no live gate

The change is a type guard and nothing else.

  • join: for a str or None, before and after keep their value, so join() and unstopped() get the same arguments.
  • sentence_repair: for a str, the loop runs protected.split("; ") exactly as before. For None, "", 0 or False, main split "", which yields no token, and the branch skips the loop. Same set.

Checked on the binary. Main's release binary and this branch's ran --pipeline on four invented texts, one after the other. The pipeline is a stub input stage that publishes before/after from a file, then sentence_repair, then join. Runs: plain (parse: false, readings: false) and with the parse and readings (--warm). With string vars or no vars, all 20 runs (12 plain, 8 with the parse and readings) give byte-identical stdout with --vars, once the .ms timing lines are removed. With a number or true under input, 11 of 12 runs differ, and only in join's lines: main applies nothing, the branch applies line start or clip stop dropped. The 12th is a two-sentence clip that join leaves alone on both sides.

No live gate: no Swift changes, and no output changes for any string input.

The other type: ignore lines hide no bug

Two remain, both in join.py, both [call-overload] at lines 195 and 424. mypy types the {} fallback in (envelope.get("ctx") or {}) as dict[Never, Never]. At run time {}.get(...) returns None and the next or {} handles it. Line 195 also checks isinstance(published, dict) and passes the value through str(...). sentence_repair.py had only the one ignore this PR removes.

Checks: main and branch print the same

check-envelope, check-python-runner, check-sentence-case, check-schema, check-catalogue, check-default-config, check-upgrade-config, check-pipeline-config and check-transform-folders all pass on both sides. Their output is the same once temp paths are removed. With the models in a scratch home, check-bare-capital (39/39), check-french-boundary (27/27) and check-sentence-join also print the same on both sides. check-join goes from 46/46 to 49/49. Not run locally: check-python-types.sh, because mypy is not installed here (CI runs it and passes); check-grammar, which needs Ollama and does not read either script. Local CodeRabbit review: 0 findings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WfxPEjc1EEGqG2rHoJcLJ2

znat and others added 4 commits November 6, 2026 08:56
Three cases put a number or `true` in place of `before` and `after`.
They fail on main: `.strip()` raises, `run` returns the clip unchanged,
and no rule fires.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WfxPEjc1EEGqG2rHoJcLJ2
Signed-off-by: Nathan Zylbersztejn <[email protected]>
`ctx.vars.input.before` and `after` are read only when they are strings.
Before this, a number or a boolean there made `.strip()` raise, `run`
caught it, and the clip was neither joined nor unstopped.

The `# type: ignore[arg-type]` on the `join` call goes: mypy now sees
`str | None`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WfxPEjc1EEGqG2rHoJcLJ2
Signed-off-by: Nathan Zylbersztejn <[email protected]>
…protected

`score.py` reads a new case key, `protected:`, the raw value the
`vocabulary` stage published, in place of `written:`. Two cases set it
to 7 and to `true`. They fail on main: `.split` raises in
`written_by_vocabulary`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WfxPEjc1EEGqG2rHoJcLJ2
Signed-off-by: Nathan Zylbersztejn <[email protected]>
… string

`written_by_vocabulary` now reads `protected` only when it is a string,
as it already does `before` and `judged`. Before this, a non-empty
number or `true` there made `.split` raise, `run` caught it, every rule
was lost, and `declined` said `failed: ...`.

The `# type: ignore[union-attr]` goes: mypy now sees `str`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WfxPEjc1EEGqG2rHoJcLJ2
Signed-off-by: Nathan Zylbersztejn <[email protected]>
@greptile-apps

greptile-apps Bot commented Nov 6, 2026

Copy link
Copy Markdown

Automatic reviews are disabled for this repository. Configure in Code Review Settings.

@znat

znat commented Nov 6, 2026

Copy link
Copy Markdown
Owner Author

Local CodeRabbit review (coderabbit review --agent --committed --base-commit dd3913cd): 0 findings. It reviewed 5 files: join/cases.yaml, join/join.py, sentence_repair/cases.yaml, sentence_repair/score.py and sentence_repair/sentence_repair.py. Nothing to fix or answer.

@coderabbitai

coderabbitai Bot commented Nov 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 20 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5ed560e2-9926-4e5a-9dda-0c37281a580e
Commits

Reviewing files that changed from the base of the PR and between dd3913c and eb40a64.

Files selected for processing: 5

  • built-in/transforms/join/cases.yaml
  • built-in/transforms/join/join.py
  • built-in/transforms/sentence_repair/cases.yaml
  • built-in/transforms/sentence_repair/score.py
  • built-in/transforms/sentence_repair/sentence_repair.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@znat
znat merged commit 43a18e5 into main Nov 6, 2026
6 checks passed
@znat
znat deleted the fix/envelope-non-string-vars branch November 6, 2026 08:28
@znat znat mentioned this pull request Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant