@fungi.computer/oyster 0.25.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,7 +23,7 @@ import { type Release } from "@fungi.computer/puffball";
23
23
  import { type AppPublisherCoreConfigInput } from "./build/effect.js";
24
24
  import { type TeamAppCandidateManifest } from "./build/submission-contract.js";
25
25
  import { type ContentObjectOwner } from "./build/content-objects.js";
26
- import { type ArtifactHeads, type ArtifactStore } from "./release.js";
26
+ import { type ArtifactDeletes, type ArtifactHeads, type ArtifactStore } from "./release.js";
27
27
  import type { PublisherTemplateSeedReceipts } from "./source/seed-receipt.js";
28
28
  /** A Computer's whole-build budget: a cold build on a 6 GiB Computer measured 185-270 s. */
29
29
  export declare const oysterAppBuildTimeoutMs = 900000;
@@ -164,13 +164,15 @@ export type OysterAppBuildOptions = Readonly<{
164
164
  port: OysterBuildComputer;
165
165
  }>;
166
166
  /** The host's artifact store; a build's objects are already in it. */
167
- artifacts: ArtifactStore & ArtifactHeads;
167
+ artifacts: ArtifactStore & ArtifactHeads & ArtifactDeletes;
168
168
  /** The seed receipts a template build must match. */
169
169
  templates: Pick<PublisherTemplateSeedReceipts, "read">;
170
170
  now?: () => number;
171
171
  }>;
172
172
  /** Create the current build tables and index atomically; an older store is refused, never converted. */
173
173
  export declare function migrateOysterAppBuilds(owner: WatchdogSqliteOwner): void;
174
+ /** Build logs kept per App; older logs are removed after each new one is written. */
175
+ export declare const retainedBuildLogs = 5;
174
176
  /** The build owner over one tenant's SQLite, Computer and artifact store. */
175
177
  export declare function createOysterAppBuilds(options: OysterAppBuildOptions): Readonly<{
176
178
  /** Record (or replace) an App's build source; the caller is the owner. */
@@ -127,6 +127,7 @@ const jobRow = Schema.Struct({
127
127
  executable_until: Schema.Number,
128
128
  });
129
129
  const decodeJob = Schema.decodeUnknownSync(jobRow);
130
+ const decodeJobId = Schema.decodeUnknownSync(Schema.Struct({ job_id: Schema.String }));
130
131
  const sourceRow = Schema.Struct({ source: Schema.String });
131
132
  const releaseRow = Schema.Struct({ release: Schema.String });
132
133
  const sourceCodec = Schema.fromJsonString(oysterBuildSourceSchema);
@@ -169,6 +170,8 @@ export function migrateOysterAppBuilds(owner) {
169
170
  sql.exec("CREATE TABLE IF NOT EXISTS oyster_build_releases (release_id TEXT PRIMARY KEY, job_id TEXT NOT NULL UNIQUE, release TEXT NOT NULL) STRICT");
170
171
  });
171
172
  }
173
+ /** Build logs kept per App; older logs are removed after each new one is written. */
174
+ export const retainedBuildLogs = 5;
172
175
  /** The build owner over one tenant's SQLite, Computer and artifact store. */
173
176
  export function createOysterAppBuilds(options) {
174
177
  const { owner } = options;
@@ -245,6 +248,16 @@ export function createOysterAppBuilds(options) {
245
248
  // It is read only through the owner build door, never exposed as a Release.
246
249
  const logRef = (jobId) => parseArtifactRef(`artifact:build-log-${jobId}`);
247
250
  const logCodec = Schema.fromJsonString(buildJobLogSchema);
251
+ // Job rows and statuses stay; only the older logs of one App are removed.
252
+ // The ranking is read from the job table each time, so replays, retries and
253
+ // an owner restart can never delete a log inside the retained five.
254
+ const pruneLogs = async (appId) => {
255
+ const stale = owner.sql
256
+ .exec("SELECT job_id FROM oyster_build_jobs WHERE app_id=? ORDER BY issued_at DESC, rowid DESC LIMIT -1 OFFSET ?", appId, retainedBuildLogs)
257
+ .toArray();
258
+ for (const row of stale)
259
+ await options.artifacts.delete(logRef(decodeJobId(row).job_id));
260
+ };
248
261
  const publisher = createTeamBuildPublisher({
249
262
  teamId: options.tenantId,
250
263
  now,
@@ -286,6 +299,7 @@ export function createOysterAppBuilds(options) {
286
299
  timeoutMs: input.timeoutMs,
287
300
  });
288
301
  await options.artifacts.put(logRef(input.jobId), new TextEncoder().encode(Schema.encodeUnknownSync(logCodec)(result.log)));
302
+ await pruneLogs(required(input.jobId).app_id);
289
303
  if (result.output === null)
290
304
  throw new BuildOutcomeUnknown();
291
305
  return result;