Skip to content

[miniflare] Publish local Artifacts push, clone, and fetch events - #16973

Open
leostera wants to merge 2 commits into
cloudflare:mainfrom
leostera:lostera/artifacts-local-git-events
Open

leostera wants to merge 2 commits into
cloudflare:mainfrom
leostera:lostera/artifacts-local-git-events

Conversation

@leostera

@leostera leostera commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

@dinasaur404 this implements the event we missed: locally, cf.artifacts.repo.pushed (and cloned/fetched) now start your Workflow when you git push, with the same triggers.events config. Could you review?

Local Artifacts accepted subscriptions to cf.artifacts.repo.pushed, cf.artifacts.repo.cloned, and cf.artifacts.repo.fetched, but never published them. Events only came from binding operations (create, import, fork, delete, tokens), and Git traffic goes through the local Git backend instead, so a Workflow subscribed to pushes never started. #16246 shipped with this documented as a known gap; this closes it.

Local namespaces now publish these events the way production does:

  • Push: after a push, one pushed event per ref it changed. The Git backend records the refs before and after while it holds the repository's lock, so concurrent pushes to one repository each report only their own refs. Branch updates list up to 20 commits along the first-parent chain from after back to before, newest first. totalCommitsCount counts at most one past that, so commitsTruncated is set when commits were left out. Commit messages are cut to 4096 UTF-8 bytes. Tags and deletions list no commits. After a force push the list also includes older history, as in production, because the walk stops only at before. Commits are read in the background, one ref at a time with one Git process per ref, so they never delay the push response.
  • Clone and fetch: after a served upload-pack request, cloned when it names no objects the client already has, fetched when it does, including gzipped requests. Like production, a fetch that negotiates over several requests publishes once per request. Ref listing (ls-refs, e.g. git ls-remote) publishes nothing.

This works the same under cf dev, whether it delegates to Wrangler (cf-wrangler, with events declared through exports.workflow({ events }) in cloudflare.config.ts) or to the Vite plugin, since both run this Miniflare Artifacts plugin.

This extra Git work only happens when a subscription receives the event type from that repository, so repositories without subscribers behave as before.

Tests:

  • Miniflare git-events.spec.ts drives real host Git against a local namespace: payload shape for a new branch, a branch update, a tag and a tag deletion; truncation at 20 commits; repository filters; concurrent pushes to one repository; a rejected push followed by a force push; and clone (protocol v0 and v2), gzipped fetch, and ls-remote.
  • Wrangler artifacts-local.test.ts runs wrangler dev with a triggers.events subscription to cf.artifacts.repo.pushed filtered to one repository, pushes with Git, and checks that only that repository's push starts the Workflow, with the production payload.
  • cf dev paths: cf-wrangler/artifacts-events.test.ts runs the cf-wrangler entrypoint, and the Vite plugin's artifacts-local.spec.ts runs Vite, both with exports.workflow({ events }) in cloudflare.config.ts. Each pushes to a filtered and an ignored repository, clones, pushes again, and fetches, then checks that the Workflow recorded exactly one push, clone, and fetch for the subscribed repository.
  • Unit tests cover ref diffing, payload bounds, upload-pack classification, and parsing git cat-file --batch output.

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: the local development guide (packages/miniflare/src/plugins/artifacts/LOCAL_DEVELOPMENT.md) is updated; the event shapes are the documented production ones.

Devin Review

@changeset-bot

changeset-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ff1c57a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
miniflare Minor
@cloudflare/deploy-helpers Patch
@cloudflare/dev-helpers Patch
@cloudflare/pages-shared Patch
@cloudflare/remote-bindings Patch
@cloudflare/runtime-types Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-plugin Patch
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

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

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Nov 17, 2026
@workers-devprod
workers-devprod requested review from a team and dario-piotrowicz and removed request for a team November 17, 2026 00:43
@workers-devprod

workers-devprod commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@devin-ai-integration devin-ai-integration 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.

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of 1e75c2f4.

This review, of ad092aa3

✅ Approved — No correctness, security, performance or release issues found in the local Git event publishing, and it is tested at both the Miniflare and Wrangler layers.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

The change only affects local Miniflare behaviour, and the changeset records it as a minor Miniflare release.


🔒 Security: ✅ LGTM

  • Admin actions: The new commitRange and pushRefs actions go through the existing admin endpoint, which needs the backend secret.
  • Inputs: Inputs are checked: commit IDs must be 40-character hex, requestId must be a UUID, and the limits are bounded integers.
  • Git commands: Git runs with argument arrays, not a shell, so there is no command or argument injection.
  • Push records: These are keyed by repository path and generation, so one repository cannot read another's refs. The map has a size cap and each record is deleted once read.

📖 AGENTS.md: ✅ LGTM

The change follows the repository's guidance: the feature is built in Miniflare, with a thin Wrangler test on top.


📋 Code Quality: ✅ LGTM

  • Push refs: The sidecar captures the refs before and after each push while it holds the repository lock, and pushRefs takes the same lock. Concurrent pushes to one repository therefore each report only their own refs.
  • Rejected pushes: Events are published only when the refs actually changed, so a rejected push publishes nothing.
  • Commit listing: The git cat-file --batch parsing checks its bounds correctly.
  • Clone and fetch: Classification handles protocol v0, v1 and v2 and gzipped bodies. Errors are logged and never fail the Git response.
  • Tests: The change is built in Miniflare and covered there by unit tests and real-Git tests, plus a Wrangler test.

⚡ Performance: ✅ LGTM

The extra Git work only runs when a subscription receives that event type from that repository. Commits are read in the background, so the push response is never delayed.


📝 Documentation: ✅ LGTM

The LOCAL_DEVELOPMENT.md update and the changeset match the new behaviour.


Reviewed commit: ad092aa3

@pkg-pr-new

pkg-pr-new Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@16973

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@16973

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@16973

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@16973

@cloudflare/containers-shared

npm i https://pkg.pr.new/@cloudflare/containers-shared@16973

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@16973

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@16973

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@16973

miniflare

npm i https://pkg.pr.new/miniflare@16973

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@16973

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@16973

@cloudflare/runtime-types

npm i https://pkg.pr.new/@cloudflare/runtime-types@16973

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@16973

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@16973

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@16973

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@16973

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@16973

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@16973

wrangler

npm i https://pkg.pr.new/wrangler@16973

commit: ff1c57a

Comment on lines +693 to +695
expect(() =>
parseCatFileBatch(Buffer.from(`${"a".repeat(40)} commit 99\nshort\n`))
).toThrow("Truncated");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this could be better placed in its own test 🤔

@dario-piotrowicz
dario-piotrowicz self-requested a review November 17, 2026 12:54

@workers-devprod workers-devprod 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.

Codeowners reviews satisfied

@dario-piotrowicz

Copy link
Copy Markdown
Member

@petebacondarwin sorry I didn't see that you un-assigned me from the PR, I gave it a high level review but I'm happy for you to re-review it 🙂

(also I was about to suggest that someone from the artifacts team should also have a look ideally)

@leostera
leostera force-pushed the lostera/artifacts-local-git-events branch from ad092aa to 1e75c2f Compare November 20, 2026 16:57

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of 086bcb18.

This review, of 1e75c2f4

✅ Approved — I found no correctness, security, performance or release issues in local publishing of push, clone and fetch events. The change has unit tests, real-Git tests in Miniflare and an end-to-end test in Wrangler.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

The change only affects local Miniflare behaviour. Its changeset records a minor Miniflare release, which follows the project's convention for new features.


🔒 Security: ✅ LGTM

  • New actions: commitRange and pushRefs go through the existing admin endpoint, which requires the backend secret.
  • Input checks: Commit IDs must be 40-character hex, requestId must be a UUID, and the limits are bounded integers.
  • Git commands: Git runs with argument arrays, not a shell, so arguments cannot be injected.
  • Push records: Records are keyed by request, repository path and generation, so one repository cannot read another's refs. The map is capped in size, and each record is deleted once read.

📖 AGENTS.md: ✅ LGTM

The change follows the repository's guidance: the feature is built in Miniflare and covered there, with a thin Wrangler test on top.


📋 Code Quality: ✅ LGTM

  • Concurrent pushes: The refs before and after a push are recorded while the repository lock is held, and pushRefs takes the same lock. Each of several concurrent pushes to one repository therefore reports only its own refs.
  • Rejected pushes: syncAfterPush now also runs for failed pushes, which releases the record of the push. Events go out only when refs actually changed, so a rejected push publishes nothing.
  • cat-file parsing: The bounds check in parseCatFileBatch is correct, and a truncated header throws an error.
  • Clone and fetch: Events are published only after a successful upload-pack response. A failure to publish is logged and never fails the Git response.

⚡ Performance: ✅ LGTM

  • Extra Git work: It runs only when a subscription receives that event type from that repository.
  • Commit reads: They are capped at 21 revisions per ref and run in the background, so they never delay the push response.
  • Push records: The map of finished pushes is capped in size.

📝 Documentation: ✅ LGTM

The LOCAL_DEVELOPMENT.md update and the changeset match the new behaviour.


Reviewed commit: 1e75c2f4

@leostera
leostera force-pushed the lostera/artifacts-local-git-events branch from 1e75c2f to 086bcb1 Compare November 23, 2026 15:50
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of a9e3704f.

This review, of 086bcb18

✅ Approved — I found no correctness, security, performance or release issues in local publishing of push, clone and fetch events. The change has unit tests, real-Git tests in Miniflare and an end-to-end test in Wrangler.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

The change only affects local Miniflare behaviour. Its changeset records a minor Miniflare release, which follows the project's convention for new features.


🔒 Security: ✅ LGTM

  • New actions: commitRange and pushRefs go through the existing admin endpoint, which requires the backend secret.
  • Input checks: Commit IDs must be 40-character hex, requestId must be a UUID, and the limits are bounded integers.
  • Git commands: Git runs with argument arrays, not a shell, so arguments cannot be injected.
  • Push records: Records are keyed by request, repository path and generation, so one repository cannot read another's refs. The map is capped in size, and each record is deleted once read.

📖 AGENTS.md: ✅ LGTM

The change follows the repository's guidance: the feature is built in Miniflare and covered there, with a thin Wrangler test on top.


📋 Code Quality: ✅ LGTM

  • Concurrent pushes: The refs before and after a push are recorded while the repository lock is held, and pushRefs takes the same lock. Each of several concurrent pushes to one repository therefore reports only its own refs.
  • Rejected pushes: syncAfterPush now also runs for failed pushes, which releases the record of the push. Events go out only when refs actually changed, so a rejected push publishes nothing.
  • cat-file parsing: The bounds check in parseCatFileBatch is correct, and a truncated header throws an error.
  • Clone and fetch: Events are published only after a successful upload-pack response. A failure to publish is logged and never fails the Git response.

⚡ Performance: ✅ LGTM

  • Extra Git work: It runs only when a subscription receives that event type from that repository.
  • Commit reads: They are capped at 21 revisions per ref and run in the background, so they never delay the push response.
  • Push records: The map of finished pushes is capped in size.

📝 Documentation: ✅ LGTM

The LOCAL_DEVELOPMENT.md update and the changeset match the new behaviour.


Reviewed commit: 086bcb18 — same changes as 1e75c2f4, so this is that commit's review (no new review was run; line numbers are as of 1e75c2f4)

@leostera
leostera enabled auto-merge (squash) November 23, 2026 15:53
Local Artifacts accepted subscriptions to `cf.artifacts.repo.pushed`,
`cf.artifacts.repo.cloned`, and `cf.artifacts.repo.fetched`, but never
published them: events came only from binding operations, and Git traffic
goes through the local Git backend instead. A Workflow subscribed to pushes
therefore never started.

The namespace now publishes them the way production does:

- After a push, one `pushed` event per ref it changed. The Git backend
  records the refs before and after the push while it holds the
  repository's lock, so concurrent pushes to one repository each report
  only their own refs. Branch updates list up to 20 commits along the
  first-parent chain from `after` until `before`, newest first, with
  `totalCommitsCount` counting at most one past that so `commitsTruncated`
  is set. Messages are cut to 4096 UTF-8 bytes. Tags and deletions list no
  commits. Commits are read in the background, one ref at a time and in one
  Git process per ref, so they never delay the push response.
- After a served upload-pack request, `cloned` when it names no objects the
  client already has and `fetched` when it does, including gzipped
  requests. Ref listing (`ls-refs`) publishes nothing.

Git work for events only happens when a subscription receives that event
type from that repository, so other repositories behave as before.
@leostera
leostera force-pushed the lostera/artifacts-local-git-events branch from 086bcb1 to a9e3704 Compare November 23, 2026 15:58

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of ff1c57a3.

This review, of a9e3704f

✅ Approved — I found no correctness, security, performance or release issues in local publishing of push, clone and fetch events. The change has unit tests, real-Git tests in Miniflare and an end-to-end test in Wrangler.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

The change only affects local Miniflare behaviour. Its changeset records a minor Miniflare release, which follows the project's convention for new features.


🔒 Security: ✅ LGTM

  • New actions: commitRange and pushRefs go through the existing admin endpoint, which requires the backend secret.
  • Input checks: Commit IDs must be 40-character hex, requestId must be a UUID, and the limits are bounded integers.
  • Git commands: Git runs with argument arrays, not a shell, so arguments cannot be injected.
  • Push records: Records are keyed by request, repository path and generation, so one repository cannot read another's refs. The map is capped in size, and each record is deleted once read.

📖 AGENTS.md: ✅ LGTM

The change follows the repository's guidance: the feature is built in Miniflare and covered there, with a thin Wrangler test on top.


📋 Code Quality: ✅ LGTM

  • Concurrent pushes: The refs before and after a push are recorded while the repository lock is held, and pushRefs takes the same lock. Each of several concurrent pushes to one repository therefore reports only its own refs.
  • Rejected pushes: syncAfterPush now also runs for failed pushes, which releases the record of the push. Events go out only when refs actually changed, so a rejected push publishes nothing.
  • cat-file parsing: The bounds check in parseCatFileBatch is correct, and a truncated header throws an error.
  • Clone and fetch: Events are published only after a successful upload-pack response. A failure to publish is logged and never fails the Git response.

⚡ Performance: ✅ LGTM

  • Extra Git work: It runs only when a subscription receives that event type from that repository.
  • Commit reads: They are capped at 21 revisions per ref and run in the background, so they never delay the push response.
  • Push records: The map of finished pushes is capped in size.

📝 Documentation: ✅ LGTM

The LOCAL_DEVELOPMENT.md update and the changeset match the new behaviour.


Reviewed commit: a9e3704f — same changes as 1e75c2f4, so this is that commit's review (no new review was run; line numbers are as of 1e75c2f4)

`cf dev` runs local development through either the `cf-wrangler` delegate
or the Vite plugin, both with events declared as
`exports.workflow({ events })` in `cloudflare.config.ts`. Only the
`wrangler.jsonc` path had a Git event test.

Both paths now have a test that pushes to a filtered repository and to an
ignored one, clones, pushes again, and fetches, then checks that the
Workflow recorded exactly one push, one clone, and one fetch for the
subscribed repository. The `cf-wrangler` test parses its arguments as the
binary does and lives in its own file: loading the `cf-wrangler` modules
next to the `wrangler dev` tests stalls the latter's reload test.

`runFixtureGit` runs host Git with the same isolated, authenticated
environment as `pushGitFixture`, for the clone, commit, push, and fetch.

@devin-ai-integration devin-ai-integration 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.

Devin Review found 3 new potential issues.

Devin Review

Comment on lines +175 to +176
const { type, source } = event.payload;
await this.env.EVENTS.put(type + ":" + source.repoName, JSON.stringify(event.payload));

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.

🔍 One push record masks missing events

RecordRepoEvent uses the same KV key for both pushes to demo. Both this test and the cf-wrangler test pass if either push fails to start a Workflow.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +109 to +117
const running = runCfWranglerDev({
...parseCfWranglerArgs(["--port=0", "--inspector-port=0"]),
showInteractiveDevSession: false,
onReady: (ip: string, port: number) => {
url = `http://${ip}:${port}`;
},
});
try {
await vi.waitUntil(() => url, { timeout: READY_TIMEOUT });

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.

🔍 Unhandled dev startup rejection

If runCfWranglerDev rejects before readiness, the test keeps polling for a URL. It attaches a rejection handler only during cleanup, after Vitest can already report an unhandled rejection.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

import { mockConsoleMethods } from "../helpers/mock-console";
import type { StartDevOptions } from "../../dev";

let stopDev: (() => Promise<void>) | undefined;

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.

🔍 Module-wide dev teardown state

stopDev stores a single test’s teardown callback in mutable module state. That conflicts with the review rule against global variables.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@clanky-the-clanker clanky-the-clanker 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.

✅ Approved — I found no correctness, security, performance, documentation or release issues. The new cf dev tests for cf-wrangler and the Vite plugin follow how Miniflare classifies push, clone and fetch.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

The change only affects local Miniflare behaviour. Its minor changeset follows the project's convention for new features.


🔒 Security: ✅ LGTM

  • Admin endpoint: commitRange and pushRefs still go through it, and it checks the backend secret.
  • Input checks: commit IDs and requestId are validated, and the walk limits are bounded.
  • Git commands: Git runs with argument arrays, not a shell.
  • Push records: each one is checked against the repository path and generation, deleted once read, and the map is capped in size.

📖 AGENTS.md: ✅ LGTM

The change follows the repository guidance for features that span several tools:

  • The feature is built and tested in Miniflare.
  • Wrangler, cf-wrangler and the Vite plugin each add only thin tests on top.

📋 Code Quality: ✅ LGTM

  • runFixtureGit (packages/workers-utils/src/test-helpers/git.ts): it uses the same isolated Git environment as pushGitFixture, creates cwd before running Git, and passes the token as an argument rather than through a shell.
  • New tests (artifacts-local.spec.ts in the Vite plugin, cf-wrangler/artifacts-events.test.ts in Wrangler): the push, clone, push, fetch sequence lines up with how Miniflare classifies requests.
    • The push to the ignored repository is filtered out.
    • The clone sends no have lines, so it is reported as cloned.
    • The second push gives the later fetch something to negotiate, so that fetch sends have lines and is reported as fetched.
    • The final assertion on exactly one push, one clone and one fetch therefore holds.

⚡ Performance: ✅ LGTM

The extra Git work runs only for subscribed repositories, and it runs in the background, so it does not delay the push response.


📝 Documentation: ✅ LGTM

The LOCAL_DEVELOPMENT.md update and the changeset match the new behaviour.


Reviewed commit: ff1c57a3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

4 participants