GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): background activity settings save without dropping the connection by bfowler · Pull Request #18129 · pingdotgg/t3code

fix(server): background activity settings save without dropping the connection #18129

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.

Sign up for GitHub

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
bfowler wants to merge 4 commits into pingdotgg:main from bfowler:fix/background-activity-save

Uh oh!

There was an error while loading. Please reload this page.

Closed

fix(server): background activity settings save without dropping the connection #18129

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
9aecd4d
fix(server): background activity settings save without dropping the c…
bfowler Oct 8, 2026
45b6435
Merge remote-tracking branch 'origin/main' into fix/background-activi…
juliusmarminge Oct 19, 2026
3fa96cf
test(server): keep the decoded settings regression focused
juliusmarminge Oct 19, 2026
e8eb111
chore(server): explain the authorization request boundary
juliusmarminge Oct 19, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Next Next commit
fix(server): background activity settings save without dropping the c…
…onnection

RPC scope authorization decoded the settings payload a second time after
the RPC server had already decoded it. Duration intervals were already
Duration objects, so the second decode threw, and because the throw was
synchronous inside middleware the server reported it as a connection
defect.

Authorization now reads the decoded payload directly. The same applies to
asset URLs, project mutations, and the prepare pull request thread scope
check. Scope calculation runs inside Effect.suspend so a throw fails only
its request.

Fixes #17233
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@bfowler
bfowler committed Oct 15, 2026
commit 9aecd4d1aeb819f47c3b48271112bf3aba6b38a1

There are no files selected for viewing

34 changes: 34 additions & 0 deletions 34 apps/server/src/auth/RpcAuthorization.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
WsRpcGroup,
} from "@t3tools/contracts";
import { describe, expect, it } from "@effect/vitest";
import * as Duration from "effect/Duration";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as RpcTest from "effect/rpc/RpcTest";
Expand Down Expand Up @@ -304,6 +305,39 @@ describe("settings mutation authorization", () => {
}).pipe(Effect.scoped),
);

it.effect("authorizes interval settings from the decoded payload", () =>
Effect.gen(function* () {
let handled = 0;
const client = yield* RpcTest.makeClient(group).pipe(
Effect.provide(
Layer.mergeAll(
group.toLayerHandler(WS_METHODS.serverUpdateSettings, () =>
Effect.sync(() => {
handled++;
return DEFAULT_SERVER_SETTINGS;
}),
),
RpcAuthorization.layer([AuthSettingsWriteScope]),
),
),
);
yield* client[WS_METHODS.serverUpdateSettings]({
patch: {
automaticGitFetchInterval: Duration.minutes(5),
backgroundActivity: {
profile: "custom",
overrides: {
automaticGitFetchInterval: Duration.minutes(5),
idleClientTtl: Duration.minutes(10),
pauseWhenHostLocked: false,
},
},
},
});
expect(handled).toBe(1);
}).pipe(Effect.scoped),
);

it.effect("does not let a settings grant create or remove providers", () =>
Effect.gen(function* () {
let handled = false;
Expand Down
59 changes: 35 additions & 24 deletions 59 apps/server/src/auth/RpcAuthorization.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ import {
type DeviceListInput,
clientRpcRequiredScopes,
authScopeRequiredResponse,
AssetCreateUrlInput,
AuthAccessReadScope,
ServerSettingsPatch,
ProviderInstanceMutation,
requiredScopesForServerSettingsPatch,
requiredScopesForProjectMutation,
ProjectMutation,
AuthSettingsWriteScope,
AuthProvidersManageScope,
AuthEnvironmentMaintainScope,
Expand All @@ -31,11 +27,13 @@ import {
WsRpcGroup,
} from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as Schema from "effect/Schema";
import * as Layer from "effect/Layer";
import type * as Rpc from "effect/rpc/Rpc";
import type * as RpcGroup from "effect/rpc/RpcGroup";

type WsRpcMethod = RpcGroup.Rpcs<typeof WsRpcGroup>["_tag"];
type WsRpc = RpcGroup.Rpcs<typeof WsRpcGroup>;
type WsRpcMethod = WsRpc["_tag"];
type WsRpcPayload<Tag extends WsRpcMethod> = Rpc.Payload<Rpc.ExtractTag<WsRpc, Tag>>;

/**
* Keep authorization coverage coupled to the RPC group itself. Adding an RPC to
Expand Down Expand Up @@ -232,13 +230,9 @@ export const rpcAuthorizationError = (requiredScope: AuthEnvironmentScope) =>
...authScopeRequiredResponse(requiredScope),
});

const SettingsUpdate = Schema.Struct({
patch: ServerSettingsPatch,
providerInstanceMutation: Schema.optionalKey(ProviderInstanceMutation),
});

const requiredScopesForSettingsUpdate = (payload: unknown) => {
const input = Schema.decodeUnknownSync(SettingsUpdate)(payload);
const requiredScopesForSettingsUpdate = (
input: WsRpcPayload<typeof WS_METHODS.serverUpdateSettings>,
) => {
const scopes = requiredScopesForServerSettingsPatch(input.patch);
if (input.providerInstanceMutation === undefined) return scopes;
// An atomic provider mutation carries an empty patch unless it also changes settings.
Expand All @@ -247,8 +241,11 @@ const requiredScopesForSettingsUpdate = (payload: unknown) => {
: [...new Set([...scopes, AuthProvidersManageScope])];
};

const decodeProjectMutation = Schema.decodeUnknownSync(ProjectMutation);

/**
* The RPC server decodes `payload` before middleware runs, so it is already the
* schema's Type side. Decoding it again fails on transformed fields, such as
* Duration intervals in a settings patch.
*/
const requiredScopesForRpcCall = (
method: string,
payload: unknown,
Expand All @@ -257,7 +254,7 @@ const requiredScopesForRpcCall = (
return [AuthEnvironmentMaintainScope, AuthDiagnosticsReadScope];
}
if (method === WS_METHODS.assetsCreateUrl) {
const { resource } = Schema.decodeUnknownSync(AssetCreateUrlInput)(payload);
const { resource } = payload as WsRpcPayload<typeof WS_METHODS.assetsCreateUrl>;
return [
resource._tag === "workspace-file" ||
resource._tag === "media-file" ||
Expand All @@ -266,22 +263,36 @@ const requiredScopesForRpcCall = (
: AuthOrchestrationReadScope,
];
}
if (method === WS_METHODS.serverUpdateSettings) return requiredScopesForSettingsUpdate(payload);
if (method === WS_METHODS.serverUpdateSettings) {
return requiredScopesForSettingsUpdate(
payload as WsRpcPayload<typeof WS_METHODS.serverUpdateSettings>,
);
}
if (method === WS_METHODS.projectsMutate) {
return requiredScopesForProjectMutation(decodeProjectMutation(payload));
return requiredScopesForProjectMutation(
payload as WsRpcPayload<typeof WS_METHODS.projectsMutate>,
);
}
const guarded = clientRpcRequiredScopes(method, payload);
if (guarded.length > 0) return guarded;
return [requiredScopeForRpcMethod(method)];
};

/** Authorizes every RPC on one connection against that connection's session scopes. */
/**
* Authorizes every RPC on one connection against that connection's session scopes.
* Suspended so a throw while computing scopes fails that request; thrown synchronously,
* the RPC server reports it as a connection defect and the client drops every request.
*/
export const layer = (scopes: ReadonlyArray<AuthEnvironmentScope>) =>
Layer.succeed(RpcScopeAuthorization)((effect, { rpc, payload }) => {
const requiredScopes = requiredScopesForRpcCall(rpc._tag, payload);
const requiredScope = requiredScopes.find((scope) => !scopes.includes(scope));
return requiredScope === undefined ? effect : Effect.fail(rpcAuthorizationError(requiredScope));
});
Layer.succeed(RpcScopeAuthorization)((effect, { rpc, payload }) =>
Effect.suspend(() => {
const requiredScopes = requiredScopesForRpcCall(rpc._tag, payload);
const requiredScope = requiredScopes.find((scope) => !scopes.includes(scope));
return requiredScope === undefined
? effect
: Effect.fail(rpcAuthorizationError(requiredScope));
}),
);

/** Retrying can install or restart tools even though ordinary listing is readable. */
export const requiredScopeForDeviceList = (input: DeviceListInput): AuthEnvironmentScope =>
Expand Down
11 changes: 6 additions & 5 deletions 11 packages/contracts/src/clientRpcPermissions.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as Schema from "effect/Schema";
import { GitPreparePullRequestThreadInput } from "./git.ts";
import type { GitPreparePullRequestThreadInput } from "./git.ts";
import {
AuthOrchestrationOperateScope,
AuthSettingsWriteScope,
Expand Down Expand Up @@ -50,14 +49,16 @@ export const CLIENT_GUARDED_RPC_SCOPES = {
} as const;
export type ClientGuardedRpcTag = keyof typeof CLIENT_GUARDED_RPC_SCOPES;

const decodePrepareThread = Schema.decodeUnknownSync(GitPreparePullRequestThreadInput);

/**
* `input` is the RPC's decoded payload: the client's typed input before encoding, or what
* the server's RPC layer already decoded. Never decode it again.
*/
export function clientRpcRequiredScopes(
method: string,
input: unknown,
): readonly AuthEnvironmentScope[] {
if (method === WS_METHODS.gitPreparePullRequestThread && input !== undefined) {
const payload = decodePrepareThread(input);
const payload = input as GitPreparePullRequestThreadInput;
if (payload.mode === "worktree" && payload.threadId !== undefined)
return [AuthSourceControlWriteScope, AuthOrchestrationOperateScope];
}
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.