Skip to content

A web fetch selection of only dots returns the whole document and still reports success #790

Closed

Description

What happens

pick(value, selector) tokenizes the selector with:

const steps = selector.match(/[^.[\]]+|\[-?\d+\]/g) ?? []

The character class matches neither . nor [ or ], so a selector built only from those characters yields an empty steps array. The for loop body never runs and pick returns current, which is still the whole parsed document.

shapeJson then computes missing = select.filter((s) => picked[s] === undefined). Nothing is missing, so the note reads selected 1 path from N characters and the not found: clause is suppressed.

Why it is wrong

The model asked to keep one narrow path, is told the selection worked, and instead receives the entire body — up to 40,000 characters of unrelated JSON plus (Selection truncated at 40,000 characters; select narrower paths.).

The not found: note is the only signal that would have told it to retry, and that is exactly the signal that gets suppressed. It costs a wasted turn on a 40 KB payload.

This is the "reports a selection that did not happen" class: the tool claims success while returning something else entirely.

Reproduction

const pypi = { info: { name: "modal" }, releases: Object.fromEntries(...) }  // > 40 KB

pick(pypi, ".")   // the entire pypi object, not undefined
pick(pypi, "..")  // the entire pypi object, not undefined
pick(pypi, "[")   // the entire pypi object, not undefined

const shaped = shapeJson(JSON.stringify(pypi), ["."])!
shaped.note       // "selected 1 path from 41,000 characters" — no "not found: ."

The existing pick reads dotted keys, indexes and the last element test covers dotted keys, [-1], a missing key, and an index on a non-array, but never a selector that matches no step at all.

Suggested fix

Return undefined when the selector names no step, so the existing not-found reporting handles it:

if (!steps.length) return undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions