Skip to content

feat: add bounded safe local test mode - #425

Open
Lysenkoneo wants to merge 7 commits into
Conway-Research:mainfrom
Lysenkoneo:pr-409
Open

Lysenkoneo wants to merge 7 commits into
Conway-Research:mainfrom
Lysenkoneo:pr-409

Conversation

@Lysenkoneo

Copy link
Copy Markdown

No description provided.

@Lysenkoneo Lysenkoneo changed the title Pr 409 feat: add bounded safe local test mode Oct 11, 2026
@NosytLabs

Copy link
Copy Markdown

Not merged yet — this branch and main now implement two different local-mode designs, and picking one is a product decision rather than a merge.

What was verified (CI Node version 22, full vitest run on the branch in isolation): 1933 tests, 0 failures. The branch itself is green; it is the integration with main that is not mechanical.

The conflict, concretely — 23 hunks across 8 files, all of them about local mode:

  • main has src/inference/local-mode.ts: isLocalMode(), resolveLocalModeSettings(), buildLocalRoutingMatrix(), createLocalClient(), filterToolsForLocalMode(), runLocalSetup(), plus forceLocalBackend in the inference client.
  • this branch has src/inference/safe-local-test.ts: isSafeLocalTest(), isStrictLocal(), prepareSafeTestConfig(), safeTestCycleLimit(), restrictConwayClient(), LOCAL_MODEL, assertLocalOllamaUrl(), bootstrapInferenceCredits().
  • the branch also adds an attempt-aware orchestration layer (src/orchestration/task-attempt.ts, result-inbox.ts, workspace-publication.ts, attemptId on tasks and workers), which touches orchestrator.ts and local-worker.ts — the same files Updated #433 had just changed.

A mechanical -X theirs merge was tried and rejected: it produced 77 failures across 6 files (including #433's local-worker-harness and orchestrator suites), because it silently reverts main's newer code in the overlapping hunks.

To land this, one of the two local-mode designs has to win, and the attempt-aware orchestration has to be re-based on whichever survives. Say which way you want it and it can be done as a deliberate port.

@NosytLabs

Copy link
Copy Markdown

Update after actually attempting the port, so the next person does not have to rediscover this.

Good news: the two local-mode implementations do not collide at the file level. Main's lives in src/local/* (mode.ts, routing.ts, tools.ts, local-client.ts) and this branch's in src/inference/local-mode.ts + safe-local-test.ts — different paths, so both can coexist. Every collision is in the eight shared call sites.

What a union actually requires. A hand-written union of the eight files compiles clean (tsc --noEmit passes) and then fails 50 tests across 6 files. The three root causes:

  1. The InferenceRouter constructor disagrees on the 4th parameter. Main's is routingMatrix?: RoutingMatrix; this branch's is localModel?: string. Merging the signatures naively means this branch's new InferenceRouter(db, registry, budget, LOCAL_MODEL) silently passes a string where main expects a matrix — every strict-local test then resolves the wrong model (expected 'gpt-5.2' to be 'qwen2.5:7b'). A union has to discriminate the argument at runtime (typeof arg === "string') or every call site has to be updated.
  2. The orchestrator models attempts differently. Main's Updated #433 harness expects the orchestrator to drive a task to classifying/dead; this branch's attemptId + result-inbox + workspace-publication layer changes what running/idle mean (expected 'idle' to be 'classifying', expected 'running' to be 'dead', timeouts waiting for conditions). This is a real design merge, not a textual one.
  3. The loop's tool assembly and financial-state signature both moved. Main filters tools for local mode and adds Monero donation tools; this branch filters by isToolAllowed(config, tool). getFinancialState gained (ollamaBaseUrl, inferenceMode) on main and (config) here, so the signature has to carry both.

Recommendation: land the strict-local/safe-test mode as a separate entry point rather than merging it into the shared startup path — isSafeLocalTest(config) already exists and is the natural fork point. That keeps main's local mode untouched, and this branch's orchestration work can then be ported on top of the merged orchestrator in a second step.

The port was reverted rather than shipped half-merged: main stays green at e38bc2d (73 files, 1757 tests, 0 failures, typecheck clean).

@NosytLabs

Copy link
Copy Markdown

Landed — the local-mode half of this PR is now on main (889924b).

What went in, as a separate entry point rather than a merge of the two startups:

  • strict local inference (one Ollama model, no Conway key, no redirect following, the model pinned even when the caller asks for another)
  • the bounded safe local test (capped cycles, throwaway identity, in-memory database, explicit tool allow-list, no worker creation)
  • the shared credit formatter so BYOK keys report honestly

What had to be reconciled by hand (neither side's version could be taken verbatim):

  • InferenceRouter's fourth argument means different things in each branch — a routing matrix on main, a model name here. The constructor now discriminates it at runtime, so neither caller changes.
  • the tool filter keeps main's local-mode behaviour; the safe test's stricter allow-list applies only inside the safe test.
  • the repetition detector keeps main's semantics (the shape of the turn, not its arguments), so three reads of different files still count as a loop.
  • the strict-local worker guard was added to main's worker pool.

Deliberately excluded: the attempt/result protocol, the orchestrator rework and the worker-protocol integration test. Those are a design merge of their own — the orchestrator's attemptId model and main's harness disagree about what running/idle mean — and their tests would have to move with them. task-attempt.ts and result-inbox.ts did land, since production code imports them, but the orchestrator side is still open for a follow-up.

Verified on main: pnpm typecheck clean, pnpm build clean, 79 files / 1964 tests / 0 failures (up from 73 files / 1757).

The local-mode work here and the #428 Pix/acct_ pivot are still independent — #428's dependency change has to be regenerated on top of main's refreshed lockfile, and it does not touch these files.

@NosytLabs

Copy link
Copy Markdown

Both halves of this PR are now on main — the local mode (889924b) and the task attempt protocol (a9b907c).

What landed, second pass:

  • every run of a task is an attempt with a private workspace, and a superseded attempt can no longer write to the task graph
  • the worker-protocol integration test and the publication tests

What had to be reconciled by hand (main's harness-driven worker vs this branch's attempt scope):

  • the attempt scope was layered onto main's worker rather than replacing it, so the planner-backed delegation and the 50-turn orchestrator budget keep working
  • a task that was never claimed has no attempt to lose — a direct spawn without an orchestrator assignment still works; once an attempt exists, the strict ownership rule applies
  • plans stay private to the attempt while it runs and are copied into the goal workspace when the attempt succeeds, so the parent reads the plan of the attempt that actually finished the task
  • the worker's liveness map is per database instead of static, so a pool rebuilt while workers are running keeps seeing them

Verified on main: pnpm typecheck clean, pnpm build clean, 81 files / 2016 tests / 0 failures (up from 73 files / 1757 before the local-mode pass).

Nothing from this PR is left out. The only open item on the Conway side is #428's Pix/acct_ pivot, which is a separate product change and does not touch these files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants