I edited this a lot now, sorry.
In short:
When a critical filling is reached, the wagon/chest or whatever can "hold back" the inserters until one/the last remaining inserter (which is not holded) filled up the small rest.
In long:
I don't think that. I think, this will make more and more problems in the future.
And if you make an easier algorithm?
Provided, that you don't insert into it "by hand", the maximum change can be only the number of inserters, that load into it, right?
So, when X is the maximum items, which can be put into it,
and N is the number of inserters, that can load into it,
and M is the inserter-stack-size-bonus,
then beginning from X - N * M items loaded into it, there can be only one inserter, which loads. All other needs to be deactivated. Or better to be hold back.
Example:
X = 100 (maximium items)
N = 5 (inserters)
M = 3 (inserter-stack-size-bonus)
if there are loaded more than 84 items, then only one inserter can load. If more than 97 items, the inserter can take only the remaining number.
So in the worst case:
Beginning with 87 items which the first inserter has just put into it (before was 84 - which is below that limit - plus 3 is now 87, which is above), there are still 4 inserters "on the way" to load 3 items each into the wagon/chest or whatever. 3 * 4 = 12, so after that, the chest is filled with 99 items.
The wagon now "holds" these 4 inserters, it avoids the return.
The first inserter will then take the last item (it should be a way to tell him "I need only 1") and load it.
There is some space for optimizing this, but I think it can work quite well. I think this is also natural, because filling of big amounts into anything needs always a slowdown at the end to avoid this kind of "deadlock".
Can be seen the best when filling a bottle of beer into an empty glass: I need to slowdown cause of the foam.
This is btw. a good idea now: a cool beer.