Skip to content
Source
Sign inSign up
pingdotgg/t3code

refactor(server): commit project commands without the V1 engine #13896

Closedjuliusmarmingewants to merge 1 commit intot3code/codex-turn-mapping fromv2/v2-nuke-v1-engine-1opened View on GitHub

juliusmarmingecommented

The V2 runtime still built V1's OrchestrationLayerLive for one caller: ProjectService dispatched project.create / project.meta.update / project.delete through the V1 OrchestrationEngine. That engine hydrated the whole V1 in-memory read model at boot (getCommandReadModel) and kept it for the process lifetime. The V1 ProjectionSnapshotQuery was also still used for project shells and a few reads.

First layer of removing the V1 engine: port the remaining callers so nothing at runtime builds the engine, projection pipeline or snapshot query. The next layer deletes the V1 decider, projector, pipeline and snapshot query.

What changed

  • Project commands (project/ProjectService.ts, new project/ProjectEvents.ts). In one SQL transaction the service checks the command receipt, re-checks the workspace-root conflict, validates the command, appends the event, writes the receipt and projects the projection_projects row with a pure projectProjectEvent. After commit it publishes the event to shell subscribers. Event types and payloads are the existing project.created / project.meta-updated / project.deleted (ApplicationProjectEvent), so rows written by V1, the 055 baseline and this code decode the same way. The validation the V1 decider did (existence, active workspace-root collision, script-ID shortcut rule with legacy IDs still editable, monogram ≤ 2 graphemes) moved with it, and so did idempotent retries by command ID, including durable rejections.
  • Readers (new project/ProjectShells.ts). They read ProjectionProjectRepository directly, which V2 already uses, instead of a new read model. Covered: ws/http shell snapshots and project deltas, startup auto-pull, storage cleanup, auto-pull policy, per-project git settings, PR list/link/sync, thread settlement, the agent-session scanner and the MCP PR tools. Enrichment reads only immediately available identity, as before.
  • Thread search moved unchanged into orchestration-v2/ThreadSearch.ts. It still covers V1 threads whose transcripts have not been imported, so the V1 message tables stay read-only import input.
  • Replay stats for shell resume is now an inline range query in ws.ts.
  • Wiring: OrchestrationEventInfrastructureLayerLive (event store + receipts) moved to orchestration-v2/runtimeLayer.ts. server.ts provides ProjectionProjectRepositoryLive where it used to provide OrchestrationInfrastructureLayerLive.
  • Deleted: orchestration/Layers/OrchestrationEngine.ts, orchestration/Services/OrchestrationEngine.ts, orchestration/runtimeLayer.ts. Also deleted: the three t3_orchestration_command* metrics, which only the V1 engine recorded, and their section in docs/operations/observability.md.

The wire contract is unchanged: no contract edits, and web/mobile untouched.

One behavior difference: V1 project deletion also wrote deleted_at on the legacy projection_threads row. That row is now import input only. The imported V2 thread is deleted through the V2 command as before, and the importer skips it, so ProjectService.deletion.test.ts now asserts on the V2 row.

Verification

  • vp exec tsc --noEmit -p . in apps/server, apps/web, apps/mobile, packages/client-runtime, packages/contracts: 0 error TS / warning TS.
  • vp run knip:check: clean.
  • vp lint on touched files: no new warnings.
  • vp test run in small groups, all passing:
    • project: ProjectService.test.ts (3 new cases: idempotent retry and no rollback from a late retry, script-ID rules with durable rejection, monogram limit; mutation-checked by disabling the receipt check and the monogram rule, and both fail), new ProjectEvents.test.ts (ports the V1 decider's project-default, env-mode/autoPull clear and delete cases), ProjectService.deletion.test.ts, http.test.ts, ProjectMutation.test.ts, AgentSessionScanner.test.ts
    • consumers: linkCreatedPullRequest.test.ts, MCP pullRequests/handlers.test.ts, McpHttpServer.test.ts, worktree/registration.test.ts, ThreadPullRequestService.test.ts, ThreadSettlementService.test.ts, PullRequestService.test.ts, PullRequestSyncReactor.test.ts
    • runtime: runtimeLayer.test.ts, DelegatedCompletionDelivery.test.ts, serverRuntimeStartup.test.ts, ws.test.ts, http.test.ts, cli/project.test.ts
    • importer and migrations: LegacyV1Cutover.integration.test.ts, LegacyV1ThreadImporter.test.ts, 055_* (3 files), 056_*
    • replay: OrchestratorReplayFixtures.integration.test.ts + .contract.test.ts (98 tests)
  • Heap after boot. The server was started with --expose-gc on a VACUUM INTO copy of a real V2 DB (29 threads, 5.7k events, 3 projects) and sampled 40 s after listening, after forced GC. Two runs each: base 175.4 / 175.4 MiB heapUsed; this layer 172.7 / 172.7 MiB. That DB has already been imported, so its V1 read model was small. The saving grows with the size of the V1 tables in a user's DB. The layer-2 PR will carry final numbers.
  • Not run: the repo-wide suite, and web/mobile in a real client (there are no client changes).

Model: Claude Opus 5.5 (Claude Code)

🤖 Generated with Claude Code


Devin Review
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. @@ -469,3 +558,3 @@
      469558 { concurrency: 1, discard: true },
      470559 );
      471560 return yield* dispatch(
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High project/ProjectService.ts:560

      The project is soft-deleted while an active V2 thread can still reference it, leaving an orphaned runnable thread. ThreadLaunchService.launch can read the project before the snapshot and commit the thread before project.delete is committed, but projectCommandRejection accepts the delete without a final active-thread check; recheck active threads in the delete transaction and reject unless force is set.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/server/src/project/ProjectService.ts around line 560:
      
      The project is soft-deleted while an active V2 thread can still reference it, leaving an orphaned runnable thread. `ThreadLaunchService.launch` can read the project before the snapshot and commit the thread before `project.delete` is committed, but `projectCommandRejection` accepts the delete without a final active-thread check; recheck active threads in the delete transaction and reject unless `force` is set.
      @@ -714,15 +715,12 @@
      714715 const projectSettingsFor = Effect.fnUntraced(function* (input: {
      715716 readonly cwd: string;
      716717 readonly threadId?: ThreadId | undefined;
      717718 }) {
      718719 const settings = yield* serverSettingsService.getSettings;
      719- if (!hasProjectSettingsOverrides(settings) || Option.isNone(projectionQuery)) return settings;
      720- const projectId = yield* (
      720+ if (!hasProjectSettingsOverrides(settings)) return settings;
      721+ const none = () => Option.none<ProjectId>();
      722+ const projectId =
      721723 input.threadId !== undefined
      722- ? projectionQuery.value
      723- .getThreadShellById(input.threadId)
      724- .pipe(Effect.map(Option.map((thread) => thread.projectId)))
      725- : projectionQuery.value
      726- .getActiveProjectByWorkspaceRoot(input.cwd)
      727- .pipe(Effect.map(Option.map((project) => project.id)))
      728- ).pipe(Effect.orElseSucceed(() => Option.none<ProjectId>()));
      724+ ? Option.isNone(threadProjections)
      725+ ? none()
      726+ : yield* threadProjections.value.getThreadShell(input.threadId).pipe(
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium git/GitManager.ts:726

      Actions for existing V1 threads use global settings when the thread has not yet been lazily imported, so project-specific source-control writer settings are ignored. getThreadShell returns no thread in this case, and this lookup never calls ensureLegacyTranscript; resolve the legacy thread before reading its projectId (or retain the previous V1-aware lookup).

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/server/src/git/GitManager.ts around line 726:
      
      Actions for existing V1 threads use global settings when the thread has not yet been lazily imported, so project-specific source-control writer settings are ignored. `getThreadShell` returns no thread in this case, and this lookup never calls `ensureLegacyTranscript`; resolve the legacy thread before reading its `projectId` (or retain the previous V1-aware lookup).
      @@ -288,16 +384,11 @@
      288384 }),
      289385 ),
      290386 );
      291- yield* assertWorkspaceAvailable(input.projectId, workspaceRoot);
      292- const now = DateTime.formatIso(yield* DateTime.now);
      293387 return yield* dispatch(
      294- input.projectId,
      388+ input.commandId,
      295389 {
      296390 type: "project.create",
      297- commandId: input.commandId,
      298391 projectId: input.projectId,
      299392 title: input.title,
      300393 workspaceRoot,
      301- defaultModelSelection: input.defaultModelSelection ?? null,
      302- scripts: [...(input.scripts ?? [])],
      303- createdAt: now,
      394+ scripts: input.scripts ?? [],
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High project/ProjectService.ts:394

      Creating a project with input.defaultModelSelection silently stores defaultModelSelection: null, so the requested default model is lost. The project.create command omits this field and planProjectEvent applies the null default; include input.defaultModelSelection in the command payload.

      Suggested change
      394- scripts: input.scripts ?? [],
      394+ defaultModelSelection: input.defaultModelSelection ?? null,
      395+ scripts: input.scripts ?? [],
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/server/src/project/ProjectService.ts around line 394:
      
      Creating a project with `input.defaultModelSelection` silently stores `defaultModelSelection: null`, so the requested default model is lost. The `project.create` command omits this field and `planProjectEvent` applies the null default; include `input.defaultModelSelection` in the command payload.
    3. @@ -23,3 +24,5 @@
      2324 layer as threadCommandExecutorLayer,
      2425 } from "../orchestration-v2/ThreadCommandExecutor.ts";
      2526 import { planThreadDeletion } from "../orchestration-v2/ThreadDeletion.ts";
      27+import { OrchestrationCommandReceiptRepository } from "../persistence/Services/OrchestrationCommandReceipts.ts";
      28+import { OrchestrationEventStore } from "../persistence/Services/OrchestrationEventStore.ts";
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      These imports consume Effect services at a service boundary but import their tags by name. Could you import each local service module as a namespace and access its tag through that namespace (for example, OrchestrationEventStore.OrchestrationEventStore)?

      Posted via Macroscope — Effect Service Conventions
      @@ -0,0 +29,21 @@
      29+ repositoryIdentity,
      30+ defaultModelSelection: row.defaultModelSelection,
      31+ defaultThreadEnvMode: row.defaultThreadEnvMode,
      32+ autoPull: row.autoPull,
      33+ faviconPath: row.faviconPath ?? null,
      34+ projectIcon: row.projectIcon ?? null,
      35+ scripts: row.scripts,
      36+ createdAt: row.createdAt,
      37+ updatedAt: row.updatedAt,
      38+ };
      39+}
      40+
      41+/** Active projects in creation order, without enrichment. */
      42+export const listActiveProjectShells = (projects: ProjectRows) =>
      43+ projects
      44+ .listAll()
      45+ .pipe(
      46+ Effect.map((rows) =>
      47+ rows.flatMap((row) => (row.deletedAt === null ? [toProjectShell(row)] : [])),
      48+ ),
      49+ );
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      These production helpers accept ProjectionProjectRepository["Service"] (and, below, ProjectEnrichmentService["Service"]) as arguments, so their Effect dependencies disappear from the environment. Could you acquire the services with yield* ProjectionProjectRepository.ProjectionProjectRepository and yield* ProjectEnrichmentService.ProjectEnrichmentService inside the Effects, and let callers provide them through layers? The same applies to the other new project-shell helpers in this file.

      Posted via Macroscope — Effect Service Conventions
    4. Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR replaces the project-command engine and rewires many production read, persistence, worker, and WebSocket paths, including a changed project default-model behavior. Unresolved findings also identify incorrect V1 settings resolution and a project-deletion race affecting active threads.

      Not approved because:

      • 3 blocking correctness issues found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire—4.9 KiB—6.8 KiB✅
      CodexThread snapshot wire—3.7 KiB—4.9 KiB✅
      CodexLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      CodexLive turn WebSocket decoded—20.4 KiB—29.3 KiB✅
      CodexLive turn messages—2—8✅
      ClaudeTotal thread wire—4.9 KiB—6.8 KiB✅
      ClaudeThread snapshot wire—3.7 KiB—4.9 KiB✅
      ClaudeLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      ClaudeLive turn WebSocket decoded—20.8 KiB—29.3 KiB✅
      ClaudeLive turn messages—2—8✅

      Baseline: unavailable · PR result: 5b6e71b · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 106.1 KiB
      • Claude decoded thread snapshot: 106.4 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    6. juliusmarminge closed this

Sign in to join this conversation.