Skip to content

docs: planning out the auto review#99

Open
nikilok wants to merge 3 commits into
mainfrom
docs/planning-auto-review
Open

docs: planning out the auto review#99
nikilok wants to merge 3 commits into
mainfrom
docs/planning-auto-review

Conversation

@nikilok
Copy link
Copy Markdown
Owner

@nikilok nikilok commented May 9, 2026

Summary by CodeRabbit

  • Documentation
    • Updated Phase 5 sweep algorithm documentation to reflect inline resolution of ambiguous company mapping cases instead of queuing them
    • Refined decision rules for handling manual and public body conflicts
    • Updated operational reporting metrics to track inline resolution outcomes

Review Change Stack

@vercel
Copy link
Copy Markdown

vercel Bot commented May 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
learn-tanstack-start Ignored Ignored Preview May 11, 2026 7:15pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

📝 Walkthrough

Walkthrough

This documentation redesigns Phase 5 of the sweep algorithm to eliminate the asynchronous review queue workflow. Same-rank company mapping ambiguities are now resolved inline during sweep execution using a configurable scoreCandidate function with a MARGIN-based promotion threshold. The decision model, operational reporting, and test expectations are updated accordingly.

Changes

Phase 5 Sweep: Inline Resolution Replaces Review Queue

Layer / File(s) Summary
Overview & Core Changes to Decision Model
docs/phase5-sweep-algorithm.md
Tables touched list is updated to reflect the review queue removal (effective 2026-05-11); per-row action dispatch model removes queue(...) and introduces inline_score (run scorer then promote/bump/log) and log_and_bump (warn and bump for conflicts); decide() clarified as pure function returning intents only.
Decision Rules for Manual & Public_Body
docs/phase5-sweep-algorithm.md
Decision table semantics change: manual mismatches and several public_body conflicts produce log_and_bump(...) intents instead of queue actions; same-rank different-company-number ties now resolve via inline_score rather than enqueueing.
Same-Rank Inline Resolution Specification
docs/phase5-sweep-algorithm.md
New section defines the pure scoreCandidate function (with route-type compatibility hard gate), inline dispatch logic using configurable MARGIN threshold to choose promotion vs bump, one-shot migration for existing 140 queued rows, and updated DDL reflecting dropping hmrc_company_mapping_review_queue.
Operational Reporting & Summary Counters
docs/phase5-sweep-algorithm.md
Per-run summary output fields replace queued metric with inline_resolved and inline_inconclusive; warned counter incremented for inline log_and_bump outcomes (manual_conflict, public_body_conflict).
Test Strategy & Expectations
docs/phase5-sweep-algorithm.md
Decision-table unit tests updated to assert inline_score outcomes for same-rank different company numbers and bump for equal-company same-method cases; integration tests extended to cover log_and_bump behavior (warn + bump + increment warned), inline scoring dispatch (promotion vs bump vs inconclusive), and counter increments.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A queue once queued, now scores instead, 🐰
Inline we trust, no wait ahead,
Same ranks untie with MARGIN's grace,
Phase Five sweeps true, no detour space. 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'docs: planning out the auto review' is vague and generic, using non-descriptive terms that don't convey specific information about the substantial technical changes documented in the PR. Use a more specific title that reflects the main changes, such as 'docs: redesign Phase 5 sweep algorithm to resolve ambiguous cases inline' or similar.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/planning-auto-review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/review-queue-resolver.md`:
- Around line 96-103: Wrap the per-row work so a single failure doesn't abort
the loop: around the existing process(row) call in the loop that iterates over
rows, add per-row try/except handling to catch/log the exception (including
which row/id failed) and continue to the next row; ensure sleep(550ms) still
runs after each row and that print summary(verified, declined, already_applied,
superseded, lock_missed, errored) is unchanged so totals include errored rows.
- Around line 90-99: The current loop uses SELECT ... FOR UPDATE SKIP LOCKED on
hmrc_company_mapping_review_queue and holds the transaction open while calling
process(row) and sleep(550ms), which keeps row locks until commit; instead
implement a two-step "claim then process" pattern: in a short transaction run a
SELECT ... FOR UPDATE SKIP LOCKED LIMIT max_rows to identify rows where
resolved_at IS NULL, update those rows to set claimed_at and claimed_by (or
similar marker) and commit immediately, then outside any transaction iterate
over the claimed rows calling process(row) and sleeping as needed; update code
paths that reference detected_at, resolved_at, process(row), and any
LIMIT/max_rows logic to use claimed_at/claimed_by so locks are not held during
CH/model I/O.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d924de4d-7a24-45ea-bc2c-7aadc762c379

📥 Commits

Reviewing files that changed from the base of the PR and between d95f9fc and 6cfd115.

📒 Files selected for processing (1)
  • docs/review-queue-resolver.md

Comment thread docs/review-queue-resolver.md Outdated
Comment thread docs/review-queue-resolver.md Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/review-queue-resolver.md`:
- Line 197: Two fenced code blocks in docs/review-queue-resolver.md (the one
showing the field list starting with "query, query_slug, query_normalised, ..."
and the project tree starting with "apps/ml-reranker/") are missing language
identifiers and trigger MD040; update both opening fences to include an explicit
language (e.g., change ``` to ```text) so the blocks are fenced as ```text;
ensure you update the fences around the blocks that contain the field list and
the apps/ml-reranker tree respectively.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7914ccbb-1b53-4296-9967-c0bd33885a3a

📥 Commits

Reviewing files that changed from the base of the PR and between 6cfd115 and b5113da.

📒 Files selected for processing (1)
  • docs/review-queue-resolver.md

Comment thread docs/review-queue-resolver.md Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/phase5-sweep-algorithm.md`:
- Around line 251-252: The scorer is being fed a self-comparison:
scoreCandidate(existing_profile, sponsor, existing_profile) passes the same
object as both candidate and existing, biasing company_type and succession
checks; change the calls to use a true baseline (e.g., the original HMRC mapping
record or the common baseline object used for comparison) so the two
scoreCandidate invocations compare different candidate objects against the same
existing baseline (or, if the third parameter is redundant, remove it and
refactor scoreCandidate signature to accept only (candidate, sponsor) and update
its internal logic); also apply the same fix to the repeated calls in the
migration script (the pair at lines ~313-314) to eliminate self-comparison.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6aa6c5be-0499-4236-aa95-e37b92e6b2f1

📥 Commits

Reviewing files that changed from the base of the PR and between b5113da and ea49545.

📒 Files selected for processing (1)
  • docs/phase5-sweep-algorithm.md

Comment on lines +251 to +252
s_e = scoreCandidate(existing_profile, sponsor, existing_profile)
s_p = scoreCandidate(proposed_profile, sponsor, existing_profile)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Logic error in scoreCandidate invocations.

When scoring the existing profile on line 251, you pass existing_profile as both the candidate and existing parameters:

s_e = scoreCandidate(existing_profile, sponsor, existing_profile)

This creates a self-comparison where:

  • Line 235's check candidate.company_type == existing.company_type always evaluates to true → always awards +1
  • Line 223's succession check compares the profile against itself

This pattern repeats on lines 313-314 in the migration script.

The scorer should evaluate both candidates against the same consistent baseline. Consider whether:

  1. The third existing parameter is actually needed, or
  2. Both calls should pass a different reference object (e.g., the original HMRC mapping record rather than a CH profile), or
  3. The scoring model needs revision to avoid self-comparison bias
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/phase5-sweep-algorithm.md` around lines 251 - 252, The scorer is being
fed a self-comparison: scoreCandidate(existing_profile, sponsor,
existing_profile) passes the same object as both candidate and existing, biasing
company_type and succession checks; change the calls to use a true baseline
(e.g., the original HMRC mapping record or the common baseline object used for
comparison) so the two scoreCandidate invocations compare different candidate
objects against the same existing baseline (or, if the third parameter is
redundant, remove it and refactor scoreCandidate signature to accept only
(candidate, sponsor) and update its internal logic); also apply the same fix to
the repeated calls in the migration script (the pair at lines ~313-314) to
eliminate self-comparison.

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