Skip to content

test(skill-reco): pin the suggest_skill wire contract, and make its field name compiler-checked - #808

Merged
huichen merged 2 commits into
mainfrom
test/skill-reco-grpc
Sep 24, 2026
Merged

huichen merged 2 commits into
mainfrom
test/skill-reco-grpc

Conversation

@huichen

@huichen huichen commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

The problem

The recommendation had no test anywhere along its wire path, so a regression could
only surface as "the card never appears". Worse, one class of regression could not
surface at all.

The handler wrote its payload as hand-written JSON:

serde_json::json!({"skill": ...})

and future_rpc::encode reads that JSON back into SuggestSkillPayload with
serde_json::from_value(..).ok()?. A renamed key therefore fails nothing: the
encoder returns None, the response carries no typed payload, and the desktop's
.catch(() => null) turns that into "no recommendation" — while the agent still
logs a successful recommendation
. The feature would quietly stop working with
healthy-looking logs.

The fix

The handler serializes the shared payload type, so the field name is the
compiler's business on both sides instead of a string that only matches by
convention. Verified by renaming the field: the encoder, the decoder and the
handler now all fail to compile (before: silent, green, broken).

No wire change — {"skill": null} and {"skill": {...}} serialize exactly as
before, which the empty-answer test pins.

The tests

Each was verified to fail on the drift it covers:

test on drift
suggest_skill_response_encodes_into_the_typed_payload (agent) skill key must be present: {"suggestion":null}
suggest_skill_round_trips_between_typed_payload_and_json (rpc) JSON → proto → JSON, the path the desktop and the mobile relay both parse
suggest_skill_round_trips_an_empty_answer_as_a_null_skill (rpc) asserts skill decodes as null rather than going missing — what the client's Option<SkillCandidate> is written against

What it came out of

An end-to-end pass over the RPC against an isolated agent home (own socket,
database and lock), 43 checks in five suites, all passing. Two findings beyond
the tests above:

  • Latency tail: 12% of my calls exceeded 1500 ms (max 2418 ms) while the
    client's deadline was 1500 ms — paid-for answers nobody saw. feat(skill-reco): lock the composer for the wait, and give it 3 s #807 has since
    raised it to 3000 ms; this data independently supports that choice. The large
    option tables (≈141 candidates, ≥2k tokens) never exceeded 1500 ms, so the tail
    comes from round-trip jitter rather than payload size.
  • Option wording decides near-miss races: an ambiguous prompt ("watercolour
    this photo, then make a PDF slide deck") picked the image skill 12/12 with one
    extra clause in its description, and 0/16 without it — the candidate text, not
    the request, decides those.

The suite itself (a plain-python grpcurl driver) stays out of the repo: it needs a
real credential and a live gateway, so it cannot run in CI.

Verified: future-rpc 123 (was 121), future-agent 1869 (was 1868), fmt and
clippy clean.

…ield name compiler-checked

The recommendation had no test anywhere along its wire path, so the only way a
regression could surface was as "the card never appears". Three additions, plus
the fix that removes the failure mode the tests were written to catch.

The handler wrote its payload as hand-written JSON:

    serde_json::json!({"skill": ...})

and `future_rpc::encode` reads that JSON back into `SuggestSkillPayload` with
`serde_json::from_value(..).ok()?`. A renamed key therefore does not fail
anything: the encoder returns `None`, the response carries no typed payload, and
the desktop's `.catch(() => null)` turns that into "no recommendation". The agent
still logs a successful recommendation, so the feature would quietly stop working
with healthy-looking logs. The handler now serializes the shared payload type, so
a rename breaks the build in all three places instead (verified by renaming the
field: the encoder, the decoder and the handler all stop compiling).

Tests, each verified to fail on the drift it covers:

* `suggest_skill_response_encodes_into_the_typed_payload` (agent) — runs the
  handler and feeds its `data` object to the encoder, asserting a typed payload
  comes back. Spelled with the wrong key, it fails with
  `skill key must be present: {"suggestion":null}`.
* `suggest_skill_round_trips_between_typed_payload_and_json` and its empty-answer
  sibling (rpc) — the JSON → proto → JSON path the desktop and the mobile relay
  both parse. The empty case asserts `skill` decodes as `null` rather than going
  missing, which is what the client's `Option<SkillCandidate>` is written against.

No wire change: `{"skill": null}` and `{"skill": {...}}` serialize exactly as
before, which the empty-answer test pins.

The suite this came out of (scripts/skill_reco/suggest-skill-tests.py, run
against an isolated agent home) exercised 43 checks over the RPC: the typed-payload
shape, every failure collapsing to "no recommendation", input that must never
reach the network (blank query or no candidates, with a credential present so the
input check is what stops it), the refusal gate, order independence, the 254
candidate cap against the gateway's 255-option limit, CJK text, and concurrency.
@huichen
huichen enabled auto-merge (squash) September 24, 2026 00:54
The suite that found the payload-drift risk (43 checks, five suites) lived in /tmp
and would have been lost. It is committed now, documented in the harness doc, and
deliberately kept out of CI: it needs grpcurl, a real credential and a live
gateway, so it costs money and depends on the network.

  future agent --home /tmp/reco-test --verbose --log-file
  python3 scripts/skill_reco/suggest-skill-tests.py            # ~33 calls, ≈¥0.04
  python3 scripts/skill_reco/suggest-skill-tests.py --only A,B,D # the free suites
  python3 scripts/skill_reco/order-sensitivity.py --runs 8

Suites: A credential/availability, B input validation (no network), C real gateway,
D protocol shape and concurrency, E boundaries. `--only A,B,D` spends nothing.

order-sensitivity.py is separate because its question needs a distribution, not an
answer: one pair of calls looked order-sensitive during the pass, and repeating each
order showed both produced the same set of answers — run-to-run noise, not ordering.
That run also produced the more useful finding that the option text decides
near-miss races (one extra clause took an ambiguous prompt from 0/16 to 12/12).

Both scripts take FUTURE_REPO and RECO_TEST_HOME from the environment instead of
hard-coding this checkout.
@huichen
huichen merged commit 4af3ed5 into main Sep 24, 2026
22 of 24 checks passed
@huichen
huichen deleted the test/skill-reco-grpc branch September 24, 2026 01:12
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