GitHub recovery connector

The GitHub recovery connector lets App Care prepare a reviewable pull request or immutable change set and—under the policy you choose—run a separately approved execute phase. Heystack remains outside your application request path.

Source repairs have two preparation paths. The repository-owned bridge runs your prepare.sh and apply-repair.sh. Managed source preparation uses Workers AI to propose whole-file replacements for an explicit allowlist of up to 10 source files and opens a draft pull request. Both paths use the repository's tests and deployment contract. A missing script, failed check, changed branch head, changed pull-request head, changed connector, or malformed result stops the run. Heystack never turns a passing GitHub check into a claim that the incident recovered; App Care re-runs the configured user journeys after deployment.

Before connecting

Add the workflow and runner contract from apps/recovery/examples to your repository:

.github/workflows/heystack-recovery.yml
.heystack/recovery/runner.mjs
.heystack/recovery/prepare.sh
.heystack/recovery/execute.sh
.heystack/recovery/apply-repair.sh
.heystack/recovery/test.sh
.heystack/recovery/deploy.sh

The Heystack repository includes reviewed templates for the workflow, runner, prepare.sh, and execute.sh; copy the two .example.sh files without the .example suffix. The last three are deployment-specific and must be implemented by the repository owner:

  • apply-repair.sh <request-file> makes the narrowly scoped source change. It must fail when it cannot produce a real change. Heystack does not run a model in the workflow as a fallback.
  • test.sh runs the checks that make the prepared change safe to review. A non-zero exit stops preparation before a result artifact is accepted.
  • deploy.sh <execution-target> <release-id-output-file> deploys the exact merged commit, or an immutable target formatted as change-set:<id>, and writes the platform's release ID to the requested file. It must not print or write production secrets.

Commit all five shell scripts with their executable bit set. Managed source preparation does not call prepare.sh or apply-repair.sh, but it still requires test.sh; the approved execute phase continues to use execute.sh and deploy.sh.

Keep these scripts under branch protection and CODEOWNERS review. The workflow template serializes recovery runs per repository. The repository-owned prepare job can write Actions artifacts, contents, and pull requests. Managed tests run in a separate job with contents: read, no persisted checkout credentials, and a scrubbed test-process environment. A fresh job checks out the fenced base revision with contents: read and writes only the result artifact. The execute job retains the write permissions needed by the repository-owned merge and deployment scripts.

Connect from Settings › App › Code repository. The repository is set once, in the Repository field, and the Recovery connection form below it asks only for the workflow, base branch and token and shows "Uses owner/name". If the app's repository later changes, the page says recovery is still connected to the old one until you reconnect with a token for the new one. A repository on another host cannot be connected.

Token and repository settings

In the app's Care → GitHub connector settings, enter:

  • Repository as owner/repository. Each app has one repository setting. In Settings › App › Code repository it is a single field and the connection form has no repository input. In the classic Care form, leave this blank to use the app's GitHub repository URL, or enter one to make it the app's repository too. Connecting overwrites a commit-link URL on another host (for example GitLab), and later edits to the app's URL never retarget the connector; Settings shows a mismatch until you reconnect it with a fresh token.
  • Workflow filename, such as heystack-recovery.yml.
  • The protected base branch, such as main.
  • A fine-grained personal access token or GitHub App installation token scoped to this repository.

Classic personal access tokens (ghp_…) and OAuth tokens are rejected because their scopes apply to every repository and often include organization or deletion rights. The token needs repository contents read/write, Actions read/write, and pull-request read/write access. Heystack validates the token identity, repository access, active workflow, write permission, and base branch before encrypting the token. Tokens are encrypted with AES-256-GCM and are never returned by the API or written to logs.

The same GitHub token is also used, read-only, for a daily check of the repository's security alerts (Dependabot, code scanning and secret scanning; secret values are never fetched). The token needs read access to those alerts for them to be listed; a source it cannot read shows as unknown, never as zero. An admin can press Scan now in Settings › App › Code repository to check immediately (scans are rate limited). Findings are visible to admins only, in Issues.

The Heystack GitHub App

The Heystack GitHub App is separate from the recovery connector. It does not run recovery workflows and needs no token from you. It is being rolled out: until it is switched on for your workspace, Settings › App › Code repository shows it as "Not configured", and the connector above keeps working as before.

An admin installs it from Settings › App › Code repository › Install the GitHub App, choosing the repositories it may see. GitHub asks you to authorise Heystack once during the install; Heystack uses that only to confirm your GitHub account owns the account the App is installed on (your own account, or an organisation you are an owner of) and to list the repositories you can reach through it, then discards it. If the app has no repository yet and you picked exactly one, the app is linked to it. An existing repository link is never changed.

Once it is installed on the app's repository:

  • Deploys show up on issues. A successful GitHub deployment is recorded as a release, with the commit's author and the merged pull request. The issue's likely cause then says who shipped the suspect release and links its pull request.
  • Merged pull requests are linked as fixes. Write Fixes HS-<issue key> (or Closes, Resolves) in the pull request description, paste the Heystack issue link, or name the branch hs/<source>/<app>/<id>. When the pull request merges, Heystack links it as the issue's fix, and shows which release contains it. Heystack does not measure the issue's earlier rate for these links, so once the release is out it reports what it sees as an observation, never as a confirmed fix. A plain mention without a closing word is not a fix. Only issues of apps linked to that repository are touched.
  • File GitHub issues from Heystack. Create a GitHub issue on an issue's Fix section files it in the repository: what happened, the likely cause, links to the evidence and a link back. No names or emails of your users are included. The same issue is filed once; asking again returns the existing link. Without the App installed, the button opens a prefilled draft for you to submit instead.

What Heystack keeps: the installation's account name and repository names, and for each commit its SHA, author login and name, the first line of its message and its time (never an email address), for 90 days. Heystack never stores a GitHub token: each action uses a short-lived token limited to the one repository and the one permission it needs. The App asks for read access to metadata, contents, pull requests and deployments, and read and write access to issues only. It never comments on pull requests, sets checks or writes code.

To remove it, uninstall the App on GitHub (Heystack stops using it straight away) or press Forget next to the installation.

Managed source preparation

Only an Admin can start managed source preparation. Choose the source_patch_deploy action and provide allowed_source_files with 1–10 repository-relative source paths. Heystack reads those files at the exact fenced commit, with per-file and total-size bounds, then asks Workers AI for complete replacements only within that allowlist. It rejects workflow and Heystack control files, authentication and authorization code, credentials, data and schema changes, deployment and infrastructure files, lockfiles, new dependencies, new network calls, and likely embedded secrets. A request that cannot be handled within those limits fails closed.

Heystack creates the managed branch from the fenced commit and opens a draft pull request. It dispatches the workflow definition from the fenced base branch, not from AI-modified code. The managed pull-request head runs test.sh in a low-permission job. A separate fresh job checks out the fenced base revision and uses its trusted runner.mjs to assemble the result artifact. The recovery service accepts that artifact only when the GitHub run itself used the expected fenced workflow commit.

The added-code check is advisory (review.safety_scan: "advisory"): pattern checks cannot prove that model-written code is safe. The repair plan's artifact.review therefore carries the complete unified diff of every proposed file, and Heystack will not approve a managed repair until that diff is on the plan. Read it before approving.

Managed preparation proposes source edits; it does not approve, merge, deploy, or establish recovery. An administrator must still review the draft and approve supervised execution. The execute phase verifies the saved artifact digest and immutable pull-request head before invoking the repository-owned deployment contract.

Prepare contract

Heystack dispatches the configured workflow with one heystack_request JSON input. The prepare job must upload exactly one artifact named heystack-repair-result containing result.json. A successful pull-request result has this shape:

{
  "version": 1,
  "request_id": "care_run_123",
  "phase": "prepare",
  "status": "prepared",
  "artifact": {
    "kind": "pull_request",
    "url": "https://github.com/acme/api/pull/42",
    "source_commit": "40-character base-branch commit",
    "preview_release_id": null
  },
  "execution_target": {
    "kind": "pull_request",
    "head_commit": "40-character immutable pull-request head"
  },
  "release_fence": {
    "expected_release_id": "release observed by Heystack",
    "expected_repo_commit": "40-character base-branch commit"
  },
  "checks": [
    { "name": "repository test suite", "status": "passed", "evidence": "the repository-owned test script exited successfully" }
  ]
}

All checks must be passed. The public artifact.source_commit identifies the fenced base revision; execution_target.head_commit pins the exact proposed revision. Change-set integrations use { "kind": "change_set", "immutable_id": "..." } instead.

Execute contract

Before dispatching execute, Heystack checks that the base branch still points at the fenced commit and that the connector has not changed. The execute request includes the prepare workflow run ID and SHA-256 digest of its result.json. The template downloads that specific artifact, verifies the digest, reads the immutable execution target, and confirms that a pull request still has the same head commit.

The execute job uploads its own heystack-repair-result/result.json:

{
  "version": 1,
  "request_id": "care_run_123",
  "phase": "execute",
  "status": "succeeded",
  "deployed_release_id": "platform-release-456",
  "checks": [
    { "name": "deployment command", "status": "passed", "evidence": "the repository-owned deploy script returned a release ID" }
  ],
  "evidence": ["merged_commit:...", "deployment_release:platform-release-456"]
}

The workflow's success is execution evidence only. App Care continues observing journeys and telemetry before it closes or rolls forward an incident.

Failure and retry behavior

Requests are idempotent. Heystack stores a durable job before dispatch and allows one active recovery per app. If GitHub rejects a dispatch, the job fails with the API error. If the network fails after dispatch may have reached GitHub, Heystack records github_dispatch_outcome_unknown_manual_review_required, returns a nonterminal 409, and retains the app's executor lock. The same request and every new repair for that app remain blocked; Heystack never blindly dispatches again. A Worker crash can leave the row at dispatching; the same explicit reconciliation action becomes available after that row has remained unchanged for five minutes.

Reconciling an uncertain dispatch

The workflow template gives every run the exact name Heystack <phase> <request_id>. An Admin must:

  1. Open the blocked repair and note its repository, workflow, phase, request ID, and dispatch time.
  2. In that repository's GitHub Actions history, filter to the configured workflow and locate the exact run name. Confirm the phase and request ID and ensure its creation time follows the stored dispatch time. Do not choose a run based only on proximity or branch name.
  3. If the exact run exists, choose Attach GitHub run, enter its numeric run ID, review the resolved run URL, and confirm. The server independently verifies the configured repository and workflow ID, workflow_dispatch event, exact run title, fenced head commit, and a narrow creation-time window before it attaches the run. Normal status polling then resumes.
  4. If GitHub conclusively has no exact matching run after its Actions history has settled, choose Confirm no dispatch and confirm. The server marks the original idempotency row github_dispatch_confirmed_absent and releases the lock. That request remains terminal and cannot dispatch again; create a new plan or action run if another attempt is appropriate.

Both decisions go through the admin-gated recovery API and the private executor binding; direct D1 edits are not part of the runbook. The state change is atomic: if two operators make conflicting decisions, one succeeds and the other must reload the final state. Keep the tenant, app, job ID, prior state, GitHub query, and chosen run URL in the operator record. Never choose Confirm no dispatch merely to unblock another repair without first proving that no exact GitHub run exists.