Isn't a thank-you blessing the wrong place to ask for something?
In the Ten Days of Repentance, the thank-you blessing contains a request: write all the children of Your covenant down for a good life. That looks like it breaks a rule. The Gemara (the rabbis' discussions built on the Mishnah) says never to ask for your needs in the first three blessings of the Amidah or the last three, only in the middle ones. Modim is one of the last three.
The Tur (a code of Jewish law from the 1300s) reports that some Geonim (heads of the great Babylonian yeshivot) used exactly that rule to say the extra lines should not be said in the first three blessings or in Modim, only later, in the blessing for peace. The Tur also quotes Tractate Soferim (an early collection of rules for Torah scrolls and prayer) as allowing such lines only on Rosh Hashanah and Yom Kippur, and only "with difficulty."
Rav Hai Gaon (head of a great academy in Babylonia about 1,000 years ago) disagreed. He wrote that the rule is about one person's private needs. Needs of the community are allowed. This line is plural: "all the children of Your covenant."
The Tur says people already had the custom of saying these lines through all ten days. The Mishnah Berurah (a central commentary on daily Jewish law, from around 1900) adds that the Geonim set them. That is why someone who forgets one of these lines does not go back for it once he has said God's Name at the end of that blessing.
So the rule was never erased. Rav Hai's reason is that this is a request for the whole community. And the Tur tells us the custom went further than Tractate Soferim allowed: from Rosh Hashanah and Yom Kippur to all ten days.
Berakhot 34a,Tur, Orach Chaim 582,Tractate Soferim 19:8,Mishnah Berurah 582:15-16Does God really keep a book with my name in it?
The picture comes from the Gemara (the rabbis' discussions built on the Mishnah). Rabbi Kruspedai says in the name of Rabbi Yochanan (a leading sage of the Land of Israel) that three books are opened on Rosh Hashanah: one for the completely wicked, one for the completely righteous, and one for people in between. The completely righteous are written and sealed for life right away, and the completely wicked for death. The people in between are left hanging from Rosh Hashanah until Yom Kippur. If they earn it, they are written for life. If not, for death.
That waiting time, from Rosh Hashanah to Yom Kippur, is the Ten Days of Repentance. The Rambam (Maimonides, 1100s) gives the same three groups. He says the in-between person is sealed for life if he returns to doing right, and for death if he does not.
Where do you fit? The Rambam says to see yourself, all year, as if you were half merit and half guilt, and the whole world as half and half. One sin, or one mitzvah, can tip the scale for you and for the world. He says that is why people give more charity and do more mitzvot in these days.
The Gemara also says what can tear up a decree: charity, crying out to God, changing your name, and changing your actions. Rabbi Yitzchak, who says this, also says that a person is judged only by what he is doing at that time.
These texts speak in pictures: books, a scale, being sealed. They do not say how literally to take them. They do say that the verdict is not fixed in advance, and that what a person does in these days can change it.
Rosh Hashanah 16b,Rambam, Laws of Repentance 3:3-4It says "for all of them." Does that include the bad things too?
"All of them" points back to everything in the thank-you blessing: your life, your soul, the miracles of every day, evening, morning and noon. A fair question is whether it also covers the parts of the year that were not good.
The Mishnah (the core text of the Oral Torah) is direct. A person must bless for the bad just as he blesses for the good. One of its readings of "with all your might" in the Shema is: for every measure God measures out to you, thank Him with everything you have. The word for "thank" there has the same root as modim.
But the Mishnah does not call the bad good. It gives different blessings. For rain and good news: "the Good and the One who does good." For bad news: "the true Judge." You do not pretend a bad day was a good one. You say the blessing that fits it.
The Gemara also gives a saying credited to Rabbi Meir and to Rabbi Akiva (two sages of the Mishnah): get used to saying, "Everything God does, He does for the best." It tells of Rabbi Akiva being refused a place to stay in a town and sleeping in a field, where his rooster, donkey and candle were each lost. That night an army took the town captive. Rabbi Akiva said: "Didn't I tell you? Everything God does is for the good."
Our blessing ends "The Good is Your Name." Abudarham ties that to Eichah 3:25, "Hashem is good to those who hope in Him." Eichah (the book read on Tisha B'Av, about the destruction of Jerusalem) is also where Modeh Ani gets its last words, two verses earlier.
None of these sources explains why bad things happen. They give a way to speak: the blessing that fits the news, and thanks that does not wait for everything to be good.
Mishnah Berakhot 9:5 and 9:2,Berakhot 60b,Abudarham, Weekday Prayers, Amidah,Eichah 3:23-25