Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

fix(runtime): take back Dispatches abandoned by a stopped Worker

rpone54409aa4bb92
diff --git a/.agents/skills/hypit/references/runtime.md b/.agents/skills/hypit/references/runtime.md
index 9cfaf82b..88fbb771 100644
--- a/.agents/skills/hypit/references/runtime.md
+++ b/.agents/skills/hypit/references/runtime.md
@@ -120,6 +120,21 @@ Builds remain archived and neither command cancels remote Provider work.
a change that costs nothing on an idle Runtime costs the whole Build on a busy one. Nothing is lost
by waiting: accepted Records are durable, and the requests still in flight are the expensive ones.
+ **Check before every restart, and treat a running Build as a stop sign rather than a delay.** The
+ reading takes one command, and it is the same one whatever the reason for restarting:
+
+ ```bash
+ hypit runtime status # proceed only on Queued 0 · Running 0
+ ```
+
+ What follows a restart taken during a Build is not only the lost generation. The Build is left
+ `running` and holding the lane it reserved, a Worker claims only `queued` and `waiting` Builds, and
+ cancelling happens on a claimed Build — so it holds that lane against every later Build, and
+ `hypit cancel` reports the request and changes nothing. A current Worker takes such a Build back at
+ startup; an older one does not, and the symptom there is a queue that never moves while
+ `Active Operations` stays `0`. Read that pair — a Build `running` with no active operation — as this,
+ and restarting again is the one thing that cannot help.
+
## Keep the Distribution and every project physically separate
The Distribution reported by `hypit paths --json` is package-manager-owned and replaceable. Never
@@ -128,6 +143,21 @@ project is any independent directory such as `<home>/<name>/`, holding its Sourc
`packages/` directory in its own Git/workspace boundary. Published examples are read-only reference
material, never a place to turn into the author's project.
+**Give the project directory its own `package.json`, before the first `check`.** Package discovery
+starts at the project and walks up until it finds one; without it the search runs past the project
+and settles on whichever directory above happens to have one, and every `packages/local-*` the
+project owns becomes unresolvable — `cannot resolve installed package @scope/local-name`. A minimal
+file is the whole fix, and it is what makes the directory a boundary rather than a place that
+happens to hold Sources:
+
+```json
+{ "name": "<project-name>", "version": "0.0.0", "private": true, "type": "module" }
+```
+
+`hypit paths --json` confirms it: `project` names the project directory rather than something above
+it. Passing `--package-root .` on each command papers over the same gap for one command at a time
+and leaves the Worker — which resolves packages on its own — still looking in the wrong place.
+
Studio and the CLI resolve explicit project packages from the project root, then fall back to the
read-only Hypit Distribution. The `@hypit/*` namespace is reserved for the active Distribution and
is resolved there first; project packages use their own scope. This bridge is Host configuration;
diff --git a/packages/runtime-local/src/worker.ts b/packages/runtime-local/src/worker.ts
index a60f1c89..b11d81fd 100644
--- a/packages/runtime-local/src/worker.ts
+++ b/packages/runtime-local/src/worker.ts
@@ -235,6 +235,9 @@ class DurableLocalWorker {
async run(options: RuntimeWorkerRunOptions): Promise<void> {
positive(options.idlePollMs, "Worker idlePollMs");
const active = new Set<Promise<void>>();
+ // A Worker that went away mid-Dispatch left it `running` and holding its lane. This Worker owns
+ // the Runtime, so nothing else can be executing those: take them back before claiming anything.
+ await this.#options.stores.dispatch.reclaimAbandoned(Date.now());
try {
while (options.signal?.aborted !== true) {
while (true) {
diff --git a/packages/runtime/src/dispatch.ts b/packages/runtime/src/dispatch.ts
index 12f3c20b..8b1af305 100644
--- a/packages/runtime/src/dispatch.ts
+++ b/packages/runtime/src/dispatch.ts
@@ -71,6 +71,17 @@ export type BuildDispatchStore = {
read(build: string): Promise<BuildDispatchSnapshot | undefined>;
list(query?: DispatchQuery): Promise<readonly BuildDispatchSnapshot[]>;
claim(now?: number): Promise<BuildDispatchSnapshot | undefined>;
+ /**
+ * Return Dispatches abandoned mid-run to the claimable set and release the capacity they hold.
+ *
+ * `claim` only takes `queued` and `waiting` Dispatches, and nothing distinguishes a `running` one
+ * whose Worker is alive from one whose Worker is gone. A Worker that stops between claiming a
+ * Dispatch and finishing it therefore strands both the Dispatch and its lane reservation for good:
+ * later Builds queue behind a slot nobody holds, and a cancellation never runs because cancelling
+ * happens on a claimed Dispatch. One Worker owns a Runtime, so every `running` Dispatch at startup
+ * is abandoned by construction.
+ */
+ reclaimAbandoned(now?: number): Promise<readonly string[]>;
release(build: string, update: BuildDispatchRelease): Promise<BuildDispatchSnapshot>;
finish(build: string, terminal: DispatchTerminal, reason?: string): Promise<BuildDispatchSnapshot>;
requestCancellation(build: string, reason?: string): Promise<BuildDispatchSnapshot>;
diff --git a/packages/store-sqlite/src/store.ts b/packages/store-sqlite/src/store.ts
index 3562887b..ee9ffae0 100644
--- a/packages/store-sqlite/src/store.ts
+++ b/packages/store-sqlite/src/store.ts
@@ -540,6 +540,29 @@ class SqliteBuildDispatchStore implements BuildDispatchStore {
this.#database.prepare("DELETE FROM hypit_capacity WHERE build_id = ?").run(build);
}
+ async reclaimAbandoned(now = Date.now()): Promise<readonly string[]> {
+ nonNegativeInteger(now, "Dispatch reclaim time");
+ return transaction(this.#database, () => {
+ const rows = this.#database.prepare(
+ "SELECT build_id FROM hypit_dispatches WHERE phase = 'running'",
+ ).all() as Row[];
+ const builds = rows.map((row) => {
+ assert(typeof row.build_id === "string", "SQLite running Dispatch has no Build id");
+ return row.build_id;
+ });
+ for (const build of builds) {
+ // The reservation outlived the process that would have released it, and the lane it holds
+ // is counted against every later Build. Drop it, then make the Dispatch claimable again so
+ // the work — or its cancellation — can actually be carried out.
+ this.#database.prepare("DELETE FROM hypit_capacity WHERE build_id = ?").run(build);
+ this.#database.prepare(
+ "UPDATE hypit_dispatches SET phase = 'queued', available_at = ? WHERE build_id = ?",
+ ).run(now, build);
+ }
+ return builds;
+ });
+ }
+
async listCapacity(): Promise<readonly CapacityReservation[]> {
return (this.#database.prepare(
"SELECT * FROM hypit_capacity ORDER BY created_at ASC, build_id ASC, command_id ASC",