Prompt file imported from zoolutions/pgbus (
.claude/commands/lfg.md). Fill in{{arguments}}before use. Copyright stays with the author.
LFG - Full Autonomous Workflow
Execute a complete engineering workflow with verification at each phase.
Phase 0: Branch Setup
BEFORE any other work, prepare the git branch:
- Check the current branch:
git branch --show-current - If NOT on
main, switch:git checkout main - Pull latest:
git pull origin main - Create feature branch:
git checkout -b issue-{number}-{brief-description}(orfeature/{description}if no issue number)
Phase 1: Understand
Step 1: Gather Requirements
If {{arguments}} is a GitHub issue number or URL:
gh issue view <number> --json title,body,labels,assignees,comments
If {{arguments}} is a description, use it directly.
Step 2: Define Acceptance Criteria
MANDATORY: Write explicit acceptance criteria:
- GIVEN [context/setup]
- WHEN [action taken]
- THEN [expected outcome]
You MUST NOT proceed until you can articulate these clearly.
Step 3: Comprehension Gate
Before proceeding, you must:
- State the problem/feature in one sentence
- Explain WHY this is needed (business context)
- List what will change from the user's perspective
- Identify edge cases not explicitly mentioned
- Explain the data flow or code path involved
If you cannot complete ALL five items, investigate further.
Step 4: Create Task List
Create a TaskCreate todo list with specific implementation steps.
Phase 2: Explore
- Find related files (Glob/Grep or Explore agent)
- Read existing patterns in similar features
- Understand dependencies and integration points
- Check existing test coverage
- Review PGMQ client interactions in
lib/pgbus/client.rb - Check ActiveJob adapter in
lib/pgbus/active_job/ - Review event bus patterns in
lib/pgbus/event_bus/ - Check process model in
lib/pgbus/process/
Phase 3: Plan
- List files to modify with specific changes
- List new files to create with purpose
- Identify migration changes needed (PGMQ queues, metadata tables)
- Plan test coverage (TDD: tests FIRST)
- Update task list with implementation steps
- Consider backwards compatibility with existing queue configurations
Phase 4: Implement (TDD)
The deviation log (keep it from the first edit)
The plan is the map; the codebase is the territory. The moment reality forces a choice the plan or issue didn't settle, log it in implementation-notes.md at the repo root — one line, at the moment it happens, not reconstructed later:
- Deviations — the plan said X, you did Y, because Z
- Discoveries — facts about the codebase the plan didn't know
- Judgment calls — choices the user might have made differently (defaults, naming, scope cuts)
Pick the conservative option and keep going. The log is how the user audits your judgment afterwards. Never commit the file: its contents move into the PR body (Phase 7), then the file is deleted.
For each logical unit:
4.1: Write Failing Test First
Create a test that demonstrates the expected behavior. Run it to confirm it FAILS:
bundle exec rspec <spec_file>
4.2: Implement Minimum Code
Write the MINIMUM code to make the test pass. Follow project patterns:
| Never Do | Always Do |
|---|---|
| Direct PGMQ SQL calls | Use Pgbus::Client wrapper |
| Skip queue prefixing | Always use config.queue_name() |
| Hardcode queue names | Use configuration |
| Skip visibility timeout | Use PGMQ's native VT mechanism |
| Ignore dead letter routing | Check read_ct against max_retries |
| Raw SQL in controllers | Use Web::DataSource for dashboard |
4.3: Refactor
Once green, refactor while keeping tests passing.
4.4: Validate
bundle exec rubocop <changed_files>
4.5: Repeat
Move to next logical unit. Mark task items complete.
Phase 5: Deep Root Cause Analysis (Bug Fixes Only)
If this is a bug fix, apply deep investigation before implementing:
Trace the Data Lifecycle
For the message/job/event causing the issue:
- Where and when was the message enqueued? By what adapter call?
- What visibility timeout was set? Has it expired?
- What ASSUMPTIONS does the code make at the failure point?
- Which assumption was violated, and WHY?
Use Git History
git log --oneline -20 <file>
git blame <file>
- When was the code written? What was the original intent?
- Has something ELSE changed that invalidated the original assumptions?
Map All Callers
Don't just look at the method that failed:
- Use Grep to find all call sites
- Different contexts (ActiveJob adapter vs event bus vs dashboard)?
- Does the error only happen in ONE context? Why?
Five Whys
Keep asking WHY until you reach a meaningful fix point:
- Error: X happened -> Why?
- Because Y -> Why was Y in that state?
- Because Z -> Why wasn't Z prevented?
- Because no check existed -> Why not?
- THIS is where the fix belongs
Fix Location Principle
The best fix is usually NOT where the error is raised:
- Nil message in executor -> fix in worker that should provide non-nil
- Queue not found -> fix in code that should ensure_queue first
- Race condition -> PGMQ-level visibility timeout
- Dead letter overflow -> fix the retry/DLQ routing logic
Ask: "Where is the EARLIEST point I could prevent this error?" Fix there.
Unacceptable Superficial Fixes -- DO NOT DO THESE
rescue nilwithout understanding why the exception occurs&.to silence nil errors without investigating why nil occursif object.present?guards without understanding why missingreturn if message.nil?to silently skip processing- Wrapping everything in
begin/rescueto swallow errors
These HIDE bugs. The root cause continues causing issues elsewhere.
Phase 6: Verify
ALL of these must pass before committing:
bundle exec rubocop # Style
bundle exec rspec <relevant_specs> # Tests
Solution Verification
Re-read the original requirements and verify:
- "If I were the requester, would I consider this fully resolved?"
- "Have I addressed the ROOT CAUSE, not just the symptom?"
- "Do my tests prove the issue is ACTUALLY fixed, not just suppressed?"
- "Does this maintain backwards compatibility?"
Phase 7: Commit & PR
Commit
git add <specific_files>
git commit -m "$(cat <<'EOF'
feat(scope): brief description
## Summary
[What changed and why]
## Test Coverage
- spec 1: validates requirement X
- spec 2: validates edge case Y
## Verification
- [x] bundle exec rubocop passes
- [x] bundle exec rspec passes
EOF
)"
Push & PR
git push -u origin $(git branch --show-current)
gh pr create --title "feat(scope): brief description" --body "$(cat <<'EOF'
## Summary
- Key change 1 touching `lib/foo.rb`
- Key change 2
Closes #<issue_number>
## Test plan
- [ ] Scenario 1
- [ ] Scenario 2
EOF
)"
Markdown inside the quoted heredoc is literal — do not escape. The single-quoted <<'EOF' delimiter disables shell expansion on the body, so:
- Write backticks as backticks:
`foo`. Do NOT write\foo``; that writes a literal backslash-backtick and breaks the code span. - Write dollar signs as-is:
$HOME. No escaping needed. - Write backslashes as-is:
\nstays\n.
The body is copied verbatim into the PR / commit message. If you would not type a backslash in a GitHub comment, do not type one in the heredoc.
If the body is long or contains many backticks / tables, prefer writing it to a temp file and passing --body-file:
cat > /tmp/pr-body.md << 'EOF'
## Summary
...any markdown...
EOF
gh pr create --title "..." --body-file /tmp/pr-body.md
rm /tmp/pr-body.md
The --body-file path avoids the double-layer of shell interpretation entirely and makes long PR bodies easier to read in the terminal buffer.
The PR body MUST end with a ## Deviations & judgment calls section copied from
implementation-notes.md (then delete the file). If the plan held completely,
write "None — the plan held." This section is read FIRST in review — it is the
audit trail for every decision the plan didn't make.
Phase 8: Comprehension Close-Out
The tests prove the CODE is right; this phase keeps the USER's mental model right. After the PR is up, end your final message with:
- The decisions, not the diff — the 3–5 non-obvious choices in this change someone must understand to maintain it. Lead with anything from the deviation log; the user has never seen those.
- Three merge-gate questions the user should be able to answer before merging. If any answer isn't obvious to them, offer a walkthrough — an unanswerable question is comprehension debt, and merging anyway is how it compounds.
Verification Checklist
- All acceptance criteria met
- Tests written BEFORE implementation
-
bundle exec rubocoppasses -
bundle exec rspecpasses - Backwards compatibility maintained
- PGMQ operations go through Client wrapper
- PR created with description
- PR body ends with
## Deviations & judgment calls(from implementation-notes.md, since deleted) - Comprehension close-out delivered (decisions + three merge-gate questions)
Handoff
When complete:
- All phases executed
- Verification passed
- PR created and linked
Now, execute this workflow for the provided issue or feature.