AI Coding in Practice: Generating a Complex Desktop Tool with Zero Runtime Errors
This article presents a practical case study of using AI-assisted coding to build a desktop batch audio extraction tool that runs without errors. It explains how to turn vague requirements into verifiable items, why asynchronous architecture is mandatory for GUI applications, how to report progress and status safely across threads, and which robustness checks beginners most often miss. It also outlines a five-scenario acceptance checklist for generated code and shows how to write prompts that convert constraints into testable acceptance criteria. The same approach applies to task-oriented applications in logging, monitoring, and container platforms.
1. Introduction: From “It Generates” to “It Actually Runs”
AI-assisted programming has entered a more demanding phase. What developers care about is no longer whether a model can produce syntactically correct code, but whether it can deliver a complete program under complex constraints: one that runs directly, feels responsive, and keeps errors under control. This article uses a typical desktop tool, a batch video-to-audio extraction utility, to discuss how to turn tedious requirements into high-quality runnable code, and presents a reusable engineering approach to acceptance testing.
The technical difficulty of this kind of tool lies not in format conversion itself, but in three things: tasks take a long and unpredictable amount of time, users need real-time progress feedback, and a failure in any single file must not break the whole run. Put a long-running task on the main thread and the UI freezes. Leave out status reporting and the progress bar is decoration. Handle exceptions incompletely and one failure aborts the entire batch.
2. Requirement Modeling: Breaking Vague Descriptions into Verifiable Items
High-quality generation starts with verifiable requirements. It helps to split requirements into four layers:
- Input layer: support common video formats, recursive directory scanning, and automatic filtering of non-target files.
- Processing layer: output mainstream audio formats and check that runtime dependencies are ready before conversion.
- Interaction layer: file list, format selection, start and exit buttons, progress bar, and status bar.
- Robustness layer: error messages, protection against overwriting same-name files, a UI that does not freeze, and interruptibility.
A sample requirement description looks like this:
Goal: batch extract audio from videosInput: single file / recursive directory, common video extensionsOutput: configurable target audio formatConstraints: long-running tasks must not block the UI; failures reported per file; duplicate output names auto-numberedAcceptance: no crash in three scenarios — empty input, missing dependency, single-file failure
Rewriting subjective phrases such as “user-friendly interface” into verifiable interaction items is the key step toward a higher generation success rate.
3. Architecture Design: Why Async Is Mandatory
Desktop GUI programs follow an event loop model. UI refreshes and button responses all depend on the main thread. If conversion runs on the main thread, the event queue is occupied for a long time and the window shows “Not Responding.”
Three approaches are common in the industry:
- Thread pool: suitable for conversion tasks dominated by IO and external processes; simple to implement.
- Queue plus worker threads: decouples tasks from the UI and makes pause, resume, and priority control easier.
- External process invocation: a mature media command-line tool performs the actual transcoding while the UI only schedules work.
A sample skeleton:
import queueimport threadingtask_q = queue.Queue()def worker():while True:item = task_q.get()if item is None:breaktry:result = convert(item) # long-running operation happens hereemit_progress(item, result)except Exception as e:emit_error(item, e)finally:task_q.task_done()
The key point: the UI thread only enqueues and refreshes; worker threads only convert and report back.
4. Progress and Status: Making the Wait Perceptible
Progress feedback needs two dimensions: overall progress and the status of the current file. A common engineering practice is for worker threads to write “number completed, current file name, status text” into a thread-safe queue, while the UI polls it on a timer and updates widgets, avoiding direct cross-thread manipulation of UI controls.
def poll_events():while not event_q.empty():evt = event_q.get_nowait()status_var.set(evt["text"])progress_var.set(evt["value"])root.after(200, poll_events)
The status bar should cover at least: ready, scanning, converting, completed, and failure count. Failure details are best also written to a log file so they can be investigated together after a batch run.
5. Robustness Checklist: Six Things Beginners Most Often Miss
- Dependency pre-check: verify the external handler exists before conversion, and show clear guidance when it is missing instead of throwing a stack trace.
- Path handling: use standard library path joining consistently to avoid failures caused by separators and spaces.
- Duplicate-name policy: append a sequence number when an output exists, preventing silent overwrites.
- Encoding: apply a consistent encoding strategy for logs and file names to avoid errors with special characters.
- Interruptibility: provide a stop button and let worker threads exit safely at file boundaries via a flag.
- Empty-input protection: disable the start button and show a hint when no files are selected.
6. How to Accept Generated Code
Once you have the generated result, accept it in this order:
- Static check: it compiles, with no undefined variables and no unused imports.
- Scenario 1: clicking start with an empty list should be blocked.
- Scenario 2: a missing external dependency should produce a message, not a crash.
- Scenario 3: a deliberately corrupted file should be logged as a failure while later tasks continue.
- Scenario 4: dragging the window during a batch run should leave the UI responsive.
- Scenario 5: if a same-name file already exists in the output directory, a new name should be generated automatically.
7. Prompt Engineering: Writing Constraints as Acceptance Criteria
An effective prompt has six parts: role, goal, tech stack, feature items, non-functional constraints, and acceptance criteria. Translating “no freezing” into “long-running tasks must run in worker threads and the UI updates via timer polling,” and “show errors” into “catch exceptions per file and write them to the log and status bar,” noticeably improves generation quality.
8. Conclusion
The value of AI coding is not that it types all the code for you, but that it moves requirement clarification, architecture choices, and acceptance criteria to the front. When requirements are verifiable, the concurrency model is correct, and exception paths are complete, generated results move from “looks right” to “runs reliably.” In engineering practice on cloud platforms such as Baidu AI Cloud, this approach of verifiable requirements plus async architecture plus complete exception handling applies equally to task-oriented application development in logging services, monitoring and alerting, and container platforms.
