Skip to content

papers search + snippet-search + author papers: add --fields-of-study filter - #133

Open
gas2own wants to merge 4 commits into
mainfrom
snippet-search-fields-of-study
Open

gas2own wants to merge 4 commits into
mainfrom
snippet-search-fields-of-study

Conversation

@gas2own

@gas2own gas2own commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The S2 graph API accepts a fieldsOfStudy filter on several endpoints, but the asta CLI had no way to send it. asta papers snippet-search exposed only --fields, --limit, --date and --inserted-before; asta papers search exposed only --fields, --limit and --date; asta papers author papers exposed only --fields and --limit. The only mention of the name in the codebase was in the semantic-scholar skill's list of returned paper fields — i.e. fieldsOfStudy as data you can ask for, not as a filter you can apply.

The gap was invisible from the outside: the API ignores unknown query parameters rather than rejecting them, so there was no error to hint that the filter wasn't reaching the endpoint.

Endpoint coverage — probed, not assumed

Because unknown parameters are silently ignored, the discriminating test for "does this endpoint support the filter" is a bogus value: an endpoint that parses the parameter must return zero results, while one that ignores it returns the unfiltered set. Comparing a real value against no filter is not sufficient — an ignored parameter and a non-restrictive one look identical.

Client method Endpoint fieldsOfStudy? Evidence
search_papers /paper/search honoured → exposed total 7,658,412 → 278,385 for Computer Science; bogus value → total 0
snippet_search /snippet/search honoured → exposed bogus value → {"data": []} at HTTP 200
get_author_papers /author/{id}/papers honoured → exposed bogus value → 0 rows; Medicine → 81 rows (of a 500 cap) for one author, 12 of 219 for another
get_paper_citations /paper/{id}/citations ignored bogus value returns the unfiltered set, byte-identical to what a made-up parameter name returns
get_paper_references /paper/{id}/references ignored same
search_author /author/search ignored bogus value → same 5 rows, same total
get_paper /paper/{id} n/a single-paper lookup, not a search

/paper/search/bulk does accept fieldsOfStudy (bogus value → total 0), but the client doesn't wrap that endpoint at all — exposing it would be a new command, not a consistency fix, so it's out of scope here.

Correction to an earlier revision of this PR: its table listed /author/{id}/papers as "not accepted". That was wrong — it rested on a probe that only covered citations/references/author-search. The endpoint does filter server-side, so the flag is now exposed there too, which is what makes the three search-shaped commands consistent.

Change

  • --fields-of-study on asta papers search, asta papers snippet-search and asta papers author papers, passed through as fields_of_study to the corresponding client method and serialized as fieldsOfStudy. Omitted from the request when unset, so existing behaviour is unchanged.
  • The semantic-scholar skill documents the flag on all three commands, with the vocabulary and matching semantics in one shared Filtering by field of study section that each option list links to instead of duplicating. That section also records which commands don't have the filter and why, so a reader doesn't hand-append the parameter to citations and assume it applied.
  • Tests in tests/test_papers_cli.py: for each of the three commands, the flag reaches the client and defaults to None.

What the filter actually matches on

Two claims in earlier revisions of this PR were wrong; both are now corrected in the skill doc.

1. It is not classifier-only. An earlier revision said the filter "keys on the classifier-derived s2FieldsOfStudy". s2FieldsOfStudy in fact carries entries from two sources — source: "s2-fos-model" (S2's classifier) and source: "external" (publisher-supplied) — and a paper matches if the requested field appears under either:

Filtered query matches with field anywhere in s2FieldsOfStudy matches via s2-fos-model alone
/author/{id}/papers, Medicine 81/81 28/81
/paper/search protein folding, Computer Science 100/100 87/100

The union explains every returned paper; the classifier source alone explains a third to seven-eighths of them. The separate fieldsOfStudy field is only a narrower projection of the external labels — which is why a paper returned under --fields-of-study "Computer Science" can still come back showing fieldsOfStudy: ["Medicine"], and why a paper with no external label at all can match.

2. A paper carrying no field label is still returned. The first revision claimed the opposite. A CS-filtered /paper/search/bulk query returns papers whose external fieldsOfStudy is null.

One gotcha worth knowing

/author/{id}/papers omits the source: "external" entries from s2FieldsOfStudy unless fieldsOfStudy is requested alongside it. Ask for s2FieldsOfStudy on its own and only 28 of the 81 Medicine matches appear to carry the label, which reads as a broken filter; ask for both and all 81 do. The returned paper set is identical either way — only the label payload changes. /paper/search returns both sources regardless. The skill tells callers to request both fields on that command.

Testing

uv run --extra test pytest tests/test_papers_cli.py — 43 passed. uvx ruff format --check . and uvx ruff check . clean; scripts/validate-skills.py reports all 25 SKILL.md files valid. Beyond the mocked tests, the new flag was smoke-tested end-to-end through the real CLI against the live API (asta papers author papers 1751762 --fields-of-study "Medicine" returns exactly the 81 rows the raw endpoint probe predicted) — mocks alone can't catch the silently-ignored-parameter failure mode this PR is about.

The full suite has 14 pre-existing failures in this sandbox (tests/test_auth_helper.py, tests/test_auth_status_enhanced.py, tests/test_skills.py, tests/test_workspace_workflow.py) caused by make and npx being absent from the environment, not by this change.

Suggested-by: @jbragg

The S2 /graph/v1/snippet/search endpoint accepts a fieldsOfStudy filter,
but the asta CLI had no way to send it: snippet-search only exposed
--fields, --limit, --date and --inserted-before, so a caller could ask for
fieldsOfStudy as a returned paper field but could not restrict results by
it. Unknown query parameters are ignored server-side, so there was also no
error to hint at the gap.

Add --fields-of-study to the command and a fields_of_study passthrough on
SemanticScholarClient.snippet_search, document the vocabulary and matching
behaviour in the semantic-scholar skill, and cover the flag in the papers
CLI tests.
@gas2own
gas2own requested a review from regan-huff September 7, 2026 06:11
…tics

Extend the fieldsOfStudy filter to `asta papers search` so the two S2 search
surfaces the CLI exposes behave the same way. /graph/v1/paper/search honours
the filter server-side (a CS-filtered "protein folding" query drops total from
7.66M to 278k; a bogus value returns zero results), so the gap was the same
silent one snippet-search had.

Also correct a claim about matching: the filter keys on the classifier-derived
s2FieldsOfStudy, not on the externally-sourced fieldsOfStudy returned in
--fields. Probing shows CS-filtered results whose returned fieldsOfStudy is
["Medicine"] with "Computer Science" present only in s2FieldsOfStudy, and
bulk-search results with no external label at all. The previous note said a
paper carrying no field label would not match, which is wrong.

The vocabulary/matching notes now live in one "Filtering by field of study"
section that both commands link to, rather than duplicated per command.

The other S2 endpoints the client wraps (paper/{id}, citations, references,
author/search, author/{id}/papers) do not accept fieldsOfStudy, so there is
nothing to make consistent there. /paper/search/bulk does accept it but is not
wrapped by the client at all.

Suggested-by: @jbragg
@gas2own gas2own changed the title papers snippet-search: add --fields-of-study filter papers search + snippet-search: add --fields-of-study filter Sep 7, 2026
@gas2own

gas2own commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Independent AI code review (Codex)

Automated review of the PR by a separately invoked Codex reviewer. Prioritised P0/P1/P2; treat as advisory input for the human reviewer, not a merge gate.

P0 (blocking)

None.

P1 (should fix)

  • plugins/asta-tools/skills/semantic-scholar/SKILL.md:113 — “Request s2FieldsOfStudy in --fields” incorrectly applies to snippet search, whose --fields accepts only snippet fields and will reject s2FieldsOfStudy. Restrict this guidance to standard search and clarify that snippet search cannot return the classifier labels.

P2 (nits)

None.

Recommendation: request-changes

@gas2own

gas2own commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the AI review's sole finding in commit 9de4b01:

  • The shared field-of-study guidance now limits s2FieldsOfStudy retrieval to asta papers search and explicitly says snippet-search --fields accepts only snippet fields, so classifier labels cannot be returned there.

Validation: scripts/validate-skills.py reports all 25 skills valid; git diff --check is clean. No review findings remain open.

Completes the fieldsOfStudy consistency pass. /graph/v1/author/{id}/papers
does honour the filter server-side, contrary to what this PR previously
claimed: a bogus value returns zero rows, and "Medicine" narrows one author's
papers from 500 (the request cap) to 81 and another's from 219 to 12, with the
filtered set a strict subset for the author whose corpus fits under the cap.
The earlier probe that classed this endpoint as "not accepted" tested only
citations/references/author-search, which genuinely do ignore the parameter --
they return a result set identical to the unfiltered one, and identical to what
a made-up parameter name returns.

So add --fields-of-study to `asta papers author papers` and a fields_of_study
passthrough on get_author_papers.

Also correct the matching semantics the skill documents. The filter does not
key on the classifier labels alone. s2FieldsOfStudy carries entries from two
sources, source="s2-fos-model" and source="external", and a paper matches if
the requested field appears under either: every paper returned by a filtered
query carries the field somewhere in s2FieldsOfStudy (81/81 and 100/100 across
the two endpoints), whereas the classifier source alone accounts for only
28/81 and 87/100.

One endpoint-specific gotcha is worth documenting because it looks like a bug
in the filter: /author/{id}/papers omits the external-source entries from
s2FieldsOfStudy unless fieldsOfStudy is requested alongside it, so asking for
s2FieldsOfStudy on its own explains only 28 of the 81 matched papers. The
paper set itself is identical either way. /paper/search returns both sources
regardless.

Tests cover the flag reaching the client and defaulting to None.

Suggested-by: @jbragg
@gas2own gas2own changed the title papers search + snippet-search: add --fields-of-study filter papers search + snippet-search + author papers: add --fields-of-study filter Sep 7, 2026
@gas2own

gas2own commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Update — third command added, and a correction to my own earlier claims

Pushed 0c2b7a2. Two things changed since the last review pass, one of which contradicts what this PR previously asserted, so it's worth calling out rather than leaving in the diff.

1. asta papers author papers now has the flag too. The earlier revision's coverage table listed /author/{id}/papers as not accepting fieldsOfStudy. That was wrong — it rested on a probe that only covered citations/references/author-search. Re-probed with a bogus-value test (the only discriminating one, since unknown parameters are silently ignored):

Query Result
fieldsOfStudy=NotARealFieldXYZ 0 rows — parsed and applied
fieldsOfStudy=Medicine, author 1751762 81 rows (of a 500 request cap)
fieldsOfStudy=Medicine, author 2827616 12 of 219 rows, strict subset of unfiltered

Citations, references and author-search do genuinely ignore it — they return a result set identical to the unfiltered one and identical to what a made-up parameter name returns. The skill now documents that explicitly, so a reader doesn't hand-append the parameter there and assume it applied.

2. The documented match semantics were wrong. The previous revision said the filter "keys on the classifier-derived s2FieldsOfStudy". It actually matches the union of the two label sources inside s2FieldsOfStudy — source: "s2-fos-model" and source: "external":

Filtered query field anywhere in s2FieldsOfStudy via s2-fos-model alone
/author/{id}/papers, Medicine 81/81 28/81
/paper/search protein folding, Computer Science 100/100 87/100

Classifier-only would leave a third to seven-eighths of the returned papers unexplained; the union explains all of them.

Worth knowing when you sanity-check this yourself: /author/{id}/papers drops the external entries from s2FieldsOfStudy unless you request fieldsOfStudy alongside it. Ask for s2FieldsOfStudy alone and only 28 of the 81 matches look like they carry Medicine — which reads as a broken filter. Ask for both and all 81 do. The paper set is identical either way; only the label payload changes. /paper/search returns both sources regardless. This is what initially made me think the filter was misbehaving, hence the note in the skill.

Prior review finding: the single P1 from the earlier Codex pass (snippet-search --fields can't return s2FieldsOfStudy) remains resolved; the rewritten section preserves that caveat.

Validation: pytest tests/test_papers_cli.py 43 passed (41 before, +2 for the new flag); ruff check / ruff format --check clean; validate-skills.py all 25 valid; CI green on 0c2b7a2. Also smoke-tested end-to-end through the real CLI against the live API — asta papers author papers 1751762 --fields-of-study "Medicine" returns exactly the 81 rows the raw probe predicted, which mocked tests can't confirm for a silently-ignored-parameter bug.

One caveat on process: an independent AI review of this latest diff could not be fired from the runtime this turn ran on, so the changes above have not had a second-model pass. Details are in the originating thread.

Suggested-by: @jbragg

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant