Skip to content

fix(triage): prevent duplicate Discord issue publishing - #6513

Merged
matthewevans merged 2 commits into
mainfrom
ship/triage-publish-lock
Jul 22, 2026
Merged

matthewevans merged 2 commits into
mainfrom
ship/triage-publish-lock

Conversation

@matthewevans

@matthewevans matthewevans commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Prevented duplicate bug reports when multiple publishing runs overlap.
    • Threads marked Handled in Discord are now skipped automatically and recorded as resolved.
    • Added safeguards to detect changed triage data and reconcile existing issue links before publishing.
    • Improved handling of accidentally published reports when a thread becomes marked Handled.
  • Documentation

    • Updated triage guidance with required snapshot, audit, reconciliation, and single-publisher procedures.

@matthewevans
matthewevans enabled auto-merge July 22, 2026 19:54
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

The publish workflow now prevents concurrent executions, checks Discord’s Handled tag before issue creation, records reconciled skips, reports them, and documents snapshot-based GitHub reconciliation and publication safeguards.

Publish safeguards

Layer / File(s) Summary
Serialize publish executions
scripts/sync-bug-reports.ts
publish uses an exclusive lock file, writes the process ID, and guarantees lock cleanup after execution.
Reconcile Discord-handled threads
scripts/lib/discord.ts, scripts/sync-bug-reports.ts, .claude/skills/bug-triage/SKILL.md
Discord thread tags are modeled and checked; Handled threads are skipped, reconciled in state, counted in output, and covered by snapshot, orphan-check, and single-publisher procedures.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant cmdPublish
  participant acquirePublishLock
  participant cmdPublishLocked
  participant Discord
  participant syncState

  cmdPublish->>acquirePublishLock: acquire exclusive lock
  acquirePublishLock-->>cmdPublish: release closure
  cmdPublish->>cmdPublishLocked: process publish batch
  cmdPublishLocked->>Discord: check thread Handled tag
  Discord-->>cmdPublishLocked: return applied tags
  cmdPublishLocked->>syncState: record reconciled sentinel
  cmdPublish-->>acquirePublishLock: release lock
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: preventing duplicate Discord issue publishing in triage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ship/triage-publish-lock

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/sync-bug-reports.ts`:
- Around line 1081-1089: Align the Handled sentinel contract by changing the
published record in scripts/sync-bug-reports.ts:1081-1089 to use mode
"mark-handled" while preserving the "Discord Handled tag" reason. Update
.claude/skills/bug-triage/SKILL.md:181-192 to document that exact mode; both
sites must use the same sentinel value.
- Around line 1077-1096: Wrap the per-target isDiscordThreadHandled() lookup
within the existing per-target error handling in the targets loop. On lookup
failure, increment the failed-target count, record the error consistently with
other target failures, and continue to the next target without publishing or
marking the thread handled; preserve the normal skip behavior when the lookup
succeeds and returns true.
- Around line 1018-1024: Update cmdPublishLocked so its error paths do not call
process.exit() while acquirePublishLock is held; throw the error or set
process.exitCode and return, allowing cmdPublish’s finally block to invoke
release(). Ensure process termination, if needed, occurs only after the lock has
been released.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9248f4a3-912b-4ca8-9971-a108d21a659f

📥 Commits

Reviewing files that changed from the base of the PR and between 3609748 and 455fb26.

📒 Files selected for processing (3)
  • .claude/skills/bug-triage/SKILL.md
  • scripts/lib/discord.ts
  • scripts/sync-bug-reports.ts

Comment on lines +1018 to +1024
const release = acquirePublishLock();
try {
await cmdPublishLocked();
} finally {
release();
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Does Bun's process.exit()unwind JavaScripttry/finally blocks before terminating the process?

💡 Result:

Bun's process.exit() does not automatically unwind JavaScript try/finally blocks [1]. When process.exit() is called, it triggers an immediate termination of the process [1][2]. In Bun, process.exit() is implemented to trigger the shutdown sequence—including emitting beforeExit and exit events and performing native cleanup (such as flushing buffers and closing resources)—before the process halts [3][4]. It does not throw an exception that would propagate up the JavaScript call stack to trigger finally blocks [1]. Instead, it signals the runtime to stop execution and exit [1][2]. Consequently, any code within a finally block that follows a process.exit() call will not execute [1][5]. For reference, this behavior is consistent with Node.js, where process.exit() also forces an immediate termination without unwinding the stack [1]. If you require cleanup logic to run upon process termination, it should be registered using process.on('exit', callback) or similar lifecycle hooks rather than relying on finally blocks [6][3][7].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant sections around the publish wrapper and exit paths.
sed -n '980,1065p' scripts/sync-bug-reports.ts
printf '\n---\n'
rg -n "process\.exit|process\.exitCode|acquirePublishLock|cmdPublishLocked" scripts/sync-bug-reports.ts

Repository: phase-rs/phase

Length of output: 3772


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '70,110p' scripts/sync-bug-reports.ts
printf '\n---\n'
sed -n '110,150p' scripts/sync-bug-reports.ts

Repository: phase-rs/phase

Length of output: 2520


Avoid calling process.exit() inside the lock scope. cmdPublishLocked() still exits directly on the error paths, so the finally in cmdPublish() never runs and triage/.publish.lock can be left behind, blocking later publishes until manual cleanup. Throw instead, or set process.exitCode = 1 and exit after the lock is released.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/sync-bug-reports.ts` around lines 1018 - 1024, Update
cmdPublishLocked so its error paths do not call process.exit() while
acquirePublishLock is held; throw the error or set process.exitCode and return,
allowing cmdPublish’s finally block to invoke release(). Ensure process
termination, if needed, occurs only after the lock has been released.

Source: Path instructions

Comment on lines 1077 to +1096
for (const threadId of targets) {
const existing = published[threadId];
if (await isDiscordThreadHandled(threadId)) {
if (existing === undefined && !dryRun) {
published[threadId] = {
issue_number: 0,
issue_url: "",
reacted_message_id: "",
reply_message_id: "",
published_at: new Date().toISOString(),
mode: "reconciled",
notes: "Discord Handled tag",
};
state.published_threads = published;
await saveSyncState(state);
}
console.log(` [skip] ${threadId} — Discord thread is tagged Handled`);
skippedHandled++;
continue;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Contain Discord tag-read failures per thread.

isDiscordThreadHandled() is awaited outside any per-target try block. A deleted thread, permissions failure, or transient Discord error aborts the entire batch without its summary, leaving later targets unprocessed. Count that target as failed and continue; do not treat a failed tag lookup as permission to publish.

As per path instructions, Discord Handled checking is a “Hard Pre-Publish Gate.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/sync-bug-reports.ts` around lines 1077 - 1096, Wrap the per-target
isDiscordThreadHandled() lookup within the existing per-target error handling in
the targets loop. On lookup failure, increment the failed-target count, record
the error consistently with other target failures, and continue to the next
target without publishing or marking the thread handled; preserve the normal
skip behavior when the lookup succeeds and returns true.

Source: Path instructions

Comment on lines +1081 to +1089
published[threadId] = {
issue_number: 0,
issue_url: "",
reacted_message_id: "",
reply_message_id: "",
published_at: new Date().toISOString(),
mode: "reconciled",
notes: "Discord Handled tag",
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Align the Handled sentinel mode contract.

The publisher writes mode: "reconciled", while the required operating procedure specifies mode:"mark-handled". Mode-based audits or repairs cannot reliably interpret these records.

  • scripts/sync-bug-reports.ts#L1081-L1089: write the agreed Handled sentinel mode.
  • .claude/skills/bug-triage/SKILL.md#L181-L192: document that same exact mode.

As per path instructions, “record it as a mark-handled sentinel with reason Discord Handled tag.”

📍 Affects 2 files
  • scripts/sync-bug-reports.ts#L1081-L1089 (this comment)
  • .claude/skills/bug-triage/SKILL.md#L181-L192
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/sync-bug-reports.ts` around lines 1081 - 1089, Align the Handled
sentinel contract by changing the published record in
scripts/sync-bug-reports.ts:1081-1089 to use mode "mark-handled" while
preserving the "Discord Handled tag" reason. Update
.claude/skills/bug-triage/SKILL.md:181-192 to document that exact mode; both
sites must use the same sentinel value.

Source: Path instructions

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 1 file(s) based on 3 unresolved review comments.

Files modified:

  • scripts/sync-bug-reports.ts

Commit: 30c4e06864af9e92e8d4757ff88151019767abd3

The changes have been pushed to the ship/triage-publish-lock branch.

Time taken: 5m 5s

Fixed 1 file(s) based on 3 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
@matthewevans
matthewevans added this pull request to the merge queue Jul 22, 2026
Merged via the queue into main with commit 4074fcf Jul 22, 2026
14 checks passed
@matthewevans
matthewevans deleted the ship/triage-publish-lock branch July 22, 2026 20:47
jsdevninja pushed a commit to jsdevninja/phase that referenced this pull request Jul 24, 2026
* fix(triage): prevent duplicate Discord issue publishing

* fix: apply CodeRabbit auto-fixes

Fixed 1 file(s) based on 3 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>

---------

Co-authored-by: matthewevans <matthewevans@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant