Repository navigation
ci(sync): add reactive sync-models workflow - #107
Conversation
damaz91
left a comment
There was a problem hiding this comment.
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.
| else | ||
| UCP_REF="main" | ||
| REQUESTED_SHA="" | ||
| FORCE="false" | ||
| fi |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
Two edge cases when REQUESTED_SHA is supplied:
- Missing target-branch ancestry check: Unlike
cut-sdk-release.ymlin#106, this does not verify thatNEW_SHAis an ancestor oforigin/${UCP_REF}. Right afterrelease/YYYY-MM-DDis cut frommainat commitC0, subsequentdraftcommits onucpmainstill haveC0(OLD_SHA) as an ancestor—so passing amaincommit hash withucp_ref=release/YYYY-MM-DD(or passingforce_resync=true, which bypasses line 179) would check outmaindraft schemas, stamp"channel": "release", and open a pull request targetingrelease/YYYY-MM-DD. - Nonexistent commit hash exits
0:git merge-base --is-ancestor "$OLD_SHA" "$NEW_SHA"exits with128(rather than1) ifNEW_SHAdoes not exist inucp-spec;if ! git ...treats128the same as1, loggingskipping out-of-order dispatchand exiting0on a mistypedworkflow_dispatchucp_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
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
Checking only refs/remotes/origin/${ROLLING_BRANCH} has two operational edge cases:
- If a sync pull request is closed without deleting
chore/sync-models-${SAFE_TARGET}, the remote branch stays atROLLING_SHAwith no open pull request. Subsequent dispatches and dailyscheduleruns withNEW_SHA == ROLLING_SHAwill hitis-ancestorand exit0without re-opening the pull request unlessforce_resync=trueis triggered manually. - If
TARGET_BRANCHadvances (for example,pyproject.tomlorgenerate_models.shchanges onmain, leaving the open sync pull request stale or conflicted), dailyscheduleruns still seeNEW_SHA == ROLLING_SHAand skip regenerating onto the updatedorigin/${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.
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
| 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" |
There was a problem hiding this comment.
Two small refinements for codegen-sync-failure issue deduplication:
- Line 363 scopes the issue title by branch (
(${UCP_REF})), butgh issue listomits--search "in:title (${UCP_REF})"(unlikerelease-cut-neededon line 123). If amainfailure issue is already open, a failure onrelease/YYYY-MM-DDwill append a comment to themainissue instead of opening a separate release-branch issue. - While an issue remains open, daily
scheduleruns failing at the sameUCP_SHAwill post duplicate comments every day. Skippinggh issue commentwhen the issue body or latest comment already mentions${UCP_SHA}would avoid daily notification noise.
There was a problem hiding this comment.
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.
ac9f575 to
3054db4
Compare
3054db4 to
2e6a17d
Compare
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).ucp-schemas-updatedrepository dispatch events fromUniversal-Commerce-Protocol/ucp, daily scheduled reconciliation runs, and manual workflow dispatches acrossmain(draft) andrelease/YYYY-MM-DD(release) branches.ucp-lock.json, installs the SHA256-verifieducp-schemaCLI 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.release/YYYY-MM-DDbranch has not been cut yet (release-cut-needed) or when model generation or testing fails (codegen-sync-failure).