One of several Bible commentaries I have explained this point about the fact that David had been in Saul's employ prior to the giant-killing episode, which raises this question as to why Saul then asked who David was. You want to know how biblical literalists cope with an apparent error in the chronology of events.
The need is to first read in 1st Samuel three whole chapters, starting at 15 with what led God to reject Saul as king. The prophet Samuel was directed by God to tell Saul to his face that "Rebellion is as sinful as witchcraft, and stubbornness as bad as worshiping idols. So because you have rejected the command of the Lord, he has rejected you as king" (1 Samuel 15:23). Saul admitted his guilt. Then, in chapter 16 God directs Saul to anoint the youngest son of Jesse, David, as the future king of Israel, resulting in "The Spirit of the Lord came powerfully upon David from that day on... Now the Spirit of the Lord had left Saul, and the Lord sent a tormenting spirit that filled him with depression and fear" (1 Sam. 16:13-14).
At that point, Saul's courtiers suggested to him that they find a good musician who could soothingly play the harp whenever Saul became so mentally troubled. One suggested a son of Jesse, the shepherd David, adding that the Lord was with him, and so David began serving in the palace (vs.15-23).
The comment on this in the N.I.V. points out that
"Jesse arranged for David to continue serving Saul while still
fulfilling his shepherding duties at home base - see 17:14-15... The
intermittent nature of David's service might explain why Saul was
unfamiliar with David during the encounter with Goliath - see
17:55-58." (NIV Study Bible pp 493-4)
This part-time service might have been one month on, one month off (for all we know) with another skilled harp-player-cum-armour-bearer taking his turn when David was off. Or, perhaps David's work was when Saul was based at the palace while another person took over when Saul was on the war campaign trail. However, the NIV Study Bible faces up to the peculiarity of 17:55-58 showing that neither Saul, nor Abner (the commander of his army) seemed to know exactly who this David was. The footnote offers an alternative view:
"In light of 16:14-23, it is surprising that neither Saul nor Abner
knew who David was. It is possible that the events of ch.17 happened
either before or long after David's tenure of intermittent service
mentioned in ch16.)" (Ibid. p497)
There simply is not enough chronological detail in the account to establish the matter clearly. But biblical literalists know full well that establishing chronological events in the Old Testament is not an exact science, yet the events recorded did literally happen, even where on some occasions precise dates or sequence of events cannot be established.
The question raised here 9 years and 10 months ago had never occurred to me until I came across this. It has no bearing on whether or not the events happened. If David had been absent from the court during this war campaign (as 17:1-23 shows) Saul would have been so preoccupied with the massive danger of the Philistines bringing about a 40-day stalemate situation, he would have needed reminding about David. And Abner is as unlikely as Saul was to be mindful of one palace-personnel amongst thousand at such a critical battle stage.
The account, being inspired of the Holy Spirit, is what we need to know about those events. If we had needed to know a precise chronological sequence of events, that information would have been incorporated. Yet when books are written by people about historical events without aid of the Holy Spirit, they often chop and change, go back and forth, building up layers. Although I greatly enjoy reading David Schama's historical tomes, I find difficulty following events chronologically because he employs this 'layering' technique, combined with jumping back and forth, nor does he keep repeating dates. Readers are expected to have the wits (and perseverance) to keep up to speed with him!
There are, therefore, a couple of suggestions that can account for lack of chronological clarity, without invoking either a contradiction in the account, or a different version of the story being inserted later.