For the complete documentation index, see llms.txt. This page is also available as Markdown.

Fix a repository

Turn a triage evidence bundle into a verified code fix — generate a decision plan, simulate its risk gate, and apply it as a patch, a local branch, or a pull request.

Triage tells you where a problem lives. This guide takes the next step: it turns a triage evidence bundle into a concrete, risk-checked code change and lands it. The engine generates a candidate patch (a decision plan), runs a deterministic simulation that scores the patch against your calibrated apply gate, and only then lets you apply it — as a raw patch, a local branch, or a remote pull request.

The fix pipeline is a strict chain. Each stage consumes the previous stage's id:

snapshot → triage → decision plan → simulate → apply

You already produced the snapshot and triage stages in Triage a repository. This guide starts from the evidence bundle they returned. All routes live under /v1/repositories and require Authorization: Bearer $ALGENTA_API_KEY.

apply performs an external write (it can push a branch or open a PR), so it is deliberately not part of the read-only agent-callback set. It rejects service keys and requires an interactive key with write_permission: true for any mode that writes.

Before you start

You need three things from the triage flow:

  • $REPOSITORY_ID — the connector id for the repository (see Connect data).

  • $SNAPSHOT_ID — an immutable snapshot of the ref you are fixing.

  • $BUNDLE_REF — the workspace_evidence_bundle_ref returned by triage. It anchors the fix to a bounded slice of the repository.

Export the first two so the commands below run unchanged:

export ALGENTA_API_KEY="de_live_..."
export REPOSITORY_ID="$REPOSITORY_ID"
export SNAPSHOT_ID="$SNAPSHOT_ID"
export BUNDLE_REF="$BUNDLE_REF"

Generate and verify a fix

1

Generate the fix (decision plan)

A decision plan is one immutable, stored fix revision. The engine reads the evidence bundle, drafts a change with the planner, validates the unified diff against the snapshot, and stores it. The response hands you both the decision_plan_id and the validated patch_diff inline.

POST /v1/repositories/{repository_id}/decision-plans

The 200 RepositoryDecisionPlanResponse carries decision_plan_id, the decision_plan object, the validated patch_diff, and planner_usage. Save the id as $DECISION_PLAN_ID. Optional fields: pass model to pin the planner model, or add ?async_execution=true to run the planner off the request path and get a 202 poll handle (see Run asynchronous jobs).

2

Simulate the risk gate

Simulation is deterministic and runs on the Mojo engine — no LLM. It measures the patch's blast radius against the snapshot's dependency graph, runs the scenario set, and scores the result against your org's calibrated apply gate. The verdict lands in recommended_action (apply_patch or hold_patch).

POST /v1/repositories/{repository_id}/simulate

The 200 response is a DecisionEnvelope. The two fields that gate apply:

The simulation_id you pass to apply lives at validated_inputs.simulation_id — grab it now and export it as $SIMULATION_ID. runs defaults to a complexity-adaptive scenario count; pass an explicit integer (100–250000) to pin it, and keep seed fixed for a reproducible gate.

3

Apply the fix

apply re-loads the stored decision plan and simulation, confirms they pin the same snapshot, and then acts according to mode. The three modes trade off how much the engine touches your repository.

POST /v1/repositories/{repository_id}/apply

Returns the unified diff and never writes. No write_permission and no passing gate required — use it to inspect or apply the change yourself.

Checks the code out, applies the patch, and commits it to a new branch. Requires write_permission: true and a passing apply gate.

Pushes the branch to the connector's remote and opens a pull request. Requires write_permission: true, a passing apply gate, and a connector that supports remote PRs.

The same call in code, opening a pull request:

Verify an in-flight patch

If you already hold a working-tree patch — for example, an edit made mid-run by an agent — you can score it directly without creating a stored decision plan. simulate-patch runs the same calibrated risk gate against the snapshot and returns the apply_patch / hold_patch verdict. It is verify-only: it does not produce a simulation_id that apply can consume.

POST /v1/repositories/{repository_id}/simulate-patch

Run the whole fix in one call

The pipeline endpoint runs snapshot → triage → plan → simulate in a single request, reusing cross-stage artifacts. Supply signals the same way you would for triage, and use stop_after to halt early — triage (before the planner) or plan (before simulation).

POST /v1/repositories/{repository_id}/pipeline

The 200 RepositoryPipelineResponse nests each stage (snapshot, triage, decision_plan, simulation) plus stage_timings and completed_stage. Read decision_plan.decision_plan_id and simulation.validated_inputs.simulation_id from it and pass them straight to apply. For a heavy pipeline, add ?async_execution=true to get a 202 poll handle instead of an inline result.

Automate fixes with the GitHub App

Install the Algenta GitHub App to have the engine open fix pull requests on its own, driven by events in your repository.

1

Start the install

Open the install endpoint in a browser while signed in with an owner or admin key. It redirects you to GitHub to choose which repositories the app can access. Only an org owner or admin can connect GitHub.

GET /github/app/install/start

2

Approve on GitHub

Pick the repositories and approve. GitHub returns you to the app's callback (/github/app/install/callback), which verifies that you administer the installation before binding it to your org.

3

Confirm the connection

You land on a short success page confirming the installation is connected. There is nothing else to configure.

Once installed, GitHub delivers events to the app's inbound receiver, POST /webhooks/github. The receiver verifies GitHub's HMAC signature, dedupes the delivery, and returns 202 within seconds; the multi-step fix runs asynchronously in the background. Three events start a fix:

  • A failing CI check — a completed check_suite whose conclusion is failure, timed_out, startup_failure, or action_required.

  • A submitted pull-request review — a review left on an open PR.

Next steps

Last updated

Was this helpful?