[Self-Heal] Add self-scheduling auto-repair workflow#41
Conversation
Adds GitHub Actions and supporting Node.js scripts to automate repository self-healing. Implements: 1. `scripts/healthcheck.mjs` for pipeline validation. 2. `scripts/self_heal.mjs` for 6 idempotent repair steps. 3. `scripts/compute_schedule.mjs` to adapt schedule dynamically. 4. `.github/workflows/self-heal.yml` triggered manually, on schedule, and after CI failure. 5. `.github/workflows/compute-schedule.yml` for periodic cadence updates. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request introduces an automated self-healing CI pipeline, including scripts for health checks, a multi-step repair process, and a telemetry-driven scheduler that adjusts execution frequency based on commit activity. Feedback focuses on improving the robustness of the telemetry logic regarding shallow clones, resolving path inconsistencies between the health check and repair steps, and removing redundant code and unused parameters. There is also a suggestion to clarify documentation where the implementation of YAML updates differs from the described behavior.
| const since = new Date(); | ||
| since.setDate(since.getDate() - days); | ||
| const dateStr = since.toISOString().split('T')[0]; | ||
| const result = execSync(`git rev-list --count HEAD --since="${dateStr}"`, { encoding: 'utf-8' }).trim(); |
There was a problem hiding this comment.
The git rev-list command will only return accurate commit counts if the repository is not a shallow clone. In many CI environments (like GitHub Actions), the default checkout depth is 1. To ensure the adaptive schedule works correctly, the workflow calling this script must be configured with fetch-depth: 0 or a sufficient depth to cover the 7-day window. Consider adding a check or a warning if the history is too shallow.
| console.log('\n--- Step 2: Format Code ---'); | ||
| try { | ||
| // Explicitly avoid formatting restricted files (e.g., .github/workflows/ci.yml) | ||
| execSync('npx prettier -w "src/**/*.{ts,js,json}" "scripts/**/*.{mjs,js,ts}" "package.json"', { stdio: 'inherit' }); |
There was a problem hiding this comment.
There is an inconsistency between the healthcheck and the repair step. healthcheck.mjs runs Prettier on the entire project (.), while this repair step only targets specific paths. Notably, it misses the bin/ directory and root files like index.js, and includes a src/ directory which does not appear to exist in this project. It is better to use . and rely on a .prettierignore file to exclude restricted files.
| execSync('npx prettier -w "src/**/*.{ts,js,json}" "scripts/**/*.{mjs,js,ts}" "package.json"', { stdio: 'inherit' }); | |
| execSync('npx prettier -w .', { stdio: 'inherit' }); |
| if (runHealthcheck() && hasDiff()) { | ||
| console.log('Successfully repaired and produced a diff. Exiting 0.'); | ||
| process.exit(0); | ||
| } | ||
| console.log('Failed to repair, or no changes needed. Exiting 1.'); | ||
| process.exit(1); |
There was a problem hiding this comment.
This final check is redundant. The exitIfHealthyAndDiff() function is already called after the last repair step at line 105. If the codebase were healthy and a diff existed, the script would have already exited with code 0. Reaching this point always implies that the repair was unsuccessful or no changes were made.
console.log('Failed to repair, or no changes needed. Exiting 1.');
process.exit(1);| return { expr: '0 0 * * 1', rationale: 'dormant (0 commits/wk)' }; | ||
| } | ||
|
|
||
| function updateYaml(filePath, newSchedule, keyPath, scheduleFile = false) { |
There was a problem hiding this comment.
The keyPath parameter is defined in the updateYaml function signature but is never used within the function body. It should be removed to simplify the function's interface.
| function updateYaml(filePath, newSchedule, keyPath, scheduleFile = false) { | |
| function updateYaml(filePath, newSchedule, scheduleFile = false) { |
| const scheduleChanged = updateYaml(configPath, newSchedule, '', true); | ||
| const workflowChanged = updateYaml(workflowPath, newSchedule, '', false); |
There was a problem hiding this comment.
Update the calls to updateYaml to match the simplified signature by removing the unused keyPath argument.
| const scheduleChanged = updateYaml(configPath, newSchedule, '', true); | |
| const workflowChanged = updateYaml(workflowPath, newSchedule, '', false); | |
| const scheduleChanged = updateYaml(configPath, newSchedule, true); | |
| const workflowChanged = updateYaml(workflowPath, newSchedule, false); |
| 2. Modify the `schedule` variable to your desired Cron expression. | ||
| 3. Update `.github/workflows/self-heal.yml` to match if the auto-update scripts were bypassing. | ||
|
|
||
| *Note: Ensure yaml is perfectly valid when modifying the metadata file, and avoid using raw `sed` across the files as the schedule mutator explicitly checks for a parseable round-trip state before replacing the `# AUTO-UPDATED` marker.* |
There was a problem hiding this comment.
The documentation states that the mutator checks for a 'parseable round-trip state' before replacing the marker. While this is true for the metadata YAML file, the implementation in scripts/compute_schedule.mjs (lines 66-78) uses a simple line-by-line string replacement for the GitHub Actions workflow file. This is more brittle than a round-trip parse and should be clarified in the documentation to avoid misleading future maintainers.
This pull request introduces a self-adapting, self-healing CI pipeline configured for this repository.
Features Included:
SELF_HEAL_SETUP.mdexplaining the configurations, rationale, triggers, and architecture of the newly added automation pipeline.Ref: Memory constraints and project standards respected via pre-commit step reviews and feedback.
PR created automatically by Jules for task 2382036800408694494 started by @badMade