GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Draft: teleport backend — import/export engine by baanish · Pull Request #7135 · pingdotgg/t3code Conversation
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Effect service conventions review for the new teleport service. Findings below cover the service module layout, layer/make exports, error modeling, and tagged-error handling in the changed files.
Posted via Macroscope — Effect Service Conventions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| export interface TeleportServiceShape { | ||
| readonly listSessions: ( | ||
| input: TeleportListSessionsInput, | ||
| ) => Effect.Effect<TeleportListSessionsResult, TeleportListSessionsError>; | ||
|
|
||
| readonly importSessions: ( | ||
| input: TeleportImportSessionsInput, | ||
| ) => Effect.Effect<TeleportImportSessionsResult, TeleportImportError>; | ||
|
|
||
| readonly exportSession: ( | ||
| input: TeleportExportSessionInput, | ||
| ) => Effect.Effect<TeleportExportSessionResult, TeleportExportError>; | ||
| } | ||
|
|
||
| export class TeleportService extends Context.Service<TeleportService, TeleportServiceShape>()( | ||
| "t3/teleport/Services/TeleportService", | ||
| ) {} |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
New service is split across teleport/Services/TeleportService.ts (tag) and teleport/Layers/TeleportService.ts (construction + layer), and keeps a standalone TeleportServiceShape. Consider one canonical module apps/server/src/teleport/TeleportService.ts in the order imports → errors/schemas → Context.Service tag with the interface declared inline → make → layer, and drop the separate shape type (use TeleportService["Service"] where the type is needed, as server.test.ts already does).
Posted via Macroscope — Effect Service Conventions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| export class TeleportInvalidInputError extends Schema.TaggedErrorClass<TeleportInvalidInputError>()( | ||
| "TeleportInvalidInputError", | ||
| { | ||
| message: TrimmedNonEmptyString, | ||
| cause: Schema.optional(Schema.Defect()), | ||
| }, | ||
| ) {} |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
TeleportInvalidInputError stores a free-form message as its only data and is used as a catch-all for semantically distinct failures (in-flight conflict, cwd mismatch, duplicate refs, running session, thread/binding load failure, dispatch failure, already-native export). Convention here is structured attributes with message derived via a getter (see contracts/src/vcs.ts). Consider splitting the distinct cases into their own tagged errors (or at minimum adding stable fields such as operation, threadId/externalSessionId) and deriving the message from them; the same applies to TeleportDiscoveryError (line 188) and TeleportProjectResolutionError (line 180), which also carry only message + cause.
Posted via Macroscope — Effect Service Conventions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const mapDispatchError = (message: string) => (cause: unknown) => | ||
| new TeleportInvalidInputError({ | ||
| message, | ||
| cause, | ||
| }); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
mapDispatchError is a curried alias whose only behavior is new TeleportInvalidInputError({ message, cause }). Suggest constructing the error at each failure boundary (call sites at lines 413, 422, 440, 450, 495, 734) so the attributes and cause stay visible, and adding real context (e.g. threadId, the dispatched command type) at those sites instead of a free-form message string.
Posted via Macroscope — Effect Service Conventions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| } | ||
|
|
||
| export const TeleportServiceLive = Layer.effect( |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The module owns construction, so it would be better to export a real make (the Effect.gen body) and the canonical layer as export const layer = Layer.effect(TeleportService, make) from the merged teleport/TeleportService.ts, rather than an inlined TeleportServiceLive. Consumers in server.ts would then use TeleportService.layer.
Posted via Macroscope — Effect Service Conventions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| import * as SessionStore from "./auth/SessionStore.ts"; | ||
| import { failEnvironmentAuthInvalid, failEnvironmentInternal } from "./auth/http.ts"; | ||
| import * as RelayClient from "@t3tools/shared/relayClient"; | ||
| import { TeleportService } from "./teleport/Services/TeleportService.ts"; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Service boundary import: every other service module in this file is imported as a namespace (import * as ProviderRegistry from ...). Suggest import * as TeleportService from "./teleport/TeleportService.ts"; and const teleport = yield* TeleportService.TeleportService; at line 425 so the module namespace is preserved.
Posted via Macroscope — Effect Service Conventions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Effect.catchTag( | ||
| "PlatformError", | ||
| (cause: PlatformError.PlatformError) => | ||
| new TeleportDiscoveryError({ | ||
| message: "Native filesystem error during teleport import.", | ||
| cause, | ||
| }), | ||
| ), |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Prefer Effect.catchTags over Effect.catchTag, even for a single tag (same pattern at line 746).
| Effect.catchTag( | |
| "PlatformError", | |
| (cause: PlatformError.PlatformError) => | |
| new TeleportDiscoveryError({ | |
| message: "Native filesystem error during teleport import.", | |
| cause, | |
| }), | |
| ), | |
| Effect.catchTags({ | |
| PlatformError: (cause: PlatformError.PlatformError) => | |
| new TeleportDiscoveryError({ | |
| message: "Native filesystem error during teleport import.", | |
| cause, | |
| }), | |
| }), |
Posted via Macroscope — Effect Service Conventions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Effect.catchIf(isIgnorableProviderStopError, (error) => | ||
| Effect.logDebug("teleport.export.stop-session-skipped", { | ||
| threadId: input.threadId, | ||
| reason: error._tag, | ||
| }), | ||
| ), |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
isIgnorableProviderStopError is a _tag switch used with catchIf purely to recover statically known tagged failures. Suggest replacing it with Effect.catchTags({ ProviderValidationError: ..., ProviderSessionNotFoundError: ..., ProviderAdapterSessionNotFoundError: ... }) and deleting the predicate (lines 126-135); catchIf is best reserved for genuinely structural predicates such as platform error codes.
Posted via Macroscope — Effect Service Conventions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return { | ||
| schemaVersion: TELEPORT_SCHEMA_VERSION, | ||
| provider, | ||
| providerInstanceId: defaultInstanceIdForDriver(driverKind), |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium Layers/TeleportService.ts:739
The export response returns the default provider instance ID even when the persisted binding uses a custom providerInstanceId, so callers receive an ID that does not identify the binding just written. Return the existing binding's providerInstanceId when present, falling back to defaultInstanceIdForDriver(driverKind) only for new bindings.
In file @apps/server/src/teleport/Layers/TeleportService.ts around line 739:
The export response returns the default provider instance ID even when the persisted binding uses a custom `providerInstanceId`, so callers receive an ID that does not identify the binding just written. Return the existing binding's `providerInstanceId` when present, falling back to `defaultInstanceIdForDriver(driverKind)` only for new bindings.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| cause: PlatformError.PlatformError, | ||
| ): Effect.Effect<void, TeleportFileLockedError | TeleportNativeWriteError> => { | ||
| if (platform === "win32" && isReplaceConflict(cause) && !isNativeFileBusy(cause)) { | ||
| return fs.remove(input.to).pipe( |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟠 High teleport/nativeWrite.ts:92
On Windows, a failed second rename deletes the existing native session: fs.remove(input.to) runs first, and scoped cleanup then removes tempPath, leaving neither copy when the replacement fails. Preserve the destination until the replacement succeeds (for example, use an atomic replacement operation or restore the original after a failed rename).
In file @apps/server/src/teleport/nativeWrite.ts around line 92:
On Windows, a failed second `rename` deletes the existing native session: `fs.remove(input.to)` runs first, and scoped cleanup then removes `tempPath`, leaving neither copy when the replacement fails. Preserve the destination until the replacement succeeds (for example, use an atomic replacement operation or restore the original after a failed rename).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (first === "home" || first === "users" || first === "root") { | ||
| return parts.length <= 2; | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium teleport/cwd.ts:76
isGenericTeleportCwd treats a UNC share root such as \\server\share as non-generic, so opencodeSessionMatchesProjectCwd can match that session as the parent of unrelated projects on the share. Recognize normalized UNC paths with only a server and share component as generic roots, like drive roots.
if (first === "home" || first === "users" || first === "root") {
return parts.length <= 2;
}
+ if (posix.startsWith("//") && parts.length <= 2) {
+ return true;
+ }In file @apps/server/src/teleport/cwd.ts around lines 76-78:
`isGenericTeleportCwd` treats a UNC share root such as `\\server\share` as non-generic, so `opencodeSessionMatchesProjectCwd` can match that session as the parent of unrelated projects on the share. Recognize normalized UNC paths with only a server and share component as generic roots, like drive roots.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| case "thread.message-sent": | ||
| case "thread.proposed-plan-upserted": | ||
| case "thread.activity-appended": | ||
| case "thread.history-replaced": |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium Layers/ProjectionPipeline.ts:872
thread.history-replaced leaves stale pending approval rows and a stale ProjectionThread.latestTurnId, so an in-place import can retain a nonzero pendingApprovalCount and point at a turn that was just deleted. Clear the pending approvals and set latestTurnId to null when replacing history, matching the client reducer.
In file @apps/server/src/orchestration/Layers/ProjectionPipeline.ts around line 872:
`thread.history-replaced` leaves stale pending approval rows and a stale `ProjectionThread.latestTurnId`, so an in-place import can retain a nonzero `pendingApprovalCount` and point at a turn that was just deleted. Clear the pending approvals and set `latestTurnId` to `null` when replacing history, matching the client reducer.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| }).pipe( | ||
| Effect.map((result) => result.stdout.trim().length > 0), | ||
| Effect.orElseSucceed(() => false), | ||
| ); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟠 High teleport/fileLock.ts:52
requireNativePathUnlocked treats every non-Windows lsof failure—including ENOENT when lsof is unavailable and the 2-second timeout—as an unlocked path, so export can proceed while a native session is actively being written. Effect.orElseSucceed(() => false) swallows the check error; remove it so the TeleportFileLockedError propagates instead of failing open.
| }).pipe( | |
| Effect.map((result) => result.stdout.trim().length > 0), | |
| Effect.orElseSucceed(() => false), | |
| ); | |
| }).pipe( | |
| Effect.map((result) => result.stdout.trim().length > 0), | |
| ); |
In file @apps/server/src/teleport/fileLock.ts around lines 52-55:
`requireNativePathUnlocked` treats every non-Windows `lsof` failure—including `ENOENT` when `lsof` is unavailable and the 2-second timeout—as an unlocked path, so export can proceed while a native session is actively being written. `Effect.orElseSucceed(() => false)` swallows the check error; remove it so the `TeleportFileLockedError` propagates instead of failing open.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (first === undefined) { | ||
| return true; | ||
| } | ||
| if (first === "home" || first === "users" || first === "root") { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium teleport/cwd.ts:76
opencodeSessionMatchesProjectCwd("/root/workspace", "/root/workspace/subproject") returns false, hiding valid OpenCode sessions launched from /root/workspace. isGenericTeleportCwd applies the /home/<user> depth rule to root, so it incorrectly classifies /root/workspace as a generic cwd; restrict the depth check for root to /root itself.
- if (first === "home" || first === "users" || first === "root") { + if (first === "home" || first === "users" || (first === "root" && parts.length <= 1)) {
In file @apps/server/src/teleport/cwd.ts around line 76:
`opencodeSessionMatchesProjectCwd("/root/workspace", "/root/workspace/subproject")` returns `false`, hiding valid OpenCode sessions launched from `/root/workspace`. `isGenericTeleportCwd` applies the `/home/<user>` depth rule to `root`, so it incorrectly classifies `/root/workspace` as a generic cwd; restrict the depth check for `root` to `/root` itself.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| }; | ||
| } | ||
|
|
||
| case "thread.history-replaced": { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟠 High state/threadReducer.ts:562
thread.history-replaced leaves the existing pagination epoch and cursor valid, so an in-flight or later loadOlderTurns response can merge pre-replacement messages, activities, plans, and checkpoints back into the imported history. Because applyItemLocked calls setThread(result.thread, "keep") and only bumps historyEpoch for thread.reverted, this event must invalidate outstanding pages and reset or rebuild pagination state.
In file @packages/client-runtime/src/state/threadReducer.ts around line 562:
`thread.history-replaced` leaves the existing pagination epoch and cursor valid, so an in-flight or later `loadOlderTurns` response can merge pre-replacement messages, activities, plans, and checkpoints back into the imported history. Because `applyItemLocked` calls `setThread(result.thread, "keep")` and only bumps `historyEpoch` for `thread.reverted`, this event must invalidate outstanding pages and reset or rebuild pagination state.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| message: `Teleport does not support provider '${provider}'.`, | ||
| }); | ||
| } | ||
| const nativePath = yield* adapter.write({ |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟠 High Layers/TeleportService.ts:687
exportSession writes or updates the native file before the binding and presence: "native" are durably persisted, so a later directory.upsert or thread.teleport.set failure leaves a native copy alongside T3-owned state. importSessions has the same inconsistency in reverse: thread mutations occur before binding/presence persistence, so failures leave orphaned threads or replaced history, and a later batch failure leaves earlier sessions partially imported. Make these operations transactional with rollback/compensation (or persist the ownership transition before the native/thread mutation) and define batch atomicity so the single-writer invariant is preserved.
In file @apps/server/src/teleport/Layers/TeleportService.ts around line 687:
`exportSession` writes or updates the native file before the binding and `presence: "native"` are durably persisted, so a later `directory.upsert` or `thread.teleport.set` failure leaves a native copy alongside T3-owned state. `importSessions` has the same inconsistency in reverse: thread mutations occur before binding/presence persistence, so failures leave orphaned threads or replaced history, and a later batch failure leaves earlier sessions partially imported. Make these operations transactional with rollback/compensation (or persist the ownership transition before the native/thread mutation) and define batch atomicity so the single-writer invariant is preserved.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const platform = yield* HostProcessPlatform; | ||
| // Default macOS volumes are case-insensitive. realpath keeps on-disk case | ||
| // when the path exists; missing paths fall back to the input spelling. | ||
| if (platform === "darwin") { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟠 High teleport/cwd.ts:113
On case-sensitive macOS volumes, teleportCwdsEquivalent returns true for distinct existing paths such as /work/Foo and /work/foo, so import validation can select the wrong project directory. The unconditional toLowerCase() comparison at line 114 must be replaced with a volume-aware case-sensitivity check.
In file @apps/server/src/teleport/cwd.ts around line 113:
On case-sensitive macOS volumes, `teleportCwdsEquivalent` returns `true` for distinct existing paths such as `/work/Foo` and `/work/foo`, so import validation can select the wrong project directory. The unconditional `toLowerCase()` comparison at line 114 must be replaced with a volume-aware case-sensitivity check.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.