Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

Post Marvin's dedupe and too-long comments from workflow steps (#6170)

Greg Aker289593680cf4
diff --git a/.github/agentic/flows/agentic_intake.py b/.github/agentic/flows/agentic_intake.py
index a77dc07b7..becbd887f 100644
--- a/.github/agentic/flows/agentic_intake.py
+++ b/.github/agentic/flows/agentic_intake.py
@@ -104,7 +104,7 @@ def duplicate_intervention(evidence: dict) -> bool:
comment
for comment in comments
if comment["user"]["type"] == "Bot"
- and "possible duplicate issues" in comment["body"].lower()
+ and "possible duplicate issue" in comment["body"].lower()
]
if any(
comment["user"]["type"] == "Bot"
diff --git a/.github/agentic/scripts/collect_fastmcp_stack_evidence.sh b/.github/agentic/scripts/collect_fastmcp_stack_evidence.sh
index b7e4c097a..5c0512f9f 100755
--- a/.github/agentic/scripts/collect_fastmcp_stack_evidence.sh
+++ b/.github/agentic/scripts/collect_fastmcp_stack_evidence.sh
@@ -47,7 +47,7 @@ while IFS= read -r comment; do
pages "repos/$repo/issues/comments/$comment/reactions" | jq --argjson comment "$comment" '[.[]|{comment_id:$comment,content,user:(.user|{id,login,type})}]' > "$scratch/reaction-page.json"
jq -s '.[0]+.[1]' "$scratch/reactions.json" "$scratch/reaction-page.json" > "$scratch/next.json"
mv "$scratch/next.json" "$scratch/reactions.json"
-done < <(jq -r '.[]|select(.user.type=="Bot" and (.body|ascii_downcase|contains("possible duplicate issues")))|.id' "$scratch/comments.json")
+done < <(jq -r '.[]|select(.user.type=="Bot" and (.body|ascii_downcase|contains("possible duplicate issue")))|.id' "$scratch/comments.json")
jq -rn --slurpfile issue "$scratch/issue.json" --arg number "$issue" '
"repo:PrefectHQ/fastmcp is:pr " + $number + " in:body",
($issue[0].title | gsub("\\[Bug\\]|\\[bug\\]";"") |
diff --git a/.github/agentic/tests/test_agentic_intake.py b/.github/agentic/tests/test_agentic_intake.py
index 8d4420c2a..b2743d437 100644
--- a/.github/agentic/tests/test_agentic_intake.py
+++ b/.github/agentic/tests/test_agentic_intake.py
@@ -152,13 +152,19 @@ def test_hold_survives_title_body_labels_and_draft_metadata(pr):
assert held(pr)
+ "marking",
+ ["Found 2 possible duplicate issues:", "Found 1 possible duplicate issue:"],
+)
@pytest.mark.parametrize(
"activity", ["comment", "reaction", "reopened", "previous_closure"]
)
-def test_duplicate_human_intervention_cannot_repeat_pruning(evidence, activity):
+def test_duplicate_human_intervention_cannot_repeat_pruning(
+ evidence, activity, marking
+):
evidence["issue"]["labels"] = ["potential-duplicate", "invalid"]
evidence["comments"] = [
- comment(1, "2026-10-15T00:00:00Z", "Possible duplicate issues", "marvin", "Bot")
+ comment(1, "2026-10-15T00:00:00Z", marking, "marvin", "Bot")
]
if activity == "comment":
evidence["comments"].append(
diff --git a/.github/workflows/marvin-dedupe-issues.yml b/.github/workflows/marvin-dedupe-issues.yml
index 02b65fd77..dbe3752a8 100644
--- a/.github/workflows/marvin-dedupe-issues.yml
+++ b/.github/workflows/marvin-dedupe-issues.yml
@@ -17,7 +17,6 @@ jobs:
permissions:
contents: read
issues: write
- id-token: write
# Pinned Claude Code; see the matching note in marvin-label-triage.yml.
env:
@@ -27,18 +26,18 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v7
- - name: Generate Marvin App token
+ - name: Generate read-only Marvin App token
id: marvin-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.MARVIN_APP_ID }}
private-key: ${{ secrets.MARVIN_APP_PRIVATE_KEY }}
- # Match the job's `permissions:` block above. Unscoped, the token
- # inherits the App installation's full set β€” which includes
- # contents: write and actions: write, neither of which this job
- # declares and both of which end up in the model's shell as GH_TOKEN.
+ # This token is the model's GH_TOKEN, so it only reads. Unscoped, it
+ # would inherit the App installation's full set, including
+ # contents: write and actions: write. The comment and label are
+ # written after the model exits, with a separate token.
permission-contents: read
- permission-issues: write
+ permission-issues: read
- name: Set dedupe prompt
id: dedupe-prompt
@@ -52,7 +51,7 @@ jobs:
# Steps
- 1. Check if the GitHub issue (a) is closed, (b) does not need to be deduped (eg. because it is broad product feedback without a specific solution, or positive feedback), or (c) already has a duplicates comment that you made earlier. If so, do not proceed.
+ 1. Check if the GitHub issue (a) is closed, (b) does not need to be deduped (eg. because it is broad product feedback without a specific solution, or positive feedback), or (c) already has a duplicates comment that you made earlier. If so, return an empty `duplicates` list.
2. View the GitHub issue and produce a summary of the issue.
@@ -68,33 +67,17 @@ jobs:
Candidates found by only one search agent deserve extra scrutiny β€” a single keyword match is often a false positive.
When in doubt, do not flag. A missed duplicate is harmless; a false positive wastes the reporter's time.
- If there are no duplicates remaining, do not proceed β€” just exit.
+ If there are no duplicates remaining, return an empty `duplicates` list.
- 5. **Quality gate**: Before commenting, re-read each candidate as a skeptical reviewer. For each one, ask: "Would a maintainer who knows this codebase agree this is a duplicate, or would they dismiss it?" If you'd need to hedge with "might" or "possibly," drop it.
+ 5. **Quality gate**: Before answering, re-read each candidate as a skeptical reviewer. For each one, ask: "Would a maintainer who knows this codebase agree this is a duplicate, or would they dismiss it?" If you'd need to hedge with "might" or "possibly," drop it.
- 6. Comment back on the issue with your findings (or exit silently if none remain). Do NOT add any labels β€” labeling is handled by a later workflow step.
+ 6. Return the numbers of the remaining duplicates, most likely first, in `duplicates`. You have no tool for commenting or labeling. A later workflow step posts the comment and applies the label.
# Notes for your agents
- Use `gh` to interact with GitHub, rather than web fetch
- Do not use other tools beyond `gh` and Task (no MCP servers, file edit, etc.)
- Never include this issue as a duplicate of itself
- When searching, read the FULL body of candidate issues β€” titles alone are not enough to judge duplication
-
- For your comment, follow this format precisely (example with 3 suspected duplicates):
-
- ---
- Found 3 possible duplicate issues:
-
- 1. #123: Issue title here
- 2. #456: Another issue title
- 3. #789: Third issue title
-
- This issue will be automatically closed as a duplicate in 3 days.
-
- - If your issue is a duplicate, please close it and πŸ‘ the existing issue instead
- - To prevent auto-closure, add a comment or πŸ‘Ž this comment
-
- ---
PROMPT_END
EOF
@@ -109,6 +92,7 @@ jobs:
"$HOME/.local/bin/claude" --version
- name: Run Marvin dedupe command
+ id: marvin
uses: anthropics/claude-code-action@v1
with:
path_to_claude_code_executable: ${{ steps.pin-claude.outputs.path }}
@@ -117,12 +101,12 @@ jobs:
prompt: ${{ steps.dedupe-prompt.outputs.PROMPT }}
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY_FOR_CI }}
allowed_non_write_users: "*"
- # No `Bash(gh api:*)`: it reaches every endpoint the token can, which
- # is the reason marvin-label-triage routes its one write through
- # .github/scripts/triage-label.sh instead. Dedupe searches, reads and
- # comments β€” the four verbs below cover that.
+ # No `Bash(gh api:*)`: it reaches every endpoint the token can. Dedupe
+ # searches and reads with the three verbs below, then returns issue
+ # numbers through --json-schema. It has no tool that writes.
claude_args: |
- --allowedTools "Bash(gh issue view:*)","Bash(gh search:*)","Bash(gh issue list:*)","Bash(gh issue comment:*)",Task
+ --allowedTools "Bash(gh issue view:*)","Bash(gh search:*)","Bash(gh issue list:*)",Task
+ --json-schema '{"type":"object","properties":{"duplicates":{"type":"array","items":{"type":"integer"},"maxItems":3}},"required":["duplicates"],"additionalProperties":false}'
settings: |
{
"model": "claude-sonnet-5",
@@ -131,23 +115,91 @@ jobs:
}
}
- - name: Add potential-duplicate label if bot commented in this run
+ - name: Generate Marvin App token for writing
+ id: marvin-write-token
+ uses: actions/create-github-app-token@v3
+ with:
+ app-id: ${{ secrets.MARVIN_APP_ID }}
+ private-key: ${{ secrets.MARVIN_APP_PRIVATE_KEY }}
+ permission-issues: write
+
+ # The comment and label always go to this issue, and the comment always
+ # has this format. The model only chooses which issue numbers appear.
+ - name: Post duplicate comment and label
env:
- GH_TOKEN: ${{ steps.marvin-token.outputs.token }}
+ GH_TOKEN: ${{ steps.marvin-write-token.outputs.token }}
+ REPO: ${{ github.repository }}
+ ISSUE: ${{ github.event.issue.number || inputs.issue_number }}
+ RESULT: ${{ steps.marvin.outputs.structured_output }}
run: |
- ISSUE=${{ github.event.issue.number || inputs.issue_number }}
- # Only match bot comments created in the last 10 minutes (this run)
- CUTOFF=$(date -u -d '10 minutes ago' '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null \
- || date -u -v-10M '+%Y-%m-%dT%H:%M:%SZ')
- HAS_RECENT=$(gh api "repos/${{ github.repository }}/issues/${ISSUE}/comments?sort=created&direction=desc&per_page=10" \
- --jq "[.[] | select(
- .user.type == \"Bot\" and
- (.body | test(\"possible duplicate issues\"; \"i\")) and
- .created_at >= \"${CUTOFF}\"
- )] | length")
- if [ "$HAS_RECENT" -gt 0 ]; then
- gh issue edit "$ISSUE" --add-label "potential-duplicate" -R "${{ github.repository }}"
- echo "Added potential-duplicate label to #${ISSUE}"
- else
- echo "No recent duplicate comment found, skipping label"
+ if [[ ! "$ISSUE" =~ ^[0-9]+$ ]]; then
+ echo "::error::Issue number must be numeric, got: $ISSUE"
+ exit 1
+ fi
+ if [[ -z "$RESULT" ]]; then
+ echo "Marvin returned no structured output; nothing to post."
+ exit 0
+ fi
+
+ # Keep positive integers other than this issue, in the model's
+ # order, without repeats, and at most 3.
+ numbers=$(jq -r --argjson self "$ISSUE" '
+ [(.duplicates // [])[]
+ | select(type == "number" and . == floor and . > 0 and . != $self)]
+ | reduce .[] as $n ([]; if any(.[]; . == $n) then . else . + [$n] end)
+ | .[:3][]
+ ' <<<"$RESULT")
+ if [[ -z "$numbers" ]]; then
+ echo "No duplicates to report."
+ exit 0
+ fi
+
+ state=$(gh api "repos/$REPO/issues/$ISSUE" --jq .state)
+ if [[ "$state" != "open" ]]; then
+ echo "Issue #$ISSUE is $state; not commenting."
+ exit 0
fi
+ bot_comments=$(gh api --paginate "repos/$REPO/issues/$ISSUE/comments" \
+ --jq '.[] | select(.user.type == "Bot") | .body')
+ if grep -qi "possible duplicate issue" <<<"$bot_comments"; then
+ echo "Issue #$ISSUE already has a duplicate comment; not commenting again."
+ exit 0
+ fi
+
+ # Pull requests and numbers that do not exist are dropped. Titles
+ # come from the API, with @-mentions broken so they notify no one.
+ lines=()
+ while read -r n; do
+ title=$(gh api "repos/$REPO/issues/$n" \
+ --jq 'select(has("pull_request") | not) | .title | gsub("@"; "@​")') || continue
+ if [[ -n "$title" ]]; then
+ lines+=("$(( ${#lines[@]} + 1 )). #$n: $title")
+ fi
+ done <<<"$numbers"
+
+ count=${#lines[@]}
+ if [[ "$count" -eq 0 ]]; then
+ echo "None of the returned numbers is an issue in $REPO; not commenting."
+ exit 0
+ fi
+ noun="issues"
+ if [[ "$count" -eq 1 ]]; then
+ noun="issue"
+ fi
+
+ body="$RUNNER_TEMP/dedupe-comment.md"
+ {
+ echo "Found $count possible duplicate $noun:"
+ echo
+ printf '%s\n' "${lines[@]}"
+ echo
+ echo "This issue will be automatically closed as a duplicate in 3 days."
+ echo
+ echo "- If your issue is a duplicate, please close it and πŸ‘ the existing issue instead"
+ echo "- To prevent auto-closure, add a comment or πŸ‘Ž this comment"
+ } > "$body"
+ # Label first. A rerun skips an issue that already has the comment,
+ # so a comment left without the label would never be auto-closed.
+ gh issue edit "$ISSUE" -R "$REPO" --add-label "potential-duplicate"
+ gh issue comment "$ISSUE" -R "$REPO" --body-file "$body"
+ echo "Posted $count possible duplicate(s) and added potential-duplicate to #$ISSUE"
diff --git a/.github/workflows/marvin-label-triage.yml b/.github/workflows/marvin-label-triage.yml
index 3b49d4695..df36cf294 100644
--- a/.github/workflows/marvin-label-triage.yml
+++ b/.github/workflows/marvin-label-triage.yml
@@ -84,7 +84,7 @@ jobs:
PROMPT<<PROMPT_END
You're an issue triage assistant for FastMCP, a Python framework for building Model Context Protocol servers and clients. Your task is to analyze issues/PRs and apply appropriate labels.
- IMPORTANT: Your primary action should be to apply labels using the locked-down helper `.github/scripts/triage-label.sh`. DO NOT post comments EXCEPT when applying the too-long label (see below).
+ IMPORTANT: Your primary action should be to apply labels using the locked-down helper `.github/scripts/triage-label.sh`. DO NOT post comments. When you apply too-long, the workflow posts the comment for you (see below).
CRITICAL β€” LABEL MECHANICS:
- Apply labels ONLY through the helper, which adds or removes repository labels on THIS issue/PR. It already knows the target repo and number (from the workflow environment) β€” you never pass them:
@@ -143,9 +143,7 @@ jobs:
- invalid: Spam, completely off-topic, or nonsensical (often LLM-generated)
- too-long: Apply when an issue or PR doesn't conform to CONTRIBUTING.md. Issues should be a short problem description, an MRE, and expected vs. actual behavior β€” not a design document. PRs should have a focused description of the change β€” not a report. We don't need proposed solutions or design alternatives (the issue should describe the problem and let maintainers architect the fix), summaries of what tests cover, explanations of code we can read ourselves, or speculative root-cause analysis. Common LLM failure modes to watch for: verbose "diagnostic" writeups, large proposed patches in issue bodies, multi-section reports restating what's visible in the diff, numbered lists of possible approaches or solutions, "suggested" schemas/shapes/APIs, generic analysis that doesn't reference specific code, and "Notes" sections. But these are heuristics, not rules β€” a complex PR may legitimately need more context, and a brief submission can still be low-quality. Judge by whether the content helps a reviewer or just adds noise. When applying too-long, still apply the core category and area labels β€” too-long is a format signal, not a replacement for categorization. Issues still need to be findable by category.
- WHEN APPLYING too-long: After labeling, post a brief comment using mcp__github__add_issue_comment:
- "Thanks for the report. This issue goes beyond what our contributor guidelines ask for β€” we just need a short problem description and an MRE. Please see our [contributing guidelines](https://github.com/PrefectHQ/fastmcp/blob/main/CONTRIBUTING.md) and condense this issue. We'll triage it once it's trimmed down."
- Use this exact text (or very close to it). Do not editorialize or add details.
+ WHEN APPLYING too-long: A later workflow step posts the contributing-guidelines comment. Do not post it yourself.
AREA LABELS (apply ONLY when thematically central to the issue):
- cli: Issues primarily about FastMCP CLI commands (run, dev, install)
@@ -170,7 +168,7 @@ jobs:
4. Apply selected labels:
Add them with `bash .github/scripts/triage-label.sh add "label1" "label2"`.
- DO NOT post any comments unless applying too-long (see above)
+ DO NOT post any comments
PROMPT_END
EOF
@@ -202,7 +200,7 @@ jobs:
allowed_non_write_users: "*"
allowed_bots: "marvin-context-protocol"
claude_args: |
- --allowedTools "Bash(bash .github/scripts/triage-label.sh:*)",mcp__github__get_issue,mcp__github__get_issue_comments,mcp__github__add_issue_comment,mcp__github__get_pull_request,mcp__github__get_pull_request_files
+ --allowedTools "Bash(bash .github/scripts/triage-label.sh:*)",mcp__github__get_issue,mcp__github__get_issue_comments,mcp__github__get_pull_request,mcp__github__get_pull_request_files
settings: |
{
"model": "claude-sonnet-5",
@@ -213,6 +211,36 @@ jobs:
}
}
+ # Marvin has no comment tool. When it applies too-long, this step posts
+ # the contributing-guidelines comment on this issue or PR, once.
+ - name: Post too-long comment
+ env:
+ GH_TOKEN: ${{ steps.marvin-token.outputs.token }}
+ REPO: ${{ github.repository }}
+ NUMBER: ${{ github.event.issue.number || github.event.pull_request.number || inputs.issue_number }}
+ run: |
+ if [[ ! "$NUMBER" =~ ^[0-9]+$ ]]; then
+ echo "::error::Issue or PR number must be numeric, got: $NUMBER"
+ exit 1
+ fi
+ labels=$(gh api --paginate "repos/$REPO/issues/$NUMBER/labels" --jq '.[].name')
+ if ! grep -qx "too-long" <<<"$labels"; then
+ echo "too-long was not applied; no comment."
+ exit 0
+ fi
+
+ marker="goes beyond what our contributor guidelines ask for"
+ bot_comments=$(gh api --paginate "repos/$REPO/issues/$NUMBER/comments" \
+ --jq '.[] | select(.user.type == "Bot") | .body')
+ if grep -qF "$marker" <<<"$bot_comments"; then
+ echo "The too-long comment is already posted."
+ exit 0
+ fi
+
+ message="Thanks for the report. This issue goes beyond what our contributor guidelines ask for β€” we just need a short problem description and an MRE. Please see our [contributing guidelines](https://github.com/PrefectHQ/fastmcp/blob/main/CONTRIBUTING.md) and condense this issue. We'll triage it once it's trimmed down."
+ gh api "repos/$REPO/issues/$NUMBER/comments" -f body="$message" > /dev/null
+ echo "Posted the too-long comment on #$NUMBER."
+
# Triage is fire-and-forget: nobody watches a green run, so a broken
# allowlist has to fail the job or it goes unnoticed indefinitely β€” a
# mangled pattern silently produced zero labels across a dozen PRs
diff --git a/scripts/auto_close_duplicates.py b/scripts/auto_close_duplicates.py
index 87965fb13..40318bfdd 100644
--- a/scripts/auto_close_duplicates.py
+++ b/scripts/auto_close_duplicates.py
@@ -219,10 +219,11 @@ class GitHubClient:
def find_duplicate_comment(comments: list[Comment]) -> Comment | None:
"""Find a bot comment marking the issue as duplicate."""
for comment in comments:
- # Check for the specific duplicate message format from a bot
+ # Check for the specific duplicate message format from a bot. With
+ # one duplicate the comment says "issue", not "issues".
if (
comment.user_type == "Bot"
- and "possible duplicate issues" in comment.body.lower()
+ and "possible duplicate issue" in comment.body.lower()
):
return comment
return None