What to do when your idea turns out to be an old one I learned yesterday that an idea (let's call it Idea A) I came up with on my own and that will appear in a paper I'm writing actually appeared in a paper 15 years ago.  (My field is math, I'm a PhD student, for context.)
The paper has other ideas that I think are significant on their own so I could remove the section where Idea A is used crucially.  However, that section helps put the overall results into perspective.  One way or another, that part of the paper should stay put, I think, even at the risk of proving results that some might claim are not really new.  (At the risk of flattering myself, I think the value of the paper will be greater than the sum of its parts: even if you might claim that many of the arguments, like Idea A, aren't hard or appeared previously, I seem to be the first one to see that they could all be combined into a considerable collection of interesting results.)
My question is how to address this in the paper.  Certainly, there's no question the older paper  will be cited and I'll mention it somewhere in the introduction.  It's just a matter of how much credit to give and to what extent it is appropriate to mention that I stumbled upon the idea &quot;independently&quot; of the older paper.  (I understand that &quot;independently&quot; usually refers to results that appear within a few months of each other rather than a decade and a half later.)
To make it slightly more concrete, in the introduction, I was planning to write: &quot;The analysis here is based on the approach in Paper 1 and Paper 2.  However, some additional arguments are necessary to deal with additional difficulties that arise in our setting.&quot;  Those additional arguments include Idea A, which I had planned to sketch immediately afterward.  I could then say later, when I give a literature review, that &quot;The idea sketched above appeared previously in Paper 3.&quot;  A difficulty with that, though, is Paper 2 cites Paper 3.  While the way I conceptualized the issues involved, Papers 1 and 2 were the starting point, it may be that Paper 3 influenced Paper 2.  One way to fix that would be to say, immediately after &quot;However, some additional arguments...,&quot; the following: &quot;(Actually, one of the key ideas here appeared previously in Paper 3.)&quot;  If I write &quot;it appeared previously,&quot; is the implication that I came on the idea on my own clear?  (Usually, in cases where other work informed my approach, I would say outright, &quot;this idea was inspired by...&quot; or &quot;it's an adaptation of arguments appearing in...&quot; or even &quot;this result relies crucially on previous work of...&quot;)  Another phrasing I have in mind is: &quot;One of the key ideas here, which was new to the author, actually appeared some time ago in Paper 3.&quot;
Similarly, I will probably mention Idea A in a conference talk next year.  Is saying something like &quot;This is an idea I stumbled upon and really like.  It turns out that the authors of Paper 3 had the same idea in mind.&quot; appropriate?  I would prefer not to think about questions like this, but it's much easier to navigate this kind of issue when you build on others' work knowingly.
Of course, all of this is actually irrelevant as far as the content of the paper is concerned.
Push Idea A into a background section and push novel results elsewhere. There's no real need to explain why you include a background section, but you might like to mention where your presentation differs from the original and explain why.

I seem to be the first one to see that they could all be combined into a considerable collection of interesting results

That's (part of) the novelty your paper provides.

to what extent it is appropriate to mention that I stumbled upon the idea &quot;independently&quot; of the older paper.

You could mention this somewhere, but it isn't necessary. Your paper has changed direction, like many papers. There's no need to provide a history of such changes. (Unless they are particularly interesting to your story.)