xtekky/gpt4free · error · ValueError

No user message found in messages

Error message

No user message found in messages

What it means

After picking an archive entry from the embed FS, fs.Open on that exact name failed. Since the name came from the same FS's directory listing, this is nearly impossible unless the embed pattern, build cache, or the embedded data is inconsistent (e.g. stale go build cache after archives changed on disk).

Source

Thrown at g4f/Provider/BraveSearch.py:224

            for message in reversed(messages):
                if message["role"] == "user":
                    prompt = message["content"]
                    if isinstance(prompt, list):
                        prompt = (
                            "\n".join(
                                [
                                    item.get("text", "")
                                    for item in prompt
                                    if isinstance(item, dict)
                                ]
                            )
                            if prompt
                            else ""
                        )
                    break

        if not prompt:
            raise ValueError("No user message found in messages")

        # Initialize conversation if needed
        if conversation is None:
            conversation = Conversation()

        headers = {
            "accept": "application/json",
            "accept-language": "en-US,en;q=0.9",
            "cache-control": "no-cache",
            "pragma": "no-cache",
            "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
            "(KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36",
        }

        # Deep Research needs a much longer timeout
        timeout = DEEP_RESEARCH_TIMEOUT if is_deep else 120

        async with StreamSession(

View on GitHub (pinned to 973504e177)

Solutions

  1. Clean the build cache and rebuild: go clean -cache then go build — a stale cache is the most common cause
  2. Inspect embed/<os>/ contents: ensure only the expected <os>-<arch>-embed-<ver>.zip files are present and pickArchive's filter (in runtime.go above extractEmbedded) only matches zip files
  3. Tighten the go:embed pattern to embed/<os>/*.zip so non-archive entries can never be listed
  4. Run go vet / rebuild in a fresh module cache to rule out a corrupted embed

Example fix

// before
//go:embed embed/*
var embedRuntimeArchive embed.FS

// after
//go:embed embed/*/*.zip
var embedRuntimeArchive embed.FS
Defensive patterns

Strategy: validation

Validate before calling

entries, err := embeddedArchives()
if err != nil || len(entries) == 0 {
    return fmt.Errorf("no embedded runtime archive for this platform (run fetch-python.sh and rebuild)")
}
if _, statErr := embedRuntimeArchive.Open(entries[0]); statErr != nil {
    // embed FS inconsistent; force clean rebuild
    return fmt.Errorf("embed FS inconsistent for %s: %w (go clean -cache and rebuild)", entries[0], statErr)
}

Prevention

When it happens

Trigger: A stale Go build cache serving an embed FS whose directory listing and file contents disagree; manual tampering with embed/<os>/ between builds; an embed pattern that matched a directory entry rather than a file which pickArchive then selects.

Common situations: Rebuilding right after fetch-python.sh replaced archives while an old build cache is reused; pickArchive selecting a non-zip entry (e.g. a README or directory) that listing returned; unusual filesystem casing issues on case-sensitive hosts.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/a3abbc7748466379. Report an issue: GitHub.