Skip to content

Fix safeoutputs MCP session expiry causing silent PR failures across all news workflows#1882

Merged
pethers merged 5 commits intomainfrom
copilot/fix-agentic-workflow-errors
Apr 20, 2026
Merged

Fix safeoutputs MCP session expiry causing silent PR failures across all news workflows#1882
pethers merged 5 commits intomainfrom
copilot/fix-agentic-workflow-errors

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

Fix safeoutputs MCP session expiry causing silent PR failures across all news workflows

The safeoutputs Streamable-HTTP MCP session expires after ~30–35 min idle. Ten content workflows called safeoutputs___create_pull_request only once at minute 40–45 — past the expiry window — producing session not found failures and silently discarding all work (confirmed: PR #1835, run #24672037751).

Every safeoutputs___create_pull_request call resets the session idle timer. The fix adds an early "heartbeat PR" call that both keeps the session alive and acts as a safety net if later phases fail.

Completed

  • safe-outputs.create-pull-request.max: 2 added to all 10 content workflows
  • Heartbeat PR guidance added to all 10 content workflows
  • SHARED_PROMPT_PATTERNS.md — rule Sync styles.css from Hack23/homepage #2 "Heartbeat PR" under UNIVERSAL SAFE OUTPUT RULES
  • >= 25 min hard-cutoff bullet in article-generator and evening-analysis

Review comments addressed

  • Timeline overlap — Pass 2 split into non-overlapping Part A + Part B around Heartbeat across all 10 workflows (60-min: 21–22 / 22–25 / 25–28 / 28–30; 30-min: 15–19 / 19–21 / 21–22 / 22–23; week-ahead: 20–22 / 22–25 / 25–27 / 27–29)
  • /tmp/doc_count.txt → per-process /tmp/doc_count.$$ + rm -f cleanup in news-weekly-review.md and news-monthly-review.md
  • /tmp/current-branch.txt → per-process /tmp/current-branch-$$.txt + rm -f cleanup in news-translate.md (both occurrences)
  • /tmp/fsize-$$.txt — added rm -f cleanup after every read FSIZE in SHARED_PROMPT_PATTERNS.md (2 places) and news-evening-analysis.md

@github-actions github-actions Bot added documentation Documentation updates workflow GitHub Actions workflows ci-cd CI/CD pipeline changes news News articles and content generation agentic-workflow Agentic workflow changes size-m Medium change (50-250 lines) labels Apr 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🏷️ Automatic Labeling Summary

This PR has been automatically labeled based on the files changed and PR metadata.

Applied Labels: documentation,workflow,ci-cd,size-m,news,agentic-workflow

Label Categories

  • 🗳️ Content: news, dashboard, visualization, intelligence
  • 💻 Technology: html-css, javascript, workflow, security
  • 📊 Data: cia-data, riksdag-data, data-pipeline, schema
  • 🌍 I18n: i18n, translation, rtl
  • 🔒 ISMS: isms, iso-27001, nist-csf, cis-controls
  • 🏗️ Infrastructure: ci-cd, deployment, performance, monitoring
  • 🔄 Quality: testing, accessibility, documentation, refactor
  • 🤖 AI: agent, skill, agentic-workflow

For more information, see .github/labeler.yml.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@pethers pethers marked this pull request as ready for review April 20, 2026 20:22
Copilot AI review requested due to automatic review settings April 20, 2026 20:22
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a “heartbeat PR” pattern and updates safe-outputs configuration to prevent safeoutputs MCP session expiry from causing silent PR creation failures in longer news workflows.

Changes:

  • Increased safe-outputs.create-pull-request.max to 2 for affected workflows to allow a heartbeat PR plus the final PR.
  • Inserted workflow guidance to create an early heartbeat PR (~minute 19–25) to refresh the safeoutputs session and preserve partial work.
  • Updated multiple shell snippets to avoid $(...) command substitution (AWF-safe), using tempfiles + read instead.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
.github/workflows/news-weekly-review.md Enables 2 PRs and adds heartbeat PR guidance; AWF-safe tempfile change in validator snippet
.github/workflows/news-week-ahead.md Enables 2 PRs and adds heartbeat PR guidance
.github/workflows/news-translate.md Replaces $(git branch --show-current) with tempfile + read in two sections
.github/workflows/news-propositions.md Enables 2 PRs and adds heartbeat PR guidance
.github/workflows/news-motions.md Enables 2 PRs and adds heartbeat PR guidance
.github/workflows/news-monthly-review.md Enables 2 PRs, adds heartbeat PR guidance; AWF-safe tempfile change in validator snippet
.github/workflows/news-month-ahead.md Enables 2 PRs and adds heartbeat PR guidance
.github/workflows/news-interpellations.md Enables 2 PRs and adds heartbeat PR guidance
.github/workflows/news-evening-analysis.md Enables 2 PRs; adds heartbeat PR + hard cutoff guidance; AWF-safe tempfile change for file sizing
.github/workflows/news-committee-reports.md Enables 2 PRs and adds heartbeat PR guidance
.github/workflows/news-article-generator.md Enables 2 PRs; adds heartbeat PR + hard cutoff guidance
.github/aw/SHARED_PROMPT_PATTERNS.md Documents heartbeat PR rule; AWF-safe tempfile changes; replaces basename usage with path-pattern case

Comment on lines 276 to 279
- **Minutes 6–21**: 🚨 **AI Analysis Pass 1 (15 min minimum)**: Read ALL methodology guides, create per-file analysis for EVERY document with Mermaid diagrams, evidence tables, SWOT entries.
- **Minutes 21–28**: 🚨 **AI Analysis Pass 2 (7 min minimum)**: Read ALL analysis back completely, improve every section, replace ALL script stubs with AI analysis. Run enrichment verification gate.
- **Minutes 22–25**: 🫀 **Heartbeat PR** — `git add && git commit` analysis artifacts so far, then `safeoutputs___create_pull_request` (title `🫀 Heartbeat - Weekly Review - {date}`). Refreshes the safeoutputs MCP session (idle timeout ~30–35 min) AND preserves work if later phases fail. Run `git checkout main` after the call so subsequent commits don't stack onto the frozen patch.
- **Minutes 28–30**: Run ENFORCED Minimum Time Gate + Enrichment Verification Gate (SHARED_PROMPT_PATTERNS.md). Both MUST pass.
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

The timeline ranges overlap: Pass 2 is defined as minutes 21–28, but the Heartbeat PR is scheduled for minutes 22–25 inside that same window. This creates contradictory instructions (do Pass 2 vs stop to commit/PR). Consider splitting Pass 2 into two explicit phases (e.g., 21–22 and 25–28) or moving the heartbeat to a non-overlapping slot so the schedule is internally consistent.

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/news-weekly-review.md Outdated
Comment on lines +774 to +776
> # AWF-safe: no $(...) command substitution — use tempfile + read redirection.
> find "analysis/daily/$ARTICLE_DATE/weekly-review/documents" -maxdepth 1 -name '*.json' 2>/dev/null | wc -l > /tmp/doc_count.txt
> read doc_count < /tmp/doc_count.txt
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

Writing to a fixed /tmp/doc_count.txt path is vulnerable to cross-step interference (and, on shared machines, symlink clobbering). Prefer a per-process unique temp filename (e.g., include $$) and delete it after reading; if you want stronger safety, use mktemp but avoid $(...) by writing its output to a separate temp path then read-ing it.

Suggested change
> # AWF-safe: no $(...) command substitution — use tempfile + read redirection.
> find "analysis/daily/$ARTICLE_DATE/weekly-review/documents" -maxdepth 1 -name '*.json' 2>/dev/null | wc -l > /tmp/doc_count.txt
> read doc_count < /tmp/doc_count.txt
> # AWF-safe: no $(...) command substitution — use a per-process temp file + read redirection.
> doc_count_tmp="/tmp/doc_count.$$"
> find "analysis/daily/$ARTICLE_DATE/weekly-review/documents" -maxdepth 1 -name '*.json' 2>/dev/null | wc -l > "$doc_count_tmp"
> read doc_count < "$doc_count_tmp"
> rm -f "$doc_count_tmp"

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/news-translate.md Outdated
Comment on lines +383 to +384
git branch --show-current > /tmp/current-branch.txt
read CURRENT_BRANCH < /tmp/current-branch.txt
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

Using a fixed /tmp/current-branch.txt filename can collide if this snippet is run in parallel (or if prior runs leave stale data). Use a unique temp path (e.g., suffix with $$) and remove it after reading to avoid cross-run interference.

Suggested change
git branch --show-current > /tmp/current-branch.txt
read CURRENT_BRANCH < /tmp/current-branch.txt
CURRENT_BRANCH_FILE="/tmp/current-branch-$$.txt"
git branch --show-current > "$CURRENT_BRANCH_FILE"
read CURRENT_BRANCH < "$CURRENT_BRANCH_FILE"
rm -f "$CURRENT_BRANCH_FILE"

Copilot uses AI. Check for mistakes.
FSIZE=$(wc -c < "$ANALYSIS_DIR/$REQUIRED_FILE")
# AWF-safe: no $(...) command substitution — use tempfile + read redirection.
wc -c < "$ANALYSIS_DIR/$REQUIRED_FILE" | tr -d ' ' > /tmp/fsize-$$.txt
read FSIZE < /tmp/fsize-$$.txt
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

The tempfile /tmp/fsize-$$.txt is reused and never cleaned up. Consider removing it after reading (or using a trap cleanup) to avoid accumulating temp artifacts across repeated gate executions.

Suggested change
read FSIZE < /tmp/fsize-$$.txt
read FSIZE < /tmp/fsize-$$.txt
rm -f /tmp/fsize-$$.txt

Copilot uses AI. Check for mistakes.
@pethers
Copy link
Copy Markdown
Member

pethers commented Apr 20, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 20, 2026

@copilot apply changes based on the comments in this thread

Addressed all 4 review comments in b4a4397:

  1. Timeline overlap — Pass 2 split into non-overlapping Part A + Part B around the Heartbeat PR across all 10 workflows (not just weekly-review; same issue existed in all). For 60-min workflows: Pass 2A 21–22 / Heartbeat 22–25 / Pass 2B 25–28 / Gate 28–30.
  2. /tmp/doc_count.txt → per-process /tmp/doc_count.$$ + rm -f cleanup (also fixed the same pattern in news-monthly-review.md).
  3. /tmp/current-branch.txt → per-process /tmp/current-branch-$$.txt + rm -f cleanup in both occurrences in news-translate.md.
  4. /tmp/fsize-$$.txt — added rm -f cleanup after each read FSIZE in SHARED_PROMPT_PATTERNS.md (2 places) and news-evening-analysis.md.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copilot AI requested a review from pethers April 20, 2026 20:44
@pethers pethers merged commit 8cc65ea into main Apr 20, 2026
12 checks passed
@pethers pethers deleted the copilot/fix-agentic-workflow-errors branch April 20, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agentic-workflow Agentic workflow changes ci-cd CI/CD pipeline changes documentation Documentation updates news News articles and content generation size-m Medium change (50-250 lines) workflow GitHub Actions workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants