t3code icon indicating copy to clipboard operation
t3code copied to clipboard

Deduplicate server helpers and drop speculative pieces

Open amnesiaof opened this issue 1 month ago • 1 comments

Eleven copies of helpers that already exist somewhere else in apps/server.

toPersistenceSqlOrDecodeError appears four times: persistence/AuthSessions.ts:191, persistence/AuthPairingLinks.ts:107, persistence/ProviderSessionRuntime, and persistence/Layers/OrchestrationEventStore. persistence/Errors.ts already holds toPersistenceSqlError and toPersistenceDecodeError, which is where a single copy belongs. About 48 lines.

stringToBytes and bytesToString appear four times: cloud/http.ts:150,154, cloud/CliTokenManager.ts:262,266, cloud/environmentKeys.ts:22,26, and cli/connect.ts:138,142. The body is TextEncoder and TextDecoder construction. About 28 lines.

normalizeRepositoryCloneUrls appears four times in sourceControl/: GitHubCli.ts:371, GitLabCli, BitbucketApi.ts:473, AzureDevOpsCli.ts:305. About 27 lines.

apps/server/src/workspace/workspaceLease.ts is a 23-line keyed semaphore built on a module-level Map<string, {semaphore, users}>. @t3tools/shared/KeyedLock with KeyedLock.make<string>() already does this, and the same call sites already import it, at OpenCode2AdapterV2:891, CheckpointService:251, ProviderSessionManager:389, ThreadCommandExecutor:9 and LegacyV1ThreadImporter:24. About 17 lines.

trimOptionalString has four copies in sourceControl/, at azureDevOpsPullRequests.ts:55 and bitbucketPullRequests.ts:58 plus the GitHub and GitLab files. trimmed(value: string | null | undefined) has four more in pullRequest/, at azureDevOpsPullRequestJson.ts:155, bitbucketPullRequestJson.ts:201, gitHubPullRequestJson.ts:1244 and gitLabMergeRequestJson.ts:245. About 24 lines together.

errorMessage(error: unknown): string has six copies across apps/server/src/mcp/, starting at OrchestratorMcpService.ts:187 and ThreadMetadataMcpService.ts:35. About 9 lines.

isCommitSha has three copies carrying the identical /^[0-9a-f]{7,64}$/i, at pullRequest/BitbucketPullRequestApi.ts:338, GitHubPullRequestCli.ts:848 and GitLabPullRequestCli.ts:471. About 6 lines.

expandHomePath in os-jank.ts:94 duplicates expandHomePathWith in pathExpansion.ts, which does the same ~ expansion. The comment at pathExpansion.ts:13 already notes the duplication.

Three speculative pieces fit the same pass.

provider/Layers/ProviderUsageLimitsIngestion.ts is 6 lines exporting Layer.empty. Its own comment says V2 drivers fold live usage events into their managed snapshots and that the layer is retained only to hold a slot in the shared composition. Delete the file, the import in server.ts and the composition entry.

sourceControl/SourceControlDiscovery.ts:51 gives VCS_PROBES a full Jujutsu entry with executable, versionArgs and installHint. VcsDriverRegistry registers git only, and jj appears nowhere else in apps/server/src outside tests. Drop the probe until a jj driver exists. This breaks one assertion at SourceControlDiscovery.test.ts:570.

cloud/traceRelayRequest.ts:6 defines traceRelayRequest as a three-line wrap over withRelayClientTracing from @t3tools/shared/relayTracing, which the same file already imports. traceAuthenticatedRelayRequest in that file is real and stays.

About 205 lines.

amnesiaof avatar Oct 05 '26 16:10 amnesiaof

[!NOTE] 🤖 Claude Opus 5.5 responding on behalf of Theo

Thanks for the idea. Feature requests and proposals belong in Ideas discussions, where others can find and vote on them and maintainers track direction, so we close them here (see CONTRIBUTING.md). If this still matters to you, please post it there and link this issue.

t3dotgg avatar Oct 21 '26 21:10 t3dotgg