by ModernMech | 2025-04-18 14:52:57+00:00
> I clearly didn't understand what you meant, because you did in fact have additional unstated requirements

Okay, but the AI understood the requirements; It confirmed to me what I intended it to do, but it couldn't produce code that met its textual descriptions. It kept returning the tutorial code.

> You didn't specify. "It's wrong, fix it". Fix it how?

Maybe I wasn't clear here but I'm not replying as if I'm prompting you like an AI. The problem domain is described better in the link in the sibling comment. When the AI gave back the initial code, I had inquired the following:

how does this work when it gets to the bottom. Let's say I have a heading at the very bottom of the page. Will the "active" one be the bottom one or the top?

It replied:

What happens at the bottom of the page? When you're near the bottom of the page and the last section (section3, say) starts to enter the top of the viewport (within 100px), it becomes the active one — exactly as you'd want. But here's the catch: if the last section is short, or you scroll all the way to the very bottom (past the heading), then no section's top may be ≤ 100px, especially if the last heading has already scrolled off the top. In that case, the last matched section (likely the one before the last) stays active, which feels wrong. We can fix this either by: Making the threshold smarter (e.g., using .bottom or checking if any part of the section is visible). Or better: use IntersectionObserver to handle this robustly. Why this is better: It triggers when a section is entering the viewport (around 30% from top). Works even when you scroll to the very bottom. It’s less sensitive to section height or viewport size.

So it identified the edge case, it identified that the behavior is incorrect and what the cause of that is, and it returned code that purportedly fixed this. But the code it returned exhibited exactly the behavior it said "feels wrong". And in interrogating it. I asked it what was broken and we went line by line:

Show me exactly what was changed from this to the last which fixed the problem Perfect — let's do a line-by-line diff-style breakdown of what changed between the buggy version and the fixed version so we can pinpoint exactly what fixed the issue.

We went line by line and it told me what exactly was wrong and why it's fixed, and confirmed that the provided code produced the expected behavior.

Why this works: We evaluate all visible headings, not just ones intersecting a line. We pick the one that’s: just above the activation line, or just below it, if none are above Handles edge cases like top/bottom of scroll

But the code doesn't do this. It continued on like this where it proposed fixes, talked about the solution correctly, but wouldn't give code that implemented the solution.

> But if your problem is that the LLMs give a bad initial answer, get anchored on it, and can't iterate, just give all the requirements up front. If they're requirements you didn't realize existed until you saw the proposed answer, just start again with a fresh context. That tends to work well for me in Aider.

Yeah that's what I tend to do as well. I don't tend to get good satisfying results though, to the point where coding it myself seems like the faster more reliable option. I'll keep trying to hold it better and maybe one day it'll work for me. Until then I'm a skeptic.