Skip to content

feat(pr-management): connect findings pane curation to render and polish review hooks - #2005

Merged
potiuk merged 6 commits into
apache:mainfrom
Kaap10:feat/pr-management-curated-render-bridge
Nov 13, 2026
Merged

potiuk merged 6 commits into
apache:mainfrom
Kaap10:feat/pr-management-curated-render-bridge

Conversation

@Kaap10

@Kaap10 Kaap10 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #1992 and maintainer review on #2005 for the magpie-pr-management code-review mod:

  • Connect curated findings to render: Syncs <file>.curated.json and <file>.curated.keep beside findings upon maintainer curation actions, allowing Step 7 render to consume curated comments directly.
  • Picker prompt precedence: Step 7b explicitly clarifies that the maintainer's typed answer at Step 7a text picker always takes precedence over sidecar recommendations.
  • In-pane button synchronization: Routes all row toggle, All, and None button onPress callbacks through updateAndSyncReviewFindingsState to keep UI state and disk in sync.
  • Preserve curation across disposition: Reconciles incoming findings with existing state across disposition re-runs to preserve maintainer actions and customized bodies.
  • Failure visibility and orphan cleanup: Surfaces syncError in pane footer and /magpie-findings status if disk writes fail, cleans up partial files on write errors, and removes orphaned sidecars when findings are empty.
  • Strict token parsing: Strictly validates keep and drop arguments (^\d+$ or ^[gG]\d+$), rejects arbitrary strings like abc, and decouples gN general observations from anchored inline comments.
  • Document $.fs.write boundary: Added a dedicated subsection in docs/setup/secure-agent-setup.md detailing unsandboxed mod write boundaries, rationale, locality constraints, and fail-open design.

Type of change

  • Skill change (.claude/skills/<name>/)
  • Tool / bridge contract (tools/<system>/*.md)
  • Python package (tools/*/ with pyproject.toml)
  • Groovy reference impl
  • Cross-cutting (RFC, AGENTS.md, sandbox, privacy-LLM)
  • Documentation (docs/, README.md, CONTRIBUTING.md)
  • Project template (projects/_template/)
  • CI / dev loop (prek, workflows, validators)
  • Other: Claude Code mod plugin hooks & tests (plugins/magpie-pr-management/hooks/)

Test plan

  • claude plugin test plugins/magpie-pr-management passes all 71 unit and integration tests (0 failures).
  • claude plugin validate --strict plugins/magpie-pr-management passes static analysis with 0 errors and 0 warnings.
  • python tools/dev/add-license-headers.py --check passes cleanly.
  • In-pane button onPress callbacks verified to sync state and disk files.
  • Disposition re-run verified to retain existing maintainer curation without writing sidecars upfront.
  • Token parser verified to reject invalid tokens (keep abc) and decouple general observations (keep g1).
  • Write failures verified to record syncError, clean up partial files, and display visible warnings.
  • Line endings verified strictly LF (crlf=0) across all touched files.

RFC-AI-0004 compliance

  • HITL — The interactive pane and /magpie-findings command curate drafted findings for the maintainer; review posting remains gated on maintainer confirmation in Step 7b and Step 8.
  • Sandbox — Files are written only to the local session path via $.fs.write.
  • Vendor neutrality — Step 7a/7b document the .curated.* path for the Claude Code mod while preserving the standard sequential text picker prompt for other harnesses.
  • Conversational + correctable — Maintainers can adjust or reset actions at any point before running render.
  • Write-access discipline — No automated GitHub review postings.
  • Privacy LLM — Zero tokens consumed by the interactive pane and /magpie-findings command.

Linked issues

Refs #1887
Follow-up to #1992

Notes for reviewers (optional)

Directly addresses @potiuk's review comments on PR #2005:

  1. Initial disposition execution no longer writes curated files upfront; files are written only upon maintainer curation. Step 7b explicitly states that typed picker answers take precedence.
  2. In-pane buttons (onPress callbacks for row toggles, All, None) now route through updateAndSyncReviewFindingsState.
  3. Disposition re-runs preserve maintainer actions and customized review bodies across runs.
  4. Failed writes surface syncError in pane footer and /magpie-findings status, partial files are cleaned up on write errors, and orphaned sidecars are purged when findings become empty.
  5. keep and drop enforce strict token validation and decouple general observations (gN) from anchored inline comments.
  6. Added documentation in docs/setup/secure-agent-setup.md covering the $.fs.write unsandboxed host boundary.

@github-actions github-actions Bot added family:pr-management pr-management-* skills capability:review Deep per-item code review or contributor mentoring labels Nov 5, 2026
@Kaap10

Kaap10 commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

up for review

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking up the #1992 notes: the docstring move and the skip filter are good. This change decides what actually gets posted, though, and the wiring can post something the maintainer dropped, so the inline comments below need answering first. Please also cover $.fs.write in docs/setup/secure-agent-setup.md: it runs outside the sandbox, this is its first use in a Magpie mod, and docs/when-to-use-mods.md requires those trade-offs to be documented.

The keep file overrides the picker (plugins/magpie-pr-management/skills/code-review/review-flow.md:347)

handleBashToolCall writes the curated files at disposition, before anyone curates, so .curated.keep normally holds ALL. This line then passes it whenever it is present. A maintainer who answers 1,3 at the picker still sends ALL, so an inline comment they dropped gets posted. The PR also removes the sentence saying only the picker's answer reaches render, and nothing now says which one wins. Please write these files only after a real curation action, and state which answer takes precedence.

The pane's own buttons do not sync (plugins/magpie-pr-management/hooks/review-findings.ts:1079)

The sync is added to handleUiPress, but the pane's row toggles and All/None buttons use their own onPress callbacks in renderFindingsPane (lines 222, 298, 372 and 381), and those call only setReviewFindingsState. The pane then shows one selection while render gets another. The new test calls handleUiPress directly, so it does not catch this. One shared helper that sets the state and syncs would cover both paths.

Re-running disposition wipes curation (plugins/magpie-pr-management/hooks/review-findings.ts:1213)

Every disposition re-reads the original findings and overwrites the curated files with fresh state. review-flow.md requires a re-run after [E]dit and after CI actions, so those ordinary paths lose the maintainer's edits and selections. Hydrating should not overwrite existing curation for the same findings.

Smaller observations

  • See inline comments on plugins/magpie-pr-management/hooks/review-findings.ts:880, plugins/magpie-pr-management/hooks/review-findings.ts:1312.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Magpie maintainer. After you've
addressed the points above and pushed an update, an Apache Magpie
maintainer — a real person — will take the next look
at the PR. The findings cite the project's review criteria;
if you think one of them is mis-applied, please reply on the
PR and a maintainer will weigh in.

More on how Apache Magpie handles maintainer review:
Contributing guide.

Kaap10 added a commit to Kaap10/magpie that referenced this pull request Nov 6, 2026
…ration bridge

Address review comments from @potiuk on PR apache#2005:
- Do not write curated files to disk upon initial disposition run
- Reconcile and preserve existing maintainer curation across disposition runs
- Clean up orphaned curated sidecars when findings become empty
- Route in-pane button onPress callbacks through updateAndSyncReviewFindingsState
- Enforce strict token validation for keep and drop commands and decouple gN observations
- Surface sync errors in pane footer and status command
- Clarify picker prompt precedence in review-flow.md Step 7b
- Document $.fs.write unsandboxed boundary in docs/setup/secure-agent-setup.md
@github-actions github-actions Bot added family:setup setup-* skills family:docs Docs, MISSION.md, READMEs labels Nov 6, 2026
Kaap10 added a commit to Kaap10/magpie that referenced this pull request Nov 6, 2026
…ration bridge

Address review comments from @potiuk on PR apache#2005:
- Do not write curated files to disk upon initial disposition run
- Reconcile and preserve existing maintainer curation across disposition runs
- Clean up orphaned curated sidecars when findings become empty
- Route in-pane button onPress callbacks through updateAndSyncReviewFindingsState
- Enforce strict token validation for keep and drop commands and decouple gN observations
- Surface sync errors in pane footer and status command
- Clarify picker prompt precedence in review-flow.md Step 7b
- Document $.fs.write unsandboxed boundary in docs/setup/secure-agent-setup.md
@Kaap10
Kaap10 force-pushed the feat/pr-management-curated-render-bridge branch from c5a4699 to ed9df03 Compare November 6, 2026 04:02
@Kaap10
Kaap10 requested a review from potiuk November 6, 2026 04:12

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the follow-up — the button sync, strict keep / drop parsing and no-write-at-disposition are fixed, and I'm resolving those three threads; what still needs work is the sidecar lifecycle: cleanup relies on $.fs.remove / unlink, which the mod API does not have, sidecars go stale when disposition is re-run, and an edited finding can still post its original comment.

GitHub has not yet computed whether this branch merges cleanly with its base.

Correctness: cleanup relies on $.fs calls the mod API does not have (plugins/magpie-pr-management/hooks/review-findings.ts:889)

await $.fs.remove(curatedJsonPath);   # ←
…
await $.fs.unlink(curatedJsonPath); # ←
…
await $.fs.write(curatedJsonPath, '[]');

The Claude Code mod $.fs API offers read, write, list, exists, stat and ancestors; there is no remove or unlink. So cleanCuratedFindingsFiles always ends up writing [] to .curated.json and NONE to .curated.keep. When a sync fails after the JSON write succeeded (the case the new test covers), cleanup leaves .curated.json as [], and Step 7b says to pass .curated.json to --findings whenever it exists, so render gets zero findings, while the pane says Step 7b will use the original findings. The tests do not catch it because the mock engine adds remove / unlink. This is the part of the earlier "failed writes are silent" thread that is still open. Drop the remove / unlink calls and make the sidecars self-invalidating instead — e.g. record the source findings file's hash (and the PR number) in .curated.json, and have Step 7b use the sidecar only when it matches. Make the pane message say what Step 7b will actually do, and remove remove / unlink from the test mock.

Correctness: sidecars go stale across disposition re-runs (plugins/magpie-pr-management/hooks/review-findings.ts:1364)

await setReviewFindingsState($, nextState);
// NOTE: Never write .curated.* files at initial disposition.  # ←

A disposition re-run now merges the earlier curation in memory, but leaves the sidecars from that earlier curation on disk untouched. After [E]dit (drop or reclassify findings, rewrite the findings file, re-run disposition), <file>.curated.json still holds the pre-edit findings, and Step 7b passes it to render, so a finding removed in [E]dit can come back and be posted. The same happens across PRs when the findings path is reused: the in-memory merge is gated on the PR number, the file on disk is not. When disposition hydrates and curated sidecars already exist, re-sync them from the merged state; otherwise invalidate them with the same hash / PR-number marker as above.

Flagged by both the primary and adversarial reviewers.

Correctness: an edited finding still posts its original comment (plugins/magpie-pr-management/hooks/review-findings.ts:841)

if (f.action === 'edit') {
  delete base.suggestion;
  if (f.body) {
    base.explanation = f.body;  # ←

Editing a finding sets explanation but keeps any existing comment, and render builds the inline comment from finding.get("comment") or <title + details> (body.py, around line 278). So when the raw finding carried a comment, the maintainer's edit is ignored and the original text is posted inline. On edit, also delete base.comment (or set it to the edited body), and add a test with a raw finding that carries comment.

Flagged by copilot (adversarial review); cross-checked.

Smaller observations

  • See inline comments on docs/setup/secure-agent-setup.md:2029, plugins/magpie-pr-management/skills/code-review/review-flow.md:348.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Magpie maintainer. After you've
addressed the points above and pushed an update, an Apache Magpie
maintainer — a real person — will take the next look
at the PR. The findings cite the project's review criteria;
if you think one of them is mis-applied, please reply on the
PR and a maintainer will weigh in.

More on how Apache Magpie handles maintainer review:
Contributing guide.

Comment thread docs/setup/secure-agent-setup.md Resolved
@Kaap10
Kaap10 force-pushed the feat/pr-management-curated-render-bridge branch from ed9df03 to 581be5b Compare November 9, 2026 07:02
Kaap10 added a commit to Kaap10/magpie that referenced this pull request Nov 9, 2026
…ration bridge

Address review comments from @potiuk on PR apache#2005:
- Do not write curated files to disk upon initial disposition run
- Reconcile and preserve existing maintainer curation across disposition runs
- Clean up orphaned curated sidecars when findings become empty
- Route in-pane button onPress callbacks through updateAndSyncReviewFindingsState
- Enforce strict token validation for keep and drop commands and decouple gN observations
- Surface sync errors in pane footer and status command
- Clarify picker prompt precedence in review-flow.md Step 7b
- Document $.fs.write unsandboxed boundary in docs/setup/secure-agent-setup.md
@github-actions github-actions Bot added family:tools tools/* substrate:analytics Tool substrate: read-only metrics / dashboards / renderers labels Nov 9, 2026
@Kaap10

Kaap10 commented Nov 9, 2026 •

Copy link
Copy Markdown
Member Author

Thanks for the thorough review, @potiuk! Addressed all points in commit 8e1f5fe:

  1. Self-invalidating sidecars (review-findings.ts): Dropped all $.fs.remove and $.fs.unlink calls from hooks and removed them from the test mock defaultFs. Instead of writing [] on cleanup/failure, sidecars are now self-invalidating: .curated.json writes a schema_version: 1 envelope embedding the active PR number and source findings SHA-256 digest (computed via a zero-dependency pure JS implementation matching mod import boundaries). On cleanup or write failure, sidecars are marked explicitly with invalidated: true and INVALIDATED in .curated.keep. cleanCuratedFindingsFiles also checks exists first and never creates phantom sidecars when none existed.
  2. Sidecar lifecycle on disposition re-run: During disposition hydration, if curated sidecars already exist on disk for the matching PR, they are re-synced from the merged curation state with the updated source hash. If the PR number mismatches (reused path across PRs) or findings become empty, sidecars on disk are marked invalidated. Initial disposition without prior curation still writes no sidecars upfront.
  3. Comment override on edit: In serializeFindingsForRender, editing a finding now explicitly deletes base.comment (along with base.suggestion) so render does not fall back to the raw unedited inline comment. Also added item.comment to rawBody extraction in normalizeFinding.
  4. CLI render envelope support: Updated cli.py to safely unpack findings whether passed as a raw array or envelope dictionary ({ schema_version, pr, source_sha256, findings }). Also synced vendored copy under plugins/magpie-security-tools.
  5. Documentation & SemBr: Updated docs/setup/secure-agent-setup.md to accurately describe unsandboxed write boundaries, source file prechecks, and the self-invalidation lifecycle. Updated review-flow.md Step 7a/7b to specify empty answer defaults (<file>.curated.keep if valid, else All), dropped "non-interactively", added sidecar hash/PR verification rules, and formatted using strict Semantic Line Breaks (one sentence per line) with a blank line before "It assembles the body...".

…ish review hooks

Connect the interactive review findings pane to Step 7 render by writing curated findings and keep answers to disk beside the findings file, omitting skipped general observations from render serialization, and relocating the register doc comment.

- Record findingsPath from Step 6 disposition command in state atom
- Sync <file>.curated.json and <file>.curated.keep on action/edit changes
- Omit unanchored findings with action skip in serializeFindingsForRender
- Move register doc comment above export function register
- Update review-flow.md Step 7a/7b to read curated files when present
…ration bridge

Address review comments from @potiuk on PR apache#2005:
- Do not write curated files to disk upon initial disposition run
- Reconcile and preserve existing maintainer curation across disposition runs
- Clean up orphaned curated sidecars when findings become empty
- Route in-pane button onPress callbacks through updateAndSyncReviewFindingsState
- Enforce strict token validation for keep and drop commands and decouple gN observations
- Surface sync errors in pane footer and status command
- Clarify picker prompt precedence in review-flow.md Step 7b
- Document $.fs.write unsandboxed boundary in docs/setup/secure-agent-setup.md
…ender bridge

- Eliminate $.fs.remove and $.fs.unlink calls from hooks and test mocks
- Implement self-invalidating sidecars using schema_version 1 envelope with PR number and source SHA-256 hash
- Invalidate sidecars on write failures and empty findings rather than leaving empty lists
- Re-sync curated sidecars on disposition re-run when curated files exist for matching PR
- Invalidate sidecars on PR mismatch when findings path is reused across PRs
- Delete base.comment on edit so maintainer edits override raw comment in render
- Unpack findings in cli.py whether passed as raw list or envelope dictionary
- Accurately document write boundaries, self-invalidation lifecycle, and fail-open behavior in docs/setup/secure-agent-setup.md
- Clarify Step 7a/7b picker precedence and empty answer defaults, remove non-interactive claims, and enforce semantic line breaks
@Kaap10
Kaap10 force-pushed the feat/pr-management-curated-render-bridge branch from 581be5b to 8e1f5fe Compare November 9, 2026 07:18
@Kaap10
Kaap10 requested a review from potiuk November 9, 2026 07:36

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The self-invalidating sidecars and the re-sync on a disposition re-run close the earlier threads; what is left is moving the sidecar validity check from the Step 7b prose into render, plus a few places where a maintainer's edit can be lost or mixed with the original suggestion.

deterministic gates (tools/pr-management/src/pr_management/code_review/cli.py:394)

Where a deterministic check (script, linter, schema validation) can replace an LLM pass, it runs first; LLM passes are not spent on what executable code already decides.

raw = json.loads(Path(path).read_text(encoding="utf-8"))
if isinstance(raw, dict):
    return raw.get("findings", [])

The sidecar validity check (invalidated marker, PR match, source_sha256 match) lives only in the Step 7b prose, where the agent is asked to hash <file> by hand and compare. _load_findings accepts any dict, so an invalidated envelope ({"invalidated": true, "findings": []}) passed to render --findings renders a review with zero findings and no error, and an envelope for another PR is accepted too. isCuratedSidecarValid is only called from the tests (and treats a missing pr / source_sha256 as a match). This is the gate the earlier thread asked for ("Step 7b use the sidecar only when it matches"): please move it into the CLI. For example, keep passing the original --findings <file> and let render pick up <file>.curated.json itself only when it is valid, refusing an invalidated or mismatched envelope. Step 7b then shrinks to one line. Add pytest cases for the invalidated and wrong-PR envelopes, and mirror the change in the vendored copy under plugins/magpie-security-tools.

Smaller observations

  • See inline comments on plugins/magpie-pr-management/hooks/review-findings.ts:1803, plugins/magpie-pr-management/hooks/review-findings.ts:970, plugins/magpie-pr-management/hooks/review-findings.ts:1436, plugins/magpie-pr-management/hooks/review-findings.ts:1111, plugins/magpie-pr-management/hooks/review-findings.ts:43, plugins/magpie-pr-management/skills/code-review/review-flow.md:326, docs/setup/secure-agent-setup.md:2033.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Magpie maintainer. After you've
addressed the points above and pushed an update, an Apache Magpie
maintainer — a real person — will take the next look
at the PR. The findings cite the project's review criteria;
if you think one of them is mis-applied, please reply on the
PR and a maintainer will weigh in.

More on how Apache Magpie handles maintainer review:
Contributing guide.

Comment thread docs/setup/secure-agent-setup.md Resolved
…r gate and edit preservation

- Move sidecar validity check into render CLI, auto-picking .curated.json and refusing invalidated/mismatched envelopes
- Mirror deterministic gate changes into vendored copy under plugins/magpie-security-tools
- Retain 'edit' action when re-keeping or bulk-accepting edited findings
- Prune suggestion_block and fixup from serialized findings on edit
- Restrict finding hydration to id/rule/body match and consume each match once
- Refuse sidecar writes to symlinks or non-regular files via $.fs.stat
- Add known-answer SHA-256 test vectors for empty, ASCII, multi-block, and UTF-8 inputs
- Update Step 7a/7b docs and secure-agent-setup write boundary documentation
…deQL pass

- Catch specific (json.JSONDecodeError, OSError, UnicodeDecodeError) instead of bare Exception
- Document fallback behavior to resolve CodeQL empty-except alert
@Kaap10
Kaap10 requested a review from potiuk November 10, 2026 14:42
…ault in render

- review-findings.ts: write `<file>.curated.json` / `<file>.curated.keep`
  (append, not replace `.json`), the names `render` reads, so curation
  reaches `render` end to end.
- review-findings.ts: a symlinked `.curated.json` no longer skips
  invalidating `.curated.keep`.
- cli.py (+ vendored copy): a missing `--findings` file is an error,
  not an empty review; a `.curated.json` passed directly must carry a
  matching `pr`, an existing source file and a matching `source_sha256`.
- cli.py, review-flow.md: `render --keep curated` uses `.curated.keep`
  only when the curated findings were used, `A` otherwise; an empty
  picker answer maps to it.
- Tests: hook-named sidecar paths, symlinked json plus regular keep,
  missing file, direct envelope without source or PR, keep curated
  valid and stale.

Generated-by: Claude Opus 5

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks — the earlier threads are addressed (edits survive keep/All, suggestion blocks drop on edit, matches are consumed once, symlinks are refused, known-answer hash tests). I pushed one fixup commit, 8580e8b, for what remained:

  • plugins/magpie-pr-management/hooks/review-findings.ts: the hook wrote findings-N.curated.json while render read findings-N.json.curated.json, so curation never reached render; the hook now appends .curated.json / .curated.keep, the names the docs and render use. A symlinked .curated.json no longer skips invalidating .curated.keep.
  • tools/pr-management/src/pr_management/code_review/cli.py (and the vendored copy): a missing --findings file is an error instead of an empty review; a .curated.json passed directly must carry a matching pr, an existing source file and a matching source_sha256.
  • cli.py and review-flow.md: the keep default moved into code — render --keep curated uses .curated.keep only when the curated findings were used, and All otherwise.
  • Tests for each of the above.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Magpie maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.

More on how Apache Magpie handles maintainer review:
Contributing guide.

@potiuk
potiuk merged commit 73c05dd into apache:main Nov 13, 2026
11 checks passed
potiuk added a commit that referenced this pull request Nov 14, 2026
Back-fills the specs for what landed since bfc99bb without a spec
change: #2005, #2040, #2055, #2056, #2057, #2063, #2068, #2069, #2070
and #2071, and moves .last-sync to 4d491b0.

Generated-by: Claude Opus 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capability:review Deep per-item code review or contributor mentoring family:docs Docs, MISSION.md, READMEs family:pr-management pr-management-* skills family:setup setup-* skills family:tools tools/* substrate:analytics Tool substrate: read-only metrics / dashboards / renderers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants