diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index b66c7cde7..25f887fe9 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -855,7 +855,17 @@ the same `persist_edges_for_post` Keyman ingestion already uses. A person R&R actor is opportunistically joined to an existing `cataloged_person` row by name (never originated by R&R itself -- documented gap in the ADR: `cataloged_person` needs `person_side_code`, which R&R's prompt does -not currently capture). +not currently capture). ADR 0019 stores that resolved catalog id on +`post_summary_role` (`cataloged_team_id` / +`cataloged_corporate_entity_id` / `cataloged_person_id`, ADR 0019 / +0021) so a later read does not rejoin `corporate_entity` by +`entity_name`. Fetch returns the person foreign key as +`catalog_node_id` the same way. Historical backfill leaves a role +unbound when two same-named mentions already exist on the post. +Open a post whose R&R names an organization that shares a display name +with another catalog row: the chip keeps the id persist stored. Click +it to walk that organization, not the homonym. Click a person chip to +walk the stored person even when Keyman was not extracted on that post. ## Phase 12: a real counterparty organization is auto-created, not left permanently unresolved diff --git a/CHANGELOG.d/0.86.3-role-person-catalog-identity.md b/CHANGELOG.d/0.86.3-role-person-catalog-identity.md new file mode 100644 index 000000000..d47037bc8 --- /dev/null +++ b/CHANGELOG.d/0.86.3-role-person-catalog-identity.md @@ -0,0 +1,3 @@ +R&R person chips read the stored catalog id. Historical person backfill +leaves homonym mentions unbound. A Pending run detail says reconstruction +has not started yet. diff --git a/CHANGELOG.md b/CHANGELOG.md index 13aeb02f9..1aa9c7594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ All notable changes to this project are documented here. Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.86.3] - 2026-08-16 + +### Fixed + +- R&R person chips now read `cataloged_person_id` from + `post_summary_role` (ADR 0021). Open a post whose R&R names a + cataloged person: the chip is a button even when Keyman extraction + was not run on that post. Click it to walk that person, not a later + same-named row. Historical backfill leaves a role unbound when two + same-named mentions already exist. +- Request a lineage reconstruction: the opened Pending panel says + reconstruction has not started yet. + ## [0.86.2] - 2026-08-16 ### Fixed diff --git a/CLAUDE.md b/CLAUDE.md index a11127584..1baf0f59e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -20,3 +20,7 @@ Opening a cutoff title shows the live post -- compare it with the cutoff before treating the body as reconstructed evidence (ADR 0016). `POST /api/analysis-runs` records Pending on an authorized cutoff capture (ADR 0017) and does not reconstruct lineage. +R&R chips read the catalog id stored on `post_summary_role` +(ADR 0019 / 0021), including `cataloged_person_id`. Do not rejoin +`corporate_entity` by `entity_name`. Historical backfill leaves a +role unbound when two same-named mentions already exist on the post. diff --git a/backend/app/post_summary_ingestion.py b/backend/app/post_summary_ingestion.py index 3febf9b21..b1c2e8c32 100644 --- a/backend/app/post_summary_ingestion.py +++ b/backend/app/post_summary_ingestion.py @@ -35,7 +35,11 @@ NullCorporateHierarchyInferenceClient, ) from lineageweave.fixtures import fixture_thread_cast -from lineageweave.knowledge_graph import NODE_CORPORATE_ENTITY, NODE_TEAM +from lineageweave.knowledge_graph import ( + NODE_CORPORATE_ENTITY, + NODE_PERSON, + NODE_TEAM, +) from lineageweave.ontology import ontology_annotations from lineageweave.post_summary import ( ACTOR_TYPE_ORGANIZATION, @@ -61,8 +65,8 @@ async def fetch_persisted_summary( """Return the stored summary payload, or None when none has been written. ``catalog_node_id`` comes from the role row's catalog foreign keys - (ADR 0019). This function does not join ``corporate_entity`` by - ``entity_name``. + (ADR 0019 / 0021). This function does not join ``corporate_entity`` + by ``entity_name``. Person chips read ``cataloged_person_id``. """ header = await conn.fetchrow( "select korean_summary from post_summary_result where post_id = $1", @@ -79,7 +83,8 @@ async def fetch_persisted_summary( select role.actor_name, role.responsibility, role.actor_type_code, role.affiliated_organization_name, role.cataloged_team_id, - role.cataloged_corporate_entity_id + role.cataloged_corporate_entity_id, + role.cataloged_person_id from post_summary_role role where role.post_id = $1 order by role.actor_name @@ -96,6 +101,9 @@ async def fetch_persisted_summary( elif row["cataloged_corporate_entity_id"] is not None: catalog_node_id = str(row["cataloged_corporate_entity_id"]) catalog_node_type_code = NODE_CORPORATE_ENTITY + elif row["cataloged_person_id"] is not None: + catalog_node_id = str(row["cataloged_person_id"]) + catalog_node_type_code = NODE_PERSON payload_roles.append( { "actor_name": row["actor_name"], @@ -215,6 +223,7 @@ async def _replace_summary_projection( for role_index, role in enumerate(summary.roles_and_responsibilities): cataloged_team_id = None cataloged_corporate_entity_id = None + cataloged_person_id = None if role.actor_type_code == ACTOR_TYPE_TEAM: cataloged_team_id = await upsert_team( conn, @@ -226,12 +235,21 @@ async def _replace_summary_projection( cataloged_corporate_entity_id = resolved_organization_ids.get( role_index ) + elif role.actor_type_code == ACTOR_TYPE_PERSON: + person_row = await conn.fetchrow( + "select person_id from cataloged_person " + "where person_name = $1 " + "order by created_at, person_id limit 1", + role.actor_name, + ) + if person_row is not None: + cataloged_person_id = str(person_row["person_id"]) await conn.execute( "insert into post_summary_role " "(post_id, actor_name, responsibility, actor_type_code, " "affiliated_organization_name, cataloged_team_id, " - "cataloged_corporate_entity_id) values " - "($1, $2, $3, $4, $5, $6, $7)", + "cataloged_corporate_entity_id, cataloged_person_id) values " + "($1, $2, $3, $4, $5, $6, $7, $8)", post_id, role.actor_name, role.responsibility, @@ -239,6 +257,7 @@ async def _replace_summary_projection( role.affiliated_organization_name, cataloged_team_id, cataloged_corporate_entity_id, + cataloged_person_id, ) if cataloged_team_id is not None: await conn.execute( @@ -255,18 +274,13 @@ async def _replace_summary_projection( post_id, cataloged_corporate_entity_id, ) - elif role.actor_type_code == ACTOR_TYPE_PERSON: - person_row = await conn.fetchrow( - "select person_id from cataloged_person where person_name = $1 limit 1", - role.actor_name, + elif cataloged_person_id is not None: + await conn.execute( + "insert into post_summary_person_mention (post_id, person_id) " + "values ($1, $2) on conflict do nothing", + post_id, + cataloged_person_id, ) - if person_row is not None: - await conn.execute( - "insert into post_summary_person_mention (post_id, person_id) " - "values ($1, $2) on conflict do nothing", - post_id, - str(person_row["person_id"]), - ) await persist_edges_for_post(conn, post_id) diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py index 21c71bc9a..cbbcc77d7 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -1514,6 +1514,37 @@ def summarize(self, post_title: str, post_body: str) -> PostSummary: assert role["catalog_node_type_code"] == "node_team" +def test_organization_mentioned_only_on_other_corp_private_post_is_forbidden( + client, demo_analyst_token, seeded_db +) -> None: + """A private org mention must not open the related walk through the UNION.""" + + admin_conn = psycopg2.connect(seeded_db["dsn"]) + admin_conn.autocommit = True + try: + with admin_conn.cursor() as cur: + cur.execute( + "insert into corporate_entity " + "(corporate_entity_code, entity_name, entity_level_code) " + "values ('HIDDEN-MENTION', 'Hidden Mention Corp', 'company') " + "returning corporate_entity_id" + ) + hidden_org_id = str(cur.fetchone()[0]) + cur.execute( + "insert into post_organization_mention " + "(post_id, corporate_entity_id) values (%s, %s)", + (seeded_db["other_private_post_id"], hidden_org_id), + ) + finally: + admin_conn.close() + + response = client.get( + f"/api/corporate-entities/{hidden_org_id}/related", + headers={"Authorization": f"Bearer {demo_analyst_token}"}, + ) + assert response.status_code == 403 + + def test_organization_mention_only_posts_appear_in_entity_related( client, demo_analyst_token, seeded_db ) -> None: diff --git a/docker/postgres-init/Dockerfile b/docker/postgres-init/Dockerfile index e394d376e..c46f1e6a0 100644 --- a/docker/postgres-init/Dockerfile +++ b/docker/postgres-init/Dockerfile @@ -25,6 +25,7 @@ COPY migrations/0016_cross_post_actor_identity.sql /docker-entrypoint-initdb.d/1 COPY migrations/0017_prov_o_standard_relations.sql /docker-entrypoint-initdb.d/18-prov-o-standard-relations.sql COPY migrations/0018_analysis_run_registry.sql /docker-entrypoint-initdb.d/19-analysis-run-registry.sql COPY migrations/0019_role_catalog_identity.sql /docker-entrypoint-initdb.d/20-role-catalog-identity.sql +COPY migrations/0021_role_person_catalog_identity.sql /docker-entrypoint-initdb.d/21-role-person-catalog-identity.sql # Official image already drops to this account at runtime; declare it so # the Dockerfile itself satisfies DS-0002 (explicit non-root USER). USER postgres diff --git a/docs/adr/0009-cross-post-actor-identity.md b/docs/adr/0009-cross-post-actor-identity.md index 7bdbfa091..ad10e6c56 100644 --- a/docs/adr/0009-cross-post-actor-identity.md +++ b/docs/adr/0009-cross-post-actor-identity.md @@ -121,7 +121,9 @@ Depends on [ADR 0006](0006-role-responsibility-agent-ontology.md) and [ADR 0007](0007-team-actor-type.md) (actor *type*) and `lineageweave.corporate_hierarchy_resolution` (Bhattacharya & Getoor, 2007, cited there) for the organization-matching this ADR reuses rather -than re-deriving. +than re-deriving. [ADR 0019](0019-role-catalog-identity.md) stores the +resolved catalog id on `post_summary_role` so fetch does not rejoin by +display name. ## References (APA 7th) diff --git a/docs/adr/0018-related-nodes-team-org-walk.md b/docs/adr/0018-related-nodes-team-org-walk.md index ae0a1c331..59eeb48f0 100644 --- a/docs/adr/0018-related-nodes-team-org-walk.md +++ b/docs/adr/0018-related-nodes-team-org-walk.md @@ -49,6 +49,8 @@ Thread-group run list visibility requires at least one ABAC-visible organization chip. - A later public post in a thread group no longer lists a January run that could not have known that post. +- Catalog ids on those chips come from `post_summary_role` (ADR 0019). + Do not rejoin `corporate_entity` by `entity_name`. ## References diff --git a/docs/adr/0019-role-catalog-identity.md b/docs/adr/0019-role-catalog-identity.md index 32b5d0a09..673fab53a 100644 --- a/docs/adr/0019-role-catalog-identity.md +++ b/docs/adr/0019-role-catalog-identity.md @@ -31,7 +31,8 @@ not. `post_summary_role` stores the resolved catalog foreign keys (`cataloged_team_id`, `cataloged_corporate_entity_id`) written during `persist_post_summary`. `fetch_persisted_summary` reads those columns. -It does not join `corporate_entity` by `entity_name`. +It does not join `corporate_entity` by `entity_name`. Person identity +is ADR 0021 (`cataloged_person_id`). Migration `0019_role_catalog_identity.sql` backfills existing rows from a post-scoped mention only when the name match is unique on that post. diff --git a/docs/adr/0021-role-person-catalog-identity.md b/docs/adr/0021-role-person-catalog-identity.md new file mode 100644 index 000000000..755f9e9a6 --- /dev/null +++ b/docs/adr/0021-role-person-catalog-identity.md @@ -0,0 +1,52 @@ +# ADR 0021 — Persist the R&R person catalog identity on the role row + +**Decision status:** Accepted +**Date:** 2026-08-16 +**Depends on:** ADR 0009 cross-post actor identity; ADR 0019 role catalog +identity + +## Context + +ADR 0019 stores `cataloged_team_id` and `cataloged_corporate_entity_id` +on `post_summary_role` so fetch does not rejoin by display name. Person +actors were still joined at read time by `person_name`, or dropped from +the payload entirely. Two people can share a display name. A later +Keyman row with the same name then steals the chip, and a person named +only in R&R (Keyman not extracted on that post) has no button. + +Fellegi and Sunter (1969) treat a match decision as a binding to one +record, not a later re-search by a non-unique attribute. + +## Decision + +`post_summary_role` stores `cataloged_person_id` written during +`persist_post_summary`. `fetch_persisted_summary` reads that column into +`catalog_node_id` / `node_person`. Person lookup, when it still resolves +by name, orders by `created_at`, then `person_id`. It still does not +create a new `cataloged_person` row (ADR 0009 gap). + +Migration `0021_role_person_catalog_identity.sql` backfills existing +rows from a post-scoped mention only when the name match is unique on +that post (`HAVING count(*) = 1`). Two same-named mentions stay unbound. + +At most one of `cataloged_team_id`, `cataloged_corporate_entity_id`, and +`cataloged_person_id` is set, and the set column must match +`actor_type_code`. + +## Consequences + +- Open a post whose R&R names a cataloged person. The chip is a button + even when Keyman extraction was not run on that post. Click it to walk + that person, not a later same-named row. +- Pre-0021 rows with two same-named mentions stay unbound until an + operator re-persists the summary. Do not guess a UUID at migrate time. + +## References + +Fellegi, I. P., & Sunter, A. B. (1969). A theory for record linkage. +*Journal of the American Statistical Association, 64*(328), 1183–1210. +https://doi.org/10.1080/01621459.1969.10501049 + +Bhattacharya, I., & Getoor, L. (2007). Collective entity resolution in +relational data. *ACM Transactions on Knowledge Discovery from Data, +1*(1), Article 5. https://doi.org/10.1145/1217299.1217304 diff --git a/docs/doctoring/ROLE_CATALOG_IDENTITY_REFERENCES.md b/docs/doctoring/ROLE_CATALOG_IDENTITY_REFERENCES.md new file mode 100644 index 000000000..46fa9c9a0 --- /dev/null +++ b/docs/doctoring/ROLE_CATALOG_IDENTITY_REFERENCES.md @@ -0,0 +1,22 @@ +# R&R catalog identity — doctoring + +These are the standards and papers that ground ADR 0019 and ADR 0021. +Cite them in APA 7th when you extend role identity binding or +related-node authorization. + +Bhattacharya, I., & Getoor, L. (2007). Collective entity resolution in +relational data. *ACM Transactions on Knowledge Discovery from Data, +1*(1), Article 5. https://doi.org/10.1145/1217299.1217304 + +Fellegi, I. P., & Sunter, A. B. (1969). A theory for record linkage. +*Journal of the American Statistical Association, 64*(328), 1183–1210. +https://doi.org/10.1080/01621459.1969.10501049 + +Hu, V. C., Ferraiolo, D., Kuhn, R., Schnitzer, A., Sandlin, K., +Miller, R., & Scarfone, K. (2014). *Guide to attribute based access +control (ABAC) definition and considerations* (NIST Special Publication +800-162). National Institute of Standards and Technology. +https://doi.org/10.6028/NIST.SP.800-162 + +Reynolds, D. (Ed.). (2014). *The organization ontology*. World Wide Web +Consortium. https://www.w3.org/TR/vocab-org/ diff --git a/frontend/package.json b/frontend/package.json index fb52f7948..b5209226e 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "frontend", "private": true, - "version": "0.86.2", + "version": "0.86.3", "type": "module", "scripts": { "dev": "vite", diff --git a/frontend/src/App.test.tsx b/frontend/src/App.test.tsx index 65d25259b..e04dbe119 100644 --- a/frontend/src/App.test.tsx +++ b/frontend/src/App.test.tsx @@ -730,6 +730,8 @@ describe("App, authenticated", () => { responsibility: "고객 측 수신", actor_type_code: "prov_person", affiliated_organization_name: "Northridge Grid", + catalog_node_id: "person-priya", + catalog_node_type_code: "node_person", }, { actor_name: "당사", @@ -1150,6 +1152,7 @@ describe("App, authenticated", () => { expect(screen.getByText("첫 번째 이벤트")).toBeInTheDocument(); expect(screen.getByText(/우리 측 후속/)).toBeInTheDocument(); expect(screen.getByRole("button", { name: "R&R Keyman: Ada West" })).toBeInTheDocument(); + expect(screen.getByRole("button", { name: "R&R person: Priya Nair" })).toBeInTheDocument(); expect(screen.getByText("당사").closest("li")).toHaveTextContent("Organization"); expect(screen.queryByRole("button", { name: "R&R Keyman: 당사" })).not.toBeInTheDocument(); await waitFor(() => expect(screen.getByText("간접")).toBeInTheDocument()); @@ -1340,6 +1343,17 @@ describe("App, authenticated", () => { ); }); + it("opens related nodes from an R&R person catalog id", async () => { + stubBackend(); + render(); + await userEvent.click(await screen.findByRole("button", { name: "View post: Public post" })); + await userEvent.click(await screen.findByRole("button", { name: "R&R person: Priya Nair" })); + await waitFor(() => expect(screen.getByText("Related to Priya Nair")).toBeInTheDocument()); + expect(screen.getByText("Related to Priya Nair").closest(".related-keymen")).toHaveTextContent( + "Ada West (Our side)", + ); + }); + it("opens related nodes from an R&R team", async () => { stubBackend(); render(); diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index a511f713d..d30114e31 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1281,7 +1281,24 @@ function PostDetailPopup({ const catalogId = rr.catalog_node_id; const catalogType = rr.catalog_node_type_code; let actorName: ReactNode = {rr.actor_name}; - if (person) { + if (catalogType === NODE_PERSON && catalogId) { + actorName = ( + + ); + } else if (person) { actorName = (