Coach: a failed run on the phone says why, a message with no plan asks for one, the chat has context

- Phone with own key: the provider's or validator's reason reaches the chat line and toast
  (BYOK_ERRORS + jobErrorText); no more "instance owner" wording where there is none (#58)
- CoachChat: a message with no routines refines/creates instead of reviewing an empty window;
  menu entry "Start a new plan" (Discord "Coach reset" thread)
- payload: refine without a previous plan becomes a create with userNote; the last six chat
  lines travel as `conversation` (documented in common.md, prompts.js regenerated)
- OpenAI model list cut to Chat-Completions models (isChatModel); Gemini placeholder names AQ. keys
- 3 new strings in 14 packs, pt-BR guard 626/616/3db560d7; tests for all of it
This commit is contained in:
Duarte Santos committed 2026-09-07 17:05:07 +02:00
1 parent 5c2005e81f
commit d0aaa7205d
26 files changed
+208 -13

No files matched your search

+20 -1
View File
@@ -36,7 +36,7 @@ const local = async () => {
// There is no admin card on a phone: the user is the operator, so failures go to them.
localMod.setNotifier(ev => {
const toast = useUI.getState().toast
if (ev.kind === 'failed') toast(JOB_ERRORS[ev.errorClass] || JOB_ERRORS.internal)
if (ev.kind === 'failed') toast(jobErrorText(ev.errorClass, ev.detail))
else if (ev.kind === 'nochange') toast(t('Nothing to change right now: {0}', String(ev.reading || '').slice(0, 140)))
})
}
@@ -131,3 +131,22 @@ export const JOB_ERRORS = {
noworkout: 'There is no workout to look at yet — log one first.',
internal: 'Something went wrong on the server.'
}
// The same failures on a phone that brought its own key: there is no instance owner to
// check anything, the person reading this is the operator, and the provider's own words
// are the only thing that lets them fix it (a spent quota, a wrong model, a rejected key).
export const BYOK_ERRORS = {
auth: 'Your AI provider rejected the key on this phone — check it under Settings → AI Coach.',
missing: 'The Coach isn’t set up on this phone — check Settings → AI Coach.',
provider: 'Your AI provider couldn’t answer.',
unusable: 'The Coach answered with something the app couldn’t use.',
internal: 'Something went wrong on this phone.'
}
/** The line the person sees for a failed job — with the reason attached where they can act on it. */
export function jobErrorText(cls, detail) {
const own = LOCAL()
const base = (own && BYOK_ERRORS[cls]) || JOB_ERRORS[cls] || (own ? BYOK_ERRORS.internal : JOB_ERRORS.internal)
const why = own && detail ? String(detail).trim().slice(0, 300) : ''
return why ? `${base}\n${why}` : base
}
+7 -2
View File
@@ -150,9 +150,14 @@ async function run(S, kind, opts, d, adapter) {
invokeOpts: { env: envOf(d, key), fetch: nativeFetch }
})
if (!attempt.ok) {
lastError = { errorClass: attempt.errorClass, detail: attempt.detail || null }
// There is no admin card on a phone, so the reason has to reach the person holding it:
// the provider's own words for a refusal, the validator's for an answer that did not fit.
const detail = attempt.detail || (Array.isArray(attempt.errors) && attempt.errors.length
? attempt.errors.slice(0, 3).map(String).join(' · ').slice(0, 300)
: null)
lastError = { errorClass: attempt.errorClass, detail }
last = { id: job.id, kind, outcome: 'failed', errorClass: attempt.errorClass, at: Date.now() }
if (notify) notify({ kind: 'failed', errorClass: attempt.errorClass, detail: attempt.detail || null })
if (notify) notify({ kind: 'failed', errorClass: attempt.errorClass, detail })
return
}
if (attempt.nochange) {
+14
View File
@@ -95,6 +95,20 @@ describe('the Coach on a phone with its own key', () => {
expect(wire.calls).toHaveLength(2)
expect(f.pending).toBeNull()
expect(f.lastError.errorClass).toBe('unusable')
expect(f.lastError.detail).toMatch(/JSON|object/i) // the validator's reason reaches the phone — there is no admin card
})
it('a provider refusal carries the provider’s own words, so the person holding the key can act on it', async () => {
// A 4xx the adapter does not retry (429 would wait out two retries first); the wording is OpenAI's.
wire.answer = { status: 404, body: { error: { message: 'The model `gpt-4o-mini-tts` does not exist or you do not have access to it.' } } }
const seen = []
local.setNotifier(ev => seen.push(ev))
await local.localReview(state())
const s = await settle()
expect(s.lastError.errorClass).toBe('provider')
expect(s.lastError.detail).toMatch(/^404 The model `gpt-4o-mini-tts` does not exist/)
expect(seen.at(-1)).toMatchObject({ kind: 'failed', errorClass: 'provider', detail: expect.stringMatching(/does not exist/) })
local.setNotifier(null)
})
it('a 401 is an auth failure, and never a proposal', async () => {
+2 -2
View File
@@ -28,10 +28,10 @@ describe('Brazilian Portuguese locale', () => {
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(626)
expect(inherited).toHaveLength(613)
expect(inherited).toHaveLength(616)
// If this fails, review the changed keys and wording before accepting a new hash. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('81d277306b3029090b7a2ba6cc19108ca207ea65d738487155123260b6e9525d')
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('3db560d7104c324bcc54c94867c5f1e2b7f5eedf393d55e424b1c8d0bd5e7901')
})
test('does not leak European Portuguese UI terms', () => {