Repository navigation
fix(composer): read dropped threads across environments #14255
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.
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
Bil0000
wants to merge
4
commits into
pingdotgg:t3code/codex-turn-mapping
from
Bil0000:t3code/cross-environment-thread-drag
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9d9d0e1
fix(composer): attach thread context across environments
Bil0000 1009ff3
fix(composer): clarify imported paths and match service conventions
Bil0000 dae7a21
fix(composer): reject oversized thread exports before transfer
Bil0000 e18817f
test(server): exercise transcript exports through real services
Bil0000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| import { | ||
| AuthSessionId, | ||
| type AuthEnvironmentScope, | ||
| EnvironmentAuthenticatedAuth, | ||
| EnvironmentAuthenticatedPrincipal, | ||
| EnvironmentHttpApi, | ||
| EventId, | ||
| ORCHESTRATION_PROTOCOL_HEADER, | ||
| ORCHESTRATION_PROTOCOL_VERSION_TEXT, | ||
| OrchestrationV2AppThread, | ||
| OrchestrationV2TurnItem, | ||
| OrchestrationV2ThreadTranscript, | ||
| ThreadId, | ||
| } from "@t3tools/contracts"; | ||
| import { expect, it } from "@effect/vitest"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Context from "effect/Context"; | ||
| import * as DateTime from "effect/DateTime"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as Schema from "effect/Schema"; | ||
| import * as HttpRouter from "effect/unstable/http/HttpRouter"; | ||
| import * as HttpPlatform from "effect/unstable/http/HttpPlatform"; | ||
| import * as Etag from "effect/unstable/http/Etag"; | ||
| import * as NodeServices from "@effect/platform-node/NodeServices"; | ||
| import * as HttpApi from "effect/unstable/httpapi/HttpApi"; | ||
| import * as HttpApiBuilder from "effect/unstable/httpapi/HttpApiBuilder"; | ||
| import { SqlitePersistenceMemory } from "../persistence/Layers/Sqlite.ts"; | ||
|
|
||
| import { OrchestrationEventStoreLive } from "../persistence/Layers/OrchestrationEventStore.ts"; | ||
| import { ProjectEnrichmentService } from "../project/ProjectEnrichmentService.ts"; | ||
| import { orchestrationHttpApiLayer } from "./http.ts"; | ||
| import { EventSinkV2 } from "./EventSink.ts"; | ||
| import * as ProjectStore from "./ProjectStore.ts"; | ||
| import * as ThreadManagementService from "./ThreadManagementService.ts"; | ||
| import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; | ||
| import { makeOrchestratorV2ReplayLayerWithRegistry } from "./testkit/ProviderReplayHarness.ts"; | ||
|
|
||
| class TranscriptTestApi extends HttpApi.make("environment").add( | ||
| EnvironmentHttpApi.groups.orchestration, | ||
| ) {} | ||
| const decodeTranscript = Schema.decodeUnknownEffect( | ||
| Schema.toCodecJson(OrchestrationV2ThreadTranscript), | ||
| ); | ||
|
|
||
| const now = DateTime.makeUnsafe("2026-09-29T00:00:00.000Z"); | ||
| const output = "Full tool output. ".repeat(4_000); | ||
| const thread = Schema.decodeUnknownSync(OrchestrationV2AppThread)({ | ||
| id: "source-thread", | ||
| projectId: "source-project", | ||
| title: "Source conversation", | ||
| providerInstanceId: "codex", | ||
| modelSelection: { instanceId: "codex", model: "gpt-5.4" }, | ||
| runtimeMode: "full-access", | ||
| interactionMode: "default", | ||
| branch: null, | ||
| worktreePath: null, | ||
| activeProviderThreadId: null, | ||
| lineage: { rootThreadId: "source-thread", parentThreadId: null, relationshipToParent: null }, | ||
| forkedFrom: null, | ||
| createdBy: "user", | ||
| creationSource: "web", | ||
| createdAt: now, | ||
| updatedAt: now, | ||
| archivedAt: null, | ||
| settledOverride: null, | ||
| settledAt: null, | ||
| lastVisitedAt: null, | ||
| deletedAt: null, | ||
| }); | ||
| const items = Schema.decodeUnknownSync(Schema.Array(OrchestrationV2TurnItem))( | ||
| Array.from({ length: 200 }, (_, position) => ({ | ||
| id: `item-${position}`, | ||
| threadId: "source-thread", | ||
| runId: null, | ||
| nodeId: null, | ||
| providerThreadId: null, | ||
| providerTurnId: null, | ||
| nativeItemRef: null, | ||
| parentItemId: null, | ||
| ordinal: position, | ||
| type: "command_execution", | ||
| status: "completed", | ||
| title: "Read notes", | ||
| input: "cat notes.md", | ||
| output: position === 0 ? output : "Done", | ||
| startedAt: now, | ||
| completedAt: now, | ||
| updatedAt: now, | ||
| })), | ||
| ); | ||
|
|
||
| it.effect("exports full history with size, scope, and missing-thread checks", () => | ||
| Effect.gen(function* () { | ||
| let allowed = true; | ||
| const runtime = makeOrchestratorV2ReplayLayerWithRegistry( | ||
| { name: "thread-transcript" }, | ||
| ProviderAdapterRegistry.makeLayer([]), | ||
| { runEffectWorker: false }, | ||
| ); | ||
| const services = yield* Layer.build( | ||
| Layer.mergeAll( | ||
| runtime, | ||
| ThreadManagementService.layer.pipe(Layer.provide(runtime)), | ||
| OrchestrationEventStoreLive, | ||
| ProjectStore.layer, | ||
| ).pipe(Layer.provideMerge(SqlitePersistenceMemory)), | ||
| ); | ||
| const eventSink = Context.get(services, EventSinkV2); | ||
| yield* eventSink.write({ | ||
| events: [ | ||
| { | ||
| id: EventId.make("create-source"), | ||
| type: "thread.created", | ||
| threadId: thread.id, | ||
| occurredAt: now, | ||
| payload: thread, | ||
| }, | ||
| ...items.map((item) => ({ | ||
| id: EventId.make(`create-${item.id}`), | ||
| type: "turn-item.updated" as const, | ||
| threadId: thread.id, | ||
| occurredAt: now, | ||
| payload: item, | ||
| })), | ||
| ], | ||
| }); | ||
| const routes = HttpApiBuilder.layer(TranscriptTestApi).pipe( | ||
| Layer.provide(orchestrationHttpApiLayer), | ||
| Layer.provide( | ||
| Layer.succeed(EnvironmentAuthenticatedAuth, (effect) => | ||
| Effect.suspend(() => | ||
| effect.pipe( | ||
| Effect.provideService(EnvironmentAuthenticatedPrincipal, { | ||
| sessionId: AuthSessionId.make("test-session"), | ||
| subject: "test", | ||
| method: "bearer-access-token", | ||
| scopes: new Set<AuthEnvironmentScope>(allowed ? ["orchestration:read"] : []), | ||
| }), | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| Layer.provide(Layer.succeedContext(services)), | ||
| Layer.provide(Layer.mock(ProjectEnrichmentService)({})), | ||
| Layer.provide(HttpPlatform.layer), | ||
| Layer.provide(Etag.layerWeak), | ||
| Layer.provide(NodeServices.layer), | ||
| ); | ||
| const { handler, dispose } = HttpRouter.toWebHandler(routes, { disableLogger: true }); | ||
| yield* Effect.addFinalizer(() => Effect.promise(dispose)); | ||
| const read = (threadId: ThreadId) => | ||
| Effect.promise(() => | ||
| handler( | ||
| new Request(`http://localhost/api/orchestration/threads/${threadId}/transcript`, { | ||
| headers: { [ORCHESTRATION_PROTOCOL_HEADER]: ORCHESTRATION_PROTOCOL_VERSION_TEXT }, | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| const response = yield* read(thread.id); | ||
| expect(response.status).toBe(200); | ||
| const transcript = yield* decodeTranscript(yield* Effect.promise(() => response.json())); | ||
| expect(transcript.items).toHaveLength(200); | ||
| expect(transcript.items[0]?.item).toMatchObject({ output }); | ||
| expect(transcript.items[0]?.visibility).toBe("local"); | ||
| expect(transcript.items[199]?.position).toBe(199); | ||
|
|
||
| const largeOutput = "界".repeat(100_000); | ||
| yield* eventSink.write({ | ||
| events: items.map((item) => ({ | ||
| id: EventId.make(`enlarge-${item.id}`), | ||
| type: "turn-item.updated" as const, | ||
| threadId: thread.id, | ||
| occurredAt: now, | ||
| payload: { ...item, output: largeOutput }, | ||
| })), | ||
| }); | ||
| const oversized = yield* read(thread.id); | ||
| expect(oversized.status).toBe(400); | ||
| expect(yield* Effect.promise(() => oversized.json())).toMatchObject({ | ||
| _tag: "EnvironmentRequestInvalidError", | ||
| reason: "thread_transcript_too_large", | ||
| }); | ||
|
|
||
| expect((yield* read(ThreadId.make("missing"))).status).toBe(404); | ||
| allowed = false; | ||
| expect((yield* read(thread.id)).status).toBe(403); | ||
| }), | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.