Skip to content

fix(mobile): importing a persona file on Android works after the file picker - #856

Merged
Jacksondr5 merged 4 commits into
j5/mainfrom
j5code/mobile-persona-import-reconnect
Nov 1, 2026
Merged

Jacksondr5 merged 4 commits into
j5/mainfrom
j5code/mobile-persona-import-reconnect

Conversation

@Jacksondr5

@Jacksondr5 Jacksondr5 commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Problem

On Android, importing a persona file from Downloads fails, and nothing is imported. It fails in one of two ways, depending on the device's file provider, and both were seen on j5/main. Closes #855.

1. The file's name is lost (wave-1a tester's debug run): "No YAML persona definitions found in the selection.", with the import never reaching the server. Confirmed by the logs, then by reading expo-file-system's source: a file picked on Android comes back as a document URI such as content://…/document/msf%3A28. expo-file-system names a File by its URI (Paths.basename(this.uri)), so the import saw the name msf%3A28. Both the client's prepareAgentPersonaImport and the server's importFiles accept only .yaml/.yml names, so the file was dropped. The real display name exists only natively and isn't passed to JS. iOS returns a copy with its real name.

2. The reconnect (wave-1b tester): "openclaw is not connected", repeatedly. Returning from more than 10 seconds in the picker reconnects the environment (MOBILE_BACKGROUND_RECONNECT_AFTER_MS). The import, sent as the picker closed, was refused for having no session (EnvironmentRpcUnavailableError) before it left the device. With the retry below, the same tester's import after more than 20 seconds in the picker worked.

What changed

The single-file pick uses expo-document-picker's getDocumentAsync({ copyToCacheDirectory: true }), as upstream's file attachments do (lib/composerImages.ts). Its asset carries the file's real name and a readable cache copy. Folder import keeps its picker.

  • The import is wrapped in sendAfterReconnect. Only a send refused with EnvironmentRpcUnavailableError, which never left the device, is sent again, and only once a newer session is up. watchEnvironmentSessions watches the target environment's own session count (sessionGenerationAtom) from just before the send. It doesn't read the connection phase, because a resume clears the session before the phase leaves "connected" (supervisor.ts). The wait is bounded at 15 seconds; after that the import fails with "The environment didn't reconnect in time. Try again." Server failures (a conflicting id, a bad file) are reported as before, with no wait and no second send.

Live testing

Android: PASS at f8718bb5ee (wave-1b tester, report test-reports/j5code-mobile-wave1b-tester/f8718bb5ee.md).

  • Delayed import: 25 s in the picker, then a Downloads YAML: "Imported 1 persona", and it appears in the library.
  • Same id: a changed file with an existing id reaches the replace prompt, and Import selected replaces it.
  • Before: on the first retry (bc756540a1) and on the picker change alone (33f3c), the delayed import failed with "not connected".
  • Earlier at bc756540a1: folder import reached its replace prompt, and a quick import worked.
Before After
Import after 20+ s in the picker, Android Delayed import failing with openclaw is not connected, before Delayed import succeeded, the persona listed in the library, after

Changed file with an existing id reaching the replace prompt, Android, after
Replace prompt confirmed and the persona imported, Android, after
Folder import reaching the replace prompt (bc756540a1), Android

iOS: not verified. iOS checks are deferred to Checkpoint 1 on Jackson's iPhone.

Checklist

  • One concern: the description has no "also"
  • Tests cover the changed behavior: an Android pick whose URI names it by id fails on trunk on the YAML name check (pickAgentDefinitions.test.ts), sendAfterReconnect.test.ts covers the retry's ordering, and watchEnvironmentSessions.test.ts covers the wait: a stale connected state with no new session doesn't resolve, and the wait gives up at 15 s
  • UI changes: none
  • Live testing: the section above says what ran live and what did not
  • Upstream-owned files: none; all J5 (apps/mobile/src/j5/agents/). expo-document-picker is already a mobile dependency.
  • Upstream product: no change
  • Surfaces: mobile persona import. The picker change affects single-file import; the reconnect retry covers file and folder import, which share the send. iOS takes the same picker but isn't checked (iOS testing is deferred to Checkpoint 1). Web has its own picker.
  • Docs: no doc describes this

Built by Claude Opus 5.5 in Claude Code (J5 Code crew seat builder-composer).

🤖 Generated with Claude Code

@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
j5-code Ready Ready Preview Nov 1, 2026 2:43am UTC

Request Review

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M 30-99 effective changed lines (test files excluded in mixed PRs). labels Nov 1, 2026

@Jacksondr5 Jacksondr5 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combined panel review (reviewer-opus + reviewer-sol) at 4359fc174e

Verdict: no findings, and the panel approves the source provisionally. It stays provisional while the PR is a draft: the tester's logs need to confirm that the failure is EnvironmentRpcUnavailableError, and a device run needs to show an import succeeding after a long stay in the picker.

  • Retrying is safe. EnvironmentRpcUnavailableError comes from currentSession in client-runtime/src/rpc/client.ts when there is no session. That happens before the request is built, so the import never reached the server and sending again can't repeat an accepted import. The message the tester saw ("openclaw is not connected.") is the one that path produces. squashAtomCommandFailure is Cause.squash, so the tag survives into Predicate.isTagged.
  • Bounded. It retries once, after at most 15 s of waiting for the environment to report connected. Otherwise it fails visibly with "didn't reconnect in time". Server refusals pass straight through, untouched (tested). The timeout clears both the timer and the registry subscription.
  • Both import kinds. importSelection serves both file and folder import, and each send inside importAgentPersonasWithConfirmation (first attempt and confirmed replacement) goes through the same wrapper.
  • Not machinery for a rare case. It's the normal Android path whenever the picker stays open past MOBILE_BACKGROUND_RECONNECT_AFTER_MS (10 s). It's J5-owned and about 50 lines.
  • The new wait helper (waitForEnvironmentConnected) has no test of its own. Its subscription and timeout are checked by reading the source only. That's acceptable for the size.

Reviewer-run checks

  • sendAfterReconnect.test.ts: 3 passed (reviewer-sol also ran the picker tests: 7 in 2 files)
  • lint: clean on the changed files

Reviewed by Claude Opus 5.5 (reviewer-opus) and Sol 6.1 (reviewer-sol) in J5 Code.

@Jacksondr5
Jacksondr5 force-pushed the j5code/mobile-persona-import-reconnect branch from 4359fc1 to 33f3c03 Compare November 1, 2026 01:46
@Jacksondr5 Jacksondr5 changed the title fix(mobile): a persona import survives the file picker's reconnect fix(mobile): importing a persona file on Android keeps the file's name Nov 1, 2026
@Jacksondr5
Jacksondr5 marked this pull request as ready for review November 1, 2026 01:46
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 7 billable files and costs up to $1.75.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 21 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available. Your 55 included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between ae7c519 and 017d3b5.

Files selected for processing: 7
  • apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx
  • apps/mobile/src/j5/agents/pickAgentDefinitions.test.ts
  • apps/mobile/src/j5/agents/pickAgentDefinitions.ts
  • apps/mobile/src/j5/agents/sendAfterReconnect.test.ts
  • apps/mobile/src/j5/agents/sendAfterReconnect.ts
  • apps/mobile/src/j5/agents/watchEnvironmentSessions.test.ts
  • apps/mobile/src/j5/agents/watchEnvironmentSessions.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@Jacksondr5 Jacksondr5 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combined panel re-review (reviewer-opus + reviewer-sol) at 33f3c039bf (repurposed PR)

Verdict: the product change is correct. One small test fix is requested so the regression test fails on trunk for the right reason. Live testing is pending.

Small should-fix: make the Android-id test fail on trunk because of the name (raised by reviewer-sol, reproduced by reviewer-opus)

The new test "names a chosen Android document by its file name, not the id in its URI" only configures documents.getDocumentAsync. When trunk's pickAgentDefinitions.ts is swapped in, File.pickFileAsync is an unconfigured vi.fn() that returns undefined. The test then fails with a TypeError on selection.canceled, not with the real bug ("No YAML persona definitions found"). reviewer-opus swapped trunk's file in and got 3 failures, all for that plumbing reason.

Fix: in that test, also give the old picker a realistic Android result: File.pickFileAsync → { canceled: false, result: new File("msf%3A28") }, while the new picker returns name: "scout.yaml". Trunk then fails on the extension filter, and the branch passes. That meets AGENTS.md's "fails on j5/main for that reason" without testing picker plumbing.

Checked and fine

  • Cause confirmed. In expo-file-system 58, File.name is Paths.basename(this.uri). A Downloads pick comes back as content://…/document/msf%3A28, so the name is msf:28 and both the client and server .yaml/.yml filters drop it.
  • The new picker is getDocumentAsync({ copyToCacheDirectory: true }), which upstream's attachments already use (expo-document-picker is already a dependency). It keeps the picker's display name and a readable file:// cache copy. size falls back to the copy's size. Cancel, including assets: null, returns no selection, and the foreground handoff still ends in finally.
  • The reconnect retry is fully removed. Its cause wasn't confirmed, so it was right to drop it.
  • Mobile vp run typecheck: exit 0. pickAgentDefinitions.test.ts: 5 passed.

Device check, not a finding: folder import from Downloads

Folder import is unchanged and still names each entry by Paths.basename(uri). For external-storage trees that decodes to the real file name (primary:Download/team/agent.yaml → agent.yaml). Children of a folder picked under the Downloads provider may instead carry ids like msf:NN, which would be dropped the same way. Please try a folder import from Downloads on Android during the device pass. If it fails, that's a follow-up issue, not this PR.

Reviewed by Claude Opus 5.5 (reviewer-opus) and Sol 6.1 (reviewer-sol) in J5 Code.

@Jacksondr5 Jacksondr5 changed the title fix(mobile): importing a persona file on Android keeps the file's name fix(mobile): importing a persona file on Android works after the file picker Nov 1, 2026

@Jacksondr5 Jacksondr5 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combined panel re-review (reviewer-opus + reviewer-sol) at bc756540a1

Verdict: the test should-fix is resolved, and the panel approves the source. Still pending: the tester's re-test at this head.

  • Test proof. The Android-id test now gives trunk's File.pickFileAsync a realistic msf%3A28 result. reviewer-opus swapped trunk's pickAgentDefinitions.ts back in: the test fails with "No YAML persona definitions found in the selection.", the real bug, and passes on the branch.
  • The retry is back. sendAfterReconnect.ts, waitForEnvironmentConnected.ts and their test are byte-identical to 4359fc174e, which the panel already reviewed: safe to retry because EnvironmentRpcUnavailableError is raised before the request leaves the device, bounded at 15 s, fails visibly, and lets server refusals through untouched. The screen wrapper is the same single change. The new device evidence (trunk keeps failing with "not connected"; the retry imports after more than 20 s in the picker) settles the cause we had held open.
  • Scope. Both fixes close the one symptom in #855, and the description explains which file provider produces which failure. That's fine as one PR.
  • Description nit (optional). The retry wraps importSelection, which serves folder import too, so "Folder import is unaffected" holds for the picker change but not for the retry.

Reviewer-run checks

  • pickAgentDefinitions.test.ts and sendAfterReconnect.test.ts: 8 passed
  • the branch is based on current j5/main (d30e293)

The device check on folder import from Downloads (entries may be named msf:NN) still stands for the tester. If it fails, it's a follow-up issue.

Reviewed by Claude Opus 5.5 (reviewer-opus) and Sol 6.1 (reviewer-sol) in J5 Code.

@Jacksondr5 Jacksondr5 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combined panel re-review (reviewer-opus + reviewer-sol) at f8718bb5ee

Verdict: the delayed-import race is fixed in source, with no new findings. The panel approves the source again. Still pending: the tester's re-check of an import after more than 20 s in the picker. That path failed on device at bc756540a1.

What failed at bc756540a1: the supervisor's connected run ends with Effect.ensuring(clearLease) (connection/supervisor.ts:842), which clears the session before the phase leaves "connected". The old wait accepted that stale "connected" phase, so the single resend hit the same missing session.

What changed:

  • The retry now waits on environmentCatalog.sessionGenerationAtom(environmentId) (client-runtime/src/state/runtime.ts:613–645). That count rises only when the target environment is "connected" and has a new, non-null session object. The stale window (connected, no session) can't advance it, and other environments can't wake it.
  • watchEnvironmentSessions subscribes before the send, so it takes its baseline first and keeps the count mounted through the reconnect. A session that arrives before the wait begins resolves at once. The watch is disposed in finally. It's still one retry, bounded at 15 s, with the visible "didn't reconnect in time" failure.
  • waitForEnvironmentConnected is deleted. sendAfterReconnect only renames its wait parameter.
  • watchEnvironmentSessions.test.ts tests the helper itself: a stale state stays pending until the count rises, an earlier session resolves at once, and it gives up at 15 s (fake timers).

Reviewer-run checks

  • mobile watchEnvironmentSessions, sendAfterReconnect and pickAgentDefinitions tests: 11 passed, 3 files (both reviewers)
  • mobile vp run typecheck: exit 0
  • lint: clean on src/j5/agents

Reviewed by Claude Opus 5.5 (reviewer-opus) and Sol 6.1 (reviewer-sol) in J5 Code.

Jacksondr5 and others added 4 commits October 31, 2026 22:41
On Android, a file picked from Downloads comes back as a document URI
such as content://…/document/msf%3A28, and expo-file-system names a File
by its URI, so the import saw "msf%3A28", found no .yaml file and failed
with "No YAML persona definitions found in the selection". The single-file
pick now uses expo-document-picker, as upstream's file attachments do,
whose asset carries the file's real name and a readable cache copy.

Closes #855

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Returning from more than 10 seconds in the file picker reconnects the
environment, and an import sent meanwhile was refused with "openclaw is
not connected" before it left the device; the tester saw that repeatedly
on j5/main, and an import after more than 20 seconds in the picker worked
with this retry. The import now waits for the reconnect, at most 15
seconds, and sends once more; if the environment doesn't come back it
says so. Server failures are reported as before.

The Android-id picker test also mocks the old picker, so on trunk it fails
on the YAML name check rather than on missing plumbing.

Refs #855

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d phase

The tester's delayed import still failed with "not connected": a resume
clears the session before the phase leaves "connected", so the retry's
wait saw "connected", resolved at once, and resent into the same missing
session. It now watches the environment's own session count
(sessionGenerationAtom) from just before the send and resends only once a
newer session is up, still bounded at 15 seconds.

Refs #855

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The import wrapper's try/finally sat inside AgentLibrarySettingsScreen, and
the React Compiler does not lower a try without a catch, so the screen fell
out of compilation (reactCompilerCoverage). The session watch and its
disposal move into sendWhenReconnected beside watchEnvironmentSessions; the
screen calls it in one expression.

Refs #855

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@Jacksondr5 Jacksondr5 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Panel delta check (reviewer-opus + reviewer-sol) at 017d3b5

Verdict: no findings. This changes no behaviour, and the panel's source approval stands.

  • Rebase only for the first three commits. git range-diff against f8718bb5ee shows the same patches. The only difference is that the import hunk now lands in trunk's renamed OwnerAgentLibrarySettingsScreen. Against the updated j5/main, the PR diff is still the 7 intended files.
  • 017d3b5 moves the watch-before-send, await sendAfterReconnect and finally dispose wrapper unchanged out of the component, into sendWhenReconnected(environmentId, send) in watchEnvironmentSessions.ts. That takes the catch-less try/finally the React Compiler can't lower out of the screen. The captured environmentId and input, the watcher and the 15 s wait are all unchanged. So the tester's Android pass at f8718bb5ee (25 s delayed import, replace prompt) still covers the runtime behaviour.

Reviewer-run checks

  • reactCompilerCoverage.test.ts, watchEnvironmentSessions, sendAfterReconnect and pickAgentDefinitions: 1025 passed, 4 files
  • mobile vp run typecheck: exit 0

Reviewed by Claude Opus 5.5 (reviewer-opus) and Sol 6.1 (reviewer-sol) in J5 Code.

@Jacksondr5
Jacksondr5 merged commit a00b049 into j5/main Nov 1, 2026
32 checks passed
@Jacksondr5
Jacksondr5 deleted the j5code/mobile-persona-import-reconnect branch November 1, 2026 03:02

This branch was successfully deployed

1 active deployment
Preview — 017d3b5c Deployed Nov 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 effective changed lines (test files excluded in mixed PRs). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mobile: importing a persona file on Android fails with "not connected" after the file picker

1 participant