Skip to content

factory: follow go-aheads itself — group policies and waits-on - #2524

Merged
santoshkumarradha merged 3 commits into
app/v3from
factory/group-policy
Nov 9, 2026
Merged

santoshkumarradha merged 3 commits into
app/v3from
factory/group-policy

Conversation

@santoshkumarradha

Copy link
Copy Markdown
Member

What

The desk turns a workstream's go-aheads into a factory group policy and calls factory.policy_set / factory.policy_get, gated on hello factory.group_policy, factory.capabilities.group_policy and factory.features containing group_policy. No codeaf served any of them, so the desk said "This codeaf can't apply go-aheads yet."

Now the factory keeps and follows them itself:

  • Store: factory-policies.json keeps each group's whole policy (allowances with job ids, cap_usd, ends_at kept as sent, stopped, owner, version). Items gain WaitsOn, PolicyRun, PolicyGroup and Blocked.
  • Factory routes: GET /v1/features, GET|PUT /v1/policy, POST /v1/jobs/{id}/waits_on. Waits are checked for loops.
  • Enforcement: intake.GoAheads runs after every poll, on all three poll paths (team serve, window floor, the app's own factory). It runs whether or not "Start on its own" is on. It starts a covered job only when all of these hold: the job never ran, is in Backlog and is not someone else's; every job it waits on has merged; its allowance is active (not stopped, before its end, inside its cap). Each started job holds its budget, lowered to what is left of the cap, so starts in one pass cannot together go over. Each start records policy_run, auto_started with "allowance ", and the policy owner as the job's person. A covered job that is waiting carries blocked {by, reason, job|allowance}. Stopping, ending or withdrawing an allowance starts nothing further. No pipeline or step names are involved.
  • Engine: adds factory.policy_get, factory.policy_set, factory.waits_set and factory.features in the desk's exact wire shape. Hello now announces factory.group_policy and factory.waits_set, and capabilities say group_policy and waits_on.
  • Docs: PROTOCOL.md rows and a paragraph. The chat manual gets a go-aheads section, two probes, and corrections to the two "nothing starts on its own" sentences.

Proof

  • Unit tests: allowance and waits bounds; policy spend and state; store CRUD (whole replace, version, refusal, reopen); the pass under a fake clock (waits then merge, cap across starts, ended / stopped / withdrawn / someone else's, refused launch retried). No sleeps.
  • End to end, TestADeskGoAheadStartsTheCoveredJobAfterItsParentMerges: real appwire → backend → HTTP → serve → store. A desk-shaped waits_set and policy_set are sent, and the read-back equals what was sent. The after-poll pass leaves the child blocked. Once the parent merges, the child starts with policy_run.
  • make pr-ready BASE=<merge-base with app/v3> is green. One cmd/codeaf test was flaky and passed on retry (TestFactoryRetryActionsDoNotReportStopped, unrelated).

Not done

  • A go-ahead does not stop or hold jobs that are already running when it ends or its cap is reached. It only governs starts.
  • waiting_on is filled on a single job read and on the waits_set answer, not in queue rows.
  • Desk-side create_group (tagging jobs with a group) is not part of this change.

The desk turns a workstream's go-aheads into a factory group policy and
sends factory.policy_set / factory.policy_get, gated on factory.group_policy,
factory.capabilities.group_policy and factory.features. No codeaf served
them, so the desk said "This codeaf can't apply go-aheads yet."

The factory now keeps group policies in its store (factory-policies.json)
and a job's waits_on, and an after-poll go-ahead pass starts a covered job
that never ran once every job it waits on has merged, inside its
allowance's cap and before its end, with no app attached. Each start is
attributed (policy_run, auto_started "allowance <id>"); a covered job that
waits carries blocked. Stopping, ending or withdrawing an allowance starts
nothing further.
L8 end-to-end findings on #2524:

- B1: codeaf factory serve's poll loop never ran the go-ahead pass. It now
  runs GoAheads on every tick, with or without a GitHub source, and its
  error never feeds the GitHub poll backoff.
- B2: the manual, PROTOCOL.md and the change entry now say the app's own
  local factory follows go-aheads only while the app is open with its
  runner on (GitHub connected), and stops when the app quits.
- B3: a full cap with less spent than the cap reads "its go-ahead's cap is
  held by jobs already running"; "its go-ahead's cap is spent" is kept for
  a cap actually spent.
- D1: every job answer fills waiting_on in withVersionKept, factory.queue
  rows included, from the floor already loaded.
@santoshkumarradha

Copy link
Copy Markdown
Member Author

L8 engine findings fixed — 85b9439

Fix Proof
B1 startFactoryServerPoll takes after and runs factoryIntakeOwned(st, operator).GoAheads on every tick, with or without a GitHub source; its error never counts toward the poll backoff. TestAServedFactoryStartsAGoAheadsJobWithNoAppAttached (refused launch on tick 1, started on tick 2, policy_run=ga_team, starter = owner) + live L8 serve run below
B2 Manual (factory.md, new section "do go-aheads run with the app closed or the laptop shut — team server versus the factory on your own machine"), PROTOCOL.md and the change entry: team server follows go-aheads with every app closed; the app's local factory only while the app is open with its runner on (GitHub connected), and stops when the app quits. manual probes incl. "will my go-ahead start jobs when the app is closed"
B3 choose: Spent >= cap → its go-ahead's cap is spent; Committed >= cap with less spent → its go-ahead's cap is held by jobs already running TestAGoAheadStartsNothingPastItsCap covers both
D1 withVersionKept fills waiting_on on every job answer; factory.queue reads it from the floor already loaded (pre-filter), no per-id store reads. TestADeskGoAheadStartsTheCoveredJobAfterItsParentMerges now asserts the queue row before/after the merge

make pr-ready (BASE = merge-base with app/v3): every selected test passed on its first run (cmd/codeaf 8 shards, appwire, factory/{,api,intake,serve,store}, manual).

Live L8 re-run — codeaf factory serve (make build of 85b9439, throwaway HOME, no model key, $0)

scenario.py serve from the L8 harness, unchanged except the binary path:

  • w1a started by the server itself with no app driving it: state:"queued", policy_run:"ga_w1", budget:4. (Before: no job ever started, no blocked field, serve-final.txt.)
  • w1b held by the $4 cap (default budget $4), reading blocked.reason: "its go-ahead's cap is held by jobs already running" with spent_usd: 0 — B3's sentence. The harness's "wave 1 … NOT within 150s" line is its predicate wanting both w1 jobs; only one fits the cap.
  • After w1a merged (simulated): w2a started 35 s later, policy_run:"ga_w2", waiting_on gone; w1b started as the cap freed; w2b held with waiting_on:[2].
  • Revoke ga_w2 + merges: w2b did not start. Stop group: version 3, stopped, empty; nothing started after.
  • waiting_on present on rows from t0 (w2a: [1], w2b: [1,2]).

D2/D3 are desk-side and not in this PR.

@santoshkumarradha
santoshkumarradha merged commit fb3ddf1 into app/v3 Nov 9, 2026
7 checks passed
@santoshkumarradha
santoshkumarradha deleted the factory/group-policy branch November 9, 2026 15:18
AbirAbbas added a commit that referenced this pull request Nov 9, 2026
Brings in go-aheads (#2524) and Claude Code as a provider (#2505).

Conflicts, resolved by keeping both sides:
- The poll loops take the branch's failure log and app/v3's after-poll
  pass (factoryAfterPoll: start rules, then go-aheads).
- routeAndPickUp keeps the branch's routing table and runs app/v3's
  go-ahead pass after it, even with Pick up issues off and no rules, so
  startOnItsOwn, which routing had replaced, is gone.
- Wire and codec carry both the AgentField fields (run_on, agentfield,
  agentfield_steps, rejection, failure_summaries, source_ref) and the
  go-ahead fields (waits_on, waiting_on, policy_run, policy_group, blocked).
- The manual keeps the routing sections and adds the go-ahead sections;
  the Pick up issues paragraph says a go-ahead still starts its jobs while
  the switch is off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AbirAbbas pushed a commit that referenced this pull request Nov 9, 2026
…an AgentField node (#2478)

General intake (inbox, Jira, the routing table with an AI filter and priority order), the factory as an AgentField node whose triggers are its intake, AgentField runs as factory steps, named pipelines and a pipeline library, the engine idle-cost rounds, codeaf --events/--steer for watched harness runs, and app/v3 (#2524 go-aheads, #2505 Claude Code, #2544, #2545) merged in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ZeroPoint95 added a commit that referenced this pull request Nov 10, 2026
Brings in the general factory's engine side (#2478), go-aheads (#2524) and
twelve smaller PRs. Where both sides changed a file:

- Accept as is, the decision pause, PR base sync and the test baseline stay,
  beside upstream's AgentField approvals, Reject and the no-repository hold
- The idle-cost work on the stop check and step budget is upstream's
  (#2545); ours did the same job, so its version of those three files is
  dropped
- A runner lost during a remote run that is owed its end queues the job
  instead of failing it, inside our markRunnerLost refactor

Co-Authored-By: Claude Opus 5.5 <[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