Skip to content

feat: persist leftover-map unexplained leftover share (ADR 0233) - #750

Merged
seonghobae merged 1 commit into
mainfrom
feat/leftover-map-unexplained-share-v2220
Aug 27, 2026
Merged

feat: persist leftover-map unexplained leftover share (ADR 0233)#750
seonghobae merged 1 commit into
mainfrom
feat/leftover-map-unexplained-share-v2220

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Persist leftover-map unexplained leftover share s = U² / R² of raw residual on leftover post–criterion pairs (ADR 0233 / migration 0233). After make seed, closest and farthest leftover pairs sit above the member list with U²/R² next to leftover-map distance d; click opens that post.

The raw-residual identity R² = R̂² + U² + 2 R̂ U yields e + s + x = 1. ADR 0185 already persists x; this increment persists s so buyers do not read leftover residual R, leftover-map distance d, or unexplained leftover U as the leftover the truncated two-axis map cannot reconstruct.

Test plan

  • pytest tests/test_leftover_pairs.py (23 passed)
  • Frontend leftover/i18n/App tests (176 passed)
  • Frontend oxlint clean
  • CI pytest + frontend on this PR
  • After seed: leftover pairs show U²/R² next to d; click opens that post. Hidden posts stay hidden. Comparison strip does not badge unexplained leftover share.

Independent APPROVE required. Do not self-approve. Issues #79 / #87 stay open.


Devin Review

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 19 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e03ce9d8-ad06-43d6-902b-51df56bfd2e8

📥 Commits

Reviewing files that changed from the base of the PR and between 1c140b6 and 4ed22b3.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (28)
  • AGENTS.md
  • ARCHITECTURE.md
  • CHANGELOG.d/2.22.0-leftover-map-unexplained-share.md
  • CHANGELOG.md
  • CLAUDE.md
  • backend/app/report_ingestion.py
  • backend/tests/test_api.py
  • docs/adr/0048-persist-lsirm-leftover-pairs.md
  • docs/adr/0049-leftover-pair-report-ui.md
  • docs/adr/0233-leftover-map-unexplained-share.md
  • frontend/package.json
  • frontend/src/App.test.tsx
  • frontend/src/api.ts
  • frontend/src/components/LeftoverPairList.stories.tsx
  • frontend/src/components/LeftoverPairList.test.tsx
  • frontend/src/components/LeftoverPairList.tsx
  • frontend/src/i18n.test.ts
  • frontend/src/i18n.ts
  • frontend/src/leftoverMapUnexplainedShare.test.ts
  • frontend/src/leftoverMapUnexplainedShare.ts
  • lineageweave/leftover_pairs.py
  • migrations/0233_report_leftover_map_unexplained_share.sql
  • migrations/rollback/0233_report_leftover_map_unexplained_share.sql
  • pyproject.toml
  • scripts/seed_demo_data.py
  • tests/test_leftover_pairs.py
  • tests/test_period_report.py
  • tests/test_schema.py

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.

@devin-ai-integration devin-ai-integration 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.

Devin Review found 1 potential issue.

Devin Review

Comment on lines +253 to +269
def _leftover_map_unexplained_share(residual: float, reconstruction: float) -> float | None:
"""Return ``s = U² / R²`` when both terms are finite; otherwise omit.

Unexplained leftover ``U = R − R̂`` is computed internally.
``s`` is nonnegative because it is a square share. A rank-0 origin
cell stores ``0.0`` when ``R = R̂ = U = 0``. A finite share greater
than 1 is stored when ``|U| > |R|``; do not clamp.
"""
if not np.isfinite(residual) or not np.isfinite(reconstruction):
return None
unexplained = float(residual - reconstruction)
if abs(residual) > _LEFTOVER_SINGULAR_FLOOR:
share = float((unexplained * unexplained) / (residual * residual))
return share if np.isfinite(share) else None
if abs(reconstruction) <= _LEFTOVER_SINGULAR_FLOOR and abs(unexplained) <= _LEFTOVER_SINGULAR_FLOOR:
return 0.0
return None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 Info: Two share functions stay consistent by construction

_leftover_map_unexplained_share mirrors _leftover_map_cross_share exactly: same finite guards, same floor branches, same 0.0/None returns. A cell yielding a finite unexplained share therefore always yields a finite cross share, so the reordered next-action fallback stays consistent and older null-share rows fall through to cross share.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Cycle 2026-08-27T17:05 KST: exact head d4f6cfd still lacks independent APPROVE. Tests/SAST green; Strix failed (fail-closed). mergeable_state=dirty vs current main e357954 (#733). Not self-approving. Not mixing into #640/#680/#720. Independent exact-head APPROVE required before squash-merge.

Persist leftover-map unexplained leftover share s = U² / R² of raw
residual on leftover post–criterion pairs so the leftover the truncated
two-axis map cannot reconstruct is not read as leftover residual R,
leftover-map distance d, unexplained leftover U, or leftover-map cross
share x. Do not persist leftover-map explained share e.

After make seed, closest and farthest leftover pairs sit above the
member list with U²/R² next to leftover-map distance d; click opens
that post. Missing or non-finite share omits the badge rather than
inventing a leftover score. A share greater than 1 is stored, never
clamped. The grouping comparison strip stays on its reduced leftover
payload (distance, residual, reconstruction).

Independent of leftover stacks #640, #680, #720 and dashboard explained
share ADR 0232 (#728).
@seonghobae
seonghobae force-pushed the feat/leftover-map-unexplained-share-v2220 branch from d4f6cfd to 4ed22b3 Compare August 27, 2026 08:48
@seonghobae
seonghobae merged commit 9eee4c1 into main Aug 27, 2026
31 of 32 checks passed
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