The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): stop showing "cannot control this task" while permissions load or after a network blip (#28708)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Tomasz Tórz committed
Nov 14, 2026 at 16:41 UTC
1e9f93a48e231db3ccc5bcde6c5d84a00d5b9e9a
5 files changed
+111
-13
apps/mobile/src/features/threads/ThreadComposer.tsx
+7
-1
@@ -15,6 +15,7 @@ import { useAtomValue } from "@effect/atom-react";
15
import { clampFileAttachmentUploadBytes } from "@t3tools/client-runtime/state/attachments";
16
import { pastedTextDisposition, replaceTextSelection } from "@t3tools/client-runtime/text-paste";
17
import {
18
+ AuthOrchestrationOperateScope,
19
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
20
PROVIDER_SEND_TURN_MAX_INPUT_CHARS,
21
type ChatAttachment,
@@ -66,6 +67,7 @@ import type { ComposerDocumentAttachment } from "../../lib/composerContext";
67
import { useProject, useVisibleThreadShells } from "../../state/entities";
68
import { useMentionableEnvironments } from "../../state/environments";
69
import { useLinkedEnvironments } from "../../state/peerLinks";
70
+import { useEnvironmentScopeDenied } from "../../state/session";
71
import { scopeProjectRef } from "@t3tools/client-runtime/environment";
72
73
import { AppText as Text } from "../../components/ui/AppText";
@@ -471,6 +473,10 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
473
setResumingQueue(false);
474
};
475
476
+ const operateDenied = useEnvironmentScopeDenied(
477
+ props.environmentId,
478
+ AuthOrchestrationOperateScope,
479
+ );
480
const uploadStates = useAtomValue(composerAttachmentUploadsAtom);
481
const attachmentsUploading =
482
props.connectionState === "connected" &&
@@ -1202,7 +1208,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
1208
</Animated.View>
1209
</ComposerSurface>
1210
1205
- {props.connectionState === "connected" && !props.canOperateThread ? (
1211
+ {props.connectionState === "connected" && operateDenied ? (
1212
<Text className="pt-2 text-xs text-foreground-muted">
1213
This connection cannot control this task. You can still edit your draft.
1214
</Text>
apps/mobile/src/state/session.ts
+24
-7
@@ -1,5 +1,8 @@
1
import { useAtomValue } from "@effect/atom-react";
2
-import { createEnvironmentSessionAtoms } from "@t3tools/client-runtime/state/session";
2
+import {
3
+ createEnvironmentSessionAtoms,
4
+ sessionDeniesScope,
5
+} from "@t3tools/client-runtime/state/session";
6
import {
7
type AuthEnvironmentScope,
8
type AuthSessionState,
@@ -25,16 +28,30 @@ export function sessionHasScope(
28
return result._tag !== "Failure" && session !== null && sessionGrantsScope(session, scope);
29
}
30
31
+function sessionStateAtomFor(environmentId: EnvironmentId | null) {
32
+ return environmentId === null
33
+ ? EMPTY_SESSION_STATE_ATOM
34
+ : environmentSession.sessionStateAtom(environmentId);
35
+}
36
+
37
+// Both hooks select a boolean: every revalidation emits a new result, and most consumers are
38
+// list rows.
39
export function useEnvironmentScope(
40
environmentId: EnvironmentId | null,
41
scope: AuthEnvironmentScope,
42
): boolean {
32
- // Select the grant: every revalidation emits a new result, and most consumers are list rows.
33
- return useAtomValue(
34
- environmentId === null
35
- ? EMPTY_SESSION_STATE_ATOM
36
- : environmentSession.sessionStateAtom(environmentId),
37
- (result) => sessionHasScope(result, scope),
43
+ return useAtomValue(sessionStateAtomFor(environmentId), (result) =>
44
+ sessionHasScope(result, scope),
45
+ );
46
+}
47
+
48
+/** Unlike `!useEnvironmentScope`, stays false until the host has answered without the scope. */
49
+export function useEnvironmentScopeDenied(
50
+ environmentId: EnvironmentId | null,
51
+ scope: AuthEnvironmentScope,
52
+): boolean {
53
+ return useAtomValue(sessionStateAtomFor(environmentId), (result) =>
54
+ sessionDeniesScope(result, scope),
55
);
56
}
57
packages/client-runtime/src/state/environmentHttpAuth.test.ts
+5
-1
@@ -12,6 +12,7 @@ import {
12
OrchestrationV2ThreadTranscript,
13
type OrchestrationV2ThreadHistoryPage,
14
} from "@t3tools/contracts";
15
+import * as Cause from "effect/Cause";
16
import * as Effect from "effect/Effect";
17
import * as Exit from "effect/Exit";
18
import * as Fiber from "effect/Fiber";
@@ -21,6 +22,7 @@ import * as Queue from "effect/Queue";
22
import * as Schema from "effect/Schema";
23
import * as TestClock from "effect/testing/TestClock";
24
import type { HttpClient } from "effect/http";
25
+import { AsyncResult } from "effect/reactivity";
26
27
import * as RemoteEnvironmentAuthorization from "../authorization/service.ts";
28
import {
@@ -33,7 +35,7 @@ import * as ManagedRelay from "../relay/managedRelay.ts";
35
import { type RemoteEnvironmentRequestError } from "../rpc/http.ts";
36
import * as RpcHttp from "../rpc/http.ts";
37
import * as PullRequestDiffLoader from "./pullRequestDiffHttp.ts";
36
-import { fetchEnvironmentSessionState } from "./session.ts";
38
+import { fetchEnvironmentSessionState, sessionDeniesScope } from "./session.ts";
39
import { fetchEnvironmentShellSnapshot } from "./shellSnapshotHttp.ts";
40
import * as ThreadSnapshotLoader from "./threadSnapshotHttp.ts";
41
import { fetchEnvironmentThreadTranscript } from "./threadTranscriptHttp.ts";
@@ -596,6 +598,8 @@ describe("authenticated environment HTTP requests", () => {
598
message: "The environment rejected the renewed session authorization.",
599
});
600
expect(harness.calls).toHaveLength(2);
601
+ const rejectedLookup = AsyncResult.failure<AuthSessionState, typeof error>(Cause.fail(error));
602
+ expect(sessionDeniesScope(rejectedLookup, "orchestration:read")).toBe(true);
603
}),
604
);
605
packages/client-runtime/src/state/session.test.ts
+25
-1
@@ -19,7 +19,7 @@ import * as EnvironmentRegistry from "../connection/registry.ts";
19
import * as EnvironmentSupervisor from "../connection/supervisor.ts";
20
import * as RpcHttp from "../rpc/http.ts";
21
import type { RpcSession } from "../rpc/session.ts";
22
-import { createEnvironmentSessionAtoms } from "./session.ts";
22
+import { createEnvironmentSessionAtoms, sessionDeniesScope } from "./session.ts";
23
24
const TARGET = new PrimaryConnectionTarget({
25
environmentId: EnvironmentId.make("environment-1"),
@@ -130,4 +130,28 @@ describe("environment session state", () => {
130
expect(yield* harness.nextSettled()).toMatchObject({ _tag: "Success", value: SESSION });
131
}),
132
);
133
+
134
+ // "Cannot control" must reflect the host's answer, not a lookup still pending or lost on the network.
135
+ it.effect("denies a scope only once the host has answered without it", () =>
136
+ Effect.gen(function* () {
137
+ const harness = yield* makeHarness((requestNumber) => {
138
+ if (requestNumber === 1) return Promise.resolve(Response.json(SESSION));
139
+ if (requestNumber === 2) return unreachable();
140
+ return Promise.resolve(new Response(null, { status: 401 }));
141
+ });
142
+ expect(sessionDeniesScope(AsyncResult.initial(), "orchestration:read")).toBe(false);
143
+
144
+ const answered = yield* harness.nextSettled();
145
+ expect(sessionDeniesScope(answered, "orchestration:read")).toBe(false);
146
+ expect(sessionDeniesScope(answered, "orchestration:operate")).toBe(true);
147
+
148
+ yield* SubscriptionRef.set(harness.transport, Option.some(rpcSession()));
149
+ const networkFailure = yield* harness.nextSettled();
150
+ expect(networkFailure._tag).toBe("Failure");
151
+ expect(sessionDeniesScope(networkFailure, "orchestration:operate")).toBe(false);
152
+
153
+ yield* SubscriptionRef.set(harness.transport, Option.some(rpcSession()));
154
+ expect(sessionDeniesScope(yield* harness.nextSettled(), "orchestration:read")).toBe(true);
155
+ }),
156
+ );
157
});
packages/client-runtime/src/state/session.ts
+50
-3
@@ -1,8 +1,18 @@
1
import { pipe } from "effect/Function";
2
-import type { AuthSessionState, EnvironmentId, ServerConfig } from "@t3tools/contracts";
3
-import * as Schema from "effect/Schema";
2
+import {
3
+ type AuthEnvironmentScope,
4
+ AuthSessionState,
5
+ EnvironmentAuthInvalidError,
6
+ type EnvironmentId,
7
+ EnvironmentOperationForbiddenError,
8
+ EnvironmentScopeRequiredError,
9
+ type ServerConfig,
10
+ sessionGrantsScope,
11
+} from "@t3tools/contracts";
12
+import * as Cause from "effect/Cause";
13
import * as Effect from "effect/Effect";
14
import * as Option from "effect/Option";
15
+import * as Schema from "effect/Schema";
16
import * as Stream from "effect/Stream";
17
import * as SubscriptionRef from "effect/SubscriptionRef";
18
import { HttpClient } from "effect/http";
@@ -13,7 +23,11 @@ import * as EnvironmentRegistry from "../connection/registry.ts";
23
import type { PreparedConnection } from "../connection/model.ts";
24
import * as EnvironmentSupervisor from "../connection/supervisor.ts";
25
import * as ManagedRelay from "../relay/managedRelay.ts";
16
-import type { RemoteEnvironmentRequestError } from "../rpc/http.ts";
26
+import {
27
+ RemoteEnvironmentAuthFetchError,
28
+ RemoteEnvironmentAuthUndeclaredStatusError,
29
+ type RemoteEnvironmentRequestError,
30
+} from "../rpc/http.ts";
31
import type { RpcSession } from "../rpc/session.ts";
32
import { safeErrorLogAttributes } from "../errors/safeLog.ts";
33
import { executeAuthenticatedEnvironmentHttpRequest } from "./environmentHttpAuth.ts";
@@ -44,6 +58,39 @@ const MAX_SESSION_STATE_TIMEOUT_MS = 60_000;
58
const SESSION_STATE_RETRY_BASE_MS = 2_000;
59
const SESSION_STATE_RETRY_MAX_MS = 60_000;
60
61
+const isSessionRejectionError = Schema.is(
62
+ Schema.Union([
63
+ EnvironmentAuthInvalidError,
64
+ EnvironmentScopeRequiredError,
65
+ EnvironmentOperationForbiddenError,
66
+ ]),
67
+);
68
+const isSessionResponse = Schema.is(AuthSessionState);
69
+const isUndeclaredStatusError = Schema.is(RemoteEnvironmentAuthUndeclaredStatusError);
70
+const isAuthFetchError = Schema.is(RemoteEnvironmentAuthFetchError);
71
+
72
+/**
73
+ * True only when the host said no: its session lacks the scope, or it rejected the credential.
74
+ * A lookup that is still pending or failed on the network is not a denial.
75
+ */
76
+export function sessionDeniesScope(
77
+ result: AsyncResult.AsyncResult<AuthSessionState, unknown>,
78
+ scope: AuthEnvironmentScope,
79
+): boolean {
80
+ if (result._tag === "Success") return !sessionGrantsScope(result.value, scope);
81
+ return result._tag === "Failure" && isSessionRejection(result.cause);
82
+}
83
+
84
+function isSessionRejection(cause: Cause.Cause<unknown>): boolean {
85
+ const error = Option.getOrNull(Cause.findErrorOption(cause));
86
+ if (isUndeclaredStatusError(error)) {
87
+ return error.status === 401 || error.status === 403;
88
+ }
89
+ // A twice-rejected relay credential arrives wrapping the `authenticated: false` response.
90
+ if (isAuthFetchError(error)) return isSessionResponse(error.cause);
91
+ return isSessionRejectionError(error);
92
+}
93
+
94
export const fetchEnvironmentSessionState = Effect.fn(
95
"clientRuntime.state.fetchEnvironmentSessionState",
96
)(function* (input: {