Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 16 additions & 1 deletion pm-stack/projector/src/projector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
upsertItem,
upsertComment,
markCommentDeleted,
deleteItem,
recordPush,
ItemRow,
CommentRow,
Expand All @@ -17,6 +18,7 @@ export interface ProjectorStore {
upsertItem(i: Omit<ItemRow, "fetched_at">): Promise<void>;
upsertComment(c: Omit<CommentRow, "fetched_at">): Promise<void>;
markCommentDeleted(c: Omit<CommentRow, "fetched_at">): Promise<void>;
deleteItem(ref: string): Promise<void>;
recordPush(p: {
deliveryId: string;
repo: string;
Expand Down Expand Up @@ -227,7 +229,20 @@ export async function applyEvent(
switch (event) {
case "issues": {
const issue = payload.issue;
if (issue) await applyIssue(issue);
if (issue && payload.action === "deleted") {
// A deleted issue must leave the read model, not be re-upserted
// by its own deletion event (#4210).
const ref = itemRef(repo, issue.number);
await store.deleteItem(ref);
addRef(ref);
hot(`issue:${issue.id ?? issue.number}`, {
ref,
actor: senderLogin,
sourceUrl: iso(issue.html_url),
sourceTimestamp: iso(issue.updated_at) ?? iso(issue.created_at),
});
wrote = true;
} else if (issue) await applyIssue(issue);
break;
}
case "pull_request": {
Expand Down
1 change: 1 addition & 0 deletions pm-stack/projector/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function libsqlStore(db: Client): ProjectorStore {
upsertItem: (i) => store.upsertItem(db, i),
upsertComment: (c) => store.upsertComment(db, c),
markCommentDeleted: (c) => store.markCommentDeleted(db, c),
deleteItem: (ref) => store.deleteItem(db, ref),
recordPush: (p) => store.recordPush(db, p),
appendHotEvents: (events) => store.appendHotEvents(db, events),
};
Expand Down
21 changes: 21 additions & 0 deletions pm-stack/projector/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,27 @@ export async function deleteLink(db: Client, subject: string, ref: string, relat
});
}

/**
* Remove an item and everything keyed off it, for a GitHub `issues`
* `deleted` event (#4210). Links and comments are projection data with
* no consumer independent of the item -- every read joins through it --
* so they go with the item row instead of becoming orphans (triage
* decision on #4210), with two refinements from review:
* - A GitHub item's outbound links are keyed by the namespaced subject
* `gh:<ref>` (schema.sql), not the bare ref; both spellings are
* removed so no writer's rows survive.
* - Comment tombstones (deleted = 1) are RETAINED: they are the
* absorbing guard that rejects stale comment replays (see
* upsertComment), and erasing one would let a delayed create/edit
* resurrect a deleted comment. Live comments are removed; the
* tombstone rows are already excluded from default reads.
*/
export async function deleteItem(db: Client, ref: string): Promise<void> {
await db.execute({ sql: `DELETE FROM pmp_items WHERE ref = ?`, args: [ref] });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve an item deletion marker for subsequent upserts

If an older, previously unprocessed issues or issue_comment delivery arrives after deletion, removing this row also removes its source-version guard: upsertItem unconditionally inserts absent items, and applyComment upserts the containing issue before processing the comment. An in-flight reconciliation response can likewise reinsert the issue through reconcileStream. Consequently, a successfully deleted issue reappears in /items; retaining individual comment tombstones does not protect the containing issue. Persist an item deletion marker and have webhook and reconciliation upserts reject deleted refs.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Disposition: valid, but a new mechanism beyond this PR's filed scope — tracked as follow-up issue #6782 instead of expanding #4210 here. Reasoning: unlike the comment-tombstone finding (where this PR regressed an existing guarantee — fixed in 34a4bf9), the item-resurrection vector has no pre-existing guard to regress: before this PR a deleted issue was never removed at all. #4210's acceptance criteria are the event-path removal plus its two tests, which this PR completes. #6782 carries the full design (durable per-ref deletion marker, absorbing semantics for stale webhook + reconcile replays, projector- and store-level tests) with queue/queued labels for a fix lane. — repo-worker-code lane code-y

await db.execute({ sql: `DELETE FROM pmp_comments WHERE ref = ? AND deleted = 0`, args: [ref] });
await db.execute({ sql: `DELETE FROM pmp_links WHERE subject IN (?, ?)`, args: [`gh:${ref}`, ref] });
}

export async function getLinks(db: Client, opts: { subject?: string; ref?: string } = {}): Promise<LinkRow[]> {
const clauses: string[] = [];
const args: string[] = [];
Expand Down
2 changes: 2 additions & 0 deletions pm-stack/projector/test/hot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
upsertItem as storeUpsertItem,
upsertComment as storeUpsertComment,
markCommentDeleted as storeMarkCommentDeleted,
deleteItem as storeDeleteItem,
recordPush as storeRecordPush,
type HotEventInput,
} from "../src/store";
Expand Down Expand Up @@ -44,6 +45,7 @@ function libsqlStore(dbx: Client): ProjectorStore {
upsertItem: (i) => storeUpsertItem(dbx, i),
upsertComment: (c) => storeUpsertComment(dbx, c),
markCommentDeleted: (c) => storeMarkCommentDeleted(dbx, c),
deleteItem: (ref) => storeDeleteItem(dbx, ref),
recordPush: (p) => storeRecordPush(dbx, p),
appendHotEvents: (events) => appendHotEvents(dbx, events),
};
Expand Down
38 changes: 37 additions & 1 deletion pm-stack/projector/test/projector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
upsertItem as storeUpsertItem,
upsertComment as storeUpsertComment,
markCommentDeleted as storeMarkCommentDeleted,
deleteItem as storeDeleteItem,
recordPush as storeRecordPush,
getItems,
} from "../src/store";
Expand All @@ -19,6 +20,7 @@ function fakeStore() {
const comments = new Map<string, Omit<CommentRow, "fetched_at">>();
const pushes: any[] = [];
const deleted: string[] = [];
const deletedItems: string[] = [];
const store: ProjectorStore = {
async upsertItem(i) {
const prev = items.get(i.ref);
Expand All @@ -34,11 +36,18 @@ function fakeStore() {
deleted.push(c.id);
comments.set(c.id, { ...c, deleted: 1 });
},
async deleteItem(ref) {
deletedItems.push(ref);
items.delete(ref);
for (const [id, c] of comments) {
if (c.ref === ref && c.deleted === 0) comments.delete(id);
}
},
async recordPush(p) {
pushes.push(p);
},
};
return { store, items, comments, pushes, deleted };
return { store, items, comments, pushes, deleted, deletedItems };
}

describe("projector: repo allow-list", () => {
Expand Down Expand Up @@ -75,6 +84,32 @@ describe("projector: issues", () => {
expect(JSON.parse(items.get("developing-today/code#100")!.labels)).toEqual(["bug", "status:backlog"]);
});

test("deleted issue is removed, not re-upserted (#4210)", async () => {
const { store, items, deletedItems } = fakeStore();
const issue = {
number: 102,
title: "Spam",
state: "open",
html_url: "https://github.com/developing-today/code/issues/102",
url: "https://api.github.com/repos/developing-today/code/issues/102",
user: { login: "dezren39" },
created_at: "2026-10-25T00:00:00Z",
updated_at: "2026-10-25T00:00:00Z",
};
const repo = { full_name: "developing-today/code" };
await applyEvent(store, "issues", { action: "opened", repository: repo, issue });
expect(items.has("developing-today/code#102")).toBe(true);
const r = await applyEvent(store, "issues", {
action: "deleted",
repository: repo,
issue: { ...issue, updated_at: "2026-10-25T01:00:00Z" },
});
expect(r.wrote).toBe(true);
expect(r.refs).toEqual(["developing-today/code#102"]);
expect(deletedItems).toEqual(["developing-today/code#102"]);
expect(items.has("developing-today/code#102")).toBe(false);
});

test("issue with pull_request field is classified as a PR", async () => {
const { store, items } = fakeStore();
const payload = {
Expand Down Expand Up @@ -391,6 +426,7 @@ describe("projector: issue-shaped payloads never reset merge fields (#4158)", ()
upsertItem: (i) => storeUpsertItem(db, i),
upsertComment: (c) => storeUpsertComment(db, c),
markCommentDeleted: (c) => storeMarkCommentDeleted(db, c),
deleteItem: (ref) => storeDeleteItem(db, ref),
recordPush: (p) => storeRecordPush(db, p),
};
await applyEvent(store, "pull_request", mergedPrEvent);
Expand Down
21 changes: 21 additions & 0 deletions pm-stack/projector/test/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
upsertItem,
upsertComment,
markCommentDeleted,
deleteItem,
upsertLink,
getItems,
getComments,
Expand Down Expand Up @@ -120,6 +121,26 @@ describe("store: items", () => {
});
});

describe("store: deleteItem (#4210)", () => {
test("removes the item row, its live comments, and its subject links; tombstones survive", async () => {
const ref = "developing-today/code#4210";
await upsertItem(db, item({ ref, number: 4210 }));
await upsertComment(db, comment({ id: "c-4210", ref }));
await markCommentDeleted(db, comment({ id: "c-4210-gone", ref }));
await upsertLink(db, { subject: `gh:${ref}`, ref: "developing-today/code#1", relation: "tracks" });
await deleteItem(db, ref);
expect(await getItems(db, [ref])).toHaveLength(0);
// The live comment is gone; the tombstone is retained so a stale
// replay of it stays absorbed (Codex review on PR #6775).
const remaining = await getComments(db, [ref], { includeDeleted: true });
expect(remaining.map((c) => c.id)).toEqual(["c-4210-gone"]);
expect(remaining[0].deleted).toBe(1);
expect(await getLinks(db, { subject: `gh:${ref}` })).toHaveLength(0);
// The linked-to item itself is untouched: only the subject side goes.
expect(await getItems(db, ["developing-today/code#1"])).toHaveLength(1);
});
});

describe("store: comments + links + subject view", () => {
test("comments upsert and read, newest first", async () => {
const base: Omit<CommentRow, "fetched_at"> = {
Expand Down
Loading