Skip to content

feat: add template sync validation to prevent consumer repo sync failures#857

Merged
stranske merged 20 commits intomainfrom
fix/template-sync-guard
Jan 12, 2026
Merged

feat: add template sync validation to prevent consumer repo sync failures#857
stranske merged 20 commits intomainfrom
fix/template-sync-guard

Conversation

@stranske
Copy link
Copy Markdown
Owner

@stranske stranske commented Jan 12, 2026

Source: Issue #123

Automated Status Summary

Scope

After merging PR #103 (multi-agent routing infrastructure), we need to:

Context for Agent

Design Decisions & Constraints

    1. Clean up comment patterns to avoid a mix of old UI-agent and new CLI-agent comments
  • The keepalive loop now:
  • | <!-- keepalive-loop-summary --> | github-actions[bot] | NEW: CLI agent iteration tracking | ✅ Keep for CLI agents |
  • | <!-- keepalive-state:v1 --> | agents-workflows-bot[bot] | State tracking | ⚠️ Multiple copies accumulate |
  • | <!-- keepalive-round: N --> | stranske | OLD: Instruction comment | ❌ CLI agents dont need this |
  • The goal: For CLI agents (agent:* label), we should have exactly one updating comment (<!-- keepalive-loop-summary -->) instead of accumulating 10+ comments per PR.
  • Requires PR #103 to be merged first
  • This round you MUST:
  • Review the Scope/Tasks/Acceptance below, identify the next incomplete task that requires code, implement it, then post a reply comment with the completed items using their exact original text.

Related Issues/PRs

References

Blockers & Dependencies

  • After merging PR #103 (multi-agent routing infrastructure), we need to:
    1. Mark a task checkbox complete ONLY after verifying the implementation works.

Tasks

  • 1. Validate the CLI agent pipeline works end-to-end with the new task-focused prompts
  • 2. Add GITHUB_STEP_SUMMARY output so iteration results are visible in the Actions UI
  • 3. Streamline the Automated Status Summary to reduce clutter when using CLI agents
  • 4. Clean up comment patterns to avoid a mix of old UI-agent and new CLI-agent comments

Acceptance criteria

  • CLI agent receives explicit tasks in prompt and works on them
  • Iteration results visible in Actions workflow run summary
  • PR body shows checkboxes but not workflow clutter when using CLI agents
  • UI Codex path (no agent label) continues to show full status summary
  • CLI agent PRs have ≤3 bot comments total (summary, one per iteration update) instead of 10+
  • State tracking is consolidated in the summary comment, not scattered

Head SHA: 77b9331
Latest Runs: ✅ success — Gate
Required: gate: ✅ success

Workflow / Job Result Logs
Agents PR meta manager ❔ in progress View run
CI Autofix Loop ✅ success View run
Gate ✅ success View run
Health 40 Sweep ✅ success View run
Health 44 Gate Branch Protection ✅ success View run
Health 45 Agents Guard ✅ success View run
Health 50 Security Scan ✅ success View run
Health 72 Template Sync ✅ success View run
Maint 52 Validate Workflows ✅ success View run
PR 11 - Minimal invariant CI ✅ success View run
Selftest CI ✅ success View run
Validate Sync Manifest ✅ success View run

stranske and others added 6 commits January 12, 2026 16:02
…d slashes

The task decomposer was incorrectly splitting compound words like
'additions/removals' or file paths like 'src/utils' into separate tasks
because it matched any '/' character.

This caused the agents:apply-suggestions workflow to corrupt issue bodies
by creating spurious subtasks like:
- Color-coded additions (verify: confirm completion in repo)
- removals (verify: confirm completion in repo)

Fix:
- task_decomposer._split_task_parts: Only split on spaced slashes ' / '
  (indicating alternatives) not unspaced slashes (compound words/paths)
- issue_optimizer._is_large_task: Only flag tasks with spaced slashes
  as 'large' requiring decomposition

Closes: Issue with corrupted tasks in PRs #4355 and #4353
The Automated Status Summary in PR bodies was extracting checkbox patterns
(- [ ]) from inside fenced code blocks and treating them as tasks.

For example, code examples like:
```python
tasks = ['- [ ] example task']
```

Were being parsed as actual tasks, corrupting the PR body.

Fix:
- Add stripCodeBlocks() function that removes fenced code blocks
  (both ``` and ~~~ style) before parsing
- Apply code block stripping in collectSections() before extracting tasks
- Add regression tests for code block handling

This is the actual fix for the corrupted tasks issue - the previous commit
(task decomposer slash splitting) addressed a different but related problem.
- Add isCodeFenceLine() helper to detect ``` and ~~~ fences
- Update normaliseChecklist() to skip checkbox normalization inside code blocks
- Update extractListBlocks() to continue through code blocks
- Update extractListBlocksWithOffsets() similarly for offset tracking
- Update collectSections() to skip heading detection inside code blocks

This fixes the issue where code examples in issue bodies containing
patterns like 'tasks:' or '- example item' were being incorrectly
detected as section headings or converted to task checkboxes.

Code blocks are now:
1. Preserved in the output (not stripped)
2. Excluded from heading detection
3. Excluded from checkbox normalization

Closes #TBD
…k.py

Per Copilot reviewer feedback: capability_check.py contains a similar
function _is_multi_action_task that also checks for '/' in task. This
had the same issue - incorrectly flagging compound words like
'additions/removals' and paths like 'src/utils' as multi-action tasks.

Changes:
- Updated _is_multi_action_task to check for ' / ' (spaced slash) instead
- Added comprehensive tests for the fix
…ures

PROBLEM: Repeatedly modifying .github/scripts/ without updating
templates/consumer-repo/.github/scripts/ causes:
- No sync PRs created for consumer repos
- Consumer repos missing critical workflow fixes
- Wasted cleanup effort

SOLUTION: Automated guards that make this mistake impossible

Changes:
1. **scripts/validate_template_sync.py** - Validates template files are
   in sync with source files by comparing SHA256 hashes

2. **scripts/sync_templates.sh** - Helper script to sync all changed
   files from .github/scripts/ to templates/consumer-repo/

3. **.github/workflows/validate-template-sync.yml** - CI workflow that
   fails if templates are out of sync (runs on PR and push to main)

4. **docs/CONTRIBUTING.md** - Added prominent warning section with
   instructions on using the validation and sync scripts

5. **Synced 7 out-of-sync template files**:
   - issue_scope_parser.js (code block handling fix)
   - keepalive_worker_gate.js
   - keepalive_instruction_template.js
   - agents_pr_meta_keepalive.js
   - agents-guard.js
   - agents_pr_meta_update_body.js
   - verifier_ci_query.js

This will now trigger consumer repo sync PRs for the code block fix.
Copilot AI review requested due to automatic review settings January 12, 2026 18:16
@stranske stranske added the autofix Opt-in automated formatting & lint remediation label Jan 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 12, 2026

Automated Status Summary

Head SHA: 40703b4
Latest Runs: ⏳ pending — Gate
Required contexts: Gate / gate, Health 45 Agents Guard / Enforce agents workflow protections
Required: core tests (3.11): ⏳ pending, core tests (3.12): ⏳ pending, docker smoke: ⏳ pending, gate: ⏳ pending

Workflow / Job Result Logs
(no jobs reported) ⏳ pending

Coverage Overview

  • Coverage history entries: 1

Coverage Trend

Metric Value
Current 92.21%
Baseline 85.00%
Delta +7.21%
Minimum 70.00%
Status ✅ Pass

Top Coverage Hotspots (lowest coverage)

File Coverage Missing
scripts/workflow_health_check.py 62.6% 28
scripts/classify_test_failures.py 62.9% 37
scripts/ledger_validate.py 65.3% 63
scripts/mypy_return_autofix.py 82.6% 11
scripts/ledger_migrate_base.py 85.5% 13
scripts/fix_cosmetic_aggregate.py 92.3% 1
scripts/coverage_history_append.py 92.8% 2
scripts/workflow_validator.py 93.3% 4
scripts/update_autofix_expectations.py 93.9% 1
scripts/pr_metrics_tracker.py 95.7% 3
scripts/generate_residual_trend.py 96.6% 1
scripts/build_autofix_pr_comment.py 97.0% 2
scripts/aggregate_agent_metrics.py 97.2% 0
scripts/fix_numpy_asserts.py 98.1% 0
scripts/sync_test_dependencies.py 98.3% 1

Updated automatically; will refresh on subsequent CI/Docker completions.


Keepalive checklist

Scope

After merging PR #103 (multi-agent routing infrastructure), we need to:

Context for Agent

Design Decisions & Constraints

    1. Clean up comment patterns to avoid a mix of old UI-agent and new CLI-agent comments
  • The keepalive loop now:
  • | <!-- keepalive-loop-summary --> | github-actions[bot] | NEW: CLI agent iteration tracking | ✅ Keep for CLI agents |
  • | <!-- keepalive-state:v1 --> | agents-workflows-bot[bot] | State tracking | ⚠️ Multiple copies accumulate |
  • | <!-- keepalive-round: N --> | stranske | OLD: Instruction comment | ❌ CLI agents dont need this |
  • The goal: For CLI agents (agent:* label), we should have exactly one updating comment (<!-- keepalive-loop-summary -->) instead of accumulating 10+ comments per PR.
  • Requires PR #103 to be merged first
  • This round you MUST:
  • Review the Scope/Tasks/Acceptance below, identify the next incomplete task that requires code, implement it, then post a reply comment with the completed items using their exact original text.

Related Issues/PRs

References

Blockers & Dependencies

  • After merging PR #103 (multi-agent routing infrastructure), we need to:
    1. Mark a task checkbox complete ONLY after verifying the implementation works.

Tasks

  • 1. Validate the CLI agent pipeline works end-to-end with the new task-focused prompts
  • 2. Add GITHUB_STEP_SUMMARY output so iteration results are visible in the Actions UI
  • 3. Streamline the Automated Status Summary to reduce clutter when using CLI agents
  • 4. Clean up comment patterns to avoid a mix of old UI-agent and new CLI-agent comments

Acceptance criteria

  • CLI agent receives explicit tasks in prompt and works on them
  • Iteration results visible in Actions workflow run summary
  • PR body shows checkboxes but not workflow clutter when using CLI agents
  • UI Codex path (no agent label) continues to show full status summary
  • CLI agent PRs have ≤3 bot comments total (summary, one per iteration update) instead of 10+
  • State tracking is consolidated in the summary comment, not scattered

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 12, 2026

🤖 Keepalive Loop Status

PR #857 | Agent: Codex | Iteration 0/5

Current State

Metric Value
Iteration progress [----------] 0/5
Action wait (missing-agent-label)
Disposition skipped (transient)
Gate success
Tasks 0/10 complete
Timeout 45 min (default)
Timeout usage 1m elapsed (4%, 44m remaining)
Keepalive ❌ disabled
Autofix ❌ disabled

🔍 Failure Classification

| Error type | infrastructure |
| Error category | resource |
| Suggested recovery | Confirm the referenced resource exists (repo, PR, branch, workflow, or file). |

@stranske stranske temporarily deployed to agent-high-privilege January 12, 2026 18:16 — with GitHub Actions Inactive
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 12, 2026

Status | ✅ no new diagnostics
History points | 1
Timestamp | 2026-01-12 18:53:53 UTC
Report artifact | autofix-report-pr-857
Remaining | 0
New | 0
No additional artifacts

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 12, 2026

Autofix updated these files:

  • tests/scripts/test_validate_template_sync.py

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 96ef587f22

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- SYNC_WORKFLOW.md: Added step 0 to verify template sync before any sync
- SETUP_CHECKLIST.md: Added explanation of template sync process
  - Clarifies how consumer repos receive updates
  - Shows validation/sync commands for contributors
  - Warns consumer repo users not to manually edit workflow files
@stranske stranske temporarily deployed to agent-high-privilege January 12, 2026 18:19 — with GitHub Actions Inactive
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

This PR introduces automated validation to ensure workflow scripts in .github/scripts/ stay synchronized with their template counterparts in templates/consumer-repo/.github/scripts/. The PR addresses a recurring problem where source file updates weren't being propagated to the template directory, preventing sync PRs to consumer repos.

Changes:

  • Added Python validation script to detect hash mismatches between source and template files
  • Added bash sync helper script to automate copying changed files to the template directory
  • Added CI workflow that fails builds when templates are out of sync with source files
  • Updated 7 out-of-sync template files (including the code block handling fix from PR #855)
  • Enhanced slash-handling logic in Python modules to distinguish between spaced slashes (alternatives) and compound words with unspaced slashes
  • Updated CONTRIBUTING.md with template sync requirements and instructions

Reviewed changes

Copilot reviewed 19 out of 21 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
scripts/validate_template_sync.py New validation script that compares SHA256 hashes of source vs template files
scripts/sync_templates.sh New helper script to automatically copy changed files to template directory
.github/workflows/validate-template-sync.yml New CI workflow that enforces template synchronization on PRs
docs/CONTRIBUTING.md Added critical template sync guard section with usage instructions
scripts/langchain/task_decomposer.py Updated to only split on spaced slashes, preserving compound words and file paths
scripts/langchain/issue_optimizer.py Updated slash detection for large task identification
scripts/langchain/capability_check.py Updated slash detection for multi-action task identification
tests/scripts/test_*.py Added comprehensive tests for spaced vs unspaced slash handling
templates/consumer-repo/.github/scripts/*.js Synced 7 files with source (code block handling, retry logic, indentation, unused variable cleanup)
.github/scripts/issue_scope_parser.js Added code fence tracking to prevent checkbox addition inside code blocks
.github/scripts/tests/issue_scope_parser.test.js Added tests for code block preservation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…ew files

Codex Review P2 Issues Fixed:
1. Validator now FAILS when template counterpart is missing (not just warns)
   - Prevents CI from passing when new .github/scripts/*.js files lack templates
2. Sync script now CREATES missing template files (not just updates existing)
   - Makes sync effective for new files, not just changed ones

Also:
- Renamed workflow to health-72-template-sync.yml (follows naming convention)
- Fixed shellcheck SC2181: check exit code directly instead of using $?
- Added to EXPECTED_NAMES in test_workflow_naming.py
- Added to docs/ci/WORKFLOWS.md workflow list
- Added to docs/ci/WORKFLOW_SYSTEM.md workflow table

This fixes the 4 failing pytest tests that check workflow naming conventions
and documentation completeness.
@stranske stranske temporarily deployed to agent-high-privilege January 12, 2026 18:25 — with GitHub Actions Inactive
@stranske stranske temporarily deployed to agent-high-privilege January 12, 2026 18:27 — with GitHub Actions Inactive
Addresses Copilot feedback requesting test coverage.

Tests verify:
- Detection of hash mismatches
- Detection of missing template files (exit 1)
- Handling of missing template directories
- Exclusion of non-.js files
- Proper error messaging and sync suggestions
- Multiple simultaneous mismatches

Follows patterns from test_validate_version_pins.py and
test_sync_dev_dependencies.py.
@stranske stranske temporarily deployed to agent-high-privilege January 12, 2026 18:30 — with GitHub Actions Inactive
…s time)

The validator detected 13 source files without template counterparts.
These are needed by consumer repos (e.g., keepalive_instruction_template.js
requires keepalive_prompt_routing.js).

Created template copies:
- conflict_detector.js
- keepalive_prompt_routing.js
- keepalive_state.js
- keepalive_loop.js
- gate-docs-only.js
- detect-changes.js
- coverage-normalize.js
- failure_comment_formatter.js
- prompt_injection_guard.js
- checkout_source.js
- github-api-with-retry.js
- maint-post-ci.js
- error_classifier.js

Previous attempt synced in wrong directory and didn't actually commit the files.
Addresses Copilot feedback: keepalive_instruction_template.js now has required dependencies.
@stranske stranske temporarily deployed to agent-high-privilege January 12, 2026 18:33 — with GitHub Actions Inactive
The previous commit updated tests and docs but forgot to rename the actual
workflow file. This fixes all remaining references:
- Renamed .github/workflows/validate-template-sync.yml
- Updated docs/SYNC_WORKFLOW.md
- Updated docs/keepalive/SETUP_CHECKLIST.md

Fixes test failures:
- test_workflow_slugs_follow_wfv1_prefixes
- test_inventory_docs_list_all_workflows
- test_workflow_names_match_filename_convention
- test_canonical_workflow_names_match_expected_mapping
@stranske stranske temporarily deployed to agent-high-privilege January 12, 2026 18:34 — with GitHub Actions Inactive
Changed 'Health 71 Template Sync' to 'Health 72 Template Sync' to match
the filename health-72-template-sync.yml.

Fixes test failures:
- test_canonical_workflow_names_match_expected_mapping
- test_workflow_names_match_filename_convention
@stranske stranske temporarily deployed to agent-high-privilege January 12, 2026 18:37 — with GitHub Actions Inactive
Tests were failing because they ran the script from tmp_path without
copying it there. Fixed by copying the script to tmp_path/scripts/
before running tests.

All tests now pass locally.
@stranske stranske temporarily deployed to agent-high-privilege January 12, 2026 18:43 — with GitHub Actions Inactive
When template directory doesn't exist, validator prints 'Template directory not found'
instead of listing individual files. Updated test to accept either message.
@stranske stranske temporarily deployed to agent-high-privilege January 12, 2026 18:48 — with GitHub Actions Inactive
CodeQL failed due to API rate limits (transient error).
Retriggering all checks.
@stranske stranske temporarily deployed to agent-high-privilege January 12, 2026 18:52 — with GitHub Actions Inactive
@stranske stranske merged commit 0cc2d38 into main Jan 12, 2026
136 checks passed
@stranske stranske deleted the fix/template-sync-guard branch January 12, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autofix Opt-in automated formatting & lint remediation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants