Skip to content

Relabel updated reports - #265

Open
mhumzaarain wants to merge 10 commits into
mainfrom
relabel-updated-reports
Open

Relabel updated reports#265
mhumzaarain wants to merge 10 commits into
mainfrom
relabel-updated-reports

Conversation

@mhumzaarain

@mhumzaarain mhumzaarain commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Report Updates trigger labelling

closes #257

  • Report updates will also trigger labeling now.
  • Replaced created_at with updated_at to query reports that need labeling

Summary by CodeRabbit

  • Improvements

    • Updated reports are now detected during labeling scans, including reports created before the scan window.
    • Report edits automatically mark related gate answers and label results as stale.
    • Stale evaluations are reprocessed during subsequent labeling runs, including previously negative gate results.
    • Status and administrative views now accurately reflect freshness after report changes.
  • Documentation

    • Updated troubleshooting guidance for labels affected by report updates and subsequent backfill or periodic scans.
  • Tests

    • Added coverage for report edits, stale status reporting, scan detection, and relabeling behavior.

mhumzaarain and others added 9 commits August 9, 2026 21:22
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings August 10, 2026 10:06

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 02fb970e-5786-49ad-b5b4-a2b5fd6ac212

📥 Commits

Reviewing files that changed from the base of the PR and between 1e76860 and f8ae554.

📒 Files selected for processing (1)
  • AGENTS.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • AGENTS.md

📝 Walkthrough

Walkthrough

Report updates now invalidate related gate answers and label results. Scans select updated reports, labeling reruns stale evaluations, status tools report stale records, and tests cover these behaviors. Design, implementation-plan, and troubleshooting documentation describe the updated timestamp rules.

Changes

Report relabeling

Layer / File(s) Summary
Scan eligibility and checkpoints
docs/superpowers/plans/..., docs/superpowers/specs/..., radis/labels/tasks.py, radis/labels/tests/test_jobs.py, radis/labels/tests/test_scan.py
Scan jobs and incremental scans use Report.updated_at. Older reports are selected after later updates.
Label freshness and reruns
docs/superpowers/plans/..., docs/superpowers/specs/..., radis/labels/labeling.py, radis/labels/scope.py, radis/labels/tests/test_labeling.py, radis/labels/tests/test_scope.py, radis/labels/tests/test_models.py
Gate answers and label results become stale after report updates. Labeling reruns stale gates and results, including previous NO answers.
Stale indicators and status reporting
docs/superpowers/plans/..., radis/labels/models.py, radis/labels/admin.py, radis/labels/management/commands/labels_status.py, radis/labels/tests/test_admin.py, radis/labels/tests/test_labels_status.py
Model, admin, and status checks include report timestamps when determining stale records.
Relabeling troubleshooting guidance
docs/superpowers/plans/..., AGENTS.md
Troubleshooting guidance states that report updates mark labels stale and can trigger processing through backfills or periodic scans.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Report
  participant IncrementalScan
  participant LabelingJob
  participant label_report
  participant GateAnswer
  participant LabelResult
  Report->>IncrementalScan: update updated_at
  IncrementalScan->>LabelingJob: select report after checkpoint
  LabelingJob->>label_report: process report
  label_report->>GateAnswer: rerun stale gate
  GateAnswer-->>label_report: return gate decision
  label_report->>LabelResult: rerun stale label result
Loading

Possibly related PRs

  • openradx/radis#231: The current changes extend its auto-labeling staleness logic to report updates.

Suggested labels: enhancement, Feature

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR relabels edited reports but uses raw updated_at, so unchanged ETL re-upserts can still trigger unnecessary relabeling [#257]. Track genuine report body changes separately, such as with body_updated_at, and use that signal for relabeling decisions.
Docstring Coverage ⚠️ Warning Docstring coverage is 13.64% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary change: relabeling reports after updates.
Out of Scope Changes check ✅ Passed The implementation, tests, design, plan, and documentation changes all support report re-labeling objectives [#257].
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch relabel-updated-reports

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.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Caution

CodeRabbit couldn't update its existing comment. The review summary may be out of date.

Error details
putComment timed out

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
radis/labels/tasks.py (1)

21-21: 🚀 Performance & Scalability | 🔵 Trivial

Add a database index for Report.updated_at.

Report.updated_at is used in scan-job scope filtering and checkpoint checks, but Report has no model indexes or db_index=True for this field, and its migrations do not add one. Add an index so incremental scans do not scan the full report table.

🤖 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 `@radis/labels/tasks.py` at line 21, Add a database index for the
Report.updated_at field, using the model’s existing indexing configuration or
db_index declaration, and create the corresponding migration so the index is
applied to existing databases.
🤖 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 `@AGENTS.md`:
- Line 228: Update the guidance around backfills and LABELING_SCAN_CRON to state
that existing reports require a backfill for a newly created label; a periodic
scan can queue labeling only when an eligible report has been created or updated
after the scan checkpoint. Preserve the note that any report update marks its
labels stale and triggers re-labeling.

In `@docs/superpowers/plans/2026-08-09-relabel-updated-reports.md`:
- Line 578: Update both fenced code examples at the affected documentation
sections to include a language identifier, such as text, immediately after each
opening fence. Ensure both fences satisfy markdownlint MD040 without changing
their example contents.
- Line 18: Replace every documented test command in the plan, including the
referenced occurrences, from `uv run pytest <path> -v` to the repository wrapper
format `uv run cli test -- <path>`, preserving any required verbosity or
arguments according to the documented command convention.

---

Nitpick comments:
In `@radis/labels/tasks.py`:
- Line 21: Add a database index for the Report.updated_at field, using the
model’s existing indexing configuration or db_index declaration, and create the
corresponding migration so the index is applied to existing databases.
🪄 Autofix

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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5a85ed64-e88e-41a6-8ebb-2f8824b08ca6

📥 Commits

Reviewing files that changed from the base of the PR and between 0c913a5 and 1e76860.

📒 Files selected for processing (16)
  • AGENTS.md
  • docs/superpowers/plans/2026-08-09-relabel-updated-reports.md
  • docs/superpowers/specs/2026-08-09-relabel-updated-reports-design.md
  • radis/labels/admin.py
  • radis/labels/labeling.py
  • radis/labels/management/commands/labels_status.py
  • radis/labels/models.py
  • radis/labels/scope.py
  • radis/labels/tasks.py
  • radis/labels/tests/test_admin.py
  • radis/labels/tests/test_jobs.py
  • radis/labels/tests/test_labeling.py
  • radis/labels/tests/test_labels_status.py
  • radis/labels/tests/test_models.py
  • radis/labels/tests/test_scan.py
  • radis/labels/tests/test_scope.py

Comment thread AGENTS.md

- Confirm the label exists and is `active`
- Ensure a backfill has run or the periodic scan (`LABELING_SCAN_CRON`) has ticked since the label/report was created
- Ensure a backfill has run or the periodic scan (`LABELING_SCAN_CRON`) has ticked since the label was created or the report was created/updated (any report update marks its labels stale and triggers re-labeling)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Do not imply that a scan after label creation is sufficient.

radis/labels/tasks.py:incremental_label_scan queues work only when a report changed after the scan checkpoint. It does not inspect label creation time. A newly created label therefore requires a backfill unless a report update also occurs.

Update this guidance to state that a backfill is required for existing reports, while an eligible periodic scan can queue work after report updates.

Proposed wording
-- Ensure a backfill has run or the periodic scan (`LABELING_SCAN_CRON`) has ticked since the label was created or the report was created/updated (any report update marks its labels stale and triggers re-labeling)
+- Run a backfill after creating a label for existing reports. For report updates, an eligible periodic scan (`LABELING_SCAN_CRON`) can queue relabeling.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Ensure a backfill has run or the periodic scan (`LABELING_SCAN_CRON`) has ticked since the label was created or the report was created/updated (any report update marks its labels stale and triggers re-labeling)
- Run a backfill after creating a label for existing reports. For report updates, an eligible periodic scan (`LABELING_SCAN_CRON`) can queue relabeling.
🤖 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 `@AGENTS.md` at line 228, Update the guidance around backfills and
LABELING_SCAN_CRON to state that existing reports require a backfill for a newly
created label; a periodic scan can queue labeling only when an eligible report
has been created or updated after the scan checkpoint. Preserve the note that
any report update marks its labels stale and triggers re-labeling.

- Line length 100 (Ruff), Google Python Style, pyright basic mode.
- Keep docstrings/comments terse — match existing house style; comments only for constraints the code can't show.
- All work happens on the existing branch `relabel-updated-reports`.
- Test command: `uv run pytest <path> -v` from the project root (`/workspaces/adit-radis-workspace/projects/radis`). Tests marked `@pytest.mark.django_db` need the dev Postgres container running.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== candidate files =="
git ls-files | rg '(^|/)docs/src/superpowers/plans/2026-08-09-relabel-updated-reports\.md$|(^|/)uv.lock$|(^|/)pyproject\.toml$|(^|/)README'xargs -r -0 -n 1 echo

echo "== plan occurrences =="
if [ -f docs/superpowers/plans/2026-08-09-relabel-updated-reports.md ]; then
  echo "plan lines count=$(wc -l < docs/superpowers/plans/2026-08-09-relabel-updated-reports.md)"
  rg -n 'uv run (pytest|cli)|pytest' docs/superpowers/plans/2026-08-09-relabel-updated-reports.md || true
fi

echo "== cli/test command declarations =="
rg -n 'name\s*=\s*["'\'']?(pytest|test|cli)|uv run cli|pytest' pyproject.toml README.md uv.lock 2>/dev/null || true

echo "== project root command snippets =="
python3 - <<'PY'
from pathlib import Path
p = Path('pyproject.toml')
if p.exists():
    text=p.read_text()
    for needle in ['name = "cli"', 'name = "test"', '[project.scripts]', '[project.optional-dependencies]', 'uv run cli', 'uv run pytest']:
        print('---', needle)
        try:
            idx=text.index(needle)
            print(text[max(0, idx-120):idx+260])
        except ValueError:
            print('NOT FOUND')
PY

Repository: openradx/radis

Length of output: 269


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== top-level files =="
git ls-files | sed -n '1,120p'

echo "== locate plan file variants =="
git ls-files | rg '2026-08-09-relabel-updated-reports\.md$|superpowers|plans' || true

echo "== locate configs =="
git ls-files | rg '(^|[\/])(pyproject\.toml|uv\.lock|README(\.md)?|tox\.ini|Makefile)$' || true

Repository: openradx/radis

Length of output: 4521


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== plan relevant command references =="
sed -n '15,25p;108,137p;206,216p;248,255p;313,322p;363,371p;436,444p;472,479p;523,531p;546,553p;586,594p' docs/superpowers/plans/2026-08-09-relabel-updated-reports.md

echo "== pyproject scripts/dependencies =="
sed -n '1,220p' pyproject.toml

echo "== root uv.lock package/entrypoint references =="
rg -n 'name\s*= "uv-run-test"|"uv-run-test"|name = "cli"|"cli"|pytest|test' pyproject.toml uv.lock 2>/dev/null || true

echo "== search repository for "uv run cli" and pytest wrapper declarations =="
rg -n 'uv run cli|uv run pytest|pytest run test|test' README.md CONTRIBUTING.md docs CONTRIBUTING.md AGENTS.md pyproject.toml 2>/dev/null || true

echo "== inspect cli.py structure =="
sed -n '1,260p' cli.py

Repository: openradx/radis

Length of output: 46152


🌐 Web query:

adit-radis-shared commands.test Typer pytest

💡 Result:

The adit-radis-shared repository is a shared library containing common Django apps, utilities, and infrastructure components used by the ADIT and RADIS projects [1][2]. Within the OpenRadX ecosystem, Typer is used for CLI commands [2], and pytest is the standard testing framework [3]. While there is no specific, public-facing command literally named commands.test in the repository, the project structure commonly employs pytest to execute test suites [3]. In development environments, such as the unified adit-radis-workspace, testing is typically handled via standard pytest commands or via wrappers provided by the dev container environment (often integrated with tools like uv) [4][5]. To run tests in projects utilizing this shared library, you would typically execute the following via your terminal: 1. Standard pytest execution (ensure you are in the project root or the directory containing your tests): pytest 2. If using the project's preferred toolchain (uv) as seen in recent repository configurations: uv run pytest 3. For specific testing configurations that might exist in the broader OpenRadX ecosystem, look for scripts in the project root or Makefile equivalents that invoke pytest, as these projects often use pytest-django and other plugins to handle complex test setups (e.g., database teardowns or async tasks) [3][6]. If you are encountering a specific "commands.test" reference, it may be a custom alias defined in the project's local Makefile, a custom Typer command implemented within the project, or a specific task defined in a task runner (like Procrastinate or a custom orchestration script) used within the ADIT/RADIS stack [2]. Check the project's pyproject.toml or Makefile for any defined script aliases.

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== repository docs for test command =="
sed -n '30,60p' AGENTS.md
sed -n '24,32p' docs/dev-docs/contributing.md

echo "== cli test command references =="
rg -n 'def test|commands\.test|test\(' cli.py pyproject.toml AGENTS.md README.md docs/dev-docs/contributing.md || true

echo "== package metadata for adit-radis-shared version and tests if any =="
rg -n 'adit-radio-shared|adit-radis-shared|commands\.test|def test' pyproject.toml uv.lock AGENTS.md cli.py || true

Repository: openradx/radis

Length of output: 3252


Use the documented uv run cli test wrapper for test steps.

cli.test is registered as the repository test command, and AGENTS.md documents tests under uv run cli test --. Replace the uv run pytest <path> command with uv run cli test -- <path> (or use the documented direct pytest exception format if it must be explicit), including lines 18, 112, 133, 211, 252, 318, 367, 440, 476, 527, 550, and 590.

🤖 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/superpowers/plans/2026-08-09-relabel-updated-reports.md` at line 18,
Replace every documented test command in the plan, including the referenced
occurrences, from `uv run pytest <path> -v` to the repository wrapper format `uv
run cli test -- <path>`, preserving any required verbosity or arguments
according to the documented command convention.

Source: Learnings


In the "Labels Not Appearing" section, change the second bullet from:

```

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add language identifiers to both fenced examples.

markdownlint-cli2 reports MD040 at Lines 578 and 584. Add text or another suitable language identifier after each opening fence.

Also applies to: 584-584

🧰 Tools
🪛 markdownlint-cli2 (0.23.2)

[warning] 578-578: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 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/superpowers/plans/2026-08-09-relabel-updated-reports.md` at line 578,
Update both fenced code examples at the affected documentation sections to
include a language identifier, such as text, immediately after each opening
fence. Ensure both fences satisfy markdownlint MD040 without changing their
example contents.

Source: Linters/SAST tools

Copilot AI review requested due to automatic review settings August 12, 2026 09:32

Copilot AI 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.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

radis/labels/tasks.py:21

  • Using the generic updated_at here makes every save a labeling event, not just a body change. In particular, _bulk_upsert_reports unconditionally assigns existing.updated_at = now (radis/reports/api/viewsets.py:153), so an identical ETL re-sync will put the entire corpus into scope and the new freshness checks will force gate and label LLM calls for every report. Key this window and staleness to an actual body revision (for example, body_updated_at or a persisted body hash updated only when body differs) so no-op re-upserts remain no-ops.
        return Report.objects.filter(updated_at__gte=job.scan_from).order_by("pk")

Comment thread radis/labels/labeling.py
Comment on lines +50 to +52
if g.id not in existing_gates
or existing_gates[g.id].generated_at < g.updated_at
or existing_gates[g.id].generated_at < report.updated_at
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.

Labeling: report body edits don't invalidate labels — and the obvious updated_at fix would re-label on every ETL re-upsert

3 participants