Skip to content

refactor(fit): the two-line rule is a screen rule, not policy data - #18

Merged
anthonyma94 merged 6 commits into
masterfrom
refactor/cue-policy-lines
Dec 5, 2026
Merged

anthonyma94 merged 6 commits into
masterfrom
refactor/cue-policy-lines

Conversation

@anthony-hermes

@anthony-hermes anthony-hermes Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

The code half of the decision that a line count is a screen rule, not language data. Lane 05 and FT5.2 are updated in #17; this is the implementation.

  • CuePolicy no longer carries max_lines. The fit lane reads MAX_DIALOGUE_LINES from pipeline/types.py, which is where the two-dialogue, two-graphics, three-on-screen budget already lives.
  • Behaviour is unchanged: dialogue is still one or two lines, and the constructor still refuses a third.
  • Two tests used a one-line policy to force a trim; they now use a narrow max_chars_per_line, which is the same pressure through a property a profile actually owns.
  • run_job builds its policy straight from the profile's cue table, so the headless command (feat(pipeline): headless command and the slow end-to-end test #13) passes no line count either.

Why it matters: with max_lines in the policy, a hand-edited profile could ask for three dialogue lines and the fit lane would happily produce a frame the writer's own budget refuses. Removing the field makes the contradiction impossible rather than merely caught.

Master is merged in at 298fa97. make check on forge at 5e3810f: ruff format and lint clean, mypy clean over src and tests, pytest 346 passed, exit 0.

CuePolicy drops max_lines and the fit lane reads MAX_DIALOGUE_LINES
from types, so a profile can no longer ask for a line count that the
screen budget forbids. Behaviour is unchanged: dialogue is still one or
two lines, and the tests that used a one-line policy to force a trim now
use a narrow width instead.
@anthony-hermes
anthony-hermes Bot requested a review from anthonyma94 as a code owner December 4, 2026 18:57
@anthony-hermes

anthony-hermes Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged the trimmed suite and ported the screen budget into it.

  • POLICY.max_lines is gone from the tests; assertions now bound lines by MAX_DIALOGUE_LINES, and the "tighter profile changes the lines" test uses three words so the trim still happens without a line setting.
  • Carries test: keep only user-facing behavior across the pipeline suite #23's cleanup: test_cues 30 to 20, test_speakers 18 to 8, and the same cuts across the other pipeline test files.

193 tests, make check exit 0, CI green.

@anthony-hermes

anthony-hermes Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Hermes PR Review

Reviewed commit: 5e3810fa6eb479f0a55a494ea62c86134c7a0168

Review status: No actionable findings

Executive summary

The PR removes the duplicated max_lines field from CuePolicy. The fit lane now reads the two-line dialogue ceiling directly from types.MAX_DIALOGUE_LINES. Production behaviour is unchanged because the only production caller previously passed max_lines=MAX_DIALOGUE_LINES, and language profiles already refused a max_lines key in both the Pydantic settings and the JSON Schema. Tests were updated to build policies with the four real policy numbers and to assert line budgets against the shared constant.

The reviewed head carries a merge of master at 298fa97417aa3d61ea5d56c7a1721c8434eeca95, which brought the headless command's run_job call site; that call site no longer passes the removed keyword. The full gate passes. This is not an approval.

Findings

No actionable findings. The changed files, their callers, the surrounding fit and profile code and the relevant tests were reviewed. No user-visible defect, regression, edge case, integration mismatch or meaningful test gap was identified.

Previously reported findings

None; this is the first review.

Verification

  • PATH=/home/hermes/.hermes/work/subsmith/.venv/bin:$PATH make check in the reviewed worktree: exit 0. Ruff format check reported 48 files already formatted, Ruff lint passed, mypy passed over 48 source files, pytest reported 346 passed and 7 deselected, and the script printed check: pass. The reviewer child reported 350 passed from the same command; the coordinator re-ran it and the count above is the one this report stands on.
  • git diff --name-only 298fa97417aa3d61ea5d56c7a1721c8434eeca95...5e3810fa6eb479f0a55a494ea62c86134c7a0168: exit 0. Only four source and test files changed. AGENTS.md, CONTRIBUTING.md, CI config and dependency manifests were not touched, so there was no instruction or manifest delta to compare.
  • CI workflow run 47571464911 on 5e3810f: completed, success.
  • Reviewer route: edi/alt, pass 1 of 3.
  • Not run: no mutation experiments were needed because there are no confirmed findings. No network fetch or PR write was performed by the reviewer.

Implementation walkthrough

Overview

The fit lane used to accept a line count as policy data. That count was never language data: every production policy was built with the same constant, and docs/spec/05-fit-and-timing.md and docs/spec/11-languages.md already describe line counts as screen rules under FT5.9. This PR aligns the code with that description. CuePolicy now contains only the four numbers that describe how the target language reads, plus two timing defaults. The screen budget is referenced from types.py wherever the fit lane needs it.

Execution flow

  1. _run_job in src/subsmith/pipeline/run.py transcribes and translates the job. Around line 230 it builds policy = CuePolicy(**pair.target.cue.model_dump()). CueSettings in src/subsmith/languages/profile.py has four fields: max_chars_per_line, max_cps, min_duration_ms and max_duration_ms, with extra="forbid". No line count reaches this constructor.
  2. fit_cues in src/subsmith/pipeline/cues.py pairs segments with translations using build_drafts, then shapes each draft with _fit_one. The chain tries minimum-duration extension, turn-boundary splitting when a cue holds more than two speakers, clause-boundary splitting, extension into following silence, condense through the injected hook, and finally trim. Each decision is recorded as an Adjustment.
  3. Fit checks use _turns_fit, which wraps turns with wrap_turns, counts the two-character » marker inside the width, and compares the line count with MAX_DIALOGUE_LINES. line_shape_ok does the same for plain text. trim falls back to _hard_trim, whose capacity is MAX_DIALOGUE_LINES * policy.max_chars_per_line, identical to the old policy.max_lines * policy.max_chars_per_line because production always supplied 2.
  4. _finalize re-wraps each draft, raises FitError if displayed lines exceed MAX_DIALOGUE_LINES, renumbers cue ids and adjustment cue ids, and returns FitResult. Cue.__post_init__ in src/subsmith/pipeline/types.py independently enforces the FT5.9 block budget: at most three total lines, at most two graphics lines and at most two dialogue lines.
  5. The updated tests construct policies with four fields and assert line budgets against the shared constant. test_policy_is_only_data_so_a_tighter_profile_changes_the_lines narrows max_chars_per_line to 3, observes a logged trim, and asserts the resulting two display lines.

Implementation decisions

  • The line count is defined once in types.py and read by the fit lane, instead of being copied through every policy instance.
  • The profile lane needed no change: its settings model, shipped TOML defaults and JSON Schema already exclude line counts.
  • The previous sole production caller injected the same constant, so removing the field does not change job output.
  • The FitError message in _finalize now names the screen budget rather than the profile, which matches the source of the limit.
  • Tests assert observable output (the trim and the resulting lines) rather than a configuration field.

Assumptions and invariants

  • MAX_DIALOGUE_LINES remains 2 and continues to match FT5.9 and the Cue invariant in types.py.
  • CueSettings.model_dump() exposes exactly the four numbers CuePolicy requires.
  • Cues from the fit lane have graphics_count == 0; graphics are handled downstream in ass.py and bounded by Cue.__post_init__.
  • No caller in the tree passes max_lines to CuePolicy. The only remaining max_lines mentions are unchanged documentation and test fixtures that assert it is refused.

Changed files

  • src/subsmith/pipeline/cues.py: the pure fit lane. Removed max_lines from CuePolicy, its validation list and its docstring. The import from types.py now includes MAX_DIALOGUE_LINES; five former policy.max_lines reads became constant reads, including _hard_trim capacity and the _finalize failure message.
  • src/subsmith/pipeline/run.py: job orchestration. Removed the MAX_DIALOGUE_LINES import and the explicit keyword argument, so the policy comes only from the target profile's four numbers.
  • tests/pipeline/test_cues.py: fit unit tests. Removed max_lines from four policies, changed the policy-data case to use a narrower line width and assert the observable trim, and replaced line-budget assertions with the shared constant.
  • tests/pipeline/test_speakers.py: two-speaker tests. Removed max_lines from the POLICY and NARROW fixtures and switched the whole-fit line assertion to the shared constant.

Assumptions and risks

  • The main risk in this kind of refactor would be a caller still passing the removed keyword, or a fit path still using a different line budget. A tree-wide search found no such caller, and mypy plus the suite passed.
  • The external API surface changes: CuePolicy(max_lines=...) now raises TypeError. This repository has no in-tree caller doing that, and the removal is the stated purpose of the PR. No packaged public API documentation in this tree promises the field.
  • Screen-budget changes now require editing the constant in types.py, which also feeds the Cue invariant. That is a single point of truth, and FT5.9 is covered by existing tests/pipeline/test_types.py cases that this PR did not touch.
  • No migration, configuration rollout, dependency change or CI change is involved.

Recommended human review order

  1. src/subsmith/pipeline/cues.py: start at the CuePolicy definition, then follow line_shape_ok, _turns_fit, _hard_trim and _finalize to confirm each line check uses the same constant.
  2. src/subsmith/pipeline/run.py: confirm the policy constructor receives the target profile's four numbers and no line count is silently dropped.
  3. src/subsmith/pipeline/types.py: confirm MAX_DIALOGUE_LINES still matches FT5.9 and the Cue invariant.
  4. tests/pipeline/test_cues.py: check that the narrowed-width case asserts real output and a logged trim.
  5. tests/pipeline/test_speakers.py: check the two-speaker path where the » prefix consumes line width.

@anthonyma94
anthonyma94 merged commit 2051e3b into master Dec 5, 2026
1 check passed
@anthonyma94
anthonyma94 deleted the refactor/cue-policy-lines branch December 5, 2026 21:36
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