Skip to content

[Self-Heal] Add self-scheduling auto-repair workflow#41

Draft
badMade wants to merge 1 commit into
mainfrom
selfheal-automation-2382036800408694494
Draft

[Self-Heal] Add self-scheduling auto-repair workflow#41
badMade wants to merge 1 commit into
mainfrom
selfheal-automation-2382036800408694494

Conversation

@badMade

@badMade badMade commented May 19, 2026

Copy link
Copy Markdown
Owner

This pull request introduces a self-adapting, self-healing CI pipeline configured for this repository.

Features Included:

  • Core idempotent repair steps executed locally resolving formatting errors, updating tests, types, and dependencies automatically.
  • Healthcheck integration acting as a gate for CI actions before and after repairs.
  • Adaptive cron schedule derived from telemetry metric (commits over 7-days window) calculating optimal run frequency to conserve action runner time while staying effective.
  • Automated PR creation that respects guard rails (secrets scanning, recursive loops, un-staged CI logic modifications).
  • Detailed documentation inside SELF_HEAL_SETUP.md explaining 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

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>
@google-labs-jules

Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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.

Comment thread scripts/self_heal.mjs
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' });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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.

Suggested change
execSync('npx prettier -w "src/**/*.{ts,js,json}" "scripts/**/*.{mjs,js,ts}" "package.json"', { stdio: 'inherit' });
execSync('npx prettier -w .', { stdio: 'inherit' });

Comment thread scripts/self_heal.mjs
Comment on lines +108 to +113
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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.

Suggested change
function updateYaml(filePath, newSchedule, keyPath, scheduleFile = false) {
function updateYaml(filePath, newSchedule, scheduleFile = false) {

Comment on lines +97 to +98
const scheduleChanged = updateYaml(configPath, newSchedule, '', true);
const workflowChanged = updateYaml(workflowPath, newSchedule, '', false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Update the calls to updateYaml to match the simplified signature by removing the unused keyPath argument.

Suggested change
const scheduleChanged = updateYaml(configPath, newSchedule, '', true);
const workflowChanged = updateYaml(workflowPath, newSchedule, '', false);
const scheduleChanged = updateYaml(configPath, newSchedule, true);
const workflowChanged = updateYaml(workflowPath, newSchedule, false);

Comment thread SELF_HEAL_SETUP.md
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.*

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant