Skip to content
Merged
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
3 changes: 2 additions & 1 deletion apps/host/src/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ export interface LocalServiceOptions {
copilot?: ManagedCopilotTransport;
commands?: FixedCommandTransport;
persistenceFault?: FaultInjector;
persistenceDurability?: "durable" | "none";
}
export function createLocalServices(options: LocalServiceOptions): HostServices & {
persistence: LocalPersistence; runtime: LocalRuntime; work: LocalWork;
createAgentSession(context: RequestContext, agentId: string): Promise<{ token: string; principal: Principal }>;
} {
const persistence = new LocalPersistence(options.directory, options.token, options.persistenceFault);
const persistence = new LocalPersistence(options.directory, options.token, options.persistenceFault, options.persistenceDurability);
const work = new LocalWork(persistence);
const transport = options.copilot ?? new CopilotSdkTransport({
directory: join(persistence.directory, "providers", "github-copilot"), home: homedir(),
Expand Down
10 changes: 8 additions & 2 deletions apps/host/src/persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ export class LocalPersistence {
private opened = false;
private closed = false;

constructor(directory: string, private readonly credential: string, private readonly fault?: FaultInjector) {
constructor(
directory: string,
private readonly credential: string,
private readonly fault?: FaultInjector,
private readonly durability: "durable" | "none" = "durable",
) {
this.directory = resolve(directory);
this.security = new SecurityAuthority({
authenticate: (credential) => credential === this.credential && this.identity
Expand Down Expand Up @@ -387,7 +392,7 @@ export class LocalPersistence {
}
private async open(): Promise<void> {
await mkdir(this.directory, { recursive: true, mode: 0o700 });
this.root = await PrivateRoot.open(this.directory);
this.root = await PrivateRoot.open(this.directory, false, { sync: this.durability === "none" ? "none" : "durable" });
await this.root.lock(async () => {
if (await this.root.stat("owner.json") === null) {
await this.root.writeAtomic("owner.json", canonicalJson({
Expand Down Expand Up @@ -429,6 +434,7 @@ export class LocalPersistence {
root: join(this.directory, "workspaces"), security: this.security,
lockTimeoutMs: 30_000,
...(this.fault ? { fault: this.fault } : {}),
...(this.durability === "none" ? { durability: this.durability } : {}),
});
this.opened = true;
for (const scope of [this.identity.catalog, this.identity.computer]) {
Expand Down
2 changes: 1 addition & 1 deletion apps/host/test/production-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export async function productionFixture(options: { computer?: boolean; commands?
let remainingCommits: number | undefined;
const token = randomBytes(48).toString("base64url");
const services = createLocalServices({
directory, token, commands, copilot,
directory, token, commands, copilot, persistenceDurability: "none",
persistenceFault: (point) => {
if (point !== "before-commit") return;
if (remainingCommits !== undefined && --remainingCommits === 0) fault = true;
Expand Down
Loading
Loading