Repository: syncthing/syncthing (language: go)

Issue:
panic: runtime error: index out of range [-1]
### What happened?

After some facepalm changes in the `.stignore` file, and then moving files into an ignored folder, and then realizing they would just be removed on other systems, reverting this, reverting that again, and more file-moving, I started receiving this error right after startup with no indication what might be the problem.

It started with v1.28.0, so I tried the new RC, but no difference.

It may not be related with the aforementioned file-moving. There's nothing in the logs that may indicate a source of the problem.

This happens _after_ the Completed initial scan of the aforementioned folder.

[error log.txt](https://github.com/user-attachments/files/17754642/error.log.txt)


### Syncthing version

v1.28.1-rc.1

### Platform & operating system

Windows 11 amd64

### Browser version

_No response_

### Relevant log output

```shell
[start] 2024/11/14 19:05:23 INFO: syncthing v1.28.1-rc.1 "Gold Grasshopper" (go1.23.3 windows-amd64) builder@github.syncthing.net 2024-11-12 09:50:19 UTC

[...]

[xxxxx] 2024/11/14 19:05:24 INFO: Completed initial scan of sendreceive folder "The Folder I Had Been Messing With" (xxxxx-xxxxx)
[xxxxx] 2024/11/14 19:05:25 INFO: Established secure connection to ABC at xx:22000-xx:22000/tcp-client/TLS1.3-TLS_AES_128_GCM_SHA256/WAN-P30-xxx
[xxxxx] 2024/11/14 19:05:25 INFO: Device xxx client is "syncthing v1.28.0" named "external device" at xxx:22000-xxx:22000/tcp-client/TLS1.3-TLS_AES_128_GCM_SHA256/WAN-P30-xxx
[xxxxx] 2024/11/14 19:05:25 INFO: Completed initial scan of sendreceive folder "Some Other Folder" (xxxxx-xxxxx)
Panic at 2024-11-14T19:05:26+01:00
panic: runtime error: index out of range [-1]

--- See error.log attached as its too large for the issue body
```



Discussion / hints:
So the moving around probably did confuse something, and it triggers a debug log that tries to describe an index inconsistency, but there is a bug so it crashes when doing that. 🤦  I'll push a fix for that shortly. You can probably work around the problem in the meantime by starting Syncthing from the command line once with `syncthing serve --reset-deltas` to force an index refresh. If that doesn't work, removing the folder and re-adding it would probably fix it.

Fix patch:
diff --git a/lib/model/indexhandler.go b/lib/model/indexhandler.go
index 407821bb520..f72315310d6 100644
--- a/lib/model/indexhandler.go
+++ b/lib/model/indexhandler.go
@@ -448,7 +448,7 @@ func (s *indexHandler) receive(fs []protocol.FileInfo, update bool, op string, p
 	seq := fset.Sequence(deviceID)
 
 	// Check that the sequence we get back is what we put in...
-	if lastSequence > 0 && seq != lastSequence {
+	if lastSequence > 0 && len(fs) > 0 && seq != lastSequence {
 		s.logSequenceAnomaly("unexpected sequence after update", map[string]any{
 			"prevSeq":     prevSequence,
 			"lastSeq":     lastSequence,


Test patch: