Repository navigation
fix(triage): prevent duplicate Discord issue publishing - #6513
Conversation
📝 WalkthroughWalkthroughChangesThe publish workflow now prevents concurrent executions, checks Discord’s Publish safeguards
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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
.claude/skills/bug-triage/SKILL.mdscripts/lib/discord.tsscripts/sync-bug-reports.ts
| const release = acquirePublishLock(); | ||
| try { | ||
| await cmdPublishLocked(); | ||
| } finally { | ||
| release(); | ||
| } | ||
| } |
There was a problem hiding this comment.
🩺 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:
- 1: Keep the watcher alive when process.exit() is called in --watch oven-sh/bun#32649
- 2: https://github.com/oven-sh/bun/blob/7abe6c38/src/bun.js/node/node_process.zig
- 3: process: reallyExit() should not emit 'exit' listeners oven-sh/bun#34997
- 4: process: emit 'beforeExit' and 'exit' through a replaced process.emit oven-sh/bun#32228
- 5: Worker continues execution after process.exit oven-sh/bun#26239
- 6: https://bun.com/reference/node/process
- 7: signal-exit onExit callback not triggered in Bun during process shutdown oven-sh/bun#29194
🏁 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.tsRepository: 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.tsRepository: 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
| 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; | ||
| } |
There was a problem hiding this comment.
🩺 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
| published[threadId] = { | ||
| issue_number: 0, | ||
| issue_url: "", | ||
| reacted_message_id: "", | ||
| reply_message_id: "", | ||
| published_at: new Date().toISOString(), | ||
| mode: "reconciled", | ||
| notes: "Discord Handled tag", | ||
| }; |
There was a problem hiding this comment.
🗄️ 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
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Fixes Applied SuccessfullyFixed 1 file(s) based on 3 unresolved review comments. Files modified:
Commit: The changes have been pushed to the Time taken: |
Fixed 1 file(s) based on 3 unresolved review comments. Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
* 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>
Summary by CodeRabbit
Bug Fixes
Documentation