The bug is reasonably common; I designed my own engines this way before I realized that it dit not work, and fixed it. I later moticed that GNUChess 5.07 also behaved this way, and now Matant.
The reason is that this is really what the description of the Winboard protocol suggests you should do:
time N
Set a clock that always belongs to the engine. N is a number in centiseconds (units of 1/100 second). Even if the engine changes to playing the opposite color, this clock remains with the engine.
It is the second sentence that causes the problem: the clocks do not belong to a certain color, they just seem to measure the time spent searching. This makes it logical to also count only the moves spent searching, or the amount of time it spent per move would start to depend on how often you change sides. E.g., if you set 40 moves in 40 minutes, but you would interpret it as that you should not exceed 40 min on your clock before the absolute move number is 40, changing side on each move would force the computer to do 80 moves in this time.
To prevent this kind of thing, I thought it quite natural to make the computer really play 40 moves in 40 minutes, if the level requested this. I.e. count the number of moves you actually do, so that you use the 40 min for the 20 white moves + 20 black moves the engine does. Of course the engine is then out of time at move 20, as it really expected to get new time at that point. After all, it had done 40 moves.
Now the problem is that Winboard does not behave according to the protocol definition. If you change the color during the game, the GUI does NOT swap the clocks of black and white, to make the clock stay with the engine!
The following definition enhances the impression that you start only measuring time. 'Associate' suggest that you keep the time that is on the clock. Otherwise it would have had to say "reset the clock to the time that color still has left on its GUI clock".
go
Leave force mode and set the engine to play the color that is on move. Associate the engine's clock with the color that is on move, the opponent's clock with the color that is not on move. Start the engine's clock. Start thinking and eventually make a move.
Of course Winboard now starts hiding the problem by synchronizing the clock before every move, so it accomplishes what the protocol definition says you should not do. But the protocol does not specify that you will get a
time and
otim command before every move. Winboard seems to do this, but there are other GUIs using Winboard protocol, and you can never be sure that they will all do it. It is not a requirement.
It is rather strange that Winboard does violate the spirit of its own protocol definition. Especially since it does it in such a way that it no longer works satisfactory with GNUChess. After all, the description says it is a GUI designed for GNUChess...
I am not sure if external books are clever enough to recognize that you return in book. If they do, they must handle it by sending the engine a force command after an earlier go command. And then, when you get out of book for the second time, send it again a go command. The important thing to realize is that with engines programmed like this, the move count is reset to the number specified in the level command every time it receives a go command. The time-remaining is usually as well, but is immediately overruled by new time commands.