Skip to content

factory: where an organization's workstream agents run, and the driver hand (W8 + E6 engine) - #2633

Merged
santoshkumarradha merged 2 commits into
work/teamsfrom
w2/w8-runner
Nov 13, 2026
Merged

santoshkumarradha merged 2 commits into
work/teamsfrom
w2/w8-runner

Conversation

@santoshkumarradha

@santoshkumarradha santoshkumarradha commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Lane W8 + the engine half of E6. Owner decision WAVE2.md §4.3: the operator chooses where an organization workstream's agent runs, agent_runner: "driver" | "server".

What landed

  • The setting. agent_runner in GET|PATCH /v1/settings. Everyone reads it. Only the operator may change it (the PATCH was already operator-only). agent_runners lists the choices this server offers. Today that list is ["driver"]. Choosing server is refused with 422 ("this organization's server cannot run agents yet…"), so the option does not appear on the desk instead of failing there. A store written before this change reads as driver.
  • The driver hand. PUT /v1/workstreams/{id}/driver takes the hand, or renews it when the caller already holds it. It answers {handle,since,until,ttl_s}, and the hand lapses 90 s after its last renewal. While someone else holds it, the answer is 409 {"error":"santosh is driving this workstream's agent","driver":{…}}. DELETE lets go; the holder, the workstream's owner (govern) or the operator may do this. Only people who can write the workstream may drive, and none may drive an archived workstream or one in an org set to server. Workstream.driver is set while the hand is held. Taking and letting go publish workstream.changed. Hands are kept in memory, so a restart works like a lapse. The caller is read through E1's access core (rebased on factory: one access core for every organization item (E1, part 1) #2632).
  • Engine methods (hello org_agent_runner): factory.org_agent_runner, factory.org_agent_runner_set, factory.org_workstream_drive, factory.org_workstream_let_go, factory.org_workstream_spend. The spend method forwards to E2's POST /v1/workstreams/{id}/spend {usd,job?,chat?} with Idempotency-Key. The contract was agreed with E2: the server stamps by, and the param struct is defined here only. A held hand's refusal is conflict with detail {reason:"driving", by:"@handle"}. OrgRequest.IdempotencyKey is new.
  • Docs: docs/design/app-v3/PROTOCOL.md; change entry 2633-org-agent-runner.md. WAVE2.md §4.3 is edited in place (~/work/teams-wave/WAVE2.md, outside the repo) under "Wire as built (W8/E6 engine)".

Proof

  • internal/factory/serve/workstream_driver_test.go uses the real handler with the org fixture (owner/operator, santosh, abir, mia). It proves: abir reads the setting; abir's PATCH is 403; the operator's server and garbage choices are 422 and driver is 200. santosh takes the hand; abir gets 409 naming santosh and sees driver on GET. mia cannot let go (403); the operator can. Renewing keeps since. A lapse after 91 s lets abir take the hand. Someone who cannot see the workstream gets 404; someone who sees it but cannot write gets 403.
  • cmd/codeaf/appfactory_org_runner_test.go covers the engine over a stub org: the hello word, the older server's default, the forbidden pass-through, the driving detail, and Idempotency-Key on spend. E2's route landed in factory: a workstream's parts live on the organization server (SQLite, per-page revs, versions) #2639, so a spend now counts on the server.
  • make pr-ready BASE=<origin/work/teams> is green. Three tests failed and then passed on re-run (TestAppChatsOlderCopyStaysLocalL1, TestAppDevicesV1OldRelayPresenceIsUnknown, TestFactorySetupContinueEndsReadingWithoutWatchingUnreadRepos). This change does not touch the code any of them test.
  • Desk half: Agent-Field/codeaf-desk#434.

Server mode: what is still needed (not in this PR, deliberately absent)

  1. Org keys on the server. An operator-only, write-only key store, e.g. PUT|DELETE /v1/org/keys/{provider}, plus a GET that answers only provider, last-4 and set-at. Keys sit in the server's vault (internal/keyvault shape) and never travel to a desk.
  2. A server runner. codeaf factory serve hosts one internal/session agent per workstream, in a per-workstream folder under the server's data dir, using the org keys and the workstream's pages as context. One runner per workstream replaces the driver hand.
  3. A conversation wire for desks. GET /v1/workstreams/{id}/agent?since= (transcript), POST …/agent/messages, and POST …/agent/stop. Events are agent.entry and agent.state, relayed like factory.org_changed, with E1 access: edit to send, view to read.
  4. Spend. The runner posts to E2's spend route under its own server session, so the server stamps by (a body by is refused with 422), and puts the asker in chat.
  5. Then agentRunners() returns ["driver","server"] once (1) has a key and (2) is built. The desk's Segmented control then appears for the operator with no desk change, and the desk adds a server-chat panel.

@santoshkumarradha
santoshkumarradha marked this pull request as ready for review November 13, 2026 19:05
@santoshkumarradha
santoshkumarradha force-pushed the w2/w8-runner branch 3 times, most recently from 4776a21 to 28162c6 Compare November 13, 2026 20:39
santoshkumarradha and others added 2 commits November 13, 2026 15:53
…ne person drives each

The operator's agent_runner setting (driver | server) lives in /v1/settings:
everyone reads it, only the operator changes it, and agent_runners lists what
this server offers (driver today; server is absent until its runner lands).
PUT|DELETE /v1/workstreams/{id}/driver is a 90-second driver hand, so two
laptops never run one workstream's agent; the engine forwards it, the
setting and E2's spend route (factory.org_agent_runner*, factory.org_workstream_drive,
_let_go, _spend), and a held hand's 409 names its holder.

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
@santoshkumarradha
santoshkumarradha merged commit d0c8ab2 into work/teams Nov 13, 2026
1 check passed
@santoshkumarradha
santoshkumarradha deleted the w2/w8-runner branch November 13, 2026 21:01
ZeroPoint95 pushed a commit that referenced this pull request Nov 24, 2026
…ne person drives each (#2633)

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
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