AI Learning Hub › Learn AI › Self-Paced Courses › Cursor: Plan, Build, Debug, and Review › Debug and Verify
Module 7 ยท Beginner to intermediate
Debug and Verify
A filter that works once and misbehaves on the second click. Find the cause from what the page actually does, fix it, and confirm the fix in a browser.
By the end
- Describe a fault as a difference between expected and actual behavior
- Use runtime evidence rather than guesswork to find a cause
- Verify a fix in a browser, including the console
A feature that works when you try it once is not the same as a feature that works. This module gives you a version of the evening filter that passes a casual test and fails a second one.
Load the broken version
You should be arriving from Module 6 with the evening filter built and reviewed. Keep a copy of it somewhere first — duplicate the folder, or commit if you use Git — then copy the three files from fallback/03-feature-buggy in the download over the ones in your project.
This version was written for the course. It is a realistic mistake — the kind that comes from adding a second filter without revisiting the first — but it is not a prediction of what Cursor produces. In testing, the plan Cursor wrote for this feature specified the correct structure. Treat it as code a colleague handed you.
Start the local server if it is not already running, and open the page:
python3 -m http.server 8000Exercise: reproduce the fault
Do these two things in order, and watch the cards.
- Tick Open evenings only. Three cards remain, which is right — three resources carry the evening mark.
- Leave the box ticked and change the category to Housing.
Two cards are showing. One of them is the Rivermont Housing Office, which is open 9:00 to 17:00, while the evening checkbox is still ticked.
Write the fault down before going further, in the form that makes it fixable:
With the evening filter on, changing the category brings back resources that are not open in the evening. Expected: one card. Actual: two.
That sentence — the steps, the expectation, the result — is most of the work. A fault described that precisely can be investigated; “the filter is broken” cannot.
Finding the cause
You can reason this one out from script.js, and it is worth trying before asking for help. The file has two functions that both decide whether cards are visible. Ask yourself what happens to the work the first one did when the second one runs.
The cause
The evening handler hides cards that are not marked for evenings, and leaves everything else as it found it. The category handler sets visibility on every card from scratch, based on category alone.
So changing the category overwrites the evening filter’s work. The checkbox still looks ticked, because nothing told it otherwise, and the page no longer reflects it.
The fix is the structure the plan in Module 4 described: one function that decides visibility from both conditions together, called whenever either control changes.
Exercise: fix it
Two routes, and both are legitimate.
By hand. You have read this file. Combining the two functions into one is a small edit, and doing it yourself is good practice.
With Debug Mode. Cursor has a mode built for faults you can reproduce but cannot explain. It runs the investigation as an investigation: it proposes several candidate explanations, adds temporary logging aimed at telling them apart, asks you to reproduce the problem so it can watch, reads what it captured, then makes a targeted fix and removes its own logging. Switch the mode chip to Debug and describe the fault using the sentence you wrote above, including both steps.
Course example — what Debug did with this fault, captured with Cursor 3.27.12
Run against this bug on 27 October 2026, Debug offered four candidate causes rather than one answer, including the right one and one worth ruling out: that Rivermont Housing Office might itself be marked as an evening resource.
It then added logging to script.js, each block fenced between // #region agent log markers and tagged with the hypothesis it was there to test, and asked for the two reproduction steps.
After reading what the logging recorded, it reported:
Hypothesis C — confirmed. The Housing entry is
applyCategorywithwanted: "housing",eveningsChecked: true, andcallsApplyEvenings: false. The category handler sees the checkbox and still does not combine the two filters.Hypothesis D — rejected. Rivermont Housing Office has
data-evenings="no". The first pass hid it for that reason. The attribute is right; the later category pass overwriteshidden.
It then combined the two passes into one function, removed every logging block it had added, started a local server, checked the result in a browser, and stopped the server again.
The part worth copying is not the fix. It is that the diagnosis quotes the values it recorded and says which explanation it ruled out and why. Your run will differ — the number of hypotheses and the logging it chooses are decided per fault — but a diagnosis you can check against evidence is what you are looking for.
Debug Mode writes to your files as part of investigating, which is how it gathers evidence. That is expected here, and the instrumentation comes out again at the end — check the diff afterward to confirm it did.
Whichever route you take, read the resulting change the way you read the last one. A fix is a diff too.
Exercise: verify it properly
Reload and run the same two steps. Ticking the box leaves three cards; adding Housing leaves one, the Tenancy Support Desk. Unticking the box brings the category-only list back.
Then open your browser’s developer console and reload once more. An empty console means no script errors. A red message means something is broken even if the page looks right.
Letting the agent check it
Cursor can drive a browser itself: open a page, click things, read the console, take screenshots. Pointed at your local address, it is a quick way to have the result checked.
Ask it to open http://localhost:8000, tick the evening checkbox, choose Housing, and report which cards are visible. Compare what it reports against what you saw yourself.
It may also do this unprompted. In the run captured for this course, Debug started its own local server, opened the page in a browser pane inside the editor, worked through the filter combinations, reported that “ticking Open evenings only leaves three cards” and that choosing Housing with it ticked “leaves only Tenancy Support Desk”, then stopped the server it had started.
Keep the agent’s browser on localhost for this course. Cursor’s documentation notes that browser state, including authentication cookies, persists between agent sessions for a workspace — so a browser the agent can drive may be holding sessions you are signed in to. Leave its approval prompts on, and do not send it to banking, email, or Stanford systems.
Your own verification stays the one that counts. The agent reporting success is another claim; the page in front of you is the evidence.
Before the next module
- You reproduced the fault and described it in expected-versus-actual terms
- You can say what caused it in one sentence
- The filter now works through both steps, and the console is clean