AI Coding in Practice: How to Generate a Desktop Tool with Zero Runtime Errors

    Generating code from a natural language prompt is easy; shipping a desktop app that actually runs is not. This article uses a batch audio and video extraction tool as a test case to show why syntactically valid output still fails at runtime, and walks through a practical workflow: writing structured requirements with non-functional constraints up front, moving blocking work off the GUI main thread with a worker and queue pattern, handling easily overlooked engineering details such as dependency pre-checks and output name collisions, and using follow-up questions to confirm default behavior before delivery.

    1. Background: Why “Generates Code” Is Not the Same as “Delivers Software”

    AI coding tools now iterate quickly enough that turning a natural language description into a complete, runnable desktop program has moved from demo to everyday development workflow. In real use, however, the gap developers hit most often is not “the code cannot be written” but “the code cannot be run”: syntax passes and the logic looks complete, yet execution fails on missing dependencies; the window opens, but clicking the convert button freezes the entire interface; a batch run finishes and same-named files in the output directory silently overwrite each other.

    So evaluating a model or an AI coding approach cannot rely on line counts and function counts alone. What matters is whether it proactively covers three categories of implicit constraints:

    • Runtime environment constraints: are external dependencies available, and is there an actionable message when they are missing;
    • Concurrency and responsiveness constraints: are long-running tasks moved off the main thread, and does the interface stay interactive;
    • Data consistency constraints: are input and output paths, naming conflicts, and rollback on failure considered.

    This article takes a typical desktop requirement, a batch audio and video extraction tool, as the sample, reviews the full process from writing the requirement to verifying the result, and presents an engineering method that can be applied directly.

    2. Requirement Description: Spelling Out the “Tedious” Parts Is the Most Effective Constraint

    Many people write prompts that are too short, such as “write a tool that converts video to audio.” The model can only return a minimal working version, and everything afterward depends on manual rework. A more effective approach is to break the requirement into four layers and state them all at once.

    The first layer is capability boundaries: which input formats are supported and which target formats can be exported. There is no need to enumerate every extension; saying “cover common industry video containers and mainstream audio codecs” is usually enough for the model to fill in the common set.

    The second layer is tech stack constraints: specify the language and GUI framework explicitly, to avoid a combination that cannot run directly in the local environment.

    The third layer is interaction completeness: a file import list, input and output format selection, run and exit entry points, progress feedback, and status messages are all required.

    The fourth layer, and the most critical one, is non-functional requirements: the interface must not freeze during conversion, and errors must produce a visible message. This single line filters out the lazy approach of putting time-consuming logic on the main thread, and it is the dividing line between generated output of high and low quality.

    A prompt skeleton you can reuse:

    1. Role: Senior desktop application developer
    2. Task: Implement a batch audio and video extraction tool
    3. Tech stack: Python + standard library GUI framework
    4. Features: file/directory import, list display, output format selection, batch conversion, exit
    5. Non-functional: time-consuming tasks must run asynchronously; provide a progress bar and status bar; catch exceptions and show messages; the interface stays interactive throughout
    6. Deliverables: complete runnable code + dependency notes + feature list

    3. The Right Architecture: Time-Consuming Work Must Leave the Main Thread

    There is essentially only one root cause of a frozen interface: the GUI main thread is handling blocking I/O and encoding computation. The event loop of a desktop framework follows a single-threaded model, so once a callback takes a long time to return, repaint and click events all queue up behind it.

    The general engineering solution is to put the conversion flow in a worker thread, leaving the main thread responsible only for event dispatch and interface updates, with the two communicating in a thread-safe way:

    1. import threading, queue
    2. task_queue = queue.Queue()
    3. ui_queue = queue.Queue()
    4. def worker():
    5. while True:
    6. item = task_queue.get()
    7. if item is None:
    8. break
    9. try:
    10. result = convert(item) # blocking, time-consuming operation
    11. ui_queue.put(("ok", item, result))
    12. except Exception as exc:
    13. ui_queue.put(("error", item, str(exc)))
    14. finally:
    15. task_queue.task_done()
    16. def poll_ui():
    17. while not ui_queue.empty():
    18. kind, src, payload = ui_queue.get_nowait()
    19. # update the progress bar and status bar on the main thread
    20. root.after(100, poll_ui) # poll on a timer, avoid touching widgets across threads

    Three points are worth emphasizing. First, decoupling tasks with a queue naturally supports batching and sequential control. Second, interface updates happen only on the main thread, which avoids concurrent access to widgets. Third, exceptions are caught inside the worker thread and passed back, so a single failure does not drag down the whole batch.

    4. Engineering Details That Are Easy to Overlook

    The gap between a high-quality and a low-quality generation approach often shows up in exactly these places, the ones nobody writes into the requirement:

    • Dependency pre-check: conversion capability usually relies on an external media processing component, so check whether it exists before startup or execution, and show installation guidance when it is missing instead of throwing a stack trace;
    • Protection against overwriting: append a sequence number or timestamp to same-named output automatically, to avoid silently overwriting user data;
    • Directory recursion: collect files recursively when a directory is imported, and filter by extension to reduce useless tasks;
    • Path handling: use the standard library’s path joining consistently, for compatibility with different separators across operating systems;
    • Interruptibility: provide a cancel entry point so queued tasks can be discarded safely;
    • Logging and status: distinguish ready / in progress / failed / completed in the status bar, so failed items can be reviewed.

    5. Follow-Up Verification: Make the “Default Behavior” Explicit

    Finishing generation is not the endpoint. One high-value follow-up question is to confirm the default behavior, for example whether the output directory is the program directory, the current working directory, or a user-selected directory. This kind of question exposes whether the implementation implicitly depends on the runtime environment: if the default is the program directory, it will fail under a read-only installation path, so it should be changed to a user-selectable directory with the configuration persisted. Similar follow-ups include whether failed tasks are retried, whether there is an upper limit on batch size, and whether encoding parameters are adjustable. Two or three rounds of follow-up questions usually move the result from “it runs” to “it can be delivered.”

    6. Cost and Process Recommendations

    In terms of input versus output, the actual cost of this kind of task is mainly model call credits and manual verification time. The former depends on how complex the requirement description is and how many follow-up rounds there are; the latter depends on whether the non-functional requirements were written clearly at the start. The recommended flow is: structured requirement → generation → syntax and import check → dry run on a small sample → follow-up on default behavior → fill in exception branches. For enterprise adoption, general cloud capabilities can round out the delivery chain, for example distributing build artifacts with object storage, standardizing the runtime environment with a container platform, and tracking task failure rates with logging and monitoring with alerting.

    7. Conclusion

    “Generating a desktop tool with zero runtime errors” is not luck; it is the result of three things stacked together: a structured requirement, a correct architecture, and complete details. State the non-functional constraints up front, hand time-consuming logic to a worker thread, and confirm default behavior through follow-up questions. That is the reusable methodology.