Skip to content

feat(runners): add the runners table and the Runner model - #583

Merged
aixle-com[bot] merged 4 commits into
developfrom
feature/runners-table-model
Oct 27, 2026
Merged

aixle-com[bot] merged 4 commits into
developfrom
feature/runners-table-model

Conversation

@aixle-com

@aixle-com aixle-com Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Task #181 (Runners 1b): the runners table and the Runner model, scoped to what task 2 (policies and controllers) reads and writes. Design: docs/design/agent-runtimes/DESIGN.md §2.1, §2.5–§2.7, §3.1, §15.

This replaces #582. Its commits had no DCO sign-off, so they were replayed here with git rebase --signoff rather than force-pushed. The tree is identical.

What changed

Migration 20261027100000_create_runners.rb creates runners with the §2.1 columns, minus encrypted_secrets. It touches no existing table.

  • Unique index (company_id, coalesce(project_id, 0), lower(name)) WHERE deleted_at IS NULL.
  • Check constraints: max_concurrency > 0, (runner_type = 'coder') = (integration_id IS NOT NULL), runner_type <> 'manual' OR max_environments IS NULL, max_environments IS NULL OR max_environments > 0.
  • Composite tenant keys (project_id, company_id) → projects (id, company_id) and (integration_id, company_id) → integrations (id, company_id), using the unique indexes from AddTenantColumnsToScopedResources.
  • Plain FKs. Company and project cascade, as in the tenant migration. The integration keys are restrictive (task 17 decides what disconnecting does).

Runner: enumerize runner_type (manual, coder, kubernetes) and reuse_policy (reuse, fresh), defaulted by type. kubernetes accepts only fresh. Validations mirror the database, plus the §2.6 Coder integration rule: provider coder, same company, company runner → company-wide integration only, project runner → company-wide or its own project's. Runner.visible_for_project has the same shape as Integration.visible_for_project and excludes deleted rows. Company and Project get has_many :runners, declared before :integrations so a Coder runner is gone before the restrictive integration key could block the destroy.

RunnerStateMachine (AASM on status): mark_connected / mark_degraded(reason) / mark_unreachable(reason), disable / enable (back to pending), revoke (terminal). It sets and clears status_reason, disabled_at and revoked_at. soft_delete! sets deleted_at and revokes in the same write.

DESIGN.md: the §2 opening (column convention and composite keys instead of TenantColumns), §2.1 (encrypted_secrets arrives with the first type that needs a secret, capabilities default, created_by_id), the §2.4 sketch, the two §2.5 clarifications, and §15 row 1b rewritten, with the moved items added to rows 4 and 5.

One deviation from the task: created_by_id is nullable

The task lists created_by_id as not null. With a NOT NULL, restrictive key, Users::PermanentDeletionService could not delete a user who created a runner. PermanentDeletionServiceTest ("a row behind every foreign key that reaches them") fails for exactly that reason. Every other authorship column was made nullable with ON DELETE SET NULL in EnablePermanentUserDeletion (e.g. integrations.connected_by_id), and runners.created_by_id follows that rule. The model still requires a creator on: :create. FullyWiredUserScenario now includes a runner, so the service test covers the key. DESIGN.md §2.1 records this.

Tests

  • test/factories/runners.rb: one trait per type, plus :project_runner.
  • test/models/runner_test.rb: validations, the §2.6 rule, reuse_policy defaults, visible_for_project (own project, company, another project, another company, deleted), and one test that writes past validations. That test checks each check constraint, composite key and the unique index refuses the row, by constraint name.
  • test/state_machines/runner_state_machine_test.rb: the allowed and refused source states for every event, status_reason, disabled_at, revoked_at, and soft delete.

How to test

docker compose exec -T web bin/rails test test/models/runner_test.rb test/state_machines/runner_state_machine_test.rb test/services/users/permanent_deletion_service_test.rb test/db/schema_parity_test.rb

I ran the migration, rolled it back (the schema after rollback matches develop's exactly), and ran it again. db/schema.rb is the dump from that run. On #582's head, CI's Rails shards 1–3, Lint, System Tests and Coverage all passed.

No CHANGELOG entry: nothing a user or operator can see yet. Everything stays behind task 2's flag-checked controllers.

aixle-com Bot pushed a commit that referenced this pull request Oct 27, 2026
Comment thread app/models/runner.rb Resolved
…ation a runner uses

- RunnerStateMachine turns on whiny_persistence, as TerminalSessionStateMachine
  does, so a bang event whose save fails raises instead of returning false.
- Integration has_many :runners, dependent: :restrict_with_error, so the
  restrictive runners keys fail with a model error, not InvalidForeignKey.
- DESIGN.md §15 task 2: the integrations controller must surface that refusal.

Signed-off-by: Aixle Flow <[email protected]>
@aixle-com
aixle-com Bot merged commit 0b92bb5 into develop Oct 27, 2026
16 checks passed
artempartos added a commit to Hitin/flow that referenced this pull request Oct 28, 2026
* origin/develop:
  docs(workflows): describe workflows as sessions made of steps (AixleHQ#595)
  feat(workflows): open archived workflows read-only in the builder (AixleHQ#594)
  feat(task-comments): let authors delete their own recent comments (AixleHQ#593)
  feat(mcp): log the JSON-RPC method and tool name of each MCP call (AixleHQ#592)
  fix(board): show a run waiting for a session slot as Queued on its card (AixleHQ#591)
  feat(brand): use the new Aixle Flow lockup and route fonts through tokens (AixleHQ#590)
  feat(overview): show tokens used and session time instead of token cost (AixleHQ#589)
  fix(agents): pre-acknowledge Claude Code's cost-threshold notice (AixleHQ#587)
  test(playwright): QA helpers batch 2 (appRequest, readInertiaPage, shot, probeRoutes, signOut) (AixleHQ#586)
  test(playwright): plain-JS QA helpers for browser_run_code on staging (AixleHQ#584)
  feat(runners): add the runners table and the Runner model (AixleHQ#583)
  refactor(feature-flags): plain cached reads, no usage tooling (AixleHQ#579)

# Conflicts:
#	CHANGELOG.md
artempartos added a commit to Hitin/flow that referenced this pull request Oct 28, 2026
* origin/develop:
  docs(workflows): describe workflows as sessions made of steps (AixleHQ#595)
  feat(workflows): open archived workflows read-only in the builder (AixleHQ#594)
  feat(task-comments): let authors delete their own recent comments (AixleHQ#593)
  feat(mcp): log the JSON-RPC method and tool name of each MCP call (AixleHQ#592)
  fix(board): show a run waiting for a session slot as Queued on its card (AixleHQ#591)
  feat(brand): use the new Aixle Flow lockup and route fonts through tokens (AixleHQ#590)
  feat(overview): show tokens used and session time instead of token cost (AixleHQ#589)
  fix(agents): pre-acknowledge Claude Code's cost-threshold notice (AixleHQ#587)
  test(playwright): QA helpers batch 2 (appRequest, readInertiaPage, shot, probeRoutes, signOut) (AixleHQ#586)
  test(playwright): plain-JS QA helpers for browser_run_code on staging (AixleHQ#584)
  feat(runners): add the runners table and the Runner model (AixleHQ#583)
  refactor(feature-flags): plain cached reads, no usage tooling (AixleHQ#579)

# Conflicts:
#	CHANGELOG.md
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.

0 participants