Skip to content

serve --pm: a spawn_worker tool that asks an executor for a long-running agent worker - #436

Merged
bong-water-water-bong merged 1 commit into
mainfrom
1bit/pm-spawn-worker
Oct 17, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
1bit/pm-spawn-worker

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

1bit serve --pm can already answer a request itself or delegate one task to an expert model. Some
work is neither: it edits files, builds, measures, or runs for hours.

With --pm-spawn-url URL the PM gets a third tool, spawn_worker(worker, box, class, task), which
POSTs a versioned proposal (schema_version, worker, box, class, task) to that executor and
puts its answer in the tool result: the accepted worker (with its box, class, resolved model, session
and brief path) or the reason it was refused. The PM tells the user either way, and the request still
answers when the executor is unreachable.

The option is off by default; without it the tool is not offered at all. The engine starts nothing
itself — no shell, no tmux, no model choice of its own. The executor decides, so the guards (worker
name, class to local model, health check before launch, duplicate names, the per-box cap, pinning
hardware work to the machine that has it, the local safety rules appended to every brief) live in one
place and cannot drift with the model. pm.spawn_timeout_s in the experts file (default 180) is the
read timeout for one proposal.

The reply's pm object gains spawns[...]{worker,box,class,model,ms,ok,reason}, and X-1bit-PM
mentions the spawn count.

  • docs/pm.md: a "Starting an agent worker (--pm-spawn-url)" section, plus the third tool and the
    spawns records in the request/reply description.
  • tests/pm_route.sh with the new tests/fake_spawn_exec.py: the tool is offered only with the
    option; the proposal the mock executor receives carries the five fields; an accepted worker and its
    pm.spawns record reach the client; a refusal and an unreachable executor are relayed with the PM
    still answering; one pm: spawn ... log line per spawn.
  • tests/fake_pm_backend.py: the spawn and spawn-rejected tool-call forms.

Rebased onto main after #434; clean build and full ctest green on this branch (31/31, of which pm_route is 40 checks).

🤖 Generated with Claude Code

…ing agent worker

The Project Manager can already answer itself or delegate one task to an expert model. Some
work is neither: it edits files, builds, measures, or runs for hours. With --pm-spawn-url URL
the PM also gets spawn_worker(worker, box, class, task), which POSTs a versioned proposal
(schema_version, worker, box, class, task) to that executor and puts its answer in the tool
result: accepted (with the worker, box, class, resolved model, session and brief path) or the
reason it was refused, and the PM tells the user either way. The option is off by default and
without it the tool is not offered.

The engine starts nothing itself: no shell, no tmux, no model choice of its own. The executor
decides, so the guards live in one place and cannot drift with the model.

docs/pm.md describes the option and the proposal; tests/pm_route.sh covers the proposal the
executor receives, an accepted worker and its pm.spawns record, a refusal, an unreachable
executor, and that the tool is absent without the option, using the new tests/fake_spawn_exec.py.
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

434 - Partially compliant

Compliant requirements:

  • Adds serve --pm-router laya functionality
  • The Laya router classifies requests before the PM's first round and picks the expert
  • Configures config/pm-experts.json with pm.routes table mapping Laya class to expert
  • Adds pm.routes_min_confidence to control routing floor
  • Validates the routes table in app/pm.cpp
  • The routed expert is injected as a hint the PM acts on
  • The final answer is composed from a real tool result
  • Without --pm-router, --pm behaves as before
  • Adds a new tool spawn_worker with --pm-spawn-url option
  • The tool POSTs a proposal to an executor and records the result in pm.spawns
  • The executor decides whether to start a worker or refuse the request
  • Tests for new pm_routes (unit) and pm_laya_route (needs Laya checkpoint)
  • Full ctest on Strix Halo: 34/34 passed
  • laya_classify still passes its 95.5% gate

Non-compliant requirements:

  • The PR description mentions live run on Strix Halo but doesn't provide specific measurements or performance data to back up claims

Requires further human verification:

  • Verification of the live run performance data on Strix Halo
  • Confirmation that the new functionality meets all documented requirements
⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential Resource Leak in Spawn Function

The run_spawn_worker function in app/pm.cpp creates an httplib::Client object but does not explicitly manage its lifetime or ensure proper cleanup in all error paths. While the client is used within a scope, if exceptions are thrown or early returns occur, there's a potential for resource leaks or improper cleanup of the HTTP client connection.

httplib::Client cli(base);
if (!cli.is_valid()) return failed("--pm-spawn-url " + cfg.spawn_url + " is not a usable http:// URL");
cli.set_connection_timeout(5);
cli.set_read_timeout(cfg.spawn_timeout_s);
cli.set_write_timeout(60);
auto r = cli.Post(path, proposal.dump(), "application/json");
if (!r) return failed("the executor at " + cfg.spawn_url + " did not answer (" + httplib::to_string(r.error()) + ")");
Possible Integer Overflow in Timing Calculation

In run_spawn_worker, the timing calculation for s.ms uses long but the duration is calculated using std::chrono::duration_cast<std::chrono::milliseconds>. If the duration exceeds the range of long, it could lead to overflow. This is a potential issue in high-precision timing scenarios.

s.ms = long(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - t0).count());
s.ok = false;
Incomplete Error Handling for HTTP Response Parsing

The run_spawn_worker function catches exceptions when parsing the HTTP response body, but it only logs the error and returns a generic failure message. It does not distinguish between different types of parsing errors (e.g., malformed JSON vs. network issues) which could be useful for debugging or handling specific error cases.

try {
    out = json::parse(r->body);
} catch (const std::exception&) {
    return failed("the executor answered HTTP " + std::to_string(r->status) + " with a body that is not JSON");
}

@bong-water-water-bong
bong-water-water-bong merged commit d9b2ee3 into main Oct 17, 2026
8 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/pm-spawn-worker branch October 17, 2026 00:44
bong-water-water-bong added a commit that referenced this pull request Oct 18, 2026
…awn_worker, census, #433) (#446)

* docs: the 2026-10-17/18 merges (HRX pins, DwarfStar, PM router and spawn_worker, census, #433)

The docs still described the pre-2026-10-18 line.

- README status: HRX pinned to AMD e3e6a976 + llama.cpp 8d9ce2c1a with the measured gate numbers;
  DwarfStar pinned to 5b013dc1bb75 (1BP v5) and its hardware check; the PM gains --pm-router laya
  and --pm-spawn-url; the census numbers of 2026-10-17.
- docs/PORTING.md: the HRX pin (step 2), the Laya source/revision bump (step 4), the 2026-10-17
  census (step 5).
- docs/registry.md: the 2026-10-17 census table, against registry/census.json, and the current
  unmapped list.
- docs/hrx.md: the engine#433 finding next to the other HRX0 known issues (no abort in 60 fresh
  loads; the 458-token prompt cannot come from this model template).
- docs/dwarfstar.md: what the 2026-10-17 pin was checked on, and that serve cannot set ds4 expert
  cache size.
- .github/workflows/bump-hrx.yml: the loom-jit trap is now described as the step that guards it,
  with #441 as the validated hand move and #422 still open.

Facts from merged PRs #441, #429, #438, #439, #434, #436 and the hardware comments on #441 (TPIN)
and #429 (TDS4).

* docs/hrx.md: the LoomC-symbol guard, which is the loom-jit trap, and #441 as the validated hand move

The workflow comment that described the trap cannot be pushed with this token (no workflow scope),
so the fact lives where the pin process is documented: docs/hrx.md, next to the hold.

---------

Co-authored-by: pi-zayap2 <bcloud@localhost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant