How to go about chasing a bug like this?

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
op12no2
Posts: 340
Joined: Tue Feb 04, 2014 11:25 am
Location: Mumbles, Wales, UK.
Contact:

How to go about chasing a bug like this?

Post by op12no2 » Thu Feb 09, 2017 6:51 pm

I was watching Lozza play a game this evening, saw a jump in eval and decided to investigate. Usually I assume it's just a horizon thing because Lozza is a relatively slow Javascript engine being interpreted in real-time (i.e. the other engine usually looks deeper).

Pre move:-

[d] 8/4k3/1r6/p5RP/1b1pp3/3p2P1/5P2/1R4K1 w - - 0 61

Post move:-

http://op12no2.me/stuff/l1.jpg

http://op12no2.me/stuff/l2.jpg

As you can see, after Lozza played Rg7+ it all went to pot and for good reason.

If I send exactly the same UCI command (highlighted above from the Arena debug log) to Lozza in isolation (i.e. not in a game) - it finds Rd5 (same as Stockfish).

Image

So how the hell do you track things like that down. I'm guessing it's probably a TT bug. All I can think of is add a whole wodge of assert()s and try and catch inconsistency. I cannot think how to replicate it (*).

The TT is very simple: always replace.

If anybody is interested the source is here: http://op12no2.me/toys/lozzadev/lozza.js

It's a very simple engine and the TT stuff is in ttPut() and ttGet().

Any insights/advice gratefully received... :) But good news really, a proper bug!

(*)Ah - send all the go commands up to that move as well...?

op12no2
Posts: 340
Joined: Tue Feb 04, 2014 11:25 am
Location: Mumbles, Wales, UK.
Contact:

Re: How to go about chasing a bug like this?

Post by op12no2 » Thu Feb 09, 2017 8:06 pm

op12no2 wrote: (*)Ah - send all the go commands up to that move as well...?
Gosh - it worked - as in replicated the problem.

Code: Select all

1.18 100p | 2.1Mn | 2090312n | 3.6s | g5g7 | Rg7
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -
11/23 (44cp) Rg7 Kd8 Rg4 Bc5 Rd1 Re6 Kg2 a4 f3 e4xf3 Kxf3 Re3 
10/22 (52cp) Rg7 Kf8 Rd7 Rd6 Rxd6 Bxd6 h6 d2 h7 Kg7 
10/18 (34cp) Rd5 Rd6 Re5 Re6 Rd5 Rd6 Re5 Re6 Rd5 Rd6 Re5 Re6 Rd5 Rd6 Re5 Re6 Rd5 Rd6 
9/17 (50cp) Rd5 Rd6 Rxd6 Bxd6 h6 d2 h7 Be5 Kg2 
9/17 (34cp) Re5 Re6 Rd5 Rd6 Rxd6 Bxd6 h6 d2 h7 
8/17 (80cp) Re5 Re6 Rxe6 Kxe6 h6 Bd6 h7 Be5 
7/17 (80cp) Re5 Re6 Rxe6 Kxe6 h6 Bd6 h7 Be5 
6/17 (46cp) Re5 Re6 Rxe6 Kxe6 h6 Kd5 h7 
6/17 (9cp) Kg2 d2 Rg4 Re6 f3 e4xf3 
6/15 (8cp) Rd5 Rd6 Re5 Re6 Rxe6 Kxe6 h6 Kd5 
5/15 (20cp) Rd5 Rd6 Rxd6 Kxd6 h6 
5/15 (7cp) Rg7 Kd8 Kg2 d2 f4 Be7 
4/11 (20cp) Rg7 Kd8 Kg2 Rc6 Rf7 
3/8 (33cp) Rg7 Kd8 Kg2 Rc6 
2/7 (41cp) Rg7 Kd8 Rc1 
2/7 (15cp) Rd5 Rd6 Rxd6 Bxd6 Rd1 Ke6 Rxd3 
2/6 (9cp) Re5 Re6 Rb5 Kd6 Rxb4 
1/6 (16cp) Re5 Re6 Rxb4 a5xb4 Rxe6 Kxe6 
1/1 (-18cp) Rd5 

AlvaroBegue
Posts: 884
Joined: Tue Mar 09, 2010 2:46 pm
Location: New York

Re: How to go about chasing a bug like this?

Post by AlvaroBegue » Thu Feb 09, 2017 9:33 pm

I don't know how much of a bug it is. My engine thinks Rg7+ is best at depths 11 and 12, then prefers Rd5. But even mighty Stockfish likes Rg7+ at depth 8.

op12no2
Posts: 340
Joined: Tue Feb 04, 2014 11:25 am
Location: Mumbles, Wales, UK.
Contact:

Re: How to go about chasing a bug like this?

Post by op12no2 » Fri Feb 10, 2017 8:12 am

AlvaroBegue wrote:I don't know how much of a bug it is. My engine thinks Rg7+ is best at depths 11 and 12, then prefers Rd5. But even mighty Stockfish likes Rg7+ at depth 8.
Hi Álvaro, OK thanks for the info. I think what worries me is the completely different analysis outputs within and outside the game.

It's something to do with history move ordering as well - which I may dump in fact.

User avatar
hgm
Posts: 22327
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

Re: How to go about chasing a bug like this?

Post by hgm » Fri Feb 10, 2017 8:47 am

Indeed, dependence on previous moves can be a nuisance whe trying to reproduce problems. My engine CrazyWa is still in the stage where I clear hash table and history before every search (killers are self-clearing), to ensure reproducibility for easy debugging. But it is so stable now that I can consider dropping that, to gain a little bit of extra speed.

What sometimes helps when suspect symptoms do not reproduce when searching from the position where they occurred in a game, is starting from the position the move before, make sure it is searched to the same depth as in the game (by giving ample time, and a depth limit), then switching on the debug output (for which I usually build a command into the engine), enter the opponent move (and start a search if this is not automatic). The previous search might be enough to prepare the TT and history toa state that is close enough to reproduce the bug. Sometimes I go back even two full moves. If that doesn't work, I usually give up. When running from the command line it is easy to copy-paste the required set of commands to order the various searches into the engine.

op12no2
Posts: 340
Joined: Tue Feb 04, 2014 11:25 am
Location: Mumbles, Wales, UK.
Contact:

Re: How to go about chasing a bug like this?

Post by op12no2 » Fri Feb 10, 2017 12:11 pm

Thanks HG. I can reproduce it by sending the last 4 go commands but it only happens about 50% of the time. I can 'fix' it by turning off top level window shrinking - the in/out game analysis become similar and stable...

op12no2
Posts: 340
Joined: Tue Feb 04, 2014 11:25 am
Location: Mumbles, Wales, UK.
Contact:

Re: How to go about chasing a bug like this?

Post by op12no2 » Fri Feb 10, 2017 12:53 pm

The traces below show the analysis for the problem move, after 5 half moves leading up to it have loaded up the TT, each simplified to search to depth 12.

Existing code:-

Code: Select all

12/22 (40cp) Rg7 Kf8 Rd7 Rd6 Rxd6 Bxd6 f4 d2 h6 Kg8 Kf2 e3 
11/22 (52cp) Rg7 Kf8 Rd7 Rd6 Rxd6 Bxd6 f4 Kf7 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