Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: harden malformed label pruning (#12579)

[._.]/ Adam Eivyb79ee9ac3187
diff --git a/server/services/autonomousJobs/selfDiagnostics.js b/server/services/autonomousJobs/selfDiagnostics.js
index c3de1f37b4..e3370ab109 100644
--- a/server/services/autonomousJobs/selfDiagnostics.js
+++ b/server/services/autonomousJobs/selfDiagnostics.js
@@ -203,7 +203,7 @@ export async function ensureDiagnosticsLabels({ cwd = PATHS.root, exec = runCli
}
}
-const MALFORMED_LABEL = /^\S+ (?:--color )?#?[0-9A-Fa-f]{6}(?: .*)?$/
+const MALFORMED_LABEL = /^\S+ (?:(--color )?#?([0-9A-Fa-f]{6}))(?: .*)?$/
/**
* Remove labels accidentally created by passing a whole "name color description"
@@ -226,7 +226,18 @@ export async function pruneMalformedLabels({ cwd = PATHS.root, exec = runCli } =
let pruned = 0
let skipped = 0
for (const { name } of labels) {
- if (!MALFORMED_LABEL.test(name)) continue
+ const malformed = name.match(MALFORMED_LABEL)
+ // A bare six-letter word such as "decade" also consists of hex digits.
+ // Keep it unless the label has the explicit --color flag or a digit makes
+ // the token look like an actual color value.
+ if (!malformed || (!malformed[1] && !/[0-9]/.test(malformed[2]))) continue
+ // gh's --label filters split commas into multiple labels, so those names
+ // cannot be checked safely through the issue/pr list commands.
+ if (name.includes(',')) {
+ skipped++
+ console.warn(`⚠️ Self-diagnostics: cannot safely verify comma-containing malformed label ${JSON.stringify(name)}; leaving it in place`)
+ continue
+ }
const usage = await Promise.all([
exec('gh', ['issue', 'list', '--state', 'all', '--label', name, '--limit', '1', '--json', 'number'], { cwd }),
@@ -331,8 +342,6 @@ export async function runSelfDiagnostics({
editArgs.push('--remove-label', NEEDS_ATTENTION_LABEL)
}
await pruneMalformedLabels({ cwd, exec })
- // Only pre-create labels when we're about to attach one (gh needs it to exist);
- // a body-only or remove-label edit doesn't (the label already exists then).
const { code, stderr } = await exec('gh', editArgs, { cwd })
if (code !== 0) {
console.warn(`⚠️ Self-diagnostics: failed to update issue #${found.issue.number}: ${stderr.trim()}`)
diff --git a/server/services/autonomousJobs/selfDiagnostics.test.js b/server/services/autonomousJobs/selfDiagnostics.test.js
index 08be263979..21f33e5777 100644
--- a/server/services/autonomousJobs/selfDiagnostics.test.js
+++ b/server/services/autonomousJobs/selfDiagnostics.test.js
@@ -167,6 +167,7 @@ function makeExec(routes) {
for (const r of routes) {
if (r.match(args)) return r.result
}
+ if (argsHave('label', 'list')(args)) return { code: 0, stdout: '[]', stderr: '' }
return { code: 0, stdout: '', stderr: '' }
})
}
@@ -240,6 +241,7 @@ describe('pruneMalformedLabels', () => {
{ match: argsHave('label', 'list'), result: { code: 0, stdout: JSON.stringify([
{ name: 'good first issue' },
{ name: 'help wanted' },
+ { name: 'needs decade' },
{ name: 'model:light D4C5F9' },
{ name: 'effort:medium --color 76C7C7' },
{ name: 'security 0366D6 Proposed from a security audit' }
@@ -294,6 +296,20 @@ describe('pruneMalformedLabels', () => {
expect(exec.mock.calls.some(([, args]) => args.includes('delete'))).toBe(false)
warn.mockRestore()
})
+
+ it('skips comma-containing labels because gh label filters split on commas', async () => {
+ const exec = makeExec([{
+ match: argsHave('label', 'list'),
+ result: { code: 0, stdout: '[{"name":"security 0366D6 Audit, high risk"}]' }
+ }])
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
+
+ const result = await pruneMalformedLabels({ exec })
+ expect(result).toEqual({ pruned: 0, skipped: 1 })
+ expect(exec.mock.calls.some(([, args]) => args.includes('issue') || args.includes('pr') || args.includes('delete'))).toBe(false)
+ expect(warn).toHaveBeenCalledWith(expect.stringContaining('cannot safely verify comma-containing'))
+ warn.mockRestore()
+ })
})
describe('runSelfDiagnostics', () => {
@@ -328,6 +344,11 @@ describe('runSelfDiagnostics', () => {
// or the claim queue would spend agent runs on them.
const labels = createCall[1].flatMap((arg, i, args) => (arg === '--label' ? [args[i + 1]] : []))
expect(labels).toEqual([MONITORING_LABEL, NEEDS_ATTENTION_LABEL])
+ const labelEnsureCalls = exec.mock.calls.filter(([, args]) => args[0] === 'label' && args[1] === 'create')
+ const pruneCall = exec.mock.calls.find(([, args]) => args[0] === 'label' && args[1] === 'list')
+ expect(labelEnsureCalls.length).toBe(2)
+ expect(exec.mock.calls.indexOf(labelEnsureCalls[1])).toBeLessThan(exec.mock.calls.indexOf(pruneCall))
+ expect(exec.mock.calls.indexOf(pruneCall)).toBeLessThan(exec.mock.calls.indexOf(createCall))
})
it('reuses (edits) an existing monitoring issue instead of filing a duplicate', async () => {
@@ -346,6 +367,26 @@ describe('runSelfDiagnostics', () => {
const editCall = exec.mock.calls.find(c => c[1].includes('edit'))
expect(editCall[1]).toContain('--body')
expect(editCall[1]).not.toContain('--add-label')
+ const pruneCall = exec.mock.calls.find(([, args]) => args[0] === 'label' && args[1] === 'list')
+ expect(exec.mock.calls.indexOf(pruneCall)).toBeLessThan(exec.mock.calls.indexOf(editCall))
+ })
+
+ it('ensures labels before pruning and editing when the attention label must be added', async () => {
+ const exec = makeExec([
+ { match: argsHave('issue', 'list'), result: { code: 0, stdout: JSON.stringify([
+ { number: 7, title: 't', body: `<!-- lil-slug: ${DIAGNOSTICS_SLUG} -->`, labels: [{ name: 'monitoring' }] }
+ ]) } },
+ { match: argsHave('label', 'create'), result: { code: 0, stdout: '' } },
+ { match: argsHave('issue', 'edit'), result: { code: 0, stdout: '' } }
+ ])
+
+ await runSelfDiagnostics({ forgeGate: okForge, loadLearning, exec, now: () => '2026-07-12T00:00:00.000Z' })
+ const ensureCall = exec.mock.calls.find(([, args]) => args[0] === 'label' && args[1] === 'create')
+ const pruneCall = exec.mock.calls.find(([, args]) => args[0] === 'label' && args[1] === 'list')
+ const editCall = exec.mock.calls.find(([, args]) => args[0] === 'issue' && args[1] === 'edit')
+ expect(editCall[1]).toContain('--add-label')
+ expect(exec.mock.calls.indexOf(ensureCall)).toBeLessThan(exec.mock.calls.indexOf(pruneCall))
+ expect(exec.mock.calls.indexOf(pruneCall)).toBeLessThan(exec.mock.calls.indexOf(editCall))
})
it('does NOT file when the issue read failed (avoids duplicate on a transient gh blip)', async () => {
@@ -364,6 +405,7 @@ describe('runSelfDiagnostics', () => {
expect(res.failingCount).toBe(0)
expect(res.issue).toBeNull()
expect(exec.mock.calls.find(c => c[1].includes('create') && c[1].includes('issue'))).toBeUndefined()
+ expect(exec.mock.calls.some(([, args]) => args[0] === 'label' && args[1] === 'list')).toBe(true)
})
it('clears the needs-attention label when the windowed failing set empties — even with lifetime failures on record (#2617)', async () => {