Skip to content

fix(skill-reco): prefetch the TUI catalogue so a fresh session can recommend - #816

Merged
huichen merged 3 commits into
mainfrom
fix/skill-reco-tui-catalogue
Sep 24, 2026
Merged

huichen merged 3 commits into
mainfrom
fix/skill-reco-tui-catalogue

Conversation

@huichen

@huichen huichen commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Why no card ever appeared in a fresh TUI session

The TUI's recommender picks from catalogue − installed, and that catalogue was
only ever loaded by the /skills panel. A session that had not opened the panel
therefore had an empty candidate set: recommendation_gates_pass refused
every message, the Jev call was never made, and the message was sent normally —
no card, no spinner, no explanation.

Reproduced against a real TUI: type 查询一下老年痴呆都有哪些常见的致病基因 in a
session that never opened /skills, press Enter → the message is sent straight
away. Direct probe of the gateway with the same question and the same candidate
list answers primekg 0.68 (none 0.10, gate 0.15), i.e. a card should have
appeared — the TUI simply never asked.

The desktop client has no such gap: it loads the catalogue when it mounts,
long before a 30-byte draft exists.

The fix

The TUI now does the equivalent, keyed off the draft rather than the startup:

  • handle_input_changed starts a quiet future skills list --json as soon as a
    draft could produce a card (same rules the gate uses: the toggle, not a slash
    command, inside the length window, no /skill already picked) — so the load
    runs while the user is still typing. A session that never writes a recommendable
    message never pays for the child (it reaches the platform over HTTP; ~0.15 s
    here).
  • maybe_recommend_skill starts it too, for a draft that never went through the
    input's change callback (-p, a scripted submit). It is never awaited: a send
    is not held for a catalogue.
  • Quiet by construction: its own UiCmd::SkillsCataloguePrefetched because
    nothing on screen asked for the call. Success fills the same cache the panel
    fills; failure is dropped, since the panel is where a catalogue problem is
    reported (opening it, or r, retries). One attempt per session, so a failure
    cannot become a child process per keystroke.
  • draft_could_be_recommended is split out of recommendation_gates_pass, so the
    prefetch asks the same question the gate asks instead of a second copy of those
    four rules that can drift.

Verification

  • Real TUI, isolated agent home (fresh port, own socket), session that never
    opened /skills: type the question, press Enter → Looking for a skill that fits…, then the card Recommended skill /primekg … with the draft still held.
    Agent log: skill reco: recommended a skill skill=primekg probability=0.44 none_probability=0.02 latency_ms=1090.
  • Four new tests pin the prefetch, its silence on failure, that it waits for a
    recommendable draft, and that a submit starts it without holding the send. All
    four fail with the two call sites removed.
  • cargo fmt -p future-tui --check, cargo clippy -p future-tui --all-targets -- -D warnings, cargo test -p future-tui (2095 passed).

Not part of this PR

While verifying I also hit — twice out of four real attempts — the Jev round trip
exceeding the client's 3 s deadline (agent.log: skill reco: call failed; reason=timeout after 5000ms), in which case the draft is sent with no card and
again no explanation. That is the agent's Jev client / gateway latency, not the
catalogue (the same request took 0.65–1.1 s on the successful attempts and
1.1–1.5 s from curl). Worth a separate look; it is left alone here.

…commend

The TUI's recommender picks from `catalogue − installed`, and that catalogue was
only ever loaded by the `/skills` panel. So in a fresh session the candidate set
was empty, `recommendation_gates_pass` refused every message, and the feature
silently did nothing until the panel had been opened once — from the user's side,
"no recommendation ever appears". Verified against a real TUI: a 19-character
question in a session that never opened the panel produced no card, no spinner,
no explanation; the message just went out.

The desktop client has no such gap: it loads the catalogue when it mounts, i.e.
long before a 30-byte draft exists. The TUI now does the equivalent, keyed off
the draft instead of the startup: `handle_input_changed` starts a quiet
`future skills list --json` the moment a draft could produce a card (length
window reached, not a slash command, no `/skill` already picked), so the load
runs while the user is still typing — and a session that never writes a
recommendable message never pays for the child (which reaches the platform over
HTTP, ~0.15 s here). `maybe_recommend_skill` starts it too, for a draft that
never went through the input's change callback, and never holds a send for it.

The prefetch is quiet by construction: it has its own `UiCmd` because nothing on
screen asked for it — success fills the same cache the panel fills, failure is
dropped in silence (the panel is where a catalogue problem is reported, and
opening it, or `r`, retries). One attempt per session, so a failure cannot turn
into a child process per keystroke.

`draft_could_be_recommended` is split out of `recommendation_gates_pass` so the
prefetch asks the same question the gate asks, instead of a second copy of those
four rules that can drift from the first.

Verified on a real TUI against an isolated agent: the card (primekg) now appears
in a fresh session with the draft held. Four new tests pin the prefetch, its
silence on failure, that it waits for a recommendable draft, and that a submit
starts it without holding the send; all four fail with the two call sites
removed.
@huichen
huichen enabled auto-merge (squash) September 24, 2026 04:10
@huichen
huichen merged commit 75b2507 into main Sep 24, 2026
12 checks passed
@huichen
huichen deleted the fix/skill-reco-tui-catalogue branch September 24, 2026 04:16
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