Skip to content

ci(sync): add reactive sync-models workflow - #107

Merged
damaz91 merged 4 commits into
mainfrom
feat/reactive-sync-models
Nov 19, 2026
Merged

damaz91 merged 4 commits into
mainfrom
feat/reactive-sync-models

Conversation

@gsmith85

@gsmith85 gsmith85 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds the Stage 1 reactive model synchronization workflow (sync-models.yml) to keep generated Pydantic models aligned with upstream UCP specification changes (ucp#909).

  • Listens for ucp-schemas-updated repository dispatch events from Universal-Commerce-Protocol/ucp, daily scheduled reconciliation runs, and manual workflow dispatches across main (draft) and release/YYYY-MM-DD (release) branches.
  • Verifies commit ancestry against ucp-lock.json, installs the SHA256-verified ucp-schema CLI binary, regenerates models, skips lockfile-only updates when generated models have zero diff, runs the unit test suite, and opens or updates a rolling pull request for maintainer review.
  • Files or updates a deduplicated issue when a target release/YYYY-MM-DD branch has not been cut yet (release-cut-needed) or when model generation or testing fails (codegen-sync-failure).

@damaz91 damaz91 added the status:needs-triage Signal that the PR is ready for human triage label Nov 5, 2026
@damaz91 damaz91 added status:under-review and removed status:needs-triage Signal that the PR is ready for human triage labels Nov 18, 2026

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

Thanks @gsmith85 for putting this together! The overall workflow design is clean—minimal permissions, hash-pinned Actions, SHA256SUMS verification on ucp-schema, and skipping lockfile-only updates when _generated.py has zero diff.

Left a few inline comments on merge ordering (feat/ucp-lock-and-draft-channel and #106) and a couple of edge cases around ucp_sha branch ancestry, rolling-branch state checks, scheduled reconciliation scope, and failure-issue deduplication.

Comment thread .github/workflows/sync-models.yml Outdated
Comment on lines +81 to +85
else
UCP_REF="main"
REQUESTED_SHA=""
FORCE="false"
fi

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.

schedule runs (EVENT_NAME == "schedule") fall into this else branch and hardcode UCP_REF="main", whereas the pull request summary notes that daily scheduled reconciliation covers both main (draft) and release/YYYY-MM-DD (release) branches.

Any missed repository_dispatch on an active release/YYYY-MM-DD branch (or updates to release/2026-08-25 unless dispatch-sdk-sync.yml is also backported there) would not be picked up by cron. Could we either iterate/matrix over active origin/release/YYYY-MM-DD (>= 20260825) branches alongside main on schedule, or update the workflow comment and pull request summary to note that scheduled reconciliation is intentionally main-only?

@gsmith85 gsmith85 Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, updated in 3054db4. Split the workflow into a prepare -> sync matrix (with per-ref concurrency) so daily schedule runs reconcile main alongside all active origin/release/YYYY-MM-DD branches from 2026-08-25 onward.

Comment on lines +163 to +187
if [ -n "$REQUESTED_SHA" ]; then
if [[ ! "$REQUESTED_SHA" =~ ^[0-9a-f]{40}$ ]]; then
echo "::error::Invalid 40-char ucp_sha '${REQUESTED_SHA}'"
exit 1
fi
NEW_SHA="$REQUESTED_SHA"
else
NEW_SHA="$(git -C "$RUNNER_TEMP/ucp-spec" rev-parse "origin/${UCP_REF}")"
fi

echo "old_sha=${OLD_SHA}" >> "$GITHUB_OUTPUT"
echo "new_sha=${NEW_SHA}" >> "$GITHUB_OUTPUT"
echo "short_sha=${NEW_SHA:0:7}" >> "$GITHUB_OUTPUT"
echo "ucp_schema_version=${UCP_SCHEMA_VERSION}" >> "$GITHUB_OUTPUT"

ROLLING_BRANCH="chore/sync-models-${SAFE_TARGET}"
if [ "$FORCE" != "true" ]; then
if [ "$OLD_SHA" = "$NEW_SHA" ]; then
echo "ucp-lock.json is already at ${NEW_SHA}; nothing to sync."
exit 0
fi
if ! git -C "$RUNNER_TEMP/ucp-spec" merge-base --is-ancestor "$OLD_SHA" "$NEW_SHA"; then
echo "::notice::Incoming ucp_sha ${NEW_SHA} is not a descendant of locked ${OLD_SHA}; skipping out-of-order dispatch."
exit 0
fi

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.

Two edge cases when REQUESTED_SHA is supplied:

  1. Missing target-branch ancestry check: Unlike cut-sdk-release.yml in #106, this does not verify that NEW_SHA is an ancestor of origin/${UCP_REF}. Right after release/YYYY-MM-DD is cut from main at commit C0, subsequent draft commits on ucp main still have C0 (OLD_SHA) as an ancestor—so passing a main commit hash with ucp_ref=release/YYYY-MM-DD (or passing force_resync=true, which bypasses line 179) would check out main draft schemas, stamp "channel": "release", and open a pull request targeting release/YYYY-MM-DD.
  2. Nonexistent commit hash exits 0: git merge-base --is-ancestor "$OLD_SHA" "$NEW_SHA" exits with 128 (rather than 1) if NEW_SHA does not exist in ucp-spec; if ! git ... treats 128 the same as 1, logging skipping out-of-order dispatch and exiting 0 on a mistyped workflow_dispatch ucp_sha.

Consider verifying commit existence and branch membership unconditionally right after resolving NEW_SHA, and checking exit code 1 specifically on the OLD_SHA ancestry check:

if ! git -C "$RUNNER_TEMP/ucp-spec" cat-file -e "${NEW_SHA}^{commit}" 2>/dev/null; then
  echo "::error::ucp_sha '${NEW_SHA}' does not exist in Universal-Commerce-Protocol/ucp"
  exit 1
fi
if ! git -C "$RUNNER_TEMP/ucp-spec" merge-base --is-ancestor "$NEW_SHA" "origin/${UCP_REF}"; then
  echo "::error::ucp_sha '${NEW_SHA}' is not an ancestor of origin/${UCP_REF}"
  exit 1
fi

@gsmith85 gsmith85 Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great catch on both counts, updated in 3054db4. We now verify commit existence and origin/${UCP_REF} ancestry unconditionally right after resolving NEW_SHA, and check exit code 1 specifically on the OLD_SHA ancestry check so unexpected git errors fail loudly.

Comment thread .github/workflows/sync-models.yml Outdated
Comment on lines +188 to +211
if git show-ref --verify --quiet "refs/remotes/origin/${ROLLING_BRANCH}"; then
ROLLING_LOCK="$(git show "origin/${ROLLING_BRANCH}:ucp-lock.json" 2>/dev/null || true)"
if [ -n "$ROLLING_LOCK" ]; then
ROLLING_SHA="$(ROLLING_LOCK="$ROLLING_LOCK" python3 - <<'PY'
import json
import os
import re

try:
data = json.loads(os.environ["ROLLING_LOCK"])
except json.JSONDecodeError:
data = {}
sha = str(data.get("ucp_sha", ""))
print(sha if re.fullmatch(r"[0-9a-f]{40}", sha) else "")
PY
)"
if [ -n "$ROLLING_SHA" ] \
&& git -C "$RUNNER_TEMP/ucp-spec" cat-file -e "${ROLLING_SHA}^{commit}" 2>/dev/null \
&& git -C "$RUNNER_TEMP/ucp-spec" merge-base --is-ancestor "$NEW_SHA" "$ROLLING_SHA"; then
echo "::notice::Rolling branch ${ROLLING_BRANCH} (${ROLLING_SHA}) is already at or ahead of ${NEW_SHA}; skipping out-of-order or duplicate dispatch."
exit 0
fi
fi
fi

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.

Checking only refs/remotes/origin/${ROLLING_BRANCH} has two operational edge cases:

  1. If a sync pull request is closed without deleting chore/sync-models-${SAFE_TARGET}, the remote branch stays at ROLLING_SHA with no open pull request. Subsequent dispatches and daily schedule runs with NEW_SHA == ROLLING_SHA will hit is-ancestor and exit 0 without re-opening the pull request unless force_resync=true is triggered manually.
  2. If TARGET_BRANCH advances (for example, pyproject.toml or generate_models.sh changes on main, leaving the open sync pull request stale or conflicted), daily schedule runs still see NEW_SHA == ROLLING_SHA and skip regenerating onto the updated origin/${TARGET_BRANCH}.

Gating this skip on an open pull request existing (gh pr list --repo "$REPOSITORY" --state open --base "$TARGET_BRANCH" --head "$ROLLING_BRANCH") and git merge-base --is-ancestor "origin/${TARGET_BRANCH}" "origin/${ROLLING_BRANCH}" would avoid both stuck states.

@gsmith85 gsmith85 Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in 3054db4. The rolling-branch skip now requires an open pull request to exist (and origin/${UCP_REF} to be an ancestor when NEW_SHA == ROLLING_SHA), so closed PRs re-open and stale PRs regenerate cleanly when the target branch advances.

Comment thread .github/workflows/sync-models.yml Outdated
FORCE_RESYNC: ${{ steps.target.outputs.force_resync }}
run: |
set -euo pipefail
./generate_models.sh "$RUNNER_TEMP/ucp-spec" --channel "$CHANNEL" --ref "$UCP_REF" --write-lock

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.

Merge-order note: --channel, --ref, --write-lock, and ucp-lock.json are not on main yet (they currently sit on the unmerged feat/ucp-lock-and-draft-channel branch, and cut-sdk-release.yml referenced on line 126 is in #106). Landing the feat/ucp-lock-and-draft-channel pull request and #106 first, then rebasing #107, will also clear the failing Generated models match the pinned UCP spec check on this pull request.

@gsmith85 gsmith85 Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed! Opened #109 (79bbf75) for the lockfile and generate_models.sh shim (scripts/generate_models.py) so we can land #109 and #106 first, and rebased #107 onto main in 3054db4 so the model-drift check is now green.

Comment thread .github/workflows/sync-models.yml Outdated
Comment on lines +350 to +365
EXISTING_ISSUE="$(gh issue list \
--repo "$REPOSITORY" \
--state open \
--label "codegen-sync-failure" \
--json number \
--jq '.[0].number // empty')"

MSG="Automated model sync failed for \`${UCP_REF}\` at \`${UCP_SHA}\`. Inspect workflow run: ${RUN_URL}"
if [ -n "$EXISTING_ISSUE" ]; then
gh issue comment "$EXISTING_ISSUE" --repo "$REPOSITORY" --body "$MSG"
else
gh issue create \
--repo "$REPOSITORY" \
--title "chore(models): automated schema sync failure (${UCP_REF})" \
--label "codegen-sync-failure" \
--body "$MSG"

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.

Two small refinements for codegen-sync-failure issue deduplication:

  1. Line 363 scopes the issue title by branch ((${UCP_REF})), but gh issue list omits --search "in:title (${UCP_REF})" (unlike release-cut-needed on line 123). If a main failure issue is already open, a failure on release/YYYY-MM-DD will append a comment to the main issue instead of opening a separate release-branch issue.
  2. While an issue remains open, daily schedule runs failing at the same UCP_SHA will post duplicate comments every day. Skipping gh issue comment when the issue body or latest comment already mentions ${UCP_SHA} would avoid daily notification noise.

@gsmith85 gsmith85 Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in 3054db4. Scoped codegen-sync-failure lookup by branch (in:title (${UCP_REF}) plus exact title matching) and suppressed duplicate comments on both codegen-sync-failure and release-cut-needed issues when the open issue body or latest comment already mentions the commit SHA.

@gsmith85
gsmith85 force-pushed the feat/reactive-sync-models branch 5 times, most recently from ac9f575 to 3054db4 Compare November 19, 2026 04:09
@gsmith85
gsmith85 force-pushed the feat/reactive-sync-models branch from 3054db4 to 2e6a17d Compare November 19, 2026 05:00

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

LGTM! Thanks for addressing all the review feedback, @gsmith85—the multi-branch schedule matrix, strict upstream SHA existence and ancestry checks, open-pull-request and rolling-branch guards, and branch-scoped issue deduplication all look great, and #109 has landed on main.

@damaz91
damaz91 merged commit aaf223f into main Nov 19, 2026
16 checks passed
@damaz91
damaz91 deleted the feat/reactive-sync-models branch November 19, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants