Skip to content

resource-groups Specification

Purpose

Groups let a script, notebook or client keep together the workers and triggers it deploys, share members such as a common schedule between groups, nest groups under several parents, give them owners, and tear a group down without deleting what another group still uses. A group is an infra concept: it carries no business meaning, which only its creator knows.

Requirements

Requirement: Group Records

The WorkManager SHALL keep groups as records in the context's state, each with its id (item-identity), parents (group ids, possibly none), owners, scopes, tags (the display name is the name tag) and its creation time, created by CreateGroup{id?, tags?, parents?, owners?, scopes?} and otherwise reached through the calls of item-identity. Record and event names SHALL come from the workmanager naming fragment.

Scenario: Created with tags

  • WHEN a script calls CreateGroup{tags: {name: "Momentum BTC", managed-by: "rebalance-notebook"}}
  • THEN the answer SHALL carry the group's generated id, and GetGroup with it SHALL return both tags

Scenario: List one parent's children

  • WHEN ListGroups{parent: "strategies"} is called
  • THEN only the groups that have strategies among their parents SHALL be returned

Scenario: A script finds its group again

  • WHEN a script created a group without an id, tagged managed-by=rebalance-notebook, and runs again
  • THEN ListGroups filtered by that tag SHALL return the group

Requirement: Group Parents

A group MAY have several parents, added and removed with AddToGroup{group, groups} and RemoveFromGroup{group, groups} like any other member. Every parent SHALL exist, and a group SHALL NOT become its own ancestor.

Scenario: Unknown parent

  • WHEN CreateGroup names a parent that does not exist
  • THEN the call SHALL fail with FAILED_PRECONDITION naming the parent

Scenario: A group under two parents

  • WHEN group s1 is added to parents sweep-a and stress
  • THEN ListGroups for either parent SHALL return s1

Scenario: A cycle

  • WHEN AddToGroup{group: "s1", groups: ["sweep-a"]} is called while s1 is a child of sweep-a
  • THEN the call SHALL fail with FAILED_PRECONDITION naming the cycle

Requirement: Group Owners

A group SHALL carry owners, a list of principals (user:<sub> or idp-group:<name> of the identity provider), changed with SetGroupOwners. A principal SHALL own a group when it is named in that group's owners or in the owners of any of its ancestors. The WorkManager SHALL store and resolve ownership; whether a call is allowed SHALL be decided by access-control.

Scenario: Inherited ownership

  • WHEN user:alice owns sweep-a, a parent of s1
  • THEN resolving the owners of s1 SHALL include user:alice

Requirement: Group Scopes

A group SHALL carry scopes, a set of name prefixes for state keys and topics (each ending with the naming separator, for example sc.S1.), changed with SetGroupScopes. A scope is an infra concept, a name prefix; what it stands for is known only to the group's creator. The WorkManager SHALL resolve, for a state key or topic, the groups whose scopes cover it. Child groups SHALL NOT inherit their parents' scopes.

Scenario: Groups covering a name

  • WHEN group scenario.S1 has scope sc.S1. and a client asks which groups cover sc.S1.positions
  • THEN the answer SHALL be scenario.S1

Requirement: Membership in Several Groups

A worker and a trigger SHALL each carry groups, a set of group ids, and MAY belong to any number of groups. AddToGroup{group, workers, triggers} and RemoveFromGroup{group, workers, triggers} SHALL change membership without touching tags, config or code; an item MAY also be created with its groups. Every named group SHALL exist.

Scenario: A trigger shared by two groups

  • WHEN the every-minute trigger tick.1m is added to groups momentum-btc and meanrev-eth
  • THEN ListTriggers filtered by either group SHALL return tick.1m, with both groups in its groups

Requirement: Atomic Membership Changes

A membership change on one item SHALL be atomic with respect to other membership changes on the same item, so two scripts changing it at the same time do not lose a change.

Scenario: Concurrent membership changes

  • WHEN two scripts add the same worker to two different groups at the same time
  • THEN the worker SHALL belong to both groups afterwards

Requirement: Deleting a Group Spares Shared Members

DeleteGroup{id} SHALL remove the group from every member, SHALL stop and delete each worker, and delete each trigger, that then belongs to no group, and SHALL keep every member that still belongs to another group, running and without this membership. The call SHALL report per member whether it was deleted, kept (with the groups it still belongs to) or failed.

Scenario: Shared trigger survives

  • WHEN group momentum-btc (workers w1, w2, trigger tick.1m) is deleted and tick.1m also belongs to meanrev-eth
  • THEN w1 and w2 SHALL be stopped and deleted
  • AND tick.1m SHALL keep firing and belong only to meanrev-eth
  • AND the answer SHALL list tick.1m as kept, with meanrev-eth

Requirement: The Last Membership Decides

Whether an item is deleted SHALL be decided by the call that removes its last membership, so deletions racing on a shared member delete it exactly once and never while it still belongs to a group.

Scenario: Two groups deleted at once

  • WHEN groups a and b, which share worker w, are deleted concurrently
  • THEN w SHALL be deleted exactly once, after both memberships are gone

Requirement: Resumable Group Deletion

If any member fails to be deleted, the group SHALL stay, marked deleting, and a repeated DeleteGroup SHALL finish the remaining work.

Scenario: A member fails to stop

  • WHEN one worker of a group cannot be deleted
  • THEN the group SHALL remain marked deleting, the answer SHALL name the worker and the reason, and a second DeleteGroup SHALL complete the deletion

Requirement: Nested Groups

A group with child groups SHALL NOT be deleted unless the call says recursive. A recursive deletion SHALL treat each child group like any other member: a child group that still has another parent SHALL be kept and only lose this parent, and every other child SHALL be deleted first, by the same rules.

Scenario: A child group with a second parent

  • WHEN sweep-a is deleted recursively and its child s1 also has parent stress
  • THEN s1 and its members SHALL be kept, with stress as its only parent

Scenario: Deleting a parent without recursive

  • WHEN DeleteGroup{id: "strategies"} is called while momentum-btc has strategies among its parents
  • THEN the call SHALL fail with FAILED_PRECONDITION naming the child group

Requirement: Removing the Last Membership Outside a Deletion

Removing an item from its last group with RemoveFromGroup SHALL leave the item ungrouped and unchanged otherwise. Only DeleteGroup SHALL delete members.

Scenario: A trigger taken out of its only group

  • WHEN a client removes trigger t from its only group with RemoveFromGroup
  • THEN t SHALL keep firing with no groups, and MAY be added to another group afterwards

Requirement: Deleting a Member Directly

Deleting a worker or trigger directly (not through its group) SHALL remove it from all its groups. A group SHALL be allowed to become empty and SHALL remain until it is deleted.

Scenario: A worker in two groups deleted from the Workers view

  • WHEN an admin deletes worker w, a member of a and b
  • THEN w SHALL be deleted, and a and b SHALL no longer list it

Requirement: Group Change Events

The WorkManager SHALL publish an event when a group is created or deleted and when its membership, tags, owners or scopes change, so clients follow groups without polling.

Scenario: A client sees a new member

  • WHEN a script adds a worker to a group
  • THEN a membership event naming the group and the worker SHALL be published

Requirement: Groups in the Local WorkManager

The worker-devkit's local WorkManagers SHALL implement groups, membership and group deletion with the same rules, verified by shared conformance vectors, so a script behaves the same locally and on a cluster.

Scenario: Conformance

  • WHEN the group conformance vectors run against a local WorkManager and against a deployed one
  • THEN both SHALL produce the same memberships and the same deleted and kept members