Repository navigation
fix(website): show a refused workflow run in the output panel #19005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1a0587f
fix(website): a refused workflow run is shown where the reader is loo…
mariana953 576cbd8
fix(website): one sentence per refusal, and a way out that reaches so…
mariana953 0f96a80
fix(website): a shared word is not a shared meaning
mariana953 8f4e4d0
fix(website): one reader, one account of a refused run
mariana953 39d925a
fix(website): a code the page has never met is absent, not inherited
mariana953 2d95263
fix(website): a run Cloud reports failed is said once, by the panel
mariana953 fa0eaa5
test(website): a failed run outranks the error that dropped the conne…
mariana953 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import { WorkshopWorkflowError } from '../../config/workshop-workflow-api' | ||
| import type { RunFailure } from '../../config/workshop-run' | ||
| import type { | ||
| WorkflowErrorCode, | ||
| WorkflowRun, | ||
| WorkflowRunSummary | ||
| } from '../../config/workshop-workflow-response' | ||
| import type { WorkflowState } from '../../config/workshop-workflow-state' | ||
| import type { SavedWorkflow } from '../../config/workshop-workflow-storage' | ||
| import { failureLabelKey } from './failure-label' | ||
| import { panelSaysRefusal, workflowRunFailure } from './workflow-refusal' | ||
|
|
||
| // Every code the API can report and the refusal the panel stands up for it. The | ||
| // table is the specification: a code whose event the panel has no sentence for | ||
| // reads as undefined here, rather than as a sentence about something else. | ||
| const REFUSALS: readonly [ | ||
| WorkflowErrorCode | 'network' | 'response' | 'persistence', | ||
| RunFailure | undefined | ||
| ][] = [ | ||
| ['insufficient_credits', 'noCredits'], | ||
| ['rate_limited', 'rateLimit'], | ||
| ['network', 'network'], | ||
| ['response', 'response'], | ||
| ['execution_failed', 'provider'], | ||
| // What is wrong with an input belongs beside the input, and the panel's own | ||
| // words for a rejection it cannot pin to a field are about a model. | ||
| ['invalid_request', undefined], | ||
| ['invalid_input', undefined], | ||
| ['payload_too_large', undefined], | ||
| ['unsupported_media_type', undefined], | ||
| // A session that expired and a form gone out of date the panel has no word | ||
| // for at all. | ||
| ['not_authenticated', undefined], | ||
| ['workflow_not_found', undefined], | ||
| ['definition_changed', undefined], | ||
| ['definition_incompatible', undefined], | ||
| // Codes the panel has a word for, about a different event: a workspace Cloud | ||
| // denied is not a provider's content policy; an input upload that never | ||
| // arrived is not a model being down; outputs that could not be fetched after | ||
| // a run finished is not a connection that dropped mid-run; browser storage | ||
| // the page could not write names its own fix, which the panel's sentence | ||
| // does not. | ||
| ['access_denied', undefined], | ||
| ['media_unavailable', undefined], | ||
| ['delivery_failed', undefined], | ||
| ['submission_unknown', undefined], | ||
| ['persistence', undefined], | ||
| ['run_not_found', undefined] | ||
| ] | ||
|
|
||
| describe('workflowRunFailure', () => { | ||
| it.for(REFUSALS)('stands %s up as %s', ([code, refusal]) => { | ||
| expect(workflowRunFailure({ code })).toBe(refusal) | ||
| }) | ||
|
|
||
| // A code this page has not met yet is not given a sentence about something | ||
| // else; the page keeps saying what it says today. 'toString' is here because | ||
| // a plain object would have answered it with a method of its prototype. | ||
| it.for(['teapot', 'toString', 'constructor'] as const)( | ||
| 'claims nothing about %s, a code it does not know', | ||
| (code) => { | ||
| expect( | ||
| workflowRunFailure({ code: code as WorkflowErrorCode }) | ||
| ).toBeUndefined() | ||
| } | ||
| ) | ||
|
|
||
| it('only ever names a refusal the panel has words for', () => { | ||
| for (const [, refusal] of REFUSALS) | ||
| if (refusal) expect(failureLabelKey[refusal]).toBeTruthy() | ||
| }) | ||
| }) | ||
|
|
||
| // Whether the page keeps quiet beside the form follows from the same table: it | ||
| // speaks exactly where the panel does not, so the reader is never handed the | ||
| // same refusal twice, nor two different accounts of it. | ||
| describe('panelSaysRefusal', () => { | ||
| it.for(REFUSALS)('leaves %s to the panel only as %s', ([code, refusal]) => { | ||
| expect( | ||
| panelSaysRefusal({ | ||
| phase: 'failed', | ||
| error: new WorkshopWorkflowError(code) | ||
| }) | ||
| ).toBe(refusal !== undefined) | ||
| }) | ||
|
|
||
| it.for([{ phase: 'idle' }, { phase: 'preparing' }] as const)( | ||
| 'says nothing about a $phase page', | ||
| (state) => { | ||
| expect(panelSaysRefusal(state)).toBe(false) | ||
| } | ||
| ) | ||
|
|
||
| // A run Cloud accepted and then reported failed is the panel's to say, and it | ||
| // says it as a provider failure. The page used to add a second sentence of its | ||
| // own here — in different words, telling the reader to change the inputs the | ||
| // panel had just told them to leave alone. | ||
| it.for([ | ||
| { reported: 'failed', panel: true }, | ||
| { reported: 'succeeded', panel: false }, | ||
| { reported: 'cancelled', panel: false } | ||
| ] as const)( | ||
| 'leaves a run reported $reported to the panel: $panel', | ||
| ({ reported, panel }) => { | ||
| expect(panelSaysRefusal(observed(reported))).toBe(panel) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| ) | ||
|
|
||
| // A dropped connection is the one state that carries both: what Cloud last | ||
| // said about the run, and the error that dropped it. The run wins. Reading the | ||
| // error first would hand this back to the page, which has a second sentence | ||
| // ready for a code the panel cannot name. | ||
| it('leaves a failed run to the panel when the connection dropped on a code it has no words for', () => { | ||
| expect( | ||
| panelSaysRefusal({ | ||
| phase: 'interrupted', | ||
| record: RECORD, | ||
| observation: run('failed'), | ||
| error: new WorkshopWorkflowError('media_unavailable') | ||
| }) | ||
| ).toBe(true) | ||
| }) | ||
| }) | ||
|
|
||
| const RECORD: SavedWorkflow = { | ||
| version: 2, | ||
| cancelRequested: false, | ||
| stage: 'run', | ||
| runId: 'run', | ||
| workflowId: 'workflow', | ||
| definitionVersion: '1' | ||
| } | ||
|
|
||
| function run(state: WorkflowRunSummary['state']): WorkflowRun { | ||
| const stamp = new Date(0).toISOString() | ||
| return { | ||
| run: { | ||
| id: 'run', | ||
| workflowId: 'workflow', | ||
| definitionVersion: '1', | ||
| state, | ||
| outputState: 'ready', | ||
| createdAt: stamp, | ||
| updatedAt: stamp | ||
| }, | ||
| outputs: [] | ||
| } | ||
| } | ||
|
|
||
| function observed(state: WorkflowRunSummary['state']): WorkflowState { | ||
| return { phase: 'settled', record: RECORD, observation: run(state) } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import type { WorkshopWorkflowError } from '../../config/workshop-workflow-api' | ||
| import type { RunFailure } from '../../config/workshop-run' | ||
| import type { WorkflowState } from '../../config/workshop-workflow-state' | ||
|
|
||
| /** | ||
| * Which refusal the output panel should stand up, where the panel's own words | ||
| * are about the same event as this page's. | ||
| * | ||
| * The two halves of the Hub refuse things in different vocabularies, and a | ||
| * shared word is not a shared meaning: Cloud denying a workspace is not a | ||
| * provider's content policy, and an input upload that never arrived is not a | ||
| * model being down. So a code reaches the panel only where the sentence the | ||
| * panel already has says what actually happened; everywhere else the page's | ||
| * own accurate sentence stays beside the form, and the panel shows nothing | ||
| * rather than either the wrong words or a picture of a run that succeeded. | ||
| */ | ||
| export function workflowRunFailure( | ||
| error: Pick<WorkshopWorkflowError, 'code'> | ||
| ): RunFailure | undefined { | ||
| return REFUSALS.get(error.code) | ||
| } | ||
|
|
||
| // A Map, not an object: a code the page has never met must read as absent, and | ||
| // an object would hand back whatever Object.prototype happens to call by that | ||
| // name — 'toString' would arrive as a refusal. | ||
| const REFUSALS = new Map<string, RunFailure>([ | ||
| // The same sentence in both, and the only way out of it — Add credits, or | ||
| // the reader's own workspace — is the panel's to offer. | ||
| ['insufficient_credits', 'noCredits'], | ||
| // The same sentence in both. | ||
| ['rate_limited', 'rateLimit'], | ||
| // Both about a connection that went while a run may be alive and billed. | ||
| ['network', 'network'], | ||
| // A response that arrived and could not be read, which is what this page | ||
| // otherwise reports only as a run it could not check. | ||
| ['response', 'response'], | ||
| // One event, and the panel says more of it: the credits that may have gone | ||
| // without a result, and the request ID to quote. | ||
| ['execution_failed', 'provider'] | ||
| ]) | ||
|
|
||
| /** | ||
| * Whether the output panel is the one saying this failure. The page then keeps | ||
| * quiet beside the form rather than handing the reader the same thing twice — | ||
| * and twice in different words wherever the two vocabularies disagree. | ||
| * | ||
| * A run Cloud reports as failed is always the panel's: it stands that up as a | ||
| * provider failure regardless of what the page made of the request. Only a | ||
| * request Cloud turned down depends on whether the panel has words for the | ||
| * code. | ||
| */ | ||
| export function panelSaysRefusal(state: WorkflowState): boolean { | ||
| if ('observation' in state && state.observation?.run.state === 'failed') | ||
| return true | ||
| return ( | ||
| state.phase === 'failed' && workflowRunFailure(state.error) !== undefined | ||
| ) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.