Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,13 @@ in the same spirit) -- never against real data, per the hard rule above.
against a live local stack (`make up`) and self-skip without one -- see
[README.md](README.md#local-product-stack-docker-compose).

Period leftover pairs (ADR 0017 / 0018) are computed in
Period leftover pairs (ADR 0048 / 0049 / 0171) are computed in
`lineageweave/leftover_pairs.py` from the residual after a real
GRM/GPCM score, never invented. Missing cells stay out of the
Gabriel factorization. Closest and farthest post–criterion pairs
persist to `report_leftover_pair` and sit above the member list so
a click opens that post.
persist to `report_leftover_pair` with leftover-map rank so rank 0
is not read as structure, and sit above the member list so a click
opens that post.

`frontend/` has its own toolchain (Node pinned via `frontend/mise.toml`,
pnpm via Corepack -- do not add a second Node package manager or a
Expand Down
7 changes: 4 additions & 3 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ on those same fixed parameters (Kim, 2006 FIPC). After scoring,
`information_polytomous` ranks the shared-bank items by Fisher
information at the group's mean θ (Lord, 1980 max-info CAT). Rankings
persist to `report_item_information`. After those IRT main effects,
residual SVD leftover pairs (Jeon et al., 2021; ADR 0017) persist to
`report_leftover_pair`. Results persist to
residual SVD leftover pairs (Jeon et al., 2021; ADR 0048 / 0171) persist to
`report_leftover_pair` with leftover-map rank. Results persist to
`report_period_score` / `report_member_score`.
`GET /api/reports/{grouping}` lists the trend;
`GET /api/reports/{grouping}/{period}` is ABAC-filtered;
Expand All @@ -601,7 +601,8 @@ bank as the dummy high/low band rows, so comparison-strip click
through opens those DAG posts. Report members include the earliest
open ticket title, status lookup label, and due date when one exists. The home page renders
the actual mean θ, the FIPC delta, the CAT-selected item, leftover
closest/farthest pairs above the member list, and the
closest/farthest pairs (leftover-map rank next to leftover-map
distance `d`) above the member list, and the
PU / corp / thread comparison -- never a placeholder. TEPP is unchanged.

## Phase 6b: Knowledge Graph as a real Ontology + Semantic Layer
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.d/2.12.21-leftover-map-rank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## 2.12.21 — Leftover-map rank

- Persist leftover-map rank on leftover post–criterion pairs (ADR 0171).
Rank is the number of Gabriel singular values above the floor. After
`make seed`, closest and farthest leftover pairs sit above the member
list with `rank {n}` next to leftover-map distance `d`; click opens
that post. Rank 0 names no leftover structure. Never invent a leftover
score or a theta.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ All notable changes to this project are documented here. Format follows
environment, so local OIDC and synthetic-data workflows resolve the same
pinned dependencies as CI.

## [2.12.21] - 2026-08-24

### Added

- Period leftover pair rows now name leftover-map rank after IRT main
effects next to leftover-map distance `d`, then open that post
(Jeon et al., 2021, eq. 3; ADR 0171). Rank 0 names no leftover
structure rather than inventing a leftover score.

Comment on lines +216 to +224

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: 2.12.21 changelog entry placed out of version order

The new ## [2.12.21] section sits between ## [2.12.19] and ## [2.12.20] (CHANGELOG.md:216). Newest-first order would put 2.12.21 above both. The surrounding entries are already non-monotonic (2.12.19 before 2.12.20), so this may reflect merge-order layout rather than a defect.

Open in Devin Review

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

## [2.12.6] - 2026-08-20

### Added
Expand Down
4 changes: 3 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ chip name contains `Corporate entity: Demo Corp` and the persisted
mean θ. The period-report panel says Demo Corp is the opened grouping
and to read its mean θ and member posts, then open a post. Those
members land immediately under that next action, ahead of Other Corp
and the week strip. Opening Public post names the next action: read
and the week strip. After `make seed`, leftover closest/farthest pairs
sit above the member list with leftover-map rank; rank 0 names no
leftover structure. Opening Public post names the next action: read
Event Lineage, Keyman, and evaluation on that post. The popup Event
Lineage DAG marks that post current. After that current node, the
popup names Keyman and evaluation as the next read. After landed
Expand Down
13 changes: 10 additions & 3 deletions backend/app/report_ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,9 @@ async def persist_period_report(
"""
insert into report_leftover_pair (
grouping_kind, grouping_key, period_code, rubric_version,
pair_kind, post_id, criterion_code, leftover_distance, leftover_residual
) values ($1,$2,$3,$4,$5,$6,$7,$8,$9)
pair_kind, post_id, criterion_code, leftover_distance, leftover_residual,
leftover_map_rank
) values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)
""",
grouping_kind,
grouping_key,
Expand All @@ -455,6 +456,7 @@ async def persist_period_report(
pair.criterion_code,
pair.leftover_distance,
pair.leftover_residual,
pair.leftover_map_rank,
)


Expand Down Expand Up @@ -601,7 +603,7 @@ async def fetch_period_reports(
leftover = await conn.fetch( # nosemgrep: python.lang.security.audit.sqli.asyncpg-sqli.asyncpg-sqli
f"""
select lp.grouping_key, lp.pair_kind, lp.post_id, lp.criterion_code,
lp.leftover_distance, lp.leftover_residual, p.post_title,
lp.leftover_distance, lp.leftover_residual, lp.leftover_map_rank, p.post_title,
p.visibility_code, p.corporate_entity_id,
({_SOURCE_CONTEXT_PRESENT_SQL}) as has_real_source_context
from report_leftover_pair lp
Expand Down Expand Up @@ -698,6 +700,11 @@ async def fetch_period_reports(
"criterion_code": str(row["criterion_code"]),
"leftover_distance": float(row["leftover_distance"]),
"leftover_residual": float(row["leftover_residual"]),
"leftover_map_rank": (
None
if row["leftover_map_rank"] is None
else int(row["leftover_map_rank"])
),
"visibility_code": row["visibility_code"],
"corporate_entity_id": str(row["corporate_entity_id"]),
"has_real_source_context": bool(row["has_real_source_context"]),
Expand Down
8 changes: 8 additions & 0 deletions backend/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
/ "migrations"
/ "0102_project_bound_summary_event.sql"
)
_LEFTOVER_MAP_RANK_MIGRATION = (
Path(__file__).resolve().parents[2]
/ "migrations"
/ "0171_report_leftover_map_rank.sql"
)


def _postgres_available() -> bool:
Expand Down Expand Up @@ -226,6 +231,7 @@ def seeded_db(demo_analyst_token):
cur.execute(_MAJOR_EVENT_ACTION_MIGRATION.read_text())
cur.execute(_PROJECT_BOUND_ACTION_MIGRATION.read_text())
cur.execute(_PROJECT_BOUND_EVENT_MIGRATION.read_text())
cur.execute(_LEFTOVER_MAP_RANK_MIGRATION.read_text())
cur.execute(
"insert into common_lookup_value (lookup_category, lookup_code, lookup_label) values "
"('corporate_entity_level', 'group', 'Group'), "
Expand Down Expand Up @@ -4518,6 +4524,8 @@ def test_seed_period_report_surfaces_on_get_reports(client, demo_analyst_token,
assert leftover_kinds <= {"closest", "farthest"}
assert all(pair["post_title"] for pair in high_report.get("leftover_pairs", []))
assert all(pair["leftover_distance"] >= 0 for pair in high_report.get("leftover_pairs", []))
for pair in high_report.get("leftover_pairs", []):
assert pair["leftover_map_rank"] >= 0

week3 = client.get(
"/api/reports/process_unit/2026-W03",
Expand Down
1 change: 1 addition & 0 deletions docker/postgres-init/migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ for migration in /opt/lineageweave/migrations/*.sql; do
case "$migration_name" in
0012_*|0013_*|0014_*|0015_*|0016_*|0017_*|0018_*|0019_*|0020_*|0021_*|0022_*|0023_*|0024_*|0025_*|0026_*|0027_*|0028_*|0029_*|0030_*|0031_*|0032_*|0033_*|0034_*|0035_*|0036_*|0037_*|0038_*|0039_*|0040_*|0041_*|0042_*|0043_*|0044_*|0045_*|0046_*|0047_*|0048_*|0049_*|0050_*) ;;
0060_*|0100_*|0101_*|0102_*) ;;
0171_*) ;;
*) continue ;;
esac
printf 'Applying %s\n' "$migration_name"
Expand Down
7 changes: 4 additions & 3 deletions docs/adr/0003-fast-mlsirm-report-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ than one large PR:
`information_polytomous` (Lord, 1980 max-info). Persist the ranking
(`report_item_information`) and show the rank-1 item on the Period
reports panel. Do not reimplement an information function here.
7. **Leftover-pair slice** (shipped in 0.71.2; ADR 0017 / 0018): after
7. **Leftover-pair slice** (shipped in 0.71.2; ADR 0048 / 0049 / 0171): after
IRT main effects, persist closest and farthest post–criterion pairs
from the residual leftover map. Do not fork LSIRM; do not invent a
leftover-pair API inside `fast-mlsirm` in this slice.
from the residual leftover map, including leftover-map rank so a
rank-0 collapse is not read as leftover structure. Do not fork LSIRM;
do not invent a leftover-pair API inside `fast-mlsirm` in this slice.

**TEPP boundary.** [ARCHITECTURE.md](../../ARCHITECTURE.md) already
assigns calibrated temporal/event measurement to
Expand Down
6 changes: 5 additions & 1 deletion docs/adr/0048-persist-lsirm-leftover-pairs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

**Decision status:** Accepted
**Date:** 2026-08-17
**Amended by:** [ADR 0171](0171-leftover-map-rank.md) (full map rank)

## Context

Expand Down Expand Up @@ -30,7 +31,10 @@ and one `farthest` observed cell per period report in
`report_leftover_pair` (3NF, two-or-more-word `snake_case`).

The biplot lives in `lineageweave/leftover_pairs.py` so leftover
tests do not import `period_report` or `fast_mlsirm`.
tests do not import `period_report` or `fast_mlsirm`. Each leftover
row names leftover-map rank: the number of Gabriel singular values
above the floor (ADR 0171). A rank-0 collapse still emits a stable
pair; the stored rank is then `0`, not invented leftover structure.

Cascade the rows with `report_period_score`. A leftover post must
also be a `report_member_score` row, and the leftover criterion
Expand Down
13 changes: 9 additions & 4 deletions docs/adr/0049-leftover-pair-report-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

**Decision status:** Accepted
**Date:** 2026-08-17
**Amended by:** [ADR 0171](0171-leftover-map-rank.md) (full map rank)

## Context

Expand All @@ -17,10 +18,14 @@ second navigation surface.

On each period-report group, render leftover pairs **above** the
member list. Each pair is a button: closest or farthest label, post
title, criterion short label, leftover-map distance, and the next
action (“Open this post to read the criterion it sat closest to /
farthest from after main effects.”). Clicking the button opens that
post with the same handler as a member row.
title, criterion short label, leftover-map distance, leftover-map
rank when the value is a finite non-negative integer, and the next
action. Rank 0 next action: leftover map has no leftover structure
after IRT main effects; open this post. Rank ≥ 1 next action: read
leftover map rank after IRT main effects, then open this post.
Missing rank omits the badge and keeps the closest/farthest action.
Clicking the button opens that post with the same handler as a member
row. Rank naming is [ADR 0171](0171-leftover-map-rank.md).

After `make seed`, closest and farthest leftover pairs sit above the
member list. Click a pair to open that post.
Expand Down
71 changes: 71 additions & 0 deletions docs/adr/0171-leftover-map-rank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ADR 0171 — Name leftover-map rank on leftover pairs

**Decision status:** Accepted
**Date:** 2026-08-24

Amends [ADR 0048](0048-persist-lsirm-leftover-pairs.md) and
[ADR 0049](0049-leftover-pair-report-ui.md).

## Context

ADR 0048 already persists leftover-map distance and leftover residual
`R = Y − E[Y|θ, item]` on `report_leftover_pair`. A rank-0 residual
still emits a stable closest/farthest pair so `make seed` is not empty;
the stored distance is then zero, not a fabricated interaction. ADR 0049
renders those pairs above the member list. Without leftover-map rank, a
buyer cannot tell a Gabriel biplot with leftover structure (Jeon et al.,
2021, eq. 3) from an origin collapse that still shows `d 0.00`.

This increment does not persist leftover-map coordinates, does not name
observed `Y` / expected `E`, does not change leftover-map axis count, and
does not land Post quality on the leftover criterion.

The unprotected-stack ADR for the same buyer fact was 0164. This
protected-main reconstruction uses **0171** so it does not collide with
two-axis leftover-map distance (0166), leftover coverage (0168),
leftover-map axis share (0169), or leftover observed Y / expected E
(0170).

## Decision

Each leftover pair names `leftover_map_rank`: the number of Gabriel
singular values above the leftover singular floor on the complete-case
residual rectangle. Closest and farthest pairs on one period report share
that rank. A fallback pair that is not placed on a leftover map stores
rank `0`. Migration `0171` is the single source of the column on every
install path; shipped migrations (`0001` / `0012`) are never rewritten.
It adds a nullable column so older leftover rows keep distance and residual
without fabricating a rank.

The pair button shows `rank {n}` when the value is a finite
non-negative integer. Rank `0` next action: leftover map has no leftover
structure after IRT main effects; open this post. Rank `≥ 1` next action:
read leftover map rank after IRT main effects, then open this post. Omit
the rank badge when the value is missing. Do not invent a leftover score.
Do not invent a theta.

## Consequences

`GET /api/reports/{grouping}/{period}` returns `leftover_map_rank`. After
`make seed`, closest and farthest leftover pairs sit above the member
list with leftover-map rank; click opens that post. Hidden posts stay
hidden.

## Related

Independent of leftover interaction-map persistence, leftover-criterion
evaluation landing, leftover residual UI extraction, leftover-map
complete-case coverage, leftover-map axis share, leftover pairs on the
grouping comparison strip, two-axis leftover-map distance, and leftover
observed `Y` / expected `E`.

## References

Gabriel, K. R. (1971). The biplot graphic display of matrices with
application to principal component analysis. *Biometrika, 58*(3),
453–467. https://doi.org/10.1093/biomet/58.3.453

Jeon, M., Jin, I. H., Schweinberger, M., & Baugh, S. (2021). Mapping
unobserved item–respondent interactions: A latent space item response
model with interaction map. *Psychometrika, 86*(2), 378–403.
https://doi.org/10.1007/s11336-021-09762-5
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "frontend",
"private": true,
"version": "2.12.6",
"version": "2.12.21",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ describe("App, authenticated", () => {
criterion_code: "sales_lead_specificity",
leftover_distance: 0.12,
leftover_residual: 0.4,
leftover_map_rank: 1,
},
{
pair_kind: "farthest",
Expand All @@ -940,6 +941,7 @@ describe("App, authenticated", () => {
criterion_code: "general_sentiment_negative",
leftover_distance: 1.84,
leftover_residual: -1.1,
leftover_map_rank: 1,
},
],
members: [
Expand Down Expand Up @@ -3357,13 +3359,15 @@ describe("App, authenticated", () => {
});
expect(closestPair).toHaveTextContent("Closest leftover: Public post · sales-lead");
expect(closestPair).toHaveTextContent(
"Open this post to read the criterion it sat closest to after main effects.",
"Leftover map rank 1 after IRT main effects. Open this post.",
);
expect(closestPair).toHaveTextContent("rank 1");
expect(closestPair).toHaveTextContent("d 0.12");
expect(farthestPair).toHaveTextContent("Farthest leftover: Specification revision requested · negative");
expect(farthestPair).toHaveTextContent(
"Open this post to read the criterion it sat farthest from after main effects.",
"Leftover map rank 1 after IRT main effects. Open this post.",
);
expect(farthestPair).toHaveTextContent("rank 1");
expect(farthestPair).toHaveTextContent("d 1.84");
const memberButton = screen.getByRole("button", { name: /open report post: public post/i });
expect(closestPair.compareDocumentPosition(memberButton) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
Expand Down
15 changes: 12 additions & 3 deletions frontend/src/App.tsx
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ import {
useLocale,
} from "./i18n";
import { rememberOidcReturnUrl, returnUrlFromLocation } from "./oidcReturnUrl";
import { formatLeftoverMapRank, LEFTOVER_RANK_STRUCTURE_ACTION, LEFTOVER_RANK_ZERO_ACTION } from "./leftoverMapRank";
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Outdated
import "./App.css";

function orchestratorUnavailableMessage(err: unknown, action: string): string {
Expand Down Expand Up @@ -3394,10 +3395,17 @@ function ReportsPanel({
{report.leftover_pairs.map((pair) => {
const kindLabel =
pair.pair_kind === "farthest" ? "Farthest leftover" : "Closest leftover";
const rankBadge = formatLeftoverMapRank(pair.leftover_map_rank);
const nextAction =
pair.pair_kind === "farthest"
? "Open this post to read the criterion it sat farthest from after main effects."
: "Open this post to read the criterion it sat closest to after main effects.";
rankBadge !== null
? pair.leftover_map_rank === 0
? t(LEFTOVER_RANK_ZERO_ACTION)
: tf(LEFTOVER_RANK_STRUCTURE_ACTION, {
rank: String(pair.leftover_map_rank),
})
: pair.pair_kind === "farthest"
? t("Open this post to read the criterion it sat farthest from after main effects.")
: t("Open this post to read the criterion it sat closest to after main effects.");
const criterion = criterionShortLabel(pair.criterion_code);
return (
<li
Expand All @@ -3413,6 +3421,7 @@ function ReportsPanel({
{kindLabel}: {pair.post_title} · {criterion}
</span>
<span className="post-badge">{nextAction}</span>
{rankBadge ? <span className="post-badge">{rankBadge}</span> : null}
<span className="post-badge">d {pair.leftover_distance.toFixed(2)}</span>
</button>
</li>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ export interface LeftoverPair {
criterion_code: string;
leftover_distance: number;
leftover_residual: number;
leftover_map_rank?: number | null;
}

export interface PeriodGroupReport {
Expand Down
Loading
Loading