Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Preserve topic review when a comment precedes intake

pulse-triage[bot]7e3dd34aa27d
diff --git a/.github/scripts/issue-version-triage.cjs b/.github/scripts/issue-version-triage.cjs
index e65fca9b00..ffff857c0a 100644
--- a/.github/scripts/issue-version-triage.cjs
+++ b/.github/scripts/issue-version-triage.cjs
@@ -478,6 +478,52 @@ async function applyLabelDelta(github, context, issue, before, after, core) {
}
}
+async function declarationSurvivesLaterComments(github, context, issue, eventIssue) {
+ // A comment advances updated_at without changing the declaration. The clock
+ // alone must not lose its review task, but identical text cannot prove that
+ // Community has not already cleared it. Consult complete, bounded history
+ // only for this delayed-comment case; never infer a disposition from silence.
+ const eventTime = typeof eventIssue.updated_at === "string" ? Date.parse(eventIssue.updated_at) : NaN;
+ const currentTime = typeof issue.updated_at === "string" ? Date.parse(issue.updated_at) : NaN;
+ if (!Number.isFinite(eventTime) || !Number.isFinite(currentTime) || currentTime <= eventTime ||
+ !Number.isInteger(eventIssue.comments) || eventIssue.comments < 0 ||
+ !Number.isInteger(issue.comments) || issue.comments <= eventIssue.comments ||
+ issue.title !== eventIssue.title || issue.body !== eventIssue.body) {
+ return false;
+ }
+
+ const perPage = 100;
+ for (let page = 1; page <= 10; page += 1) {
+ const { data: events } = await github.rest.issues.listEvents({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: issue.number,
+ per_page: perPage,
+ page,
+ });
+ if (!Array.isArray(events) || events.length > perPage) {
+ throw new Error("Issue review history was not a complete event page");
+ }
+ for (const event of events) {
+ const time = typeof event?.created_at === "string" ? Date.parse(event.created_at) : NaN;
+ if (typeof event?.event !== "string" || !Number.isFinite(time) ||
+ (event.event === "unlabeled" && typeof event.label?.name !== "string")) {
+ throw new Error("Issue review history contained an unreadable event");
+ }
+ // Treat same-second dispositions conservatively. A history newer than
+ // our issue snapshot, or an intervening lifecycle change, is not proof
+ // that this queued declaration is still eligible.
+ if (time > currentTime || (time >= eventTime && (
+ (event.event === "unlabeled" &&
+ event.label.name.toLowerCase() === NEEDS_DECOMPOSITION_LABEL) ||
+ ["closed", "reopened", "transferred", "converted_to_discussion"].includes(event.event)
+ ))) return false;
+ }
+ if (events.length < perPage) return true;
+ }
+ throw new Error("Issue review history exceeded the bounded event read");
+}
+
async function syncLabels({ github, context, core }) {
const eventIssue = context.payload.issue;
// Jobs can start after another edit, comment or Community disposition.
@@ -512,11 +558,14 @@ async function syncLabels({ github, context, core }) {
const eventIsCurrent = typeof issue.updated_at === "string" &&
issue.body === eventIssue.body &&
issue.updated_at === eventIssue.updated_at;
- const newlyDeclared = eventIsCurrent && hasAdditionalActionableTopics === true && (
+ const declarationChanged = hasAdditionalActionableTopics === true && (
context.payload.action === "opened" ||
(context.payload.action === "edited" && previousBody !== undefined &&
topicText(additionalActionableTopicsValue(previousBody)) !== topicText(additionalTopicsValue))
);
+ const newlyDeclared = declarationChanged && !nextLabels.has(NEEDS_DECOMPOSITION_LABEL) && (
+ eventIsCurrent || await declarationSurvivesLaterComments(github, context, issue, eventIssue)
+ );
if (newlyDeclared) {
core.info("Issue newly declares additional actionable topics; decomposition is required.");
nextLabels.add(NEEDS_DECOMPOSITION_LABEL);
diff --git a/.github/scripts/issue-version-triage.test.cjs b/.github/scripts/issue-version-triage.test.cjs
index 1ef8768840..d759af9278 100644
--- a/.github/scripts/issue-version-triage.test.cjs
+++ b/.github/scripts/issue-version-triage.test.cjs
@@ -68,6 +68,7 @@ function createGithub({
existingComments = [],
issues = [],
currentIssue = null,
+ events = [],
} = {}) {
const calls = {
createComment: [],
@@ -78,6 +79,7 @@ function createGithub({
addLabels: [],
removeLabel: [],
getIssue: [],
+ getEvents: [],
};
const github = {
@@ -88,6 +90,11 @@ function createGithub({
calls.getIssue.push(payload);
return { data: github.currentIssue };
},
+ async listEvents(payload) {
+ calls.getEvents.push(payload);
+ const start = (payload.page - 1) * payload.per_page;
+ return { data: events.slice(start, start + payload.per_page) };
+ },
async getLabel({ name }) {
calls.getLabel.push(name);
if (existingLabels.has(name)) {
@@ -2836,3 +2843,191 @@ test("label-creation reconciliation still respects a newer Community decision",
assert.deepEqual(calls.removeLabel, []);
assert.deepEqual(calls.createComment, []);
});
+
+function delayedTopicFixture({ action = "opened", events = [], currentChanges = {}, eventChanges = {} } = {}) {
+ const issue = {
+ number: 2900,
+ title: "Notification delivery",
+ body: "### Additional actionable topics\nAlso retain per-host notification identity.\n",
+ labels: [{ name: "enhancement" }],
+ updated_at: "2026-10-26T06:00:00Z",
+ comments: 0,
+ ...eventChanges,
+ };
+ const { github, calls } = createGithub({ events, currentIssue: {
+ ...issue, state: "open", comments: 1, updated_at: "2026-10-26T06:01:00Z", ...currentChanges,
+ } });
+ return { github, calls, args: { github, core: createCore(), context: createContext({
+ issue, action, previousBody: "### Additional actionable topics\nNone.\n",
+ }) } };
+}
+
+for (const action of ["opened", "edited"]) {
+ test(`a comment before ${action} processing cannot lose a declared topic review`, async () => {
+ const { args, calls } = delayedTopicFixture({ action });
+ await triage.syncLabels(args);
+ assert.deepEqual(calls.getEvents, [{ owner: "rcourtman", repo: "Pulse", issue_number: 2900,
+ per_page: 100, page: 1 }]);
+ assert.deepEqual(calls.addLabels.map(call => call.labels), [["needs-decomposition"]]);
+ assert.equal(calls.getIssue.length, 2, "the final current-report guard still runs");
+ assert.deepEqual(calls.removeLabel, []);
+ assert.deepEqual(calls.createComment, []);
+ assert.deepEqual(calls.getLatestRelease, []);
+ });
+}
+
+test("a revised topic after an earlier review survives a later comment", async () => {
+ const { args, calls } = delayedTopicFixture({ action: "edited", events: [{
+ event: "unlabeled", label: { name: "needs-decomposition" }, created_at: "2026-10-26T05:59:59Z",
+ }] });
+ args.context.payload.changes.body.from = "### Additional actionable topics\nRetain one host name.\n";
+ await triage.syncLabels(args);
+ assert.deepEqual(calls.addLabels.map(call => call.labels), [["needs-decomposition"]]);
+});
+
+for (const created_at of ["2026-10-26T06:00:00Z", "2026-10-26T06:00:01Z"]) {
+ test(`a completed review at ${created_at} cannot be restored by a comment-delayed event`, async () => {
+ const { args, calls } = delayedTopicFixture({ events: [{
+ event: "unlabeled", label: { name: "Needs-Decomposition" }, created_at,
+ }] });
+ await triage.syncLabels(args);
+ assert.deepEqual(calls.addLabels, []);
+ assert.deepEqual(calls.removeLabel, []);
+ assert.deepEqual(calls.createComment, []);
+ });
+}
+
+test("review history is paginated before allowing a delayed declaration", async () => {
+ const unrelated = { event: "labeled", label: { name: "unrelated" }, created_at: "2026-10-26T05:00:00Z" };
+ for (const cleared of [false, true]) {
+ const events = [...Array(100).fill(unrelated), ...(cleared ? [{
+ event: "unlabeled", label: { name: "needs-decomposition" }, created_at: "2026-10-26T06:00:30Z",
+ }] : [])];
+ const { args, calls } = delayedTopicFixture({ events });
+ await triage.syncLabels(args);
+ assert.deepEqual(calls.getEvents.map(call => call.page), [1, 2]);
+ assert.deepEqual(calls.addLabels.flatMap(call => call.labels), cleared ? [] : ["needs-decomposition"]);
+ }
+});
+
+test("a comment and unrelated label changes do not dispose of a declared topic", async () => {
+ const { args, calls } = delayedTopicFixture({
+ currentChanges: { labels: [{ name: "enhancement" }, { name: "operator-reviewed" }, { name: "needs-human" }] },
+ events: [{ event: "unlabeled", label: { name: "unrelated" }, created_at: "2026-10-26T06:00:20Z" }],
+ });
+ await triage.syncLabels(args);
+ assert.deepEqual(calls.addLabels.map(call => call.labels), [["needs-decomposition"]]);
+ assert.deepEqual(calls.removeLabel, []);
+});
+
+for (const event of ["closed", "reopened", "transferred", "converted_to_discussion"]) {
+ test(`an intervening ${event} event prevents comment-delayed restoration`, async () => {
+ const { args, calls } = delayedTopicFixture({ events: [{ event, created_at: "2026-10-26T06:00:30Z" }] });
+ await triage.syncLabels(args);
+ assert.deepEqual(calls.addLabels, []);
+ assert.deepEqual(calls.removeLabel, []);
+ });
+}
+
+test("history newer than the current report snapshot is not permission to restore a task", async () => {
+ const { args, calls } = delayedTopicFixture({ events: [{
+ event: "labeled", created_at: "2026-10-26T06:01:01Z", label: { name: "unrelated" },
+ }] });
+ await triage.syncLabels(args);
+ assert.deepEqual(calls.addLabels, []);
+});
+
+test("only a readable, unchanged declaration with a later comment needs review history", async () => {
+ for (const options of [
+ { currentChanges: { body: "### Additional actionable topics\nA different topic.\n" } },
+ { currentChanges: { title: "A different report title" } },
+ { currentChanges: { comments: 0 } },
+ { currentChanges: { comments: undefined } },
+ { eventChanges: { comments: undefined } },
+ { eventChanges: { comments: -1 } },
+ { currentChanges: { updated_at: "unknown" } },
+ { currentChanges: { updated_at: 1792994460000 } },
+ { eventChanges: { updated_at: null } },
+ { currentChanges: { updated_at: "2026-10-26T05:59:59Z" } },
+ { action: "reopened" },
+ { action: "edited", eventChanges: { body: "### Additional actionable topics\nNone.\n" } },
+ ]) {
+ const { args, calls } = delayedTopicFixture(options);
+ await triage.syncLabels(args);
+ assert.deepEqual(calls.getEvents, [], JSON.stringify(options));
+ assert.deepEqual(calls.addLabels, [], JSON.stringify(options));
+ }
+ const { args, calls } = delayedTopicFixture({ action: "edited" });
+ args.context.payload.changes.body.from = args.context.payload.issue.body;
+ await triage.syncLabels(args);
+ assert.deepEqual(calls.getEvents, []);
+ assert.deepEqual(calls.addLabels, []);
+});
+
+test("current or already queued declarations do not add a history read", async () => {
+ for (const currentChanges of [
+ { comments: 0, updated_at: "2026-10-26T06:00:00Z" },
+ { labels: [{ name: "enhancement" }, { name: "needs-decomposition" }] },
+ ]) {
+ const { args, calls } = delayedTopicFixture({ currentChanges });
+ await triage.syncLabels(args);
+ assert.deepEqual(calls.getEvents, []);
+ assert.deepEqual(calls.addLabels.flatMap(call => call.labels),
+ currentChanges.labels ? [] : ["needs-decomposition"]);
+ }
+});
+
+for (const status of [403, 404, 500]) {
+ test(`a review-history ${status} fails without mutation or an alternate read`, async () => {
+ const { args, github, calls } = delayedTopicFixture();
+ github.rest.issues.listEvents = async payload => {
+ calls.getEvents.push(payload);
+ const error = new Error("history unavailable");
+ error.status = status;
+ throw error;
+ };
+ await assert.rejects(triage.syncLabels(args), error => error.status === status);
+ assert.equal(calls.getEvents.length, 1);
+ assert.deepEqual(calls.createLabel, []);
+ assert.deepEqual(calls.addLabels, []);
+ assert.deepEqual(calls.removeLabel, []);
+ assert.deepEqual(calls.createComment, []);
+ });
+}
+
+test("malformed or incomplete review history never becomes an empty successful read", async () => {
+ for (const data of [null, {}, [null], [{ event: "unlabeled", created_at: "2026-10-26T06:00:30Z" }],
+ [{ event: "labeled", created_at: "unknown" }], [{ event: "labeled", created_at: 1792994430000 }],
+ Array(101).fill({ event: "labeled", created_at: "2026-10-26T06:00:30Z" })]) {
+ const { args, github, calls } = delayedTopicFixture();
+ github.rest.issues.listEvents = async () => ({ data });
+ await assert.rejects(triage.syncLabels(args), /Issue review history/);
+ assert.deepEqual(calls.createLabel, []);
+ assert.deepEqual(calls.addLabels, []);
+ assert.deepEqual(calls.removeLabel, []);
+ }
+});
+
+test("the bounded review-history limit stops without writes or another route", async () => {
+ const event = { event: "labeled", created_at: "2026-10-26T05:00:00Z", label: { name: "unrelated" } };
+ const { args, calls } = delayedTopicFixture({ events: Array(1000).fill(event) });
+ await assert.rejects(triage.syncLabels(args), /exceeded the bounded event read/);
+ assert.equal(calls.getEvents.length, 10);
+ assert.deepEqual(calls.createLabel, []);
+ assert.deepEqual(calls.addLabels, []);
+ assert.deepEqual(calls.removeLabel, []);
+});
+
+test("the final report guard still rejects changes during history collection", async () => {
+ const { args, github, calls } = delayedTopicFixture();
+ github.rest.issues.listEvents = async payload => {
+ calls.getEvents.push(payload);
+ github.currentIssue = { ...github.currentIssue, updated_at: "2026-10-26T06:02:00Z",
+ labels: [...github.currentIssue.labels, { name: "needs-human" }] };
+ return { data: [] };
+ };
+ await triage.syncLabels(args);
+ assert.deepEqual(calls.addLabels, []);
+ assert.deepEqual(calls.removeLabel, []);
+ assert.deepEqual(calls.createComment, []);
+});