Skip to content

fix(distill): add to existing articles; name the PR head; create labels - #297

Merged
jflowers merged 3 commits into
unbound-force:mainfrom
jflowers:distill-pr-safety
Nov 30, 2026
Merged

jflowers merged 3 commits into
unbound-force:mainfrom
jflowers:distill-pr-safety

Conversation

@jflowers

Copy link
Copy Markdown
Contributor

Fixes the correctness bugs from #295 in dewey_rolling_pr.

Changes

  • Existing articles are added to, never replaced. The create path wrote a draft rendered from the theme's members alone over theme.ExistingArticle. That dropped the article's prose, cited sources and tier. In the run that filed dewey-distill-auto: rolling_pr replaces validated articles with raw draft dumps of new learnings #295, all 33 PRs did this. RenderThemeArticle now renders onto the article as checked out, on both the create and update paths:
    • The body and other frontmatter keys stay as they are.
    • Members not already cited are appended as ## <id> sections and added to sources.
    • tier becomes draft, since the additions are unreviewed and the human merge is the promotion.
    • A base that already cites every member is left unchanged, so no commit is made.
    • A render that would drop any cited source is refused. This is suggested fix 2 from the issue.
  • Fork checkouts. gh pr create now gets --head <owner>:<branch>, with the owner read from the push remote's URL. The branch is pushed by explicit refspec with no upstream, so gh couldn't infer the head when origin is a fork.
  • Labels. human-gate, dewey-distill and needs-human-resolution are created once per run where missing, before a PR is created or labeled. An existing label is fine.

The dropped learning

group_learners doesn't drop identities. In the #295 run, dewey_scope returned 1,090 in_scope, but the agent passed 1,089 to group_learners. It left out issue-triage-20261102T005717-jay-flowers when copying the list. That's the same through-the-model problem as the truncated decisions, so it belongs with passing the grouping by reference (below), not in this PR.

Not in this PR

  • Passing scope and grouping by reference. For example, dewey_scope and group_learners could write a run file and return its id, and rolling_pr could read it. That removes the model copying a 2,000-item list (the dropped learning, the decisions cut to one per theme, the truncated JSON) and the payload size limit.
  • Timeouts. Process themes so a cancelled call still records an artifact for the themes it finished.
  • Grouping quality, where 93% of decisions are tie-breaks. It's being measured separately against embedding models on the hub.

Tests

  • New: a fixture run where a validated article goes through the create path. It keeps its prose and old source, adds the new member, becomes draft, and the PR gets --head and both labels.
  • New: RenderThemeArticle cases (fresh, unchanged, idempotent append, inline sources, no frontmatter, tier guard), plus ownerFromRemoteURL and ensureLabels.
  • Changed: TestEdgeCase_EmptyScopePostsNothingAndLeavesPRs now opens its prior-run PR before the citing article lands.
  • go build, go vet and go test -race ./... pass.
  • golangci-lint reports only the 2 staticcheck QF1001 findings in artifacts/ that are already on main.

/uf.review-council hasn't been run yet, so this is a draft.

🤖 Generated with Claude Code

rolling_pr's create path checked out the base and wrote a fresh draft
rendered from the theme's members alone to theme.ExistingArticle, so a
theme joining an existing compiled article replaced it: its prose, its
cited sources and its tier were lost (unbound-force#295). The update path rendered
the same way.

- RenderThemeArticle renders onto the article as checked out: the base
  body and frontmatter stay, members it does not already cite are
  appended as sections and added to its sources, and tier becomes draft.
  A base citing every member is returned unchanged (no commit), and a
  render that would drop a citation is refused.
- gh pr create gets --head <owner>:<branch>, the owner read from the
  push remote, so a fork checkout (origin = fork) opens its PR: the
  branch is pushed by explicit refspec with no upstream, so gh could not
  infer the head.
- The human-gate, dewey-distill and needs-human-resolution labels are
  created once per run where missing; gh pr create fails on an unknown
  label.

The edge-case fixture that opened a "prior run" PR for an article
already citing every member now opens it before the citation lands, as a
real prior run would: re-rendering a fully cited article is a no-op.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
writeThemeFiles crossed cyclomatic complexity 15, pushing CI's Gaze
CRAPload count to 49 against the 48 ceiling. Extract the pure
newly-cited-members computation (dropped/existing set filtering) into
newlyCitedMembers, dropping writeThemeFiles to cx 10 (crap 10.3) with
the helper at cx 6 and 100% line coverage. Behavior-preserving:
identical iteration order and outputs. CI parity verified locally:
build, vet, full -race test suite, and gaze 47/48 CRAPload,
43/45 GazeCRAPload (both PASS).
Address all nine review-council findings on the dewey_rolling_pr fix:

- fakeGH now models gh label semantics: a label registry populated by
  'label create' and consulted by 'pr create --label' and
  'pr edit --add-label' (unknown labels fail), a failure-injection
  knob for the ensureLabels hard-failure arm, a runErr knob for the
  gh.Run error wrap, and ordered call recording so tests enforce
  labels-before-create ordering.
- writeThemeFiles read path gains the same traversal guard
  writeFileInVault enforces on writes.
- distillLabels mutable package map becomes the distillLabelMeta
  lookup function (CS-007: no mutable package-level state).
- ownerFromRemoteURL treats file:// remotes as local transports and
  returns "" instead of a bogus owner.
- New tests: citation-preservation refusal negative path (render that
  would drop a quoted cited source is refused, nothing written),
  frontmatter helper unit tests (splitFrontmatter CRLF/unterminated/
  fence-edge cases, renderSourcesBlock, setFrontmatterLine block
  replacement), owner-qualified --head on fork remotes with
  label-before-create ordering, ensureLabels failure arms, and
  append-preservation assertions in the second-run update test.

CI parity: go build/vet, go test -race -count=1 (all packages),
gaze CRAPload 47/48 and GazeCRAPload 43/45 both pass.
@jflowers
jflowers marked this pull request as ready for review November 30, 2026 00:23

@uf-divisor uf-divisor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Council verdict: APPROVE WITH ADVISORIES — 5/5 reviewers succeeded; adversary, architect, and guard returned APPROVE; gaze-testing and testing returned APPROVE WITH ADVISORIES. All findings are test-quality advisories (1 MEDIUM, 2 LOW after dedup); none block the merge.

What this fixes (issue #295)

  • Existing articles are added to, never replaced: RenderThemeArticle renders onto the article as checked out — body and frontmatter stay, newly-cited members append as ## <id> sections, tier becomes draft, a fully-cited base returns unchanged, and a render that would drop a cited source refuses.
  • gh pr create names its head (--head <owner>:<branch>), resolving fork checkouts.
  • Labels (human-gate, dewey-distill, needs-human-resolution) are created once per run before create/edit.

Advisories

  • MEDIUM (test-coverage) — the read-path traversal guard and non-IsNotExist read-error arm in writeThemeFiles ship without a test for either refusal arm (inline below). [gaze-testing + testing]
  • LOW (test-quality) — the git-fixture integration tests carry no testing.Short() guard, so go test -short cannot skip them (TC-011). [gaze-testing]
  • LOW (assertion-depth) — the "no base renders a fresh draft" subtest uses RenderDraftArticle as its oracle, so it cannot independently catch a regression there (inline below). [testing]

CI — all checks green on head e26ee333: build-and-test (build, vet, test -race -count=1, Gaze CRAPload 47/48, GazeCRAPload 43/45), MegaLinter, CI OK.

This review was generated by /uf.review-pr (AI-assisted).

Comment thread tools/rolling_pr.go
articlePath := themeArticlePath(theme)
content, dropped, err := RenderDraftArticle(theme, input.Texts, DistillTierDraft)
// The article as checked out (the base's on the create path, the
// branch's on the update path): the render keeps it and adds to it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM (test-coverage, advisory) — The read-path traversal guard and the non-IsNotExist read-error arm added to writeThemeFiles have no test covering either refusal arm (TC-001/TC-005). The read contract has four behaviors — read absent → fresh render (tested), read present → additive render (tested), path escaping the vault root → refuse (untested), read error other than not-exist → refuse (untested). The guard is reachable: themeArticlePath composes distillCompiledPrefix + theme.Name (tag-derived, unsanitized — only the branch goes through SanitizeThemeBranch) and uses theme.ExistingArticle verbatim, and this suite's poisoned-assignment tests (TestValidateAssignedBranches_FailsClosedOnPoisonedAssignment, TestSanitizeThemeBranch with "../../etc/passwd") treat poison tags as anticipated input. The symmetric write guard has a dedicated test (TestWriteFileInVault_RejectsTraversal, rolling_pr_test.go:1793), so deleting or breaking this read guard regresses silently. A table-driven test calling writeThemeFiles with a theme whose Name/ExistingArticle escapes the vault root, asserting the refusal error, mirrors that precedent.


t.Run("no base renders a fresh draft", func(t *testing.T) {
got, _, err := RenderThemeArticle("", distillTestTheme("auth", "", alice), texts, DistillTierDraft)
want, _, _ := RenderDraftArticle(distillTestTheme("auth", "", alice), texts, DistillTierDraft)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOW (assertion-depth, advisory) — This subtest derives its expected value from RenderDraftArticle — the same function RenderThemeArticle delegates to — so both sides of the assertion change together, and a regression inside RenderDraftArticle's render cannot fail this subtest (oracle coupling; the same pattern masked a trimming regression in PR #156). The risk is contained: RenderDraftArticle is independently pinned by structural tests (TestRenderDraftArticle_DraftRender, _Deterministic, _MissingTextDropped), and the delegation equivalence is the documented contract. Two literal structural assertions (frontmatter prefix, member section) — or a comment naming the dependency on the sibling structural tests — let this subtest fail independently.

@jflowers
jflowers merged commit 00804d9 into unbound-force:main Nov 30, 2026
7 checks passed
@jflowers
jflowers deleted the distill-pr-safety branch November 30, 2026 03:28
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