Skip to content

fix(local-db): report a chapter whose frontmatter status cannot be rendered (I-000405) - #696

Open
auto-wood wants to merge 3 commits into
mainfrom
fix/i-000405-frontmatter-status-skip-visible
Open

auto-wood wants to merge 3 commits into
mainfrom
fix/i-000405-frontmatter-status-skip-visible

Conversation

@auto-wood

Copy link
Copy Markdown
Contributor

Intent

Reconcile silently skipped a chapter when its frontmatter status could not be rendered: no write, no op, but the chapter still counted. The skip is now a first-class, countable outcome.

Surface

3 files, +131 −7:

  • crates/nexus-local-db/src/work_chapters.rs: compute_reconcile_diff emits ResyncFileStatus only when render_frontmatter_status produced bytes; an unrenderable chapter becomes ReconcileSkip { path, reason } on ReconcileDiff/ReconcileReport plus a tracing::warn!(target: "reconcile"). apply_reconcile_diff derives the report from the diff, so counts match what was written. push_reconcile_skip keeps the function under clippy's 100-line bound.
  • crates/nexus-local-db/src/lib.rs: re-exports ReconcileSkip.
  • apps/nexus42/src/commands/creator/works/mod.rs: struct-literal adaptation only (skipped: Vec::new()), with #[serde(skip_serializing_if = "Vec::is_empty")] so the JSON shape is unchanged and the fn stays const.

Verification

  • cargo test -p nexus-local-db -> 691 passed, 0 failed (incl. 386 lib and doc-tests).
  • New test_reconcile_reports_unrenderable_frontmatter_as_skipped asserts both halves: report has 1 skip with the path and a "cannot be rendered" reason; created+updated+resynced+preserved+skipped == 2; resynced == 0, preserved == 1; diff.ops contains no ResyncFileStatus; the broken file's bytes are unchanged.
  • cargo clippy -p nexus-local-db --all-targets -- -D warnings clean; cargo fmt -p nexus-local-db -p nexus42 -- --check clean; cargo check -p nexus42 ok.
  • Negative control 1 (unconditional resync op restored): no resync op may stand for an unrenderable chapter: [ResyncFileStatus { rel_child: "Stories/ch01-broken.md", … }].
  • Negative control 2 (same state, op assertion suppressed): one chapter cannot be rendered — left: 0 right: 1 (the count side). Restored, 691 green.

Residuals:

  • The defensive let Some(rendered) = … else { continue; } in crates/nexus-core/src/owner/work_artifact.rs:298 can still skip-silently if a file becomes unrenderable between diff and write; that is nexus-core, outside this boundary — worth the same treatment.
  • nexus-contracts::WorkReconcileReport has no skip field (no schema change here), so CLI --json/daemon responses do not expose the detail; it is visible in the local-db report (--dry-run included) and the warn log.
  • skipped is not folded into preserved, so the four legacy counts can sum to less than the chapter total when a skip occurs (documented on the field).

Closes I-000405.

…ed in reconcile (I-000405)

- compute_reconcile_diff no longer emits a ResyncFileStatus op when render_frontmatter_status cannot produce bytes, so `resynced` counts only files that are actually written.
- ReconcileReport/ReconcileDiff carry a `skipped` list (chapter path + reason) and log a reconcile warn; the sum of created/updated/resynced/preserved/skipped still accounts for every chapter once.
- Added a regression test: one unclosed-frontmatter chapter plus one unchanged chapter must yield no resync op, one skip entry, and consistent counters.
- apps/nexus42 wire projection adapted to the new field (JSON shape unchanged via skip_serializing_if).
devin-ai-integration[bot]

This comment was marked as resolved.

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5 · The PR appears safe to merge, with a non-blocking clarification needed about what a skipped chapter means.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect the bounded chapter-reconciliation workflow.

The PR appears safe to merge, with a non-blocking clarification needed about what a skipped chapter means.

Findings

  1. P2 Skipped does not mean untouched ▶
Fix with agent prompt
### Issue 1
crates/nexus-local-db/src/work_chapters.rs:623-624
`ReconcileDiff::skipped` says no write decision was produced, but an unclosed block with a conflicting status and a changed `word_count` produces both a skip and `UpdateWordCount`. `apply_reconcile_diff` still updates that row.

Document that only the file status rewrite is skipped, and add a mixed-case test. Otherwise callers may treat skipped chapters as untouched or assume the counts cover each chapter once.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR records failed chapter status rewrites in ReconcileSkip instead of counting them as successful resyncs.

  • Reconcile reports chapters whose status it cannot write.

Acknowledged by auto-wood in the PR description: the core write-time race remains outside this boundary, and skip details remain absent from CLI and daemon wire responses because this PR does not change the schema.

Reviews (1) · Last reviewed commit: "fix(nexus-local-db): report unrenderable..." · Reviewed by Greptile

greptile-apps[bot]

This comment was marked as resolved.

@m-inspector

m-inspector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Verdict: ship it · Score 90% (mergeable)

Findings Count
🔴 must-fix 0
🟠 should-fix 0
🟡 may-fix 2
🔵 nit 0

📋 Review

What this PR does: Reconcile currently no-ops in silence when a chapter's frontmatter status cannot be rendered: nothing is written, no op is emitted, but the chapter is still counted. This PR makes that an explicit, countable outcome — compute_reconcile_diff emits ResyncFileStatus only when render_frontmatter_status produced bytes, records the failure as ReconcileSkip { path, reason } on ReconcileDiff/ReconcileReport, derives the report from the diff so counters match what was written, re-exports the type, and adds DB tests for both the skip and the word-count-still-mirrors case. It also keeps the Creator CLI JSON shape unchanged by hardcoding skipped: Vec::new() in the wire projection. The skip is additionally printed to stderr from inside nexus-local-db, which is the subject of both open may-fix findings.

Findings

🟡 [DEBT-01] Reconcile skip diagnostic is written as raw stderr from the DB library, on a justification bounded only to the Creator CLI

  • Evidence:

    [DEBT-01] Reconcile skip diagnostic is written as raw stderr from the DB library, on a justification bounded only to the Creator CLI

    • Evidence: crates/nexus-local-db/src/work_chapters.rs:966 — the newly added record_skipped_status_write_back calls eprintln! from the read-only compute phase; the call site is crates/nexus-local-db/src/work_chapters.rs:925 inside compute_reconcile_diff.
    • Evidence: crates/nexus-local-db/src/work_chapters.rs:883 — the same function already emits its other per-chapter diagnostic through tracing::warn! (invalid-volume fallback), so the diff introduces a second, differently-routed output channel inside one function.
    • Evidence: crates/nexus-local-db/src/cas.rs:169, crates/nexus-local-db/src/file_lock.rs:262 — crate-wide diagnostic convention is tracing (the only other eprintln! in crates/ are test/build-script sites).
    • Evidence: crates/nexus-core/src/owner/work_artifact.rs:453 — compute_reconcile_diff is also driven from the core/daemon path, not only from a terminal CLI.
    • Evidence: apps/nexus42/src/cli.rs:83 — is_data_output() is matches!(… Commands::Ops { … }), i.e. the global subscriber writes to stdout for Creator commands (apps/nexus42/src/main.rs:18, :159), so the doc comment's premise at work_chapters.rs:954-959 holds only for the Creator CLI -- it says nothing about the core/daemon caller.
    • Impact: The helper's stated bound is "under Creator commands the global subscriber's writer is stdout" and "creator works reconcile-chapters --json", yet the same library routine runs inside the core/daemon reconcile path where that bound does not apply: there the line lands as unstructured, unfilterable process stderr (no level, no target, no request/work correlation beyond the ad-hoc prefix), once per unrenderable chapter per reconcile request, and no host subscriber can route or silence it. The structured carrier for exactly this signal already exists (`Reconc…
  • Location: crates/nexus-local-db/src/work_chapters.rs:966-969

  • Category: tech-debt

  • Merge class: may-fix

🟡 Skipped-chapter report is stderr-only; every structured surface still drops skipped

  • Evidence:

    BUG-01 Skipped-chapter report is stderr-only; every structured surface still drops skipped

    • Evidence: crates/nexus-local-db/src/work_chapters.rs:966-972 — the new record_skipped_status_write_back prints the skip to stderr and pushes it into ReconcileDiff.skipped. But ReconcileSkip/ReconcileReport.skipped (work_chapters.rs:529-537, 558-559 with #[serde(skip_serializing_if = "Vec::is_empty")]) is the only structured carrier, and it is discarded at both projections: crates/nexus-core/src/works.rs:290-296 defines WorkReconcileReport with only created/updated/resynced/preserved and works.rs:498-503 builds it from exactly those four counters, and apps/nexus42/src/commands/creator/works/mod.rs:1143-1152 (reconcile_report_wire) hardcodes skipped: Vec::new() while print_reconcile_report (same file, human path) prints only the four counters.
    • Impact: For creator works reconcile-chapters --json and --dry-run --json, a chapter whose status write-back was skipped (no opening --- or an unclosed block) produces no skipped field, exit 0 and a clean report; the only signal is the unstructured stderr line this helper adds, which is outside the JSON contract and unfilterable by --verbose/reversed by no flag. The daemon route surfaces the same four-field report through CoreService::reconcile_work_chapters, so the skip list is lost there too. Net effect: the helper makes the skip visible to a human reading a terminal, while the patch's structured data channel — the one automation would use before mutating — remains blind.
    • Effort: S — add skipped: Vec<ReconcileSkip> to WorkReconcileReport, populate it in reconcile_work_chapters, and project it (instead of Vec::new()) in reconcile_report_wire; render it in print_reconcile_report.
    • Risk: LOW — additive field on an internal core type; the DB wire type already carries it and no TS consumer currently reads skipped (apps/nexus-service/src/works.ts has no `…
  • Location: crates/nexus-local-db/src/work_chapters.rs:966-972

  • Category: BUG

  • Merge class: may-fix

Revalidated findings

Reassessed 4/4 prior finding(s) this round · 0 invalid-output · 0 omitted · 0 over cap · 4 recheckable · context coverage: truncated

finding disposition evidence thread
Reconcile skip loses its only operator signal: helper's tracing::warn! deleted while report.skipped is dropped at the API/CLI boundary addressed (verified-fix) current-code -
reconcile-chapters wire projection hard-codes skipped: Vec::new(), so --json can never report an unrenderable chapter unverifiable (conflict) current-code -
Reconcile skip lost its only operator-visible signal: tracing::warn! deleted with push_reconcile_skip addressed (verified-fix) current-code -
Reconcile skip list is populated but no consumer surface ever receives it unverifiable (conflict) current-code -

Linked-issue AC

none — the PR declares Closes I-000405, but the review context's issues array is empty and no issue body or acceptance criteria were supplied, so no criterion can be marked met, unmet or cut without inventing it. The PR body's own stated intent ("skip is now a first-class, countable outcome") is covered by the ReconcileSkip shaping and the new skip test, but that is the PR's claim, not an issue AC.

✅ Verified

- Read record_skipped_status_write_back (crates/nexus-local-db/src/work_chapters.rs:966-980): it pushes ReconcileSkip { path, reason } into diff.skipped and emits an eprintln! line with UNRENDERABLE_FRONTMATTER_REASON.
- Read ReconcileSkip/ReconcileReport (work_chapters.rs:520-560): skipped is #[serde(skip_serializing_if = "Vec::is_empty")] and documented as per-chapter, not folded into preserved or resynced.
- Read test_reconcile_reports_unrenderable_frontmatter_as_skipped and test_reconcile_skips_status_write_back_but_mirrors_word_count (work_chapters.rs:2590-2683): both assert no ResyncFileStatus op, skipped[0].path, a reason containing "cannot be rendered", and the second asserts word_count still mirrors while DB status stays SSOT.
- Read the CLI projection (apps/nexus42/src/commands/creator/works/mod.rs:1143-1152): reconcile_report_wire hardcodes skipped: Vec::new(); print_reconcile_report destructures only the four legacy counters.
- grep in crates/nexus-local-db/src/work_chapters.rs confirms the two I-000405 test annotations near the skip tests.
- ❓ PR-reported cargo test -p nexus-local-db (691 passed), cargo clippy -p nexus-local-db --all-targets -- -D warnings, cargo fmt --check, cargo check -p nexus42, and both negative controls were not re-run — read-only seat, static review only.
- ❓ crates/nexus-core/src/owner/work_artifact.rs:453 and the daemon-side stderr handling were not opened; that half of DEBT-01 is static inference from the grep hit and the core/CLI evidence.
- ❓ crates/nexus-core/src/works.rs:290-296 / :498-503 (WorkReconcileReport four-field shape) is taken from the review document's read, not re-read here.

🗑️ Considered & rejected

- "The new reason constant breaks the existing skip tests" — rejected: both skip tests assert reason.contains("cannot be rendered"), a substring the new constant retains, and they were read directly.
- "nexus-local-db silently loses the skip entirely" — rejected: the diff pushes ReconcileSkip and apply_reconcile_diff copies it into ReconcileReport.skipped; the loss happens later, at the core/CLI projections, which is what BUG-01 records rather than a defect in this helper's data path.
- "eprintln! instead of tracing is a style violation" — rejected as inadmissible on style grounds alone; DEBT-01 is retained only because the documented justification (Creator CLI subscriber) is exceeded by the existing core/daemon caller.
- "The neighbouring pre-existing tracing::warn! for invalid frontmatter volume (work_chapters.rs ~895) hits the same stdout-writer hazard" — rejected as a finding here: it predates this diff and is called out only as a non-finding note.
- "The skip count should be folded into preserved so the four legacy counters always sum to the chapter total" — rejected: the PR documents the partition explicitly and the new test asserts created+updated+resynced+preserved+skipped == 2, so the semantics are intentional and tested.

🛠️ Plan to fix

Expand fix plan
Both open findings are the same repair: make the skip signal travel through owned report/output surfaces instead of being printed inside the DB library. Suggested order:

1. **Make `nexus-local-db` return-only.** In `crates/nexus-local-db/src/work_chapters.rs:954-970`, delete the `eprintln!` from `record_skipped_status_write_back` and rewrite its doc comment; keep `diff.skipped.push(...)` as the sole emission, and drop the now-false "stdout would be corrupted" justification. (DEBT-01)
2. **Carry `skipped` on the core report.** In `crates/nexus-core/src/works.rs:290-296`, add `skipped: Vec<ReconcileSkip>` to `WorkReconcileReport` (wire-stable: `skip_serializing_if = "Vec::is_empty"` if the service surface is serialized), and populate it from `report.skipped` in the constructor at `:498-503`; update other literals/destructures. (BUG-01)
3. **Project it at the CLI.** In `apps/nexus42/src/commands/creator/works/mod.rs`, replace `skipped: Vec::new()` in `reconcile_report_wire` (`:1143-1152`) with the report's list; that fn is `const`, and `Vec::clone` is not const-callable, so either drop `const`/take the report by value or restructure the projection. Render one line per skip (`path` + `reason`, labelled dry-run vs applied) in `print_reconcile_report`, leaving the four-counter line intact.
4. **Log on the daemon side only where a subscriber is owned.** For the core/daemon reconcile path (`crates/nexus-core/src/owner/work_artifact.rs:453` and `CoreService::reconcile_work_chapters`), emit the skip through the daemon's own `tracing` subscriber or let the caller render it after receiving the report — never from `nexus-local-db`.
5. **Tests.** Keep the two DB skip tests; add a core test asserting `WorkReconcileReport.skipped` survives `apply_reconcile_diff` → core report, and a CLI/output test (human and `--json`, `--dry-run --json`) asserting `skipped` appears only when non-empty and includes path + reason. Update any snapshot of the JSON shape.
6. **Verification gates.** `cargo test -p nexus-local-db -p nexus-core -p nexus42`; `cargo clippy -p nexus-local-db -p nexus-core -p nexus42 --all-targets -- -D warnings`; `cargo fmt -p nexus-local-db -p nexus-core -p nexus42 -- --check`; then exercise both `creator works reconcile-chapters --json` / `--dry-run --json` on a chapter with an unclosed frontmatter block and confirm the skip is in the JSON and no raw stderr line is emitted by the DB layer. Keep the scenario from the PR's negative controls (no `ResyncFileStatus`, counters partition the chapters, broken bytes unchanged).

Review 3 · commit 6c6afdc · since c35302c

m-inspector[bot]

This comment was marked as resolved.

…write-back (I-000405)

- Removed the reconcile `tracing::warn!` added in the previous commit: it reached stdout for `creator works reconcile-chapters` (the subscriber only routes Ops commands to stderr), corrupting `--json`; the skip is diagnosed through `diff.skipped` / `report.skipped`.
- ReconcileSkip now documents exactly what was skipped: the frontmatter status write-back. Word-count mirroring for the same chapter is still emitted and applied; report/diff field docs and the reason wording say so.
- Added a mixed regression test: status conflict + word_count change -> one skip entry, no ResyncFileStatus, an UpdateWordCount op, and after apply the DB word_count is mirrored while the file frontmatter status is untouched.
m-inspector[bot]

This comment was marked as resolved.

…r (I-000405)

- The skip branch now writes one line to stderr explicitly (`record_skipped_status_write_back`); `diff.skipped` / `report.skipped` stay the structured channel. No `tracing` call, so nothing reaches the stdout writer `Creator` commands use for `--json`.
- Comment at the write records why it must not be `tracing` (global subscriber writer is stdout under `Creator`); `is_data_output()` and logging init untouched.
- The reason string is now cause-only, so the stderr line and the structured reason do not repeat "write-back skipped".
- Existing reconcile skip tests keep asserting the structured entry (path + reason, report == diff); the stderr routing was verified out of band (`--nocapture` split: stdout 0 hits, stderr 1 hit).

@m-inspector m-inspector Bot 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.

mstar-inspector line comments · round 3 · 6c6afdc

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