JuliusBrussee/caveman · error

history requires memory id

Error message

history requires memory id

What it means

History rejects an empty or whitespace-only memory ID because lineage cannot be looked up without one. The store requires a non-blank id before querying the memories table, failing fast with this message instead of issuing a doomed lookup.

Solutions

  1. Pass the actual memory ID returned by a previous Remember/Supersede call.
  2. Validate/trim the ID at the call site and return a clear user-facing message when blank.
  3. For CLI usage, require the id argument/flag up front (flag wiring or cobra Args validation).

Example fix

// before
chain, err := store.History(flagID) // flagID may be ""
// after
flagID = strings.TrimSpace(flagID)
if flagID == "" {
	return fmt.Errorf("--id is required for history")
}
chain, err := store.History(flagID)
Defensive patterns

Strategy: validation

Validate before calling

id = strings.TrimSpace(id)
if id == "" { return fmt.Errorf("memory id required") }

Try / catch

chain, err := store.History(id)
if err != nil && strings.Contains(err.Error(), "requires memory id") {
	return fmt.Errorf("provide a memory id (from remember/supersede output)")
}

Prevention

When it happens

Trigger: Calling Store.History("") or Store.History(" ") — typically when an upstream variable (CLI flag, struct field, parsed ID) was never populated.

Common situations: A CLI invocation missing the --id flag so an empty string is passed through; a caller splitting an output string that yielded an empty ID; uninitialized struct field before calling History.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/9d8f083a44377041. Report an issue: GitHub.

Appendix: source

Thrown at mem/store.go:279

		Text:       newText,
		CreatedAt:  now,
		ValidFrom:  now,
		Supersedes: oldID,
	}, nil
}

func validateMemorySize(text string) error {
	if len(text) > MaxMemoryBytes {
		return fmt.Errorf("%w: memory is %d bytes, over the %d-byte cap", ErrMemoryTooLarge, len(text), MaxMemoryBytes)
	}
	return nil
}

// History returns the complete oldest-to-newest supersession chain containing
// id. Broken/cyclic lineage is rejected rather than returning partial history.
func (s *Store) History(id string) ([]Memory, error) {
	if strings.TrimSpace(id) == "" {
		return nil, fmt.Errorf("history requires memory id")
	}
	current, err := s.memoryByID(id)
	if err != nil {
		return nil, err
	}
	seen := map[string]bool{current.ID: true}
	var before []Memory
	cursor := current
	for cursor.Supersedes != "" {
		prev, err := s.memoryByID(cursor.Supersedes)
		if err != nil {
			return nil, fmt.Errorf("broken supersession history at %s: %w", cursor.ID, err)
		}
		if seen[prev.ID] {
			return nil, fmt.Errorf("cyclic supersession history at %s", prev.ID)
		}
		seen[prev.ID] = true
		before = append(before, prev)

View on GitHub (pinned to 3ee70a1026)