Skip to content

feat(placement): shared native placement policy and peer load evidence - #67

Merged
nullStack65 merged 1 commit into
release/native-0.1.10from
feat/native-0.1.10-placement-admission
Nov 18, 2026
Merged

nullStack65 merged 1 commit into
release/native-0.1.10from
feat/native-0.1.10-placement-admission

Conversation

@nullStack65

Copy link
Copy Markdown
Owner

Why

Universal placement of NEW threads (CLO-866) needs one admission decision that every creation path reaches. On native 0.1.10 the pieces are scattered:

  • Selector: the resource selector (15 s freshness, 95% CPU, 5% available RAM) lives only in client-runtime, and only web/desktop automatic drafts use it.
  • Server entrypoints: none of MCP create_threads/delegate_task/t3_thread_launch, CLI or schedules make an automatic choice, and a server has no load evidence for linked environments.
  • Manual targets: an explicit environmentId already routes through PeerForwarding/RemoteDelegation, but nothing binds an automatic choice before the remote effect. RemoteDelegation records the task only after the remote launch, the documented crash window.

This PR: foundation layer, no behaviour change

  1. One selector: chooseLoadBalancedEnvironment moves unchanged to @t3tools/shared/loadBalancing. @t3tools/client-runtime/load-balancing re-exports it, so web and desktop automatic drafts are untouched.
  2. Shared placement policy: @t3tools/shared/threadPlacement chooseThreadPlacement, a pure function with no transport effects. It's PR feat(server): add scoped founder inbox and fleet admission gates #58's policy reimplemented for native; feat(server): add scoped founder inbox and fleet admission gates #58 is not merged.
    • Named target: wins.
    • Local state (workspace, worktree, attachments, context, dependent parent): the work stays here, and a conflicting target fails as conflicting-locality.
    • Independent work: goes to the environment that has an operate link, the project and the requested model, with the most fresh headroom.
    • Failures: duplicate evidence is ambiguous-environment; no fresh unsaturated host is no-eligible-environment.
  3. Peer load evidence: orchestrator_capabilities reports this machine's hostResources as an optional field, read from the existing HostResources service. A server reads a linked environment's load over the existing peer link. Older peers omit the field and are never chosen.

Not in this PR (next layers, same owner)

  • Durable binding (required first): an automatic remote choice must be written to the parent's event history, keyed by the caller-scoped clientRequestId, before the remote launch. Retries, lost replies and restarts then reuse that destination and never re-decide. That needs a new orchestration event and receipt-backed replay, so it isn't faked here.
  • Entrypoint wiring: after that, wire delegate_task → create_threads → t3_thread_launch through RemoteDelegation's existing follow/recovery. Then web/desktop/mobile, CLI, fresh-thread schedules and Tots move onto this shared policy.

Verification (local ASUS, no paid calls)

  • Locked install, then typecheck: contracts, shared, client-runtime, server and web — 0 errors.
  • Format/lint on changed files: pass. Lint caught a Hermes-unsupported toSorted, which is fixed.
  • Focused tests: 6 files, 166 passed. New threadPlacement.test.ts (5 cases); the moved selector's existing tests; OrchestratorMcpService.test.ts, whose capabilities case now asserts hostResources; RemoteDelegation; PeerForwarding; contracts.
  • Workflow list: 6 files, 104 passed.
  • Pre-commit hook skipped: it fails on knip findings that are identical on the base.

Task: CLO-866

🤖 Generated with Claude Code

First layer of native thread placement on release/native-0.1.10. No
behaviour changes for any existing launch path.

- Move chooseLoadBalancedEnvironment (15 s freshness, 95% CPU, 5%
  available RAM) unchanged from client-runtime to @t3tools/shared so the
  server and clients use one selector; client-runtime/load-balancing
  re-exports it, so web is unchanged.
- Add chooseThreadPlacement, a pure decision over evidence the deciding
  server gathered: a named target wins, work that needs local state stays
  here (a conflicting target fails), and independent work goes to the
  operable environment with the project and requested model that has the
  most fresh headroom. Ambiguous evidence and no eligible host fail
  explicitly.
- orchestrator_capabilities now reports this machine's hostResources, an
  optional field, so a server can read a linked environment's load through
  the existing peer link. Older peers omit it and are never chosen.

Automatic remote placement is not enabled: it first needs the chosen
destination bound durably to the caller's request before any remote
effect, so a retry after an uncertain launch reuses it.

Task: CLO-866
Model: claude-opus-5-5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nullStack65

Copy link
Copy Markdown
Owner Author

RESULT

RESULT (CLO-866, placement layer 1 of the minimal stack)

  • PR head: ad825f9a92952ffc8769ec32324fd2b643456389, parent release/native-0.1.10 d1d1ec359d3d4bdd76aabe1e5bb63741604ccd57; 8 files.
  • CI: ARC run 44238594580, job 134580637090 on t3code-ci-arc-s5fvz-runner-n6kqx: success, 15/15 steps, 104 tests. Merge source 789b0ec3111e1133042242a837ef493791315e18.
  • Local checks: typecheck clean across contracts, shared, client-runtime, server and web; focused tests 166/166.

Scope:

  • Delivered: the shared selector, the pure placement policy, and peer hostResources evidence. No launch behaviour changes.
  • Not delivered: automatic remote placement. It's disabled until layer 2 binds the chosen destination durably (a parent-thread event keyed by the caller-scoped clientRequestId) before the remote launch.
  • Layer 3: wires delegate_task, create_threads and t3_thread_launch through RemoteDelegation recovery, then UI, CLI, schedules and Tots.

Merge path: SHA-guarded squash at ad825f9a.

@nullStack65
nullStack65 merged commit 3596754 into release/native-0.1.10 Nov 18, 2026
2 checks passed
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.

1 participant