chenhg5/cc-connect · error

index %d out of bounds

Error message

index %d out of bounds

What it means

parseDeleteBatchIndices rejects any single index that is not within the valid 1..max range. Each comma-separated item must parse as an integer and reference an existing item; zero, negative, or too-large indices produce this error.

Source

Thrown at core/engine.go:15688

			if start < 1 || end < 1 || start > end || end > max {
				return nil, fmt.Errorf("range %q out of bounds", part)
			}
			for idx := start; idx <= end; idx++ {
				if _, ok := seen[idx]; ok {
					continue
				}
				seen[idx] = struct{}{}
				indices = append(indices, idx)
			}
			continue
		}

		idx, err := strconv.Atoi(part)
		if err != nil {
			return nil, err
		}
		if idx < 1 || idx > max {
			return nil, fmt.Errorf("index %d out of bounds", idx)
		}
		if _, ok := seen[idx]; ok {
			continue
		}
		seen[idx] = struct{}{}
		indices = append(indices, idx)
	}

	return indices, nil
}

func (e *Engine) cmdDeleteBatch(p Platform, msg *Message, deleter SessionDeleter, sessions []AgentSessionInfo, indices []int) {
	lines := make([]string, 0, len(indices))
	for _, idx := range indices {
		matched := &sessions[idx-1]
		if line := e.deleteSingleSessionReply(msg, deleter, matched); line != "" {
			lines = append(lines, line)
		}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Use indices between 1 and the number of displayed items
  2. Re-list the history/session items to confirm valid indices before deleting
  3. Fix callers that build 0-based indices to add 1 before invoking the parser

Example fix

// before
parseDeleteBatchIndices("0,25", 20)
// after
parseDeleteBatchIndices("1,20", 20)
Defensive patterns

Strategy: validation

Validate before calling

idx, err := strconv.Atoi(part)
if err != nil || idx < 1 || idx > max {
    return fmt.Errorf("index must be between 1 and %d, got %q", max, part)
}

Try / catch

if _, err := parseDeleteBatchIndices(spec, max); err != nil {
    reply("bad index: %v (valid: 1-%d)", err, max)
}

Prevention

When it happens

Trigger: Passing an index like '0', '-1', or '25' when only 20 items exist (max=20) to parseDeleteBatchIndices, e.g. via a '/history delete 25' command.

Common situations: 1-based vs 0-based indexing confusion; the listed items changed since the user looked; off-by-one errors in generated specs.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/8edaf860d06ec4bf. Report an issue: GitHub.