Both sections of the advice arrived in the language she is not learning
Reported from the phone: "I have my main language set as Portuguese and I say
I'm learning English but yet Petal presents the Ask Petal advice in both
sections as Portuguese."
Nothing was wrong with targetFor again. A Portuguese document by a Portuguese
writer is explained in Portuguese, which is the whole point of Phase 28. The
card was right. What was wrong was the tap underneath it: /suggestions/{id}
/translate answered "" for exactly that case, on the reasoning that an
unasked-for English rendering of an explanation she can already read is not a
seed but noise. That reasoning had the writer facing the wrong way. She is
learning English. The half she is *practising* is the half worth a tap, and the
bubble sits directly beneath the explanation inside the same card, so answering
"" left her with Portuguese, the same Portuguese again, and no English anywhere
on the card. targetFor's own comment promised the other language stays one tap
away in both directions; only one direction had ever been built.
So the endpoint keeps the one rule it always claimed: render into whichever
half the explanation is not already in. English explanation into her language,
as before; her language into the English she is learning, which is new. Both
ends of that are now parameters — TranslateMessages took the source language
for granted as English because until Phase 28 it always was. The zh prompt is
unchanged byte for byte, which its test still pins.
The client fallback was the same symptom from a different cause and would have
survived the server fix: an empty answer, or an unreachable model, seeded the
bubble with the explanation itself — a verbatim repeat of the line two above
it, which reads as Petal replying in the language the tap was pressed to
escape. With the endpoint always having somewhere to go, empty now means only
that the model didn't answer, so the panel opens with no bubble at all and the
input where she can ask. AskPetal no longer takes the explanation as a prop; it
never needed anything but the id.
The test that pinned the refusal now pins the rendering, and carries the report.
Claude-Session: https://claude.ai/code/session_01KGACAtTPjvZ2PipDZ5qD99
This commit is contained in:
@@ -371,10 +371,15 @@ func seedExplanation(t *testing.T, h *Handler, docID, explanation string) string
|
||||
|
||||
// The tap-through has to read the same decision the card was written under. On a
|
||||
// Portuguese document by a Portuguese writer the explanation already arrived in
|
||||
// Portuguese, and the old endpoint would have sent it to the model to be
|
||||
// rendered into Portuguese again.
|
||||
func TestTranslateSkipsWhenTheExplanationIsAlreadyHers(t *testing.T) {
|
||||
client := &stubClient{response: "Não devia ser chamado."}
|
||||
// Portuguese, so the destination is the other half of the pair — the English she
|
||||
// is practising — and never Portuguese into Portuguese again.
|
||||
//
|
||||
// This pins the report that "Petal presents the Ask Petal advice in both
|
||||
// sections as Portuguese": the endpoint used to answer "" here, which left the
|
||||
// card Portuguese, the bubble beneath it the same Portuguese, and no English on
|
||||
// the card at all for a writer whose whole reason for the pair is English.
|
||||
func TestTranslateRendersHerExplanationIntoTheEnglishSheIsLearning(t *testing.T) {
|
||||
client := &stubClient{response: "Use this one here."}
|
||||
srv, docID, h := newDirectedServer(t, client, "pt-PT", auth.DirectionLearningEn, ptDocument)
|
||||
setDocLang(t, h, docID, docLangPair)
|
||||
sugID := seedExplanation(t, h, docID, "Aqui usa-se isto.")
|
||||
@@ -387,11 +392,14 @@ func TestTranslateSkipsWhenTheExplanationIsAlreadyHers(t *testing.T) {
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
|
||||
t.Fatalf("decode: %v", err)
|
||||
}
|
||||
if out.Translation != "" {
|
||||
t.Fatalf("translation = %q, want empty: the bubble seeds from the explanation itself", out.Translation)
|
||||
if out.Translation == "" {
|
||||
t.Fatal("a Portuguese explanation left the tap with nowhere to go")
|
||||
}
|
||||
if client.calls != 0 {
|
||||
t.Fatal("the model was asked to render Portuguese into Portuguese")
|
||||
if !strings.Contains(client.lastPrompt, "into natural, friendly English") {
|
||||
t.Fatalf("translate didn't render into English:\n%s", client.lastPrompt)
|
||||
}
|
||||
if strings.Contains(client.lastPrompt, "into natural, friendly European Portuguese") {
|
||||
t.Fatalf("the model was asked to render Portuguese into Portuguese:\n%s", client.lastPrompt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,11 +30,18 @@ type translateResponse struct {
|
||||
// this endpoint has to read the same decision back, or it round-trips Portuguese
|
||||
// into Portuguese and calls it a translation.
|
||||
//
|
||||
// So: render into whichever half the explanation is NOT already in, and when the
|
||||
// explanation already arrived in the language this bubble exists to reach her
|
||||
// in, skip the model call and answer "". The client seeds the bubble with the
|
||||
// explanation itself when the translation comes back empty, which is exactly
|
||||
// right — there is nothing to add.
|
||||
// So: render into whichever half the explanation is NOT already in — and that
|
||||
// is the whole rule, in both directions. When it first shipped this endpoint
|
||||
// answered "" for a Portuguese explanation on the reasoning that an English
|
||||
// rendering she hadn't asked for was noise. It was reported as the opposite: a
|
||||
// writer whose pair is Portuguese and English, learning English, met a
|
||||
// Portuguese card with a Portuguese bubble under it and no English anywhere on
|
||||
// the card. The tap is the one place the other language was promised, and the
|
||||
// half she is *practising* is exactly the half worth a tap.
|
||||
//
|
||||
// The bubble sits directly beneath the explanation inside the card, so between
|
||||
// the two the writer always has both languages, whichever way round the document
|
||||
// put them.
|
||||
func (h *Handler) translate(w http.ResponseWriter, r *http.Request) {
|
||||
sugID := chi.URLParam(r, "id")
|
||||
|
||||
@@ -69,15 +76,14 @@ func (h *Handler) translate(w http.ResponseWriter, r *http.Request) {
|
||||
// today; the alternative is a language column on every suggestion row, and the
|
||||
// cost of being wrong is one bubble seeded in the language it was already in.
|
||||
target := targetFor(pairLang, direction, docLang)
|
||||
if target.Explain.Code == target.Pair.Code {
|
||||
// Already in her language. The other half is English — the language she is
|
||||
// practising — and an unasked-for English rendering of an explanation she
|
||||
// can already read is not a seed, it's noise.
|
||||
httputil.WriteJSON(w, http.StatusOK, translateResponse{Translation: ""})
|
||||
return
|
||||
from, to := target.Explain, target.Pair
|
||||
if from.Code == to.Code {
|
||||
// The explanation is already in her language, so the half this tap has to
|
||||
// reach is the other one: the English she is practising.
|
||||
to = llm.English
|
||||
}
|
||||
|
||||
out, err := llm.RunTranslate(r.Context(), h.Client, explanation, target.Pair)
|
||||
out, err := llm.RunTranslate(r.Context(), h.Client, explanation, from, to)
|
||||
if err != nil {
|
||||
httputil.UpstreamError(w, "translate", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user