Skip to content

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

Draft
badMade wants to merge 1 commit into
mainfrom
self-heal-automation-11639397237310114463
Draft

[Self-Heal] Add self-scheduling auto-repair workflow#44
badMade wants to merge 1 commit into
mainfrom
self-heal-automation-11639397237310114463

Conversation

@badMade

@badMade badMade commented May 22, 2026

Copy link
Copy Markdown
Owner

Self-Healing CI Pipeline

This PR introduces an automated self-healing CI pipeline that detects code drift, formatting issues, and test failures, and automatically proposes fixes via Pull Requests.

Triggers

  1. Scheduled: Proactively runs based on a self-computed schedule (to catch drift).
  2. CI Failure: Reactively runs when the main ci workflow fails.
  3. Manual Dispatch: Can be manually triggered via the GitHub Actions tab.

Features

  • Self-Scheduling: Dynamically computes its own optimal run frequency based on repository telemetry (commit frequency, pull request velocity).
  • Idempotent Repair: Executes a 6-step repair sequence (install deps -> lint/format -> snapshot updates -> type stubs -> deps resolve -> asset regen).
  • Fail-Fast & Health Checked: Runs a health check after each step. Exits early if it produces a healthy diff.
  • Safety Measures: Includes branch loop prevention, basic entropy checking to avoid committing secrets, stale PR cleanup, duplicate PR detection, timeout limits, and an oscillation guard to prevent schedule thrashing.
  • Dependencies: Adds js-yaml, prettier, and eslint to devDependencies to power the scripts reliably out-of-the-box.

Please review the proposed architecture and SELF_HEAL_SETUP.md for complete details.


PR created automatically by Jules for task 11639397237310114463 started by @badMade

This adds a comprehensive, self-adapting repair automation system for CI failures and code drift. The system includes:

- `scripts/healthcheck.mjs`: Centralized health validation (build, types, lint, test).
- `scripts/self_heal.mjs`: Idempotent 6-step repair pipeline.
- `scripts/compute_schedule.mjs`: Telemetry-based cadence generator to intelligently adjust execution times.
- GitHub Actions workflows (`self-heal.yml` and `compute-schedule.yml`) with reactive, scheduled, and dispatch triggers. Includes duplicate PR prevention and timeout limits.
- `SELF_HEAL_SETUP.md`: Documentation for maintaining and overriding the automation.

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 documentation, scheduling logic, and healthcheck scripts. The implementation adds several dependencies like eslint, prettier, and js-yaml to manage code quality and configuration. Feedback focuses on improving the robustness and correctness of the scripts: specifically, limiting the git log buffer to prevent crashes on large repositories, expanding ESLint configuration detection to include modern file formats, correcting the non-standard --latest flag in the npm update command, and recommending that typesync be added to devDependencies rather than relying on transient npx execution.

// Very basic active period detection (mock for hour of least commits)
function getQuietHour() {
try {
const dates = execSync("git log --format=%aI")

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

Executing git log without a time or count limit on a large repository can produce an output that exceeds the default 1MB buffer of execSync, causing the script to crash with ENOBUFS. Since this is used for computing a quiet hour, limiting the analysis to the last 30 days is sufficient and much safer.

Suggested change
const dates = execSync("git log --format=%aI")
const dates = execSync("git log --since='30 days ago' --format=%aI")

Comment thread scripts/healthcheck.mjs
Comment on lines +37 to +39
const hasEslintConfig = existsSync(path.join(process.cwd(), 'eslint.config.js')) ||
existsSync(path.join(process.cwd(), '.eslintrc.json')) ||
existsSync(path.join(process.cwd(), '.eslintrc.js'));

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 ESLint configuration detection logic is incomplete. It misses several valid formats such as .eslintrc.yml, .eslintrc.yaml, and the newer eslint.config.mjs or eslint.config.cjs files. This could lead to the healthcheck incorrectly skipping linting steps.

Suggested change
const hasEslintConfig = existsSync(path.join(process.cwd(), 'eslint.config.js')) ||
existsSync(path.join(process.cwd(), '.eslintrc.json')) ||
existsSync(path.join(process.cwd(), '.eslintrc.js'));
const hasEslintConfig = [
'eslint.config.js', 'eslint.config.mjs', 'eslint.config.cjs',
'.eslintrc.json', '.eslintrc.js', '.eslintrc.yml', '.eslintrc.yaml'
].some(file => existsSync(path.join(process.cwd(), file)));

Comment thread scripts/self_heal.mjs

// 4. Type stubs (Mock/skip as 'typesync' isn't explicitly configured)
console.log('\n--- Step 4: Type stubs ---');
runCmd('npx typesync || true');

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 typesync package is invoked here but is not listed in the project's devDependencies. Relying on npx to download it during every CI run is inefficient and prone to failure if the registry is unreachable. It should be added to package.json.

Comment thread scripts/self_heal.mjs

// 5. Dependency re-resolve
console.log('\n--- Step 5: Dependency re-resolve ---');
runCmd('npm update --latest');

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 --latest flag is not a standard option for the npm update command. To update dependencies within their defined semver ranges, use npm update without this flag.

Suggested change
runCmd('npm update --latest');
runCmd('npm update');

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