Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 144 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
build:
name: Build
runs-on: ${{ github.event.repository.fork && 'ubuntu-24.04' || 'blacksmith-8vcpu-ubuntu-2404' }}
timeout-minutes: 10
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v6
Expand Down Expand Up @@ -129,6 +129,38 @@ jobs:
- name: Verify preload bundle output
run: node apps/desktop/scripts/verify-preload-bundle.mjs

- name: Build unsigned desktop archive without publishing
env:
T3CODE_DESKTOP_SIGNED: "false"
run: |
sudo apt-get install -y imagemagick
node scripts/build-desktop-artifact.ts --platform linux --target tar.gz --arch x64 --skip-build --output-dir "$RUNNER_TEMP/t3-desktop-archive"

- name: Verify Riftri in the complete desktop archive
run: |
mkdir "$RUNNER_TEMP/t3-desktop-extracted"
tar -xzf "$RUNNER_TEMP"/t3-desktop-archive/*.tar.gz -C "$RUNNER_TEMP/t3-desktop-extracted"
T3CODE_TEST_DESKTOP_ASAR=$(find "$RUNNER_TEMP/t3-desktop-extracted" -name app.asar -type f)
test -f "$T3CODE_TEST_DESKTOP_ASAR"
export T3CODE_TEST_DESKTOP_ASAR
export T3CODE_TEST_ELECTRON_BINARY=$(node -e "console.log(require(require.resolve('electron', { paths: ['./apps/desktop'] })))")
unset RIFTRI_BINARY
vp test run scripts/lib/riftri-packaging.test.ts -t 'complete desktop archive'

- name: Build CLI single-executable
env:
# Match the release build and SEA_NODE_VERSION in the server config.
VP_NODE_VERSION: "26.8.2"
run: node apps/server/scripts/cli.ts build-exe --verbose

- name: Package and start the standalone CLI in a temporary home
run: |
t3_artifact_version=$(node -p "require('./apps/server/package.json').version")
mkdir -p "$RUNNER_TEMP/t3-cli-resource-monitor/linux-x64"
cp native/resource-monitor/target/x86_64-unknown-linux-gnu/release/t3-resource-monitor "$RUNNER_TEMP/t3-cli-resource-monitor/linux-x64/"
node scripts/build-cli-archive.ts --platform linux --arch x64 --version "$t3_artifact_version" --resource-monitor-dir "$RUNNER_TEMP/t3-cli-resource-monitor" --output-dir "$RUNNER_TEMP/t3-cli-archive"
node scripts/smoke-cli-archive.ts --archive "$RUNNER_TEMP"/t3-cli-archive/*.tar.gz --expect-version "$t3_artifact_version"

# Everything except `t3` (apps/server) and the web app, which has its own job
# below. `--parallel` drops the package dependency ordering that `vp run`
# applies by default: these `test` tasks declare no `dependsOn` and resolve
Expand Down Expand Up @@ -478,6 +510,116 @@ jobs:
- name: Exercise release-only workflow steps
run: node scripts/release-smoke.ts

riftri_storage:
name: Riftri storage (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
os: [macos-15, ubuntu-24.04]
steps:
- name: Checkout
uses: actions/checkout@v6
with:
sparse-checkout: |
/*
!/.repos/
sparse-checkout-cone-mode: false

- name: Setup Vite+
uses: voidzero-dev/setup-vp@v1
with:
node-version-file: package.json
cache: true
run-install: true

- name: Ensure Electron runtime is installed
run: vp run --filter @t3tools/desktop ensure:electron

- name: Resolve published native runtimes
run: |
node --input-type=module <<'NODE' >> "$GITHUB_ENV"
import { createRequire } from 'node:module';
const server = createRequire(`${process.cwd()}/apps/server/package.json`);
const desktop = createRequire(`${process.cwd()}/apps/desktop/package.json`);
console.log(`T3CODE_TEST_RIFTRI_BINARY=${server('riftri').resolveBinary()}`);
console.log(`T3CODE_TEST_ELECTRON_BINARY=${desktop('electron')}`);
NODE
echo 'T3CODE_TEST_RIFTRI_PACKAGE=1' >> "$GITHUB_ENV"
echo 'RIFTRI_BYPASS=1' >> "$GITHUB_ENV"

- name: Prepare disposable Linux OverlayFS volume
if: runner.os == 'Linux'
run: |
# Only this disposable runner's mount namespace is used by the tests.
if test -e /proc/sys/kernel/apparmor_restrict_unprivileged_userns; then
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
fi
truncate -s 2G "$RUNNER_TEMP/t3-riftri-overlay.img"
mkdir "$RUNNER_TEMP/t3-riftri-overlay"
mkfs.ext4 -F "$RUNNER_TEMP/t3-riftri-overlay.img"
sudo mount -o loop "$RUNNER_TEMP/t3-riftri-overlay.img" "$RUNNER_TEMP/t3-riftri-overlay"
sudo chown "$(id -u):$(id -g)" "$RUNNER_TEMP/t3-riftri-overlay"

- name: Prepare disposable macOS APFS volume
if: runner.os == 'macOS'
run: |
hdiutil create -size 1g -fs APFS -volname T3RiftriProof -type SPARSEBUNDLE "$RUNNER_TEMP/t3-riftri-apfs.sparsebundle"
mkdir "$RUNNER_TEMP/t3-riftri-apfs"
hdiutil attach -nobrowse -mountpoint "$RUNNER_TEMP/t3-riftri-apfs" "$RUNNER_TEMP/t3-riftri-apfs.sparsebundle"
touch "$RUNNER_TEMP/t3-riftri-apfs/.metadata_never_index"

- name: Test native Git lifecycle and packaged runtime
shell: bash
run: |
unset RIFTRI_BINARY
command=(vp test run --fileParallelism=false
apps/server/src/vcs/RiftriWorktrees.test.ts
apps/server/src/vcs/GitVcsDriverCore.riftri.test.ts
apps/server/src/vcs/GitVcsDriverCore.riftri.performance.test.ts
apps/server/src/git/GitManager.test.ts
apps/server/src/orchestration-v2/ProjectionStore.worktreeRoots.test.ts
apps/server/src/serverRuntimeStartup.test.ts
apps/server/src/serverRuntimeStartup.autoPull.test.ts
apps/server/src/workspace/WorkspaceStorage.test.ts
scripts/lib/riftri-packaging.test.ts)
export T3CODE_TEST_RIFTRI_REPORT="$RUNNER_TEMP/t3-riftri-performance.json"
if test "$RUNNER_OS" = Linux; then
export T3CODE_TEST_RIFTRI_BACKEND=overlay-fs
export TMPDIR="$RUNNER_TEMP/t3-riftri-overlay"
export T3CODE_TEST_RIFTRI_VOLUME="$TMPDIR"
unshare --user --map-root-user --mount --propagation private -- "${command[@]}"
else
export T3CODE_TEST_RIFTRI_BACKEND=apfs-clone
export TMPDIR="$RUNNER_TEMP/t3-riftri-apfs"
export T3CODE_TEST_RIFTRI_VOLUME="$TMPDIR"
"${command[@]}"
fi

- name: Upload physical storage and latency measurements
if: always()
uses: actions/upload-artifact@v7
with:
name: riftri-performance-${{ matrix.os }}
path: ${{ runner.temp }}/t3-riftri-performance.json
if-no-files-found: error
retention-days: 30

- name: Unmount disposable macOS volume
if: always() && runner.os == 'macOS'
run: |
if mount | grep -Fq " on $RUNNER_TEMP/t3-riftri-apfs "; then
hdiutil detach "$RUNNER_TEMP/t3-riftri-apfs"
fi

- name: Unmount disposable Linux volume
if: always() && runner.os == 'Linux'
run: |
if mountpoint -q "$RUNNER_TEMP/t3-riftri-overlay"; then
sudo umount "$RUNNER_TEMP/t3-riftri-overlay"
fi

# Branch protection requires this job by its name, `Check`. It fails when any
# other job fails, is cancelled, or is skipped without a reason, so splitting
# or resharding jobs needs no ruleset change. Add every new job to `needs`.
Expand All @@ -499,6 +641,7 @@ jobs:
mobile_native_changes,
mobile_native_static_analysis,
release_smoke,
riftri_storage,
]
runs-on: ${{ github.event.repository.fork && 'ubuntu-24.04' || 'blacksmith-2vcpu-ubuntu-2404' }}
timeout-minutes: 5
Expand Down
1 change: 1 addition & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"node-pty": "^1.2.0-beta.15",
"playwright-core": "1.60.0",
"proper-lockfile": "4.1.2",
"riftri": "0.6.4",
"stream-chain": "^4.2.5",
"stream-json": "3.6.0",
"yaml": "catalog:",
Expand Down
8 changes: 8 additions & 0 deletions apps/server/src/git/GitManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ import * as ProjectSetupScriptRunner from "../project/ProjectSetupScriptRunner.t
import * as ProviderRegistry from "../provider/ProviderRegistry.ts";
import * as ServerSettings from "../serverSettings.ts";
import * as GitManager from "./GitManager.ts";
import * as WorkspaceStorage from "../workspace/WorkspaceStorage.ts";
import { HostProcessEnvironment } from "@t3tools/shared/hostProcess";

const encodeCliJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
const decodeForgejoPullRequest = Schema.decodeEffect(ForgejoPullRequestSchema);
Expand Down Expand Up @@ -732,6 +734,7 @@ function makeManager(input?: {
),
),
).pipe(
Layer.provide(WorkspaceStorage.layer),
Layer.provideMerge(VcsProcess.layer),
Layer.provideMerge(NodeServices.layer),
Layer.provideMerge(layerServerConfig),
Expand Down Expand Up @@ -794,6 +797,11 @@ const layerGitManagerTest = GitVcsDriver.layer.pipe(
Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "t3-git-manager-test-" })),
Layer.provideMerge(VcsProcess.layer),
Layer.provideMerge(NodeServices.layer),
// These fixtures remove their temporary directories directly. Native bases
// need journaled cleanup, covered by GitVcsDriverCore.riftri.test.ts instead.
Layer.provideMerge(
Layer.succeed(HostProcessEnvironment, { ...process.env, T3CODE_WORKTREE_STORAGE: "git" }),
),
);

it.layer(layerGitManagerTest)("GitManager", (it) => {
Expand Down
36 changes: 36 additions & 0 deletions apps/server/src/orchestration-v2/ProjectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
ThreadId,
TurnItemId,
NodeId,
ProjectId,
} from "@t3tools/contracts";
import {
createOrchestrationV2TurnItemVisibility,
Expand Down Expand Up @@ -91,6 +92,8 @@ import {
OLDER_THREAD_USER_TURN_LIMIT,
} from "./threadHistoryPaging.ts";

const WorktreeRoot = Schema.Struct({ projectId: ProjectId, worktreePath: Schema.String });

export class ProjectionStoreApplyEventError extends Schema.TaggedError<ProjectionStoreApplyEventError>()(
"ProjectionStoreApplyEventError",
{
Expand Down Expand Up @@ -383,6 +386,11 @@ export interface ProjectionStoreV2Shape {
Effect.Effect<OrchestrationV2ThreadShellSnapshot, ProjectionStoreV2Error>,
ProjectionStoreV2Error
>;
/** Storage startup needs roots, not run/session/message enrichment. Includes archives. */
readonly getWorktreeRoots: () => Effect.Effect<
ReadonlyArray<typeof WorktreeRoot.Type>,
ProjectionStoreV2Error
>;
readonly getThreadShell: (
threadId: ThreadId,
) => Effect.Effect<OrchestrationV2ThreadShell | null, ProjectionStoreV2Error>;
Expand Down Expand Up @@ -5515,6 +5523,19 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
)
.pipe(Effect.mapError((cause) => new ProjectionStoreSetupError({ cause })));

const getWorktreeRoots: ProjectionStoreV2Shape["getWorktreeRoots"] = () =>
sql`
SELECT DISTINCT
json_extract(payload_json, '$.projectId') AS projectId,
json_extract(payload_json, '$.worktreePath') AS worktreePath
FROM orchestration_v2_projection_threads
WHERE deleted_at IS NULL
AND json_extract(payload_json, '$.worktreePath') IS NOT NULL
`.pipe(
Effect.flatMap(Schema.decodeUnknownEffect(Schema.Array(WorktreeRoot))),
Effect.mapError((cause) => new ProjectionStoreSetupError({ cause })),
);

const getThreadsWithPullRequests: ProjectionStoreV2Shape["getThreadsWithPullRequests"] = (
threadId,
) =>
Expand Down Expand Up @@ -5877,6 +5898,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
apply,
getShellSnapshot,
readShellSnapshot,
getWorktreeRoots,
getThreadShell,
getThread,
getSettlementCandidates,
Expand Down Expand Up @@ -5922,6 +5944,20 @@ export const layerMemory: Layer.Layer<ProjectionStoreV2> = Layer.effect(
const sequence = yield* Ref.make(0);

const service: ProjectionStoreV2Shape = {
getWorktreeRoots: () =>
Ref.get(replayState).pipe(
Effect.map(({ projections }) => {
const roots = new Map<string, typeof WorktreeRoot.Type>();
for (const { thread } of projections.values()) {
if (thread.deletedAt !== null || thread.worktreePath === null) continue;
roots.set(JSON.stringify([thread.projectId, thread.worktreePath]), {
projectId: thread.projectId,
worktreePath: thread.worktreePath,
});
}
return [...roots.values()];
}),
),
apply: (event) =>
Effect.gen(function* () {
const result = yield* Ref.modify(replayState, (existing) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { assert, it } from "@effect/vitest";
import { EventId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
import * as DateTime from "effect/DateTime";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as ProjectionStore from "./ProjectionStore.ts";
import * as SqlitePersistence from "../persistence/Sqlite.ts";

it.effect.each([
{
name: "sqlite",
layer: ProjectionStore.layer.pipe(Layer.provide(SqlitePersistence.layerMemory)),
},
{ name: "memory", layer: ProjectionStore.layerMemory },
])("$name: startup reads distinct live worktree roots, including archived threads", ({ layer }) =>
Effect.gen(function* () {
const store = yield* ProjectionStore.ProjectionStoreV2;
const now = yield* DateTime.now;
const providerInstanceId = ProviderInstanceId.make("codex");
for (const [suffix, worktreePath, archived, deleted, project] of [
["main", null, false, false, "one"],
["active", "/views/shared", false, false, "one"],
["duplicate", "/views/shared", false, false, "one"],
["archived", "/views/archived", true, false, "one"],
["deleted", "/views/deleted", false, true, "one"],
["other-project", "/views/shared", false, false, "two"],
] as const) {
const threadId = ThreadId.make(`thread:${suffix}`);
yield* store.apply({
id: EventId.make(`event:${suffix}`),
type: "thread.created",
threadId,
occurredAt: now,
payload: {
id: threadId,
projectId: ProjectId.make(project),
title: suffix,
createdBy: "user",
creationSource: "web",
providerInstanceId,
modelSelection: { instanceId: providerInstanceId, model: "gpt-5.4" },
runtimeMode: "full-access",
interactionMode: "default",
branch: null,
worktreePath,
activeProviderThreadId: null,
lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
forkedFrom: null,
createdAt: now,
updatedAt: now,
archivedAt: archived ? now : null,
deletedAt: deleted ? now : null,
settledOverride: null,
settledAt: null,
lastVisitedAt: null,
},
});
}
const roots = yield* store.getWorktreeRoots();
assert.deepEqual(
roots.toSorted((a, b) =>
`${a.projectId}:${a.worktreePath}`.localeCompare(`${b.projectId}:${b.worktreePath}`),
),
[
{ projectId: "one", worktreePath: "/views/archived" },
{ projectId: "one", worktreePath: "/views/shared" },
{ projectId: "two", worktreePath: "/views/shared" },
],
);
}).pipe(Effect.provide(layer)),
);
Loading
Loading