Repository navigation
fix(mobile): persist the new-session prompt and retry a failed repo prefill #6771
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
Merged
iscekic
merged 3 commits into
main
from
kwf/janitor-mobile-agent-chat-new-session-00e7216c8c
Sep 28, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
94 changes: 94 additions & 0 deletions
94
apps/mobile/src/components/agents/new-session-prompt-seed.test.ts
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,94 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { | ||
| type NewSessionPromptSeedInput, | ||
| resolveNewSessionPromptSeedDecision, | ||
| } from './new-session-prompt-seed'; | ||
|
|
||
| function decide(overrides: Partial<NewSessionPromptSeedInput> = {}) { | ||
| return resolveNewSessionPromptSeedDecision({ | ||
| draftSettled: true, | ||
| seed: 'pending', | ||
| prompt: '', | ||
| initialPrompt: undefined, | ||
| sharePrefillText: null, | ||
| userEdited: false, | ||
| ...overrides, | ||
| }); | ||
| } | ||
|
|
||
| describe('resolveNewSessionPromptSeedDecision', () => { | ||
| it('keeps waiting while the draft load has not settled', () => { | ||
| expect(decide({ draftSettled: false })).toEqual({ type: 'keep' }); | ||
| }); | ||
|
|
||
| it('settles in place instead of restoring a stored draft when the user cleared a pre-identity prompt', () => { | ||
| // Type, clear, then the identity resolves with an older saved draft: the | ||
| // explicit clear must win over the stored draft. | ||
| expect( | ||
| decide({ | ||
| prompt: '', | ||
| initialPrompt: 'older saved draft', | ||
| userEdited: true, | ||
| }) | ||
| ).toEqual({ type: 'settle' }); | ||
| }); | ||
|
|
||
| it('restores the stored draft when the user never edited the prompt', () => { | ||
| expect( | ||
| decide({ | ||
| prompt: '', | ||
| initialPrompt: 'older saved draft', | ||
| }) | ||
| ).toEqual({ | ||
| type: 'restore', | ||
| prompt: 'older saved draft', | ||
| hasPrompt: true, | ||
| seed: 'restore', | ||
| }); | ||
| }); | ||
|
|
||
| it('settles when the user typed before the identity resolved', () => { | ||
| expect( | ||
| decide({ | ||
| prompt: 'typed before identity', | ||
| initialPrompt: 'older saved draft', | ||
| userEdited: true, | ||
| }) | ||
| ).toEqual({ type: 'settle' }); | ||
| }); | ||
|
|
||
| it('does not remount for a share prefill that already seeded the first render', () => { | ||
| expect( | ||
| decide({ | ||
| initialPrompt: 'shared text', | ||
| sharePrefillText: 'shared text', | ||
| }) | ||
| ).toEqual({ | ||
| type: 'restore', | ||
| prompt: 'shared text', | ||
| hasPrompt: true, | ||
| seed: 'settled', | ||
| }); | ||
| }); | ||
|
|
||
| it('settles when there is no stored draft to restore', () => { | ||
| expect(decide({ initialPrompt: undefined })).toEqual({ type: 'settle' }); | ||
| }); | ||
|
|
||
| it('preserves a settled non-empty prompt across an identity change', () => { | ||
| expect(decide({ draftSettled: false, seed: 'settled', prompt: 'typed' })).toEqual({ | ||
| type: 'keep', | ||
| }); | ||
| }); | ||
|
|
||
| it('resets a restored draft when the identity changes', () => { | ||
| expect(decide({ draftSettled: false, seed: 'restore', prompt: 'stored draft' })).toEqual({ | ||
| type: 'reset', | ||
| }); | ||
| }); | ||
|
|
||
| it('leaves an already settled seed untouched', () => { | ||
| expect(decide({ seed: 'settled' })).toEqual({ type: 'keep' }); | ||
| }); | ||
| }); |
70 changes: 70 additions & 0 deletions
70
apps/mobile/src/components/agents/new-session-prompt-seed.ts
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,70 @@ | ||
| /** | ||
| * The uncontrolled prompt input's remount seed. `pending` is the initial and | ||
| * re-armed state while the identity-bound draft loads; `settled` means the | ||
| * input already shows the right text; `restore` is the only value that changes | ||
| * the form key and remounts the input onto a stored draft. | ||
| */ | ||
| export type NewSessionPromptSeed = 'pending' | 'settled' | 'restore'; | ||
|
|
||
| /** What the seed effect should do for one render. */ | ||
| export type NewSessionPromptSeedDecision = | ||
| | { type: 'keep' } | ||
| | { type: 'reset' } | ||
| | { type: 'settle' } | ||
| | { type: 'restore'; prompt: string; hasPrompt: boolean; seed: NewSessionPromptSeed }; | ||
|
|
||
| export type NewSessionPromptSeedInput = { | ||
| draftSettled: boolean; | ||
| seed: NewSessionPromptSeed; | ||
| prompt: string; | ||
| initialPrompt: string | undefined; | ||
| sharePrefillText: string | null; | ||
| /** Whether the user edited the prompt (including clearing it) before the load settled. */ | ||
| userEdited: boolean; | ||
| }; | ||
|
|
||
| /** | ||
| * Resolves the seed effect's action from the draft-load and prompt state. | ||
| * | ||
| * The prompt input is uncontrolled: only a `restore` decision remounts it onto | ||
| * a stored draft. A prompt the user edited before the identity-bound draft | ||
| * load settled — including one the user cleared back to empty — is already the | ||
| * input's visible text, so it must settle in place instead of being treated as | ||
| * an untouched empty ref and overwritten by an older saved draft. | ||
| */ | ||
| export function resolveNewSessionPromptSeedDecision( | ||
| input: NewSessionPromptSeedInput | ||
| ): NewSessionPromptSeedDecision { | ||
| const { draftSettled, seed, prompt, initialPrompt, sharePrefillText, userEdited } = input; | ||
| if (!draftSettled) { | ||
| if (seed === 'pending') { | ||
| return { type: 'keep' }; | ||
| } | ||
| // The identity or entity changed. A `restore` seed is a stored draft the | ||
| // input remounts away, so reset the route-owned prompt with it. A | ||
| // `settled` seed keeps its non-empty text: the remount key stays `empty`, | ||
| // so resetting the route-owned prompt would desync it from the visible | ||
| // field. | ||
| if (seed === 'settled' && prompt !== '') { | ||
| return { type: 'keep' }; | ||
| } | ||
| return { type: 'reset' }; | ||
| } | ||
| if (seed !== 'pending') { | ||
| return { type: 'keep' }; | ||
| } | ||
| // An explicit pre-identity edit beats a stored draft, even when the edit is | ||
| // an intentional clear to empty: the input already shows it, and a restore | ||
| // would remount the older text over it. | ||
| if (prompt !== '' || userEdited || !initialPrompt) { | ||
| return { type: 'settle' }; | ||
| } | ||
| return { | ||
| type: 'restore', | ||
| prompt: initialPrompt, | ||
| hasPrompt: initialPrompt.trim().length > 0, | ||
| // A share prefill already seeded the first render; only a stored draft | ||
| // needs the remount. | ||
| seed: initialPrompt === sharePrefillText ? 'settled' : 'restore', | ||
| }; | ||
| } |
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
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.