Skip to content

fix: enforce forecast attribution and allergen advice - #31

Merged
IceCodeNew merged 1 commit into
masterfrom
codex/fix-forecast-attribution-allergens
Jul 16, 2026
Merged

fix: enforce forecast attribution and allergen advice#31
IceCodeNew merged 1 commit into
masterfrom
codex/fix-forecast-attribution-allergens

Conversation

@IceCodeNew

@IceCodeNew IceCodeNew commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • require source IDs for forecast headlines and overviews, and render every attribution with an explicit “来源” label
  • preserve conflicting weather-source claims in the LLM contract and prefer identifiable local weather authorities
  • add structured advice topics and reject forecasts that omit required advice, including allergen guidance when QWeather or Open-Meteo provides allergen data
  • document the updated attribution and advice-validation contracts

Root cause

Headline and overview fields had no source-ID fields, so their claims could not be attributed. Lifestyle advice was prompt-only: the validator checked source IDs, publication state, and message length, but did not verify required advice categories. QWeather allergy index data therefore reached the model but could be silently omitted.

Validation

  • mise exec -- prek run
  • mise exec -- uv run --with pytest --with pytest-cov -- pytest --cov --cov-branch --cov-report=xml
  • 445 tests passed
  • line coverage: 99.70% (master: 99.69%)
  • branch coverage: 98.31% (master: 98.28%)

Summary by CodeRabbit

  • New Features
    • Weather briefings now provide clearly categorized lifestyle advice, including allergen-related guidance when available.
    • Briefing headlines, overviews, conclusions, warnings, and advice include source attributions.
    • Conflicting weather information is presented transparently instead of being merged into a single definitive statement.
  • Improvements
    • Source links and attribution formatting are more consistent across HTML and plain-text reports.
    • Briefing validation now catches incomplete advice and invalid source references before delivery.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@IceCodeNew, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7e1b910f-1670-43cd-a9c6-ef8d61134e38

📥 Commits

Reviewing files that changed from the base of the PR and between 819b6ab and 6981ebe.

📒 Files selected for processing (17)
  • docs/design.md
  • tests/test_allergen.py
  • tests/test_llm.py
  • tests/test_prompts.py
  • tests/test_reference_data.py
  • tests/test_render.py
  • tests/test_service.py
  • tests/test_weather_context.py
  • weather_briefing/allergen.py
  • weather_briefing/data/provider_defaults.json
  • weather_briefing/llm.py
  • weather_briefing/models.py
  • weather_briefing/prompts.py
  • weather_briefing/reference_data.py
  • weather_briefing/render.py
  • weather_briefing/service.py
  • weather_briefing/weather_context.py
📝 Walkthrough

Walkthrough

The change adds allergen availability metadata, introduces typed advice topics, strengthens source citation validation and conflict-handling prompts, enforces required forecast advice, and centralizes source attribution in HTML and plain-text renderers.

Changes

Briefing contracts and validation

Layer / File(s) Summary
Allergen availability propagation
weather_briefing/models.py, weather_briefing/weather_context.py, weather_briefing/allergen.py, tests/test_weather_context.py, tests/test_allergen.py, docs/design.md
Weather snapshots and source documents record allergen information derived from provider lifestyle indices.
Sourced briefing contract
weather_briefing/models.py, weather_briefing/llm.py, weather_briefing/prompts.py, tests/test_llm.py, tests/test_prompts.py, docs/design.md
Advice uses explicit topics, while briefing fields and array entries require non-empty known source IDs and prompts describe source conflicts.
Forecast advice enforcement
weather_briefing/service.py, tests/test_service.py
Forecast payloads receive required advice topics, including conditional allergen advice, and validation rejects missing topics.
Attribution rendering updates
weather_briefing/render.py, tests/test_render.py
HTML and plain-text output centralize attribution formatting for conclusions, advice, and active warnings.

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

Sequence Diagram(s)

sequenceDiagram
  participant QWeatherProvider
  participant BriefingService
  participant LLM
  participant parse_result
  participant Renderer
  QWeatherProvider->>BriefingService: provide weather documents and allergen metadata
  BriefingService->>LLM: send required advice topics
  LLM->>parse_result: return sourced briefing JSON
  parse_result->>BriefingService: return validated BriefingResult
  BriefingService->>Renderer: render structured conclusions and advice
  Renderer-->>BriefingService: return attributed HTML or plain text
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: forecast attribution/source IDs and allergen advice enforcement.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-forecast-attribution-allergens

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.

@IceCodeNew
IceCodeNew requested a review from Copilot July 16, 2026 02:28

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.

@IceCodeNew
IceCodeNew marked this pull request as ready for review July 16, 2026 02:29
@IceCodeNew
IceCodeNew force-pushed the codex/fix-forecast-attribution-allergens branch from 907dab8 to 819b6ab Compare July 16, 2026 02:57
@IceCodeNew

Copy link
Copy Markdown
Owner Author

Review feedback handled

Independently verified all six reported items.

  • Applied two maintainability improvements: renamed the generic sourced-text parser and initialized the QWeather allergen-availability flag before the conditional fetch.
  • Added renderer contract coverage confirming that missing source references fail fast instead of being hidden behind placeholder attribution.
  • Kept current-context-only allergen requirements and the deliberate invalid-briefing test path unchanged because both match the documented contract.

Validation: 447 tests passed; line coverage 99.70%; branch coverage 98.31%; all pre-commit hooks passed.

Amended commit: 819b6ab

@IceCodeNew

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@IceCodeNew
IceCodeNew requested a review from Copilot July 16, 2026 03:07

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.

@IceCodeNew
IceCodeNew force-pushed the codex/fix-forecast-attribution-allergens branch from 819b6ab to 5e38c20 Compare July 16, 2026 03:11
@IceCodeNew
IceCodeNew requested a review from Copilot July 16, 2026 03:11

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

🤖 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 `@weather_briefing/llm.py`:
- Around line 103-110: Update _summarize’s sourced-field parsing to normalize
malformed model responses into LLMError: make cited_source_ids safely validate
source_ids before iterating, and use sourced_text(value, key) for conclusions
and disaster tracking plus sourced_text(value, "advice") for advice. Ensure
missing, null, non-string, or empty text fields raise LLMError so the existing
retry path handles them.

In `@weather_briefing/service.py`:
- Around line 259-262: Update the validation around the required-topic checks
and the corresponding logic at the alternate location to ensure every allergen
advice item cites at least one current document whose has_allergen_information
is true. Do not accept allergen advice solely because its source ID is known;
preserve existing validation for other topics and raise LLMError when the
allergen citation requirement is unmet.

In `@weather_briefing/weather_context.py`:
- Around line 228-232: Replace the hardcoded QWeather allergy type value in the
daily advice logic with a value loaded from a validated data configuration file
under the existing weather briefing data resources. Add the configuration entry,
load it through the established configuration mechanism, and use that value in
the allergen_advice_available check while preserving the current matching
behavior.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 21cd6a34-0ca6-4ab6-b87d-a5613eac879e

📥 Commits

Reviewing files that changed from the base of the PR and between 2cf8e66 and 819b6ab.

📒 Files selected for processing (14)
  • docs/design.md
  • tests/test_allergen.py
  • tests/test_llm.py
  • tests/test_prompts.py
  • tests/test_render.py
  • tests/test_service.py
  • tests/test_weather_context.py
  • weather_briefing/allergen.py
  • weather_briefing/llm.py
  • weather_briefing/models.py
  • weather_briefing/prompts.py
  • weather_briefing/render.py
  • weather_briefing/service.py
  • weather_briefing/weather_context.py

Comment thread weather_briefing/llm.py
Comment thread weather_briefing/service.py
Comment thread weather_briefing/weather_context.py
@IceCodeNew
IceCodeNew force-pushed the codex/fix-forecast-attribution-allergens branch from 5e38c20 to 6981ebe Compare July 16, 2026 03:15
@IceCodeNew
IceCodeNew requested a review from Copilot July 16, 2026 03:15

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.

@IceCodeNew

Copy link
Copy Markdown
Owner Author

Review-autofix complete

Verified the local Codex review and the completed CodeRabbit review independently.

  • Moved the QWeather allergen index code into validated reference data and renamed the result validator.
  • Rejected enum-derived required topics because allowed advice vocabulary and mandatory forecast coverage are separate contracts.
  • Normalized malformed sourced text/source IDs to LLMError so model retries can repair them.
  • Required allergen advice to cite a current allergen-capable source.
  • Left the remaining optional abstractions and intentional fail-fast/rendering behavior unchanged.

Final validation: 468 tests passed; line coverage 99.70%; branch coverage 98.34%; all pre-commit hooks and CI checks passed. CodeRabbit completed with no unresolved threads. Copilot could not run because the requester quota is exhausted.

Final amended commit: 6981ebe

@IceCodeNew
IceCodeNew merged commit b9b522a into master Jul 16, 2026
18 checks passed
@IceCodeNew
IceCodeNew deleted the codex/fix-forecast-attribution-allergens branch July 16, 2026 03:23
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