Skip to content

feat(emdash-bot): reporter-verified pkg.pr.new fix loop (bot next-gen 4/5) - #2382

Open
ascorbic wants to merge 3 commits into
bot-nextgen/03-computer-execfrom
bot-nextgen/04-fix-loop-wiring
Open

feat(emdash-bot): reporter-verified pkg.pr.new fix loop (bot next-gen 4/5)#2382
ascorbic wants to merge 3 commits into
bot-nextgen/03-computer-execfrom
bot-nextgen/04-fix-loop-wiring

Conversation

@ascorbic

@ascorbic ascorbic commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Slice 4 of the bot next-gen stack (on #2381). Wires the reporter-verified fix loop onto the machine states from #2376, reusing gen-1's bot/fix-* + pkg.pr.new conventions with the worker as orchestrator.

  • Preview flow: the fix-mode investigation pushes bot/fix-<n> (+ orphan bot/artifacts-<n> screenshots) through the capability-scoped push proxy; preview-releases.yml (untouched — Actions/OIDC is the only pkg.pr.new publisher) builds the package preview; the DO polls the install URL on its existing alarm tick (bounded, 10-min budget as a tunable constant) and only advertises once it resolves — removing gen-1's "if npm i 404s, retry" reporter-facing race.
  • Ask comment: gen-1's shape (hidden bot-ask marker, notes, full-ref npm i https://pkg.pr.new/emdash@bot/fix-<n>, screenshots, @reporter), posted comment-first so a failed post can't strand the state; restart-safe via a persisted marker check (no duplicate asks).
  • Confirmation → draft PR with a useful body (closes-link, verified preview link, regression-test note); cleanup gains the open-PR guard on branch reaping (review flag from feat(emdash-bot): maintainer-triggered investigation + fix-loop states (bot next-gen 2/5) #2376) and an issues.closed path mirroring gen-1's bot-cleanup semantics.
  • Orchestrator bug fixed en route: the side-effect drain guard matched undefined === undefined, deferring standalone effects forever — first reachable here (the ask), but also affecting readonly status replies. Now guarded explicitly; restart idempotency covered by tests.

Adversarially reviewed: single-alarm multiplexing traced (the poll rides the existing tick, earliest-deadline-wins), push-proxy admission HMAC-scoped per issue, injection surfaces validated.

Closes #

Type of change

Maintainer-directed: implements the bot next-gen design; no separate Discussion.

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes — n/a-with-note: same pre-existing infra/emdash-bot baseline as the stack; zero new production error classes
  • pnpm lint passes — oxlint --type-aware --deny-warnings exit 0
  • pnpm test passes — unit 126/126, integration 42/42 (workers pool)
  • pnpm format has been run — oxfmt (note: .flue/ is dot-dir-skipped; tab style verified by review)
  • I have added/updated tests for my changes — poll success/timeout, comment-first ordering (failed post leaves labels unflipped), open-PR reap guard, ask composition + injection rejection, issues.closed cleanup
  • User-visible strings in the admin UI are wrapped for translation — n/a
  • I have added a changeset — n/a, unpublished infra worker
  • New features link to an approved Discussion — see note above

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Fable 5 (Claude Code; built and adversarially reviewed by Fable subagents)

Screenshots / test output

unit:        126 passed (126)
integration:  42 passed (42)

Try this PR

Open a fresh playground →

A full working EmDash site, deployed from this branch. Each visit gets its own session-scoped sandbox: no login needed and no shared state. Try the admin, edit content, hit the public site.

Tracks bot-nextgen/04-fix-loop-wiring. Updated automatically when the playground redeploys.

…acts push

Reader-side of the fix loop's preview build. `preview.ts` centralises the
full-ref pkg.pr.new install URL (which the poll probes and the ask advertises),
the fix/artifacts branch names, a bounded readiness probe, and the reap
branch-set. `comments.ts` gains the ask renderer (bot-ask marker, install
command, screenshots served from the artifacts branch with filename validation
and markdown escaping, reporter ask) and the confirmed draft-PR body.

The outbound push proxy now admits `bot/artifacts-<n>` alongside `bot/fix-<n>`
for the issue, and the fix agent reports screenshots and pushes the orphan
artifacts branch so the ask can render them.
…ose cleanup

The orchestrator now drives the fix loop end to end. On entering
preview_building it schedules a bounded pkg.pr.new poll on the DO alarm (one
probe per tick, ~10min budget); a 200 fires preview.ready, exhaustion fires
preview.failed back to the reproduced verdict. preview.ready composes the ask
from the persisted fix notes, screenshots, and the reporter login and posts it
before flipping labels, so a failed comment can't strand the issue in
awaiting-reporter with no ask.

Branch reaping now guards the fix branch behind an open-PR check and always
drops the artifacts branch (review flag F4), on the reject/expire/decline edges
and a new issues.closed cleanup path that bypasses the machine.

Also fixes a latent drain bug: a standalone side effect (runId undefined) with
no dispatch pending matched `undefined === pendingDispatch?.runId` and was
deferred forever. The poll-fired ask is the first non-dry-run standalone effect
to exercise it.
@changeset-bot

changeset-bot Bot commented Aug 8, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: dcdec94

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 860 lines across 13 files. Large PRs are harder to review and more likely to be closed without review.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@ascorbic ascorbic changed the title bot nextgen/04 fix loop wiring feat(emdash-bot): reporter-verified pkg.pr.new fix loop (bot next-gen 4/5) Aug 8, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 8, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache dcdec94 Aug 08 2026, 04:52 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 8, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground dcdec94 Aug 08 2026, 04:53 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 8, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-do dcdec94 Aug 08 2026, 04:55 PM

@pkg-pr-new

pkg-pr-new Bot commented Aug 8, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@2382

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@2382

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/@emdash-cms/auth-atproto@2382

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@2382

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@2382

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/contentful-to-portable-text@2382

emdash

npm i https://pkg.pr.new/emdash@2382

create-emdash

npm i https://pkg.pr.new/create-emdash@2382

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@2382

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@2382

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@2382

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@2382

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@2382

@emdash-cms/registry-verification

npm i https://pkg.pr.new/@emdash-cms/registry-verification@2382

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@2382

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@2382

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@2382

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@2382

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@2382

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@2382

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@2382

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@2382

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@2382

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@2382

commit: dcdec94

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
🔵 In progress
View logs
docs aa22dad Aug 08 2026, 04:47 PM

@ascorbic
ascorbic marked this pull request as ready for review August 8, 2026 16:51
Copilot AI lite review requested due to automatic review settings August 8, 2026 16:51
@github-actions github-actions Bot added the review/needs-review No maintainer or bot review yet label Aug 8, 2026

Copilot AI 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.

Pull request overview

Wires the reporter-verified fix loop into the next-gen emdash-bot orchestration: adds pkg.pr.new preview polling, a preview-ready “ask” comment (with optional screenshots), and an issues.closed cleanup path that reaps fix-loop branches safely.

Changes:

  • Add pkg.pr.new preview helpers and orchestrator polling to advance preview_buildingawaiting_reporter only once the preview URL resolves.
  • Introduce a preview-ready ask comment renderer (install command, notes, screenshots) and a richer draft PR body.
  • Add issues.closed webhook normalization + synchronous cleanup to reap bot/fix-* / bot/artifacts-* with an open-PR guard.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
infra/emdash-bot/tests/unit/webhook.test.ts Adds unit coverage for issues.closed cleanup normalization.
infra/emdash-bot/tests/unit/preview.test.ts Adds unit tests for preview URL/branch helpers and readiness probe behavior.
infra/emdash-bot/tests/unit/orchestrator-comments.test.ts Tests new comment/body renderers (ask + draft PR) including screenshot escaping/injection rejection.
infra/emdash-bot/tests/unit/github-proxy.test.ts Extends push-proxy tests to allow artifacts branch pushes scoped to the issue.
infra/emdash-bot/tests/integration/webhook.test.ts Verifies issues.closed drives the cleanup path in the worker.
infra/emdash-bot/tests/integration/orchestrator.test.ts Adds integration coverage for preview polling outcomes and comment-first side-effect ordering.
infra/emdash-bot/.flue/skills/verify/SKILL.md Minor markdown formatting adjustments.
infra/emdash-bot/.flue/skills/investigate/SKILL.md Minor markdown formatting adjustments.
infra/emdash-bot/.flue/skills/fix/SKILL.md Minor markdown formatting adjustments.
infra/emdash-bot/.flue/skills/diagnose/SKILL.md Minor markdown formatting adjustments.
infra/emdash-bot/.flue/routes.ts Adds synchronous issue-close cleanup handling in the webhook route.
infra/emdash-bot/.flue/lib/webhook.ts Normalizes issues.closed to a cleanup action (skipping PR-as-issue closes).
infra/emdash-bot/.flue/lib/preview.ts New helpers for fix/artifacts branches, preview URL/install command, and readiness probing.
infra/emdash-bot/.flue/lib/orchestrator.ts Implements preview polling, preview-ready ask composition, comment-first side effects, and branch reaping guard via open-PR check.
infra/emdash-bot/.flue/lib/github-proxy.ts Allows receive-pack updates for both bot/fix-* and bot/artifacts-* for the current issue.
infra/emdash-bot/.flue/lib/comments.ts Adds preview-ready ask and draft PR body renderers; introduces screenshot rendering/escaping.
infra/emdash-bot/.flue/agents/investigate.ts Extends agent result schema to include screenshots for preview ask rendering.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +109 to +114
const SCREENSHOT_FILENAME_RE = /^[a-zA-Z0-9._-]{1,80}$/;
const MD_ESCAPE_RE = /([\\[\]()])/g;

function mdEscape(text: string): string {
return text.replace(MD_ESCAPE_RE, "\\$1");
}
Comment on lines +58 to +61
const screenshotSchema = v.object({
filename: v.pipe(v.string(), v.minLength(1), v.maxLength(80)),
description: v.optional(v.string()),
});
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-review No maintainer or bot review yet labels Aug 8, 2026
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Aug 8, 2026
@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Aug 8, 2026

@emdashbot emdashbot 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.

This is a focused, well-scoped slice of the bot next-gen work: it wires the reporter-confirmed fix loop onto the existing machine states, adds bounded pkg.pr.new polling, comment-first ask ordering, open-PR-guarded branch cleanup, and the corresponding tests. The approach fits the stated maintainer-directed design and reuses gen-1 conventions (bot/fix-* branches, the bot-ask marker, and the emdash package-name URL).

I checked the diff and the full changed files, traced call sites in machine.ts, router.ts, github.ts, and investigation-result.ts, and looked for the usual cross-cutting issues. The new code is clean:

  • No new SQL, content-table queries, admin UI strings, or logged-out hot-path queries (AGENTS.md items are n/a for the infra worker).
  • The side-effect drain guard fix correctly distinguishes undefined run ids from pending-dispatch run ids.
  • Preview poll state is set/cleared only on entry/exit of preview_building, and the alarm multiplexing uses earliest-deadline-wins correctly.
  • commentFirst ordering is implemented so a failed ask comment leaves labels unchanged and the effect pending for retry.
  • Push-proxy admission now allows the issue-scoped artifacts branch alongside the fix branch, and the receive-pack parser is unchanged in its security-critical bounds checks.
  • Tests cover poll success/timeout, comment-first ordering, open-PR reap guard, ask composition/injection rejection, and issues.closed cleanup.

I did not find any new blocking issues. One pre-existing inconsistency worth noting: the legacy agent.fix_ready path in renderAgentComment still advertises https://pkg.pr.new/emdash-cms/emdash@..., while the new next-gen path (and gen-1 investigate.yml) uses the package-name URL https://pkg.pr.new/emdash@.... That’s not introduced by this PR, but it would be good to align the legacy lane with the canonical helper in a follow-up.

@github-actions github-actions Bot added the review/approved Approved; no new commits since label Aug 8, 2026
@github-actions github-actions Bot removed the review/awaiting-author Reviewed; waiting on the author to respond label Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants