spec-kit icon indicating copy to clipboard operation
spec-kit copied to clipboard

Add Post-Implementation Debugging and Fixing Workflow

Open RotRot-pi opened this issue 1 year ago β€’ 11 comments

Problem Statement

The current Spec-Driven Development workflow provides excellent structure for initial development (constitution β†’ specify β†’ plan β†’ tasks β†’ implement), but lacks a systematic approach for handling broken or incomplete implementations that result from the /implement command.

Current Gap

What happens now:

  1. /implement executes the planned tasks
  2. Code is generated but may contain runtime errors, logic bugs, or missing functionality
  3. Developer is left to manually debug and fix issues outside the Spec Kit framework
  4. No structured way to ensure fixes align with original specifications

Real-world scenarios:

Scenario 1: Build Failures

  • AI agent generates Flutter app code following the implementation plan
  • Code contains syntax errors, missing imports, or incorrect API usage
  • flutter build or dart analyze fails with compilation errors
  • Developer must manually identify and fix code issues outside the Spec Kit framework

Scenario 2: Runtime Issues

  • AI agent successfully generates Flutter app structure that compiles
  • App builds but crashes on startup due to missing dependencies or configuration
  • Runtime errors appear in device logs or debug console during testing
  • Logic bugs surface during user testing that weren't caught in generation
  • No clear path to systematically address these issues within the Spec Kit methodology

Proposed Solution

Add a post-implementation workflow to handle debugging and fixes while maintaining spec-driven principles:

Option 1: Dedicated Fix Commands

/diagnose    # Analyze errors, identify root causes, check spec alignment
/fix         # Implement targeted fixes based on diagnosis

Option 2: Enhanced Iteration Command

/iterate     # Fix issues and improve implementation while maintaining spec compliance

Option 3: Robust Implementation

Enhance /implement to include error handling, validation, and retry logic for common failure scenarios.

Why This Aligns with Spec-Driven Development

  1. Iterative Enhancement Phase: The mention of "Iterative Enhancement (Brownfield)" as a supported development phase
  2. Specification Integrity: Bugs often reveal gaps in original specs - fixes should update both code AND specifications
  3. Complete Development Lifecycle: Real software development includes debugging, not just initial creation
  4. Enterprise Readiness: Mission-critical applications need robust error handling and fixing workflows

Expected Behavior

A /fix or similar command should:

  • Analyze current codebase against specifications
  • Identify discrepancies between expected and actual behavior
  • Generate targeted fixes that maintain spec compliance
  • Update relevant specification documents if gaps are discovered
  • Preserve the structured, traceable development approach

Use Case Example

# After /implement generates broken code
/diagnose "App crashes on startup with SQLite connection error"

# Command would:
# 1. Analyze error logs
# 2. Check against database setup in plan.md
# 3. Identify missing configuration or dependencies
# 4. Suggest specific fixes

/fix
# Execute the identified fixes while maintaining spec alignment

Benefits

  • Maintains Spec-Driven Approach: Fixes are systematic, not ad-hoc
  • Improves Success Rate: Higher likelihood of working implementations
  • Enterprise Viability: Addresses real-world development cycles
  • Specification Evolution: Allows specs to improve based on implementation learnings

Impact on Current Workflow

This would extend the existing workflow from: constitution β†’ specify β†’ plan β†’ tasks β†’ implement

To: constitution β†’ specify β†’ plan β†’ tasks β†’ implement β†’ [diagnose/fix as needed]

The addition is backwards-compatible and optional - projects with successful implementations wouldn't need the debugging workflow.


Environment:

  • Using Spec Kit with Flutter desktop application development
  • Observed this gap during real project implementation
  • AI Agent: Qwen Code

Related: This enhancement would support the "Iterative Enhancement" and "Enterprise constraints" experimental goals.

RotRot-pi avatar Sep 21 '25 10:09 RotRot-pi

+1 This is definitely required.

nitish-raj avatar Sep 21 '25 16:09 nitish-raj

@RotRot-pi - what is the delta between /diagnose and /fix? Seems somewhat redundant. I also think this should likely be better integrated either into one command or, if split, potentially rely on /implement in some capacity to prevent command sprawl.

localden avatar Sep 22 '25 17:09 localden

@localden Thanks for replying. My original thought was like this:

-/diagnose = analyze and identify issues -/fix = actually implement the fixes

It felt necessary to have two separate commands. One to identify the issues and plan for a fix while the other to implement the plan. Since you have mentioned it, I understand that it can feel redundant.

We already have a powerful /implement command, and we can treat the bugs/errors as another kind of tasks. We can use /diagnose command to analyze the error, logs, and project context and run some validation scripts (flutter analyze) to gather more data.

Then it will create a new set of tasks using the same tasks.md format. We can then use the /implement command to work on these new tasks.

We can have a new section in the generated tasks dedicated for the tasks related to fixing issues, or we can have a separate file in the same format of tasks.md where we have the issues as tasks. Then using a new flag /implement --fix "path/to/file" we implement the necessary fixes.

RotRot-pi avatar Sep 22 '25 20:09 RotRot-pi

I'm new to spec kit and am loving it. I'm also at exactly this stage of things, having spec'ed a very substantial project and had great success so far with spec kit guiding it after a fairly miserable experience of letting Claude Code tackle what I thought was a sufficiently well thought out spec.

I'd be happy to be a guinea pig for this new facility or help in whatever other way might be useful. Cheers!

joesh avatar Sep 26 '25 16:09 joesh

+1 - I've only been working with spec-kit for a few days; I always find more details/fixes/tweaks needed after implementation and we are left with starting over going to a previous commit and rerun the clarify all the way to implement, but that is not ideal because you already spent so many tokens on the first implementation. I have been trying to /clarify without backing out the current state, but it gets confused quickly.

I am definitely eager for features like the /fix /iterate /update-spec etc.

onarres avatar Sep 29 '25 20:09 onarres

Somewhat related to https://github.com/github/spec-kit/issues/549

ebramirez avatar Sep 30 '25 12:09 ebramirez

λ‚˜λ„ ν•„μš”ν•˜λ‹€κ³  λŠλ‚€λ‹€. +1

grayson1999 avatar Nov 26 '25 02:11 grayson1999

@RotRot-pi - what is the delta between /diagnose and /fix? Seems somewhat redundant. I also think this should likely be better integrated either into one command or, if split, potentially rely on /implement in some capacity to prevent command sprawl.

I agree with this direction, and I think it also lines up really well with how Spec Kit already handles planning and gives the user an opportunity to look at the plan.

A β€œfix” can’t really happen without diagnosing first, and Spec Kit already has a pattern where nothing changes until there’s a plan the user can review. So if /fix existed, it would still need to analyze the error, propose tasks, and let the user correct assumptions before touching code, which starts to look a lot like /implement.

Because of that, it feels cleaner if /diagnose just generates fix tasks (maybe in the tasks.md file or a debug.md) that capture what failed, what was already tried, and any user corrections. Then you just run/implement (or /implement --fix) on those tasks.

One thing this would help with is avoiding the agent from retrying the same bad assumptions during debugging. If prior attempts and corrections are written down explicitly, its less likely to forget and loop.

That keeps debugging consistent with the existing workflow and avoids adding commands that overlap too much. But that's just my two cents from a mostly outside perspective.

Kataki-Takanashi avatar Jan 08 '26 22:01 Kataki-Takanashi

I would like to say bump, but there definitely needs to be some type of post-command(s).

Many times after the implementation phase the feature will pass all checks, but there is nuanced things that require attention and updating. This could be stuff as simple as layout changes that were not covered in the flow... Or this could be bugs that pass compile/checks.

I have been able to rerun through specify > plan > tasks > implement with prefixing something like "Update Spec" but iterating through all steps. Though as stated before even when editing, it can be quite token heavy.

ErraticFox avatar Mar 09 '26 23:03 ErraticFox

Glad to see others are having similar thoughts. I kept seeing bug fixes breaking the documentation flow, so I created this section in my constitution before stumbling across this discussion. Here is what I am using locally

Bug Management

Bug Collection

When a user identifies a bug, the agent MUST record it in the master issues.md file at the project root. The agent MUST NOT attempt to fix bugs immediately β€” they are processed one at a time at the user's direction.

Each bug MUST be assigned a unique ID using a BUG- prefix followed by a zero-padded three-digit sequential number, independent of the feature numbering sequence. The bug sequence starts at BUG-001 and increments within issues.md only.

Each bug entry MUST include the following fields:

  • Bug ID: Next available BUG-NNN sequential number.
  • Description: The user's description of the bug.
  • Date reported: ISO 8601 date (YYYY-MM-DD).
  • Priority: P1 (critical), P2 (high), P3 (medium), or P4 (low), assigned collaboratively with the user.
  • Expected result: What the user expects to happen when the bug is not present.

Entries MUST use checkbox format:

- [ ] **BUG-001** **[P1]** (2026-04-22)
      Description of the bug as reported by the user.
      **Expected:** What should happen instead.
  • [ ] = open / unfixed.
  • [x] = fixed and verified.

Bugs MUST remain in issues.md until the user explicitly requests resolution. The agent MUST NOT remove or archive entries without user approval.

Bug Resolution

When the user requests a bug fix, the agent MUST process one bug at a time. If multiple bugs are open, the agent MUST select the highest-priority bug (P1 first, then P2, and so on). Within the same priority level, earlier-reported bugs take precedence.

Before beginning the Spec Kit workflow, the agent MUST create a new branch from the current branch named after the bug ID (e.g., BUG-001). All subsequent Spec Kit workflow steps and code changes for that bug MUST occur inside this branch. The branch MUST NOT be merged until the bug is fully resolved and verified.

ALL bug fixes MUST follow the full Spec Kit workflow inside the bug fix branch:

  1. /speckit-specify β€” create a bug-fix specification capturing the defect, its root cause (if known), and acceptance criteria for the fix.
  2. /speckit-clarify β€” refine the specification. This step MUST proactively identify implied or adjacent changes beyond the literal bug report. For example, if a bug states "user settings are not loaded," the clarify phase MUST also investigate whether there are related UI updates, data migration needs, error handling gaps, state synchronization issues, or other dependent fixes that MUST accompany the resolution.
  3. /speckit-plan β€” generate the implementation plan.
  4. /speckit-tasks β€” generate the task breakdown.
  5. /speckit-analyze β€” cross-artifact consistency analysis.
  6. /speckit-checklist β€” generate the implementation checklist.
  7. /speckit-implement β€” execute the implementation.

Code MUST NOT be changed until specifications, requirements, tests, and user acceptance criteria have been updated first. This applies to all source files, configurations, and build artifacts. The only artifacts that may be modified before the implement phase are spec documents, plans, and task lists.

Once a bug is fixed and verified (tests pass, acceptance criteria met), its entry in issues.md MUST be transitioned from - [ ] to - [x]. The bug fix branch is then ready for merge.

No-Shortcut Policy

Bug fixes MUST NOT bypass the Spec Kit workflow regardless of perceived simplicity. Even a one-line fix requires at minimum a specification and clarification pass to ensure no implied changes are missed.

  • "Simple" bugs often have non-obvious side effects. The clarify step exists to surface them before code is touched.
  • Skipping workflow steps for expediency has compounding cost: incomplete test coverage, undocumented fixes, and missed regressions.

Single exception β€” critical production outage: When a bug causes complete loss of functionality or data corruption, a hotfix MAY be applied to restore service before the full workflow completes. However, a retroactive spec pass (specify β†’ clarify β†’ plan β†’ tasks β†’ analyze) MUST follow immediately after the hotfix is deployed. The hotfix MUST be treated as provisional until the retroactive workflow confirms it is correct and complete.

Rationale: Rigorous bug management prevents the accumulation of undocumented fixes, ensures every change is tested against acceptance criteria, and catches cascading issues that a surface- level fix would miss.

JoeG-SP avatar Apr 23 '26 18:04 JoeG-SP

Thanks @RotRot-pi for raising this, and to @nitish-raj, @joesh, @onarres, @Kataki-Takanashi, and @grayson1999 for the discussion that shaped how we approached it.

Addressed by #2871 (tracked in #2870), which adds a bundled bug extension. Install with specify extension add bug once it lands. See extensions/bug/README.md in that PR for the full surface; in short, it provides speckit.bug.assess, speckit.bug.fix, and speckit.bug.test, each writing one Markdown report into a per-bug directory under .specify/bugs/<slug>/.

On the design tension I raised earlier in the thread about command sprawl: the three commands are namespaced under an opt-in extension (speckit.bug.*) rather than added to the core CLI, so they do not enlarge the top-level surface. They stay separated because triage, remediation, and verification operate on different inputs and produce distinct artifacts β€” collapsing them loses the audit trail, which is the point of the per-bug directory.

We considered the /diagnose β†’ tasks.md β†’ /implement --fix integration the thread converged on, and chose against it for two reasons: bugs often arrive against code with no active feature branch or tasks.md (post-merge, production, hotfix scenarios), and an opt-in extension is reversible (extension disable bug) in a way that changing /implement's contract is not.

Closing as addressed by #2871. If the extension falls short for your real workflows β€” especially the integration story with feature specs β€” please open a follow-up issue against the bug extension specifically.

mnriem avatar Jun 05 '26 16:06 mnriem