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.

Recheck issue changes between metadata removals

pulse-triage[bot]702129f20562
diff --git a/.github/scripts/issue-version-triage.cjs b/.github/scripts/issue-version-triage.cjs
index ea6acbdca4..0f50b7d5d5 100644
--- a/.github/scripts/issue-version-triage.cjs
+++ b/.github/scripts/issue-version-triage.cjs
@@ -522,6 +522,7 @@ async function applyLabelDelta(github, context, issue, before, after, core) {
};
const changed = () => core.info("Issue changed during metadata preparation. Skipping outdated label delta.");
const current = await readCurrent();
+ let checked = current;
if (!decisionInputsMatch(current)) {
changed();
return;
@@ -545,18 +546,36 @@ async function applyLabelDelta(github, context, issue, before, after, core) {
changed();
return;
}
+ checked = final;
}
+ const expectedLabels = new Set(beforeKeys);
if (additions.length) {
await github.rest.issues.addLabels({ ...target, labels: additions });
+ for (const name of additions) expectedLabels.add(name.toLowerCase());
}
for (const name of removals) {
+ // The preceding label write is another asynchronous boundary. A reporter
+ // or Community can change the report before the next removal, even after
+ // the preparation fence passed. Account only for our completed writes;
+ // never adopt unrelated activity as permission to finish a stale delta.
+ // Our own writes can advance updated_at, so compare content, comments and
+ // the provider's case-insensitive label identities instead of that clock.
+ const latest = await readCurrent();
+ const labels = new Set((latest.labels || []).map((label) => label.name.toLowerCase()));
+ if (latest.state !== "open" || latest.pull_request ||
+ ["title", "body", "comments"].some((field) => latest[field] !== checked[field]) ||
+ labels.size !== expectedLabels.size || [...expectedLabels].some((label) => !labels.has(label))) {
+ changed();
+ return;
+ }
try {
await github.rest.issues.removeLabel({ ...target, name });
} catch (error) {
// Another synchronizer may already have removed this label.
if (error.status !== 404) throw error;
}
+ expectedLabels.delete(name.toLowerCase());
}
}
diff --git a/.github/scripts/issue-version-triage.test.cjs b/.github/scripts/issue-version-triage.test.cjs
index 05af569617..098c8d1c56 100644
--- a/.github/scripts/issue-version-triage.test.cjs
+++ b/.github/scripts/issue-version-triage.test.cjs
@@ -111,10 +111,23 @@ function createGithub({
},
async addLabels(payload) {
calls.addLabels.push(payload);
+ if (github.currentIssue) {
+ const labels = new Map((github.currentIssue.labels || [])
+ .map(label => [label.name.toLowerCase(), label]));
+ for (const name of payload.labels) {
+ if (!labels.has(name.toLowerCase())) labels.set(name.toLowerCase(), { name });
+ }
+ github.currentIssue = { ...github.currentIssue, labels: [...labels.values()] };
+ }
return { data: payload };
},
async removeLabel(payload) {
calls.removeLabel.push(payload);
+ if (github.currentIssue) {
+ github.currentIssue = { ...github.currentIssue,
+ labels: (github.currentIssue.labels || [])
+ .filter(label => label.name.toLowerCase() !== payload.name.toLowerCase()) };
+ }
return { data: payload };
},
async createComment(payload) {
@@ -3850,3 +3863,105 @@ for (const labelLength of [50, 51, 512]) {
assert.equal(calls.getIssue.length, 2, "keep the final live-read guard");
});
}
+
+// Model actual successive provider writes: unlike a call-only mock, each GET
+// returns the labels left by completed writes and any intervening human edit.
+function midWriteFixture({ afterAdd, afterRemove, labels } = {}) {
+ let current = {
+ number: 42, title: "Synthetic missing readings", state: "open", comments: 0,
+ body: "### Pulse version\n6.7.0\n", updated_at: "2026-10-29T00:00:00Z",
+ labels: (labels || ["bug", "affects-6.5.0", "needs-version-info", "needs-human"])
+ .map(name => ({ name })),
+ };
+ const issue = structuredClone(current);
+ const calls = { get: 0, added: [], removed: [], comments: 0 };
+ const github = { rest: { issues: {
+ async get() {
+ calls.get += 1;
+ return { data: structuredClone(current) };
+ },
+ async getLabel({ name }) { return { data: { name } }; },
+ async addLabels({ labels: additions }) {
+ calls.added.push(...additions);
+ current.labels.push(...additions.map(name => ({ name })));
+ current.updated_at = "2026-10-29T00:00:01Z";
+ afterAdd?.(current, github, calls);
+ return { data: structuredClone(current.labels) };
+ },
+ async removeLabel({ name }) {
+ calls.removed.push(name);
+ current.labels = current.labels.filter(label => label.name.toLowerCase() !== name.toLowerCase());
+ current.updated_at = "2026-10-29T00:00:02Z";
+ afterRemove?.(current, github, calls);
+ return { data: structuredClone(current.labels) };
+ },
+ async createComment() { calls.comments += 1; },
+ } } };
+ return { calls, github, read: () => structuredClone(current),
+ run: () => triage.syncLabels({ github, core: createCore(),
+ context: createContext({ issue }) }) };
+}
+
+const midWriteChanges = {
+ "reporter version correction": current => { current.body = "### Pulse version\nunknown\n"; },
+ "report title correction": current => { current.title = "Different affected workload"; },
+ "same-second human comment": current => { current.comments += 1; },
+ "Community label addition": current => { current.labels.push({ name: "operator-reviewed" }); },
+ "Community label removal": current => {
+ current.labels = current.labels.filter(label => label.name !== "needs-human");
+ },
+ "closed report": current => { current.state = "closed"; },
+ "converted pull request": current => { current.pull_request = {}; },
+};
+
+for (const [name, change] of Object.entries(midWriteChanges)) {
+ test(`a ${name} after label additions stops stale removals`, async () => {
+ const fixture = midWriteFixture({ afterAdd: change });
+ await fixture.run();
+ assert.deepEqual(fixture.calls.added, ["affects-6.7.0"]);
+ assert.deepEqual(fixture.calls.removed, [], "do not complete or undo an obsolete prepared delta");
+ assert.equal(fixture.calls.comments, 0);
+ });
+
+ test(`a ${name} between removals stops the remaining write`, async () => {
+ const fixture = midWriteFixture({ afterRemove: change });
+ await fixture.run();
+ assert.deepEqual(fixture.calls.removed, ["affects-6.5.0"]);
+ assert.ok(fixture.read().labels.some(label => label.name === "needs-version-info"));
+ assert.equal(fixture.calls.comments, 0);
+ });
+}
+
+test("completed own label writes do not obstruct the remaining exact delta", async () => {
+ for (const labels of [undefined,
+ ["bug", "affects-6.7.0", "affects-6.5.0", "needs-version-info", "needs-human"]]) {
+ const fixture = midWriteFixture({ labels });
+ await fixture.run();
+ assert.deepEqual(fixture.calls.added, labels ? [] : ["affects-6.7.0"]);
+ assert.deepEqual(fixture.calls.removed, ["affects-6.5.0", "needs-version-info"]);
+ assert.deepEqual(fixture.read().labels.map(label => label.name).sort(),
+ ["affects-6.7.0", "bug", "needs-human"]);
+ }
+});
+
+test("post-write reads follow the provider's label identities, not requested spelling", async () => {
+ const fixture = midWriteFixture({ afterAdd: current => {
+ current.labels.find(label => label.name === "affects-6.7.0").name = "AFFECTS-6.7.0";
+ } });
+ await fixture.run();
+ assert.deepEqual(fixture.calls.removed, ["affects-6.5.0", "needs-version-info"]);
+ assert.ok(fixture.read().labels.some(label => label.name === "AFFECTS-6.7.0"));
+});
+
+for (const after of ["add", "remove"]) {
+ test(`a failed read after a completed ${after} stops without replay or rollback`, async () => {
+ const fail = (_current, github) => {
+ github.rest.issues.get = async () => { throw Object.assign(new Error("read denied"), { status: 403 }); };
+ };
+ const fixture = midWriteFixture(after === "add" ? { afterAdd: fail } : { afterRemove: fail });
+ await assert.rejects(fixture.run(), error => error.status === 403);
+ assert.deepEqual(fixture.calls.added, ["affects-6.7.0"]);
+ assert.deepEqual(fixture.calls.removed, after === "add" ? [] : ["affects-6.5.0"]);
+ assert.equal(fixture.calls.comments, 0);
+ });
+}