## insert_bug_into_queue
# queue header
# [DONE] docs/a.md#t-done
# enqueue-bug: BUG-1 (P0) filed by QA — fix ahead of pending feature work
harness/stories/S/bugs/BUG-1.md#bug-1
# enqueue-bug: BUG-2 (P1) filed by QA — fix ahead of pending feature work
harness/stories/S/bugs/BUG-2.md#bug-2
docs/a.md#t-a-1
docs/a.md#t-a-2
# enqueue-bug: BUG-3 (P2) filed by QA — appended at end of active queue
harness/stories/S/bugs/BUG-3.md#bug-3
# enqueue-bug: BUG-4 (P3) filed by QA — appended at end of active queue
harness/stories/S/bugs/BUG-4.md#bug-4
# trailing comment
-- no active lines:
# only
# comments
# enqueue-bug: BUG-5 (P0) filed by QA — fix ahead of pending feature work
harness/stories/S/bugs/BUG-5.md#bug-5
# enqueue-bug: BUG-6 (P2) filed by QA — appended at end of active queue
harness/stories/S/bugs/BUG-6.md#bug-6
-- empty queue file:
# enqueue-bug: BUG-7 (P1) filed by QA — fix ahead of pending feature work
harness/stories/S/bugs/BUG-7.md#bug-7
## handle_enqueue_bug
--- ok
LOG   Inbox: enqueued BUG-9 (P1) fix → harness/stories/S/bugs/BUG-9.md#bug-9
CALL check_bug_spec_sections harness/stories/S/bugs/BUG-9.md BUG-9 enqueue
METRIC {"event":"bug_enqueued","bug_id":"BUG-9","severity":"P1","spec_ref":"harness/stories/S/bugs/BUG-9.md#bug-9","at":"2026-10-17T00:00:00+00:00"}
rc=0 rejected=[]
--- dup
LOG   Inbox: BUG-9 is already queued (harness/stories/S/bugs/BUG-9.md#bug-9) — duplicate enqueue skipped
rc=0 rejected=[]
--- terminal
LOG   Inbox: enqueued BUG-? (P2) fix → docs/a.md#t-done
CALL check_bug_spec_sections docs/a.md BUG-? enqueue
METRIC {"event":"bug_enqueued","bug_id":"BUG-?","severity":"P2","spec_ref":"docs/a.md#t-done","at":"2026-10-17T00:00:00+00:00"}
rc=0 rejected=[]
--- defaults
LOG   Inbox: enqueued BUG-? (P2) fix → harness/stories/S/bugs/BUG-10.md#bug-10
CALL check_bug_spec_sections harness/stories/S/bugs/BUG-10.md BUG-? enqueue
METRIC {"event":"bug_enqueued","bug_id":"BUG-?","severity":"P2","spec_ref":"harness/stories/S/bugs/BUG-10.md#bug-10","at":"2026-10-17T00:00:00+00:00"}
rc=0 rejected=[]
--- noref-origin
ERR   ! Inbox: enqueue-bug 'noref-origin.yaml' has no spec_ref — cannot enqueue a fix line
METRIC {"event":"bug_enqueue_failed","reason":"no-spec_ref","file":"noref-origin.yaml","at":"2026-10-17T00:00:00+00:00"}
CALL write_blocker [T-O-1] [(none)] [qa-bug-not-enqueued] [state/session.log]
- **Bug:** BUG-11 — inbox event `noref-origin.yaml` names no spec_ref, bug_file, or story + bug_id, so no fix task was queued.
- **Do:** write `spec_ref: <paths.stories>/<STORY>/bugs/<BUG>.md#<bug-id-lowercase>` into a new event in the inbox (see core/events/schemas/inbox-event.v1.md).
rc=0 rejected=[no-spec_ref]
--- noref-task
ERR   ! Inbox: enqueue-bug 'noref-task.yaml' has no spec_ref — cannot enqueue a fix line
METRIC {"event":"bug_enqueue_failed","reason":"no-spec_ref","file":"noref-task.yaml","at":"2026-10-17T00:00:00+00:00"}
CALL write_blocker [T-O-2] [(none)] [qa-bug-not-enqueued] [state/session.log]
- **Bug:** BUG-12 — inbox event `noref-task.yaml` names no spec_ref, bug_file, or story + bug_id, so no fix task was queued.
- **Do:** write `spec_ref: <paths.stories>/<STORY>/bugs/<BUG>.md#<bug-id-lowercase>` into a new event in the inbox (see core/events/schemas/inbox-event.v1.md).
rc=0 rejected=[no-spec_ref]
--- noref-bare
ERR   ! Inbox: enqueue-bug 'noref-bare.yaml' has no spec_ref — cannot enqueue a fix line
METRIC {"event":"bug_enqueue_failed","reason":"no-spec_ref","file":"noref-bare.yaml","at":"2026-10-17T00:00:00+00:00"}
CALL write_blocker [BUG-?] [(none)] [qa-bug-not-enqueued] [state/session.log]
- **Bug:** BUG-? — inbox event `noref-bare.yaml` names no spec_ref, bug_file, or story + bug_id, so no fix task was queued.
- **Do:** write `spec_ref: <paths.stories>/<STORY>/bugs/<BUG>.md#<bug-id-lowercase>` into a new event in the inbox (see core/events/schemas/inbox-event.v1.md).
rc=0 rejected=[no-spec_ref]
-- queue after:
# queue header
# [DONE] docs/a.md#t-done
# enqueue-bug: BUG-9 (P1) filed by QA — fix ahead of pending feature work
harness/stories/S/bugs/BUG-9.md#bug-9
docs/a.md#t-a-1
docs/a.md#t-a-2
# enqueue-bug: BUG-? (P2) filed by QA — appended at end of active queue
docs/a.md#t-done
# enqueue-bug: BUG-? (P2) filed by QA — appended at end of active queue
harness/stories/S/bugs/BUG-10.md#bug-10
# trailing comment
## file_qa_bug
rc=0 ref=[LOG   Filed BUG-001 (P1) from QA verdict on T-A-1 → harness/stories/STORY-7/bugs/BUG-001.md#bug-001
METRIC {"event":"bug_filed","bug_id":"BUG-001","severity":"P1","origin_task":"T-A-1","at":"2026-10-17T00:00:00+00:00"}
harness/stories/STORY-7/bugs/BUG-001.md#bug-001]
rc=0 ref=[LOG   Filed BUG-002 (P3) from QA verdict on T-A-2 → harness/stories/STORY-7/bugs/BUG-002.md#bug-002
METRIC {"event":"bug_filed","bug_id":"BUG-002","severity":"P3","origin_task":"T-A-2","at":"2026-10-17T00:00:00+00:00"}
harness/stories/STORY-7/bugs/BUG-002.md#bug-002]
rc=1 ref=[ERR   ! file_qa_bug: story.sh bug failed for T-A-3: story.sh: no such story]
rc=1 ref=[ERR   ! file_qa_bug: could not parse story.sh output: something unexpected]
-- bug files:
=== harness/stories/STORY-7/bugs/BUG-001.md
---
id: BUG-001
---

## Expected behaviour

user logs in

<!-- quote the AC -->

## Actual behaviour

500 error

<!-- what happened -->

## Evidence

logs/qa.log:12

<!-- links -->

## Acceptance criteria

1. Expected behaviour is restored: user logs in
2. The failure no longer reproduces: 500 error
3. A regression test is added that FAILS before the fix and PASSES after it
   (mandatory — a bug fix without a failing-first regression test is not done).
<!-- Filed by qa-agent from a QA FAIL verdict on T-A-1. The fix must
     satisfy every criterion above; criterion 3 is mandatory for every QA bug. -->

<!-- numbered -->
=== harness/stories/STORY-7/bugs/BUG-002.md
---
id: BUG-002
---

## Expected behaviour

line one
line two

<!-- quote the AC -->

## Actual behaviour

fails 1/5

<!-- what happened -->

## Evidence

junit.xml

<!-- links -->

## Acceptance criteria

1. Expected behaviour is restored: line one
line two
2. The failure no longer reproduces: fails 1/5
3. A regression test is added that FAILS before the fix and PASSES after it
   (mandatory — a bug fix without a failing-first regression test is not done).
<!-- Filed by flake-quarantine from a QA FAIL verdict on T-A-2. The fix must
     satisfy every criterion above; criterion 3 is mandatory for every QA bug. -->
-- inbox:
=== enqueue-bug-STORY-7-BUG-001.yaml
type: enqueue-bug
bug_id: BUG-001
severity: P1
origin_task: T-A-1
spec_ref: harness/stories/STORY-7/bugs/BUG-001.md#bug-001
=== enqueue-bug-STORY-7-BUG-002.yaml
type: enqueue-bug
bug_id: BUG-002
severity: P3
origin_task: T-A-2
spec_ref: harness/stories/STORY-7/bugs/BUG-002.md#bug-002
-- story.sh calls:
story.sh bug --origin-task T-A-1 --severity P1 --found-by qa-agent --title Login fails
story.sh bug --origin-task T-A-2 --severity P3 --found-by flake-quarantine --title Flaky --affected src/a.ts
story.sh bug --origin-task T-A-3 --severity P2 --found-by qa-agent --title x
story.sh bug --origin-task T-A-4 --severity P2 --found-by qa-agent --title x
