# openspec/changes/wf-agent-broke-production/proposal.md

## Why

A production error lands and nobody can say which agent session wrote the change behind it. The fix ships, and two weeks later nobody checks whether it held. When an agent's change breaks production, the team needs the session that wrote it and a record that the fix still holds two weeks on.

## What Changes

- Add the `agent-broke-production` workflow to the PromptReports workflow library, run by the workflow runner as an agent acting for a person.
- RepoOps: Read the production error and its source (get_prod_incidents) (today: Built).
- RepoOps: Trace the error to the change and the agent session (get_incident_attribution) (today: Built).
- RepoOps: Read the handoff a person sent to the causing session, when the start names a case (get_agent_handoff) (today: Built).
- RepoOps: Send the handoff to the causing session once a person approves, when the start names a case and none was sent (send_agent_handoff) (today: Built).
- ContextFile: Read the context version the session read (context_versions) (today: Built).
- RepoOps: Build the fix a person approves, as a pull request with auto-merge off (build_fix) (today: Built).
- RepoOps: Measure recovery 24 hours after the fix (get_incident_recovery) (today: Built).
- RepoOps: Check that recovery held 14 days after the fix (get_incident_recovery) (today: Built).
- RepoOps: Propose a lesson to the RepoOps brain (propose_brain_entry) (today: Built).
- RepoOps: Promote the lesson a person approves (promote_lesson) (today: Built).
- Gate `repoops.build_fix`, `repoops.agent_handoff.send`, `repoops.lesson.promote` through PromptCompute approvals; each gated step runs only after `verifyResume` passes, with `final_args`.
- Write a signed record at the end of each run and count one workflow request.

## Impact

- Products: RepoOps, ContextFile, PromptCompute.
- Outside the family: GitHub.
- State: Partly built. The workflow is the code loop at version 0.4.0, merged in promptcompute.ai #836 (0.3.0 in #816); the production run is still to do. When the start names a case and no handoff was sent, the run sends it to the causing session once a person approves; a person can still send it from the RepoOps case page instead. RepoOps's own reliability record in AI Source of Truth seals the fix-held rate each week, not this run. The fix pull request opens with auto-merge off and never merges from the run.
- Plan row: none yet (Proposed).

# openspec/changes/wf-agent-broke-production/tasks.md

## 1. Connect and authorize

- [ ] 1.1 Confirm the org has a connection for each of: RepoOps, ContextFile, PromptCompute. Stop and tell the user which is missing.
- [ ] 1.2 Get a PromptReports ID agent token for each product the run calls (RFC 8693 exchange). Where a product does not accept ID tokens yet, use its connect key.
- [ ] 1.3 Register policy for `repoops.build_fix`, `repoops.agent_handoff.send`, `repoops.lesson.promote` with `require_approval` as the default.

## 2. Build the steps

- [ ] 2.1 RepoOps: Read the production error and its source (get_prod_incidents).
- [ ] 2.2 RepoOps: Trace the error to the change and the agent session (get_incident_attribution).
- [ ] 2.3 RepoOps: Read the handoff a person sent to the causing session, when the start names a case (get_agent_handoff).
- [ ] 2.4 RepoOps: Send the handoff to the causing session once a person approves, when the start names a case and none was sent (send_agent_handoff).
- [ ] 2.5 ContextFile: Read the context version the session read (context_versions).
- [ ] 2.6 RepoOps: Build the fix a person approves, as a pull request with auto-merge off (build_fix).
- [ ] 2.7 RepoOps: Measure recovery 24 hours after the fix (get_incident_recovery).
- [ ] 2.8 RepoOps: Check that recovery held 14 days after the fix (get_incident_recovery).
- [ ] 2.9 RepoOps: Propose a lesson to the RepoOps brain (propose_brain_entry).
- [ ] 2.10 RepoOps: Promote the lesson a person approves (promote_lesson).

## 3. Verify and record

- [ ] 3.1 Run a dry run with the user's inputs: Production error = evt_9f2; Incident = inc-0a1b2c3d; Repository = repo-dashboard; Base branch = main; Case = case_7f3a (optional).
- [ ] 3.2 Run it once for real; approve each gate as the user.
- [ ] 3.3 Measure the outcomes: Errors traced to a change and an agent session; Hours from the error to an approved fix; Fixes still recovered 14 days later.
- [ ] 3.4 Confirm the run left a signed record with a task id and one workflow request counted.

# openspec/changes/wf-agent-broke-production/specs/workflow-agent-broke-production/spec.md

## ADDED Requirements

### Requirement: A person approves the handoff

The workflow SHALL send the handoff to the causing session only when the start names a case and no handoff was sent, and only after a person approves it.

#### Scenario: A person approves the handoff (1)

- **WHEN** the start names a case and no handoff was sent
- **THEN** the run asks a person, sends the handoff once approved, and goes on to the fix if the person declines

#### Scenario: A person approves the handoff (2)

- **WHEN** a handoff was already sent from the case page
- **THEN** the run sends nothing and asks for no approval for it

### Requirement: The fix never merges from the run

The fix SHALL open as a pull request with auto-merge off, and merging SHALL stay a separate code.pr.merge request.

#### Scenario: The fix never merges from the run

- **WHEN** a person approves the fix
- **THEN** RepoOps opens the pull request and nothing merges

### Requirement: The run does not seal the fix-held rate

The workflow SHALL report recovery at 24 hours and at 14 days, and SHALL leave the weekly fix-held rate to RepoOps's reliability record in AI Source of Truth.

#### Scenario: The run does not seal the fix-held rate

- **WHEN** recovery held for 14 days
- **THEN** the run reports its own outcome, and the weekly rate comes from RepoOps's record

### Requirement: Evidence stays honest

Each step SHALL report what it saw as measured, inferred or missing, and SHALL never report missing as measured.

#### Scenario: A product part is not built

- **WHEN** a step depends on a part that is Planned or Proposed
- **THEN** the step records `missing`, names the part, and the approval card shows the gap

### Requirement: One run is one workflow request

The runner SHALL count one workflow request at the run's first connector action, and SHALL NOT count retries, resumes, dry runs or a run a filter stops first.

#### Scenario: A gated step resumes after two days

- **WHEN** a person approves a step and the run resumes
- **THEN** the org's usage does not change
