mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-15 02:20:38 +09:00
Add local environment lifecycle (#4297)
## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies. > - Every heartbeat run needs a concrete place where the agent's adapter process executes. > - Today that execution location is implicitly the local machine, which makes it hard to track, audit, and manage as a first-class runtime concern. > - The first step is to represent the current local execution path explicitly without changing how users experience agent runs. > - This pull request adds core Environment and Environment Lease records, then routes existing local heartbeat execution through a default `Local` environment. > - The benefit is that local runs remain behavior-preserving while the system now has durable environment identity, lease lifecycle tracking, and activity records for execution placement. ## What Changed - Added `environments` and `environment_leases` database tables, schema exports, and migration `0065_environments.sql`. - Added shared environment constants, TypeScript types, and validators for environment drivers, statuses, lease policies, lease statuses, and cleanup states. - Added `environmentService` for listing, reading, creating, updating, and ensuring company-scoped environments. - Added environment lease lifecycle operations for acquire, metadata update, single-lease release, and run-wide release. - Updated heartbeat execution to lazily ensure a company-scoped default `Local` environment before adapter execution. - Updated heartbeat execution to acquire an ephemeral local environment lease, write `paperclipEnvironment` into the run context snapshot, and release active leases during run finalization. - Added activity log events for environment lease acquisition and release. - Added tests for environment service behavior and the local heartbeat environment lifecycle. - Added a CI-follow-up heartbeat guard so deferred issue comment wakes are promoted before automatic missing-comment retries, with focused batching test coverage. ## Verification Local verification run for this branch: - `pnpm -r typecheck` - `pnpm build` - `pnpm exec vitest run server/src/__tests__/environment-service.test.ts server/src/__tests__/heartbeat-local-environment.test.ts --pool=forks` Additional reviewer/CI verification: - Confirm `pnpm-lock.yaml` is not modified. - Confirm `pnpm test:run` passes in CI. - Confirm `PAPERCLIP_E2E_SKIP_LLM=true pnpm run test:e2e` passes in CI. - Confirm a local heartbeat run creates one active `Local` environment when needed, records one lease for the run, releases the lease when the run finishes, and includes `paperclipEnvironment` in the run context snapshot. Screenshots: not applicable; this PR has no UI changes. ## Risks - Migration risk: introduces two new tables and a new migration journal entry. Review should verify company scoping, indexes, foreign keys, and enum defaults are correct. - Lifecycle risk: heartbeat finalization now releases environment leases in addition to existing runtime cleanup. A finalization bug could leave stale active leases or mark a failed run's lease incorrectly. - Behavior-preservation risk: local adapter execution should remain unchanged apart from environment bookkeeping. Review should pay attention to the heartbeat path around context snapshot updates and final cleanup ordering. - Activity volume risk: each heartbeat run now logs lease acquisition and release events, increasing activity log volume by two records per run. ## Model Used OpenAI GPT-5.4 via Codex CLI. Capabilities used: repository inspection, TypeScript implementation review, local test/build execution, and PR-description drafting. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots (N/A: no UI changes) - [x] I have updated relevant documentation to reflect my changes (N/A: no user-facing docs or commands changed) - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge
This commit is contained in:
parent
b69b563aa8
commit
13551b2bac
17 changed files with 1098 additions and 2 deletions
34
packages/shared/src/validators/environment.ts
Normal file
34
packages/shared/src/validators/environment.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { z } from "zod";
|
||||
import {
|
||||
ENVIRONMENT_DRIVERS,
|
||||
ENVIRONMENT_LEASE_CLEANUP_STATUSES,
|
||||
ENVIRONMENT_LEASE_STATUSES,
|
||||
ENVIRONMENT_STATUSES,
|
||||
} from "../constants.js";
|
||||
|
||||
export const environmentDriverSchema = z.enum(ENVIRONMENT_DRIVERS);
|
||||
export const environmentStatusSchema = z.enum(ENVIRONMENT_STATUSES);
|
||||
export const environmentLeaseStatusSchema = z.enum(ENVIRONMENT_LEASE_STATUSES);
|
||||
export const environmentLeaseCleanupStatusSchema = z.enum(ENVIRONMENT_LEASE_CLEANUP_STATUSES);
|
||||
|
||||
const environmentFields = {
|
||||
name: z.string().min(1),
|
||||
description: z.string().optional().nullable(),
|
||||
driver: environmentDriverSchema,
|
||||
status: environmentStatusSchema.optional().default("active"),
|
||||
config: z.record(z.unknown()).optional().default({}),
|
||||
metadata: z.record(z.unknown()).optional().nullable(),
|
||||
};
|
||||
|
||||
export const createEnvironmentSchema = z.object(environmentFields).strict();
|
||||
export type CreateEnvironment = z.infer<typeof createEnvironmentSchema>;
|
||||
|
||||
export const updateEnvironmentSchema = z.object({
|
||||
name: z.string().min(1).optional(),
|
||||
description: z.string().optional().nullable(),
|
||||
driver: environmentDriverSchema.optional(),
|
||||
status: environmentStatusSchema.optional(),
|
||||
config: z.record(z.unknown()).optional(),
|
||||
metadata: z.record(z.unknown()).optional().nullable(),
|
||||
}).strict();
|
||||
export type UpdateEnvironment = z.infer<typeof updateEnvironmentSchema>;
|
||||
|
|
@ -24,6 +24,16 @@ export {
|
|||
type UpdateCompany,
|
||||
type UpdateCompanyBranding,
|
||||
} from "./company.js";
|
||||
export {
|
||||
environmentDriverSchema,
|
||||
environmentStatusSchema,
|
||||
environmentLeaseStatusSchema,
|
||||
environmentLeaseCleanupStatusSchema,
|
||||
createEnvironmentSchema,
|
||||
updateEnvironmentSchema,
|
||||
type CreateEnvironment,
|
||||
type UpdateEnvironment,
|
||||
} from "./environment.js";
|
||||
export {
|
||||
feedbackDataSharingPreferenceSchema,
|
||||
feedbackTargetTypeSchema,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue