Skip to content

ci: Document with a patched roxygen2 that keeps the sentence gap - #791

Closed
krlmlr wants to merge 9 commits into
claude/readme-goalsfrom
claude/roxygen2-fork
Closed

krlmlr wants to merge 9 commits into
claude/readme-goalsfrom
claude/roxygen2-fork

Conversation

@krlmlr

@krlmlr krlmlr commented Sep 13, 2026 •

Copy link
Copy Markdown
Member

Stacked on #788, which this pull request targets. It does not depend on it, and can be retargeted to main so that it is decided on its own and CI runs on it.

The problem

commonmark discards the whitespace a line break stands for. roxygen2 turns every softbreak into a bare newline, so the .Rd carries a line break with nothing after it and Rd2txt() renders it as a single space. Prose written one sentence per line therefore comes out single-spaced, while the same words wrapped to a fixed width with two spaces after the period keep the gap.

That makes the two styles mutually exclusive: splitting a sentence pair separated by two spaces silently drops one of them. That is what forced the very long single roxygen lines this package used to carry, because joining was the only way to keep the gap.

Only the text renderer is affected. Rd2HTML() and Rd2latex() differ by whitespace that HTML and TeX collapse, and LaTeX applies its own sentence spacing regardless. But text is what ?topic shows, so it is the version most people read.

The change

A new composite action, .github/workflows/roxygen2-fork, installs roxygen2 from upstream with the R/ part of the fork branch krlmlr/roxygen2@f-sentence-spacing applied on top. The repository's own hook, .github/workflows/custom/after-install, runs it in the rcc-smoke job only, before the Roxygenize step; the other jobs do not document and skip it. The step runs with continue-on-error: if the install fails, R-CMD-check.yaml skips Roxygenize and lists the failure in the check summary, so the other checks still run.

The action fetches upstream and the fork by pinned full commit SHAs (upstream-sha and fork-sha, which move together in a reviewed commit), with history but without file contents, and retries the fetches. It computes the diff against their merge base restricted to R/, and applies it with git apply --3way. Restricting to R/ means an unrelated upstream change to a test fixture cannot fail the documentation step. It aborts if the patch is empty or does not apply, rather than silently installing an unpatched build, and afterwards asserts that what it installed really carries the patch.

Config/roxygen2/version becomes 8.1.1.9100: upstream's 8.1.1.9000 with the .9100 suffix, which distinguishes a patched build from upstream's own .9000 development builds. The suffix is stamped with a single-line edit of roxygen2's Version: field. DESCRIPTION is DCF and cannot carry a comment line, since read.dcf() rejects one as malformed, so the explanation lives in a Config/cynkra/roxygen2 field.

Why it is a separate pull request

Taking it changes rendered help across the package; leaving it means the reformatting renders exactly as the package renders today, with one space between sentences. Neither half needs the other to be correct, so they should be able to be decided separately.

man/ is not edited by hand here. The .Rd files are generated output, so CI roxygenises and commits them itself; 16 regenerated .Rd files are part of this pull request's diff as an automated commit, and the hand-written half stays reviewable on its own.

Upstream

The roxygen2 side is krlmlr/roxygen2#8, on the fork, not yet filed with r-lib. It is deliberately narrow: mid-sentence breaks are untouched, links are unaffected, and two guards keep it from firing wrongly: an abbreviation list so a line ending in e.g. or et al. does not gain a mid-sentence gap, and a fix for a determinism bug where a line starting with \doi{} or \code{} gained or lost its gap at random, because the test was reading roxygen2's own random placeholder for protected Rd tags.

Review

A clean-context review found one High and four Medium issues, all fixed; what remains is listed under Accepted limitations, most importantly that nothing of the new setup has run in CI yet.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE

krlmlr and others added 2 commits September 14, 2026 05:43
commonmark discards the whitespace a line break stands for, so roxygen prose written
one sentence per line loses the gap between sentences in the rendered help.
Only the text renderer is affected, which is what `?topic` shows.

A new composite action installs roxygen2 from upstream with the R/ part of
krlmlr/roxygen2@f-sentence-spacing applied on top, and runs just before the
Roxygenize step. It shallow-clones upstream, fetches the branch, applies the diff
restricted to R/ so conflicts in the test files cannot fail it, and aborts rather
than silently installing an unpatched build. It then asserts that what it installed
really carries the patch.

Config/roxygen2/version becomes 8.1.0.9100. The .9100 suffix distinguishes a patched
build from upstream's own .9000 development builds; if upstream moves, the x.y.z part
follows it and the suffix stays. DESCRIPTION is DCF and cannot carry a comment, so the
explanation lives in a Config/cynkra/roxygen2 field.

This is a separate decision from the line-break reformatting below it, and is kept in
its own pull request so it can be taken or left on its own. Without it, the
reformatting simply renders as it does today, with one space between sentences.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WWhverMTZZKgEpUuTK117m
…l escape

The version stamp passed `"\1"` as the replacement in the `sub()` call that derives the `.9100` build number.
R parses `"\1"` in a string literal as the octal escape for `\001`, not as a regex backreference,
so `DESCRIPTION` received a control character where the `x.y.z` prefix belonged,
and `R CMD INSTALL` aborted with "Malformed package version".
The replacement is now `"\\1"`, which reaches the regex engine as a backreference and stamps `8.1.0.9000` to `8.1.0.9100`.

The post-install guard asserted only the `.9100` suffix, which the corrupt `"\001.9100"` also satisfies.
That is why the bug survived the very check that was meant to catch it.
The guard now asserts the whole `x.y.z.9100` shape, and passes `inherits = FALSE` to `exists()`.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WWhverMTZZKgEpUuTK117m
@krlmlr
krlmlr force-pushed the claude/roxygen2-fork branch from ad7af65 to f3e9e4d Compare September 14, 2026 05:43
@krlmlr
krlmlr marked this pull request as draft September 26, 2026 14:44

krlmlr commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

Review of this PR at 3289d28, by a Claude Code reviewer with clean context that read the two hand-written commits (17c10ac, f3e9e4d), ran the action's clone, merge-base, diff, git apply --3way and version-stamp steps against today's r-lib/roxygen2 and krlmlr/roxygen2@f-sentence-spacing, and did a trial merge with the base branch, and posted nothing itself. Line numbers refer to that commit. "Confirmed" means reproduced by running code. The final R CMD INSTALL of the patched roxygen2 and the assertion after it were not run, because the review sandbox refused to install it.

High

1. The new step is the only unguarded step in that part of the smoke test, so any failure in it stops R CMD check for every run. By reading: .github/workflows/R-CMD-check.yaml:190-191 has no id, no continue-on-error and no entry in the "Collect the outcomes of the checks" list, while the comment at .github/workflows/R-CMD-check.yaml:147-150 states that every step from there on is continue-on-error so that one failure does not hide the others. The action exits non-zero on four separate conditions (.github/workflows/roxygen2-fork/action.yml:39 and :43 when either clone or fetch fails, :48-52 when no merge base is found, :62-67 when the patch is empty, :73-78 when it conflicts), and there is no retry. Each of those then skips Roxygenize, the commit step, R CMD check, coverage and the pkgdown build, on pushes to main, on every pull request and on the nightly schedule, and the remedy for two of them is a rebase of a branch in a personal fork. Failing loudly instead of installing an unpatched build is the right instinct; the blast radius is the problem. Suggested fix: give the step an id and continue-on-error: true, add it to the outcomes list, and run Roxygenize only when it succeeded, so a failed install costs the documentation step and nothing else; add a retry around the two network calls.

Medium

2. The job executes code from a mutable branch of a personal fork with a write token. By reading: the defaults at .github/workflows/roxygen2-fork/action.yml:15 and :19 name a branch, not a commit, and the patched package is then run by Roxygenize inside rcc-smoke, which holds contents: write, pull-requests: write and actions: write (.github/workflows/R-CMD-check.yaml:93-97) and pushes commits back. Whoever can push to that branch can run code with that token on the next scheduled run, with no review in this repository. The existing workflow already trusts unpinned sources (r-lib/roxygen2 at .github/workflows/R-CMD-check.yaml:132, the cynkra/cynkratemplate actions at @main), and the fork belongs to this package's maintainer, so the increment is modest, but it moves the trust boundary from two organisations to a personal account. Suggested fix: pin the fork to a full commit SHA, and bump it in a reviewed commit.

3. Upstream is taken at its moving tip with a 50-commit window, and both have already drifted. Confirmed: today upstream r-lib/roxygen2 is at c0ba461, 12 commits past the branch point 1d79aa6 (4 September), so about a quarter of the --depth 50 window at .github/workflows/roxygen2-fork/action.yml:39 and :43 is used after seven weeks; once it is exceeded, git merge-base fails and finding 1 applies. The patch still applies cleanly today (R/markdown.R and the new R/sentence-spacing.R). Upstream's version is now 8.1.1.9000, so the stamp at :86-92 produces 8.1.1.9100, not the 8.1.0.9100 recorded in DESCRIPTION:146; the next CI run will rewrite that field. More generally every upstream commit can change generated man/ in an unrelated pull request. Suggested fix: pin upstream to a SHA or tag as well and move both pins together; that removes the depth limit, the conflict risk between bumps, and the nondeterminism.

4. GitHub reports the PR as not mergeable because of one conflict in DESCRIPTION. Confirmed with a trial merge of claude/readme-goals (9447a87) into this head: the only conflicting file is DESCRIPTION, at the last field. This branch has Config/roxygen2/version: 8.1.0.9100 followed by the new Config/cynkra/roxygen2 field (DESCRIPTION:146-153); the base, through its merge of main, has Config/roxygen2/version: 8.1.1.9000. .github/workflows/R-CMD-check.yaml and all of man/ merge automatically. Resolving it takes merging the base (or main) into the branch, keeping the Config/cynkra/roxygen2 field and setting the version to 8.1.1.9100, which is what the action stamps today; CI then regenerates man/ for whatever main documented with stock roxygen2 in the meantime. Separately, nothing in this PR depends on #788, so retargeting it to main would let it be decided on its own as the description intends; the conflict is the same either way.

5. The step is added to the shared workflow file instead of the repository's hook. By reading: R-CMD-check.yaml is the file that fleet-wide commits on main keep rewriting (for example c15ab37 and 139270b), and it provides ./.github/workflows/custom/after-install for repository-specific steps (.github/workflows/R-CMD-check.yaml:134-136), which exists on main. A local edit at :190-191 is likely to be dropped or to conflict at the next sync, and would then fail silently in the bad direction: stock roxygen2 regenerates all 16 files without the gap. Suggested fix: call the action from custom/after-install/action.yml after merging main, and keep the assertion so a missing patch is noticed.

Low

6. Anyone documenting locally with stock roxygen2 reverts the change, and roxygen2 does not stop them. By reading upstream at c0ba461: when the installed version is older than Config/roxygen2/version, roxygen2 only prints an informational message and still rewrites man/. A contributor on roxygen2 8.1.1 or 8.1.1.9000 will therefore produce a diff that removes the leading spaces from 16 files, and CI will put them back. The Config/cynkra/roxygen2 note in DESCRIPTION:147-153 explains this but nothing enforces it. Suggested fix: mention it in the contributing notes, or accept the churn knowingly.

7. The inputs are interpolated straight into the shell script. By reading: .github/workflows/roxygen2-fork/action.yml:29-31 expands ${{ inputs.* }} inside run:. The values are constants today, so this is not exploitable, but it is the pattern GitHub's hardening guide advises against. Suggested fix: pass them through env:.

8. Two comments do not match what the code does. Confirmed: the patch touches two hunks of R/markdown.R, not the "one line" stated at .github/workflows/roxygen2-fork/action.yml:57, and the write.dcf() call at :90 reflows the whole of roxygen2's DESCRIPTION (the Authors@R indentation is lost) despite keep.white. Neither affects the installed package. Suggested fix: correct the comment; replace the single Version: line with sed or desc if a minimal change is wanted.

Checked and found sound

  • The patch applies cleanly onto today's upstream with git apply --3way, and the diff restricted to R/ is non-empty (confirmed).
  • The stamp expression at .github/workflows/roxygen2-fork/action.yml:89 turns 8.1.1.9000 into 8.1.1.9100 (confirmed), and the assertion at :104 checks the whole version shape and the presence of the patched function, so an unpatched or mis-stamped install cannot pass silently (by reading).
  • No other workflow in .github/workflows/ runs roxygen2, so there is no second job regenerating man/ with a stock build (confirmed with grep).
  • The rendered effect is as described: for man/sqliteRemote.Rd, tools::Rd2txt() gives "immutable flags. Requires" at this head and "immutable flags. Requires" on main, and tools::checkRd() reports nothing for any file in man/ (confirmed).
  • The PR's own diff is 17c10ac and f3e9e4d plus two bot commits touching 16 .Rd files, as the description says; Config/cynkra/roxygen2 is a valid Config/ field.

Generated by Claude Code

…/roxygen2-fork

Keep the Config/cynkra/roxygen2 field, and set Config/roxygen2/version
to 8.1.1.9100, which is what the action stamps onto upstream 8.1.1.9000.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Pin both sides to full commit SHAs and fetch them by SHA,
so a push to the fork's branch cannot change what the job runs with a write token.
Fetch the history without file contents, so finding the branch point no longer depends on a 50-commit window.
Retry the two network fetches.
Pass the inputs through `env:` instead of interpolating them into the script.
Stamp the version with a single-line edit of `Version:` instead of rewriting DESCRIPTION with `write.dcf()`,
which lost the `Authors@R` indentation, and correct the comment on the size of the patch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Call the action from `custom/after-install` instead of editing `R-CMD-check.yaml`,
which fleet-wide syncs keep rewriting.
The hook runs before Roxygenize.
The step has `continue-on-error`, so a failed install no longer stops the other checks.
Roxygenize is skipped when it failed, and the outcome is listed in "Collect the outcomes of the checks",
so the job still goes red.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The after-install hook is called by `rcc-smoke`, `rcc-full` and `rcc-suggests`.
Only `rcc-smoke` runs Roxygenize,
so the other jobs built the patched roxygen2 for nothing and gained a failure surface.
Restrict the install and the outcome record to `github.job == 'rcc-smoke'`.
An unset `ROXYGEN2_FORK_OUTCOME` is not `failure`, so nothing else changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE

krlmlr commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

Accepted limitations

Findings 1 to 5, 7 and 8 of the review above are fixed in aafd9d5 (merge, DESCRIPTION conflict), aef7d48 (pinning), f0d3e5c (hook, continue-on-error, outcome in the summary, env: inputs, single-line version stamp) and 5a0cb42 (the install runs only in rcc-smoke). These remain:

  • .github/workflows/custom/after-install/action.yml: nothing of the new setup has run end to end. The patched R CMD INSTALL and the assertion after it, the github.job gate inside the composite action, and the hand-off of ROXYGEN2_FORK_OUTCOME through GITHUB_ENV were validated only up to the install step and by yq/actionlint, because CI does not run on a pull request that targets docs: State the goals and non-goals #788's branch. Relevance: high until the first CI run; confidence that it works: medium.
  • .github/workflows/R-CMD-check.yaml: two small edits still live in the fleet-synced workflow, the if: on Roxygenize and the outcomes line at L318. If a sync drops them, a failed install shows only as an annotation and Roxygenize runs with stock roxygen2, which removes the gap again in the next automated commit. Relevance: medium; reviewer's confidence: high (by reading).
  • DESCRIPTION: documenting locally with stock roxygen2 reverts the gap in 16 .Rd files, because roxygen2 only informs about an older version; CI puts it back. The Config/cynkra/roxygen2 field explains it, nothing enforces it. Relevance: low; reviewer's confidence: high (by reading).

Generated by Claude Code

krlmlr commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

Closing: the decision is to stay with stock roxygen2. The work, including the review fixes, remains on the branch claude/roxygen2-fork at 5a0cb42 if it is ever wanted again.


Generated by Claude Code

@krlmlr krlmlr closed this Nov 10, 2026
An error occurred while trying to automatically change base from claude/readme-goals to main November 10, 2026 15:21
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.

2 participants