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
GetGroupwith it SHALL return both tags
Scenario: List one parent's children
- WHEN
ListGroups{parent: "strategies"}is called - THEN only the groups that have
strategiesamong 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
ListGroupsfiltered 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
CreateGroupnames a parent that does not exist - THEN the call SHALL fail with
FAILED_PRECONDITIONnaming the parent
Scenario: A group under two parents
- WHEN group
s1is added to parentssweep-aandstress - THEN
ListGroupsfor either parent SHALL returns1
Scenario: A cycle
- WHEN
AddToGroup{group: "s1", groups: ["sweep-a"]}is called whiles1is a child ofsweep-a - THEN the call SHALL fail with
FAILED_PRECONDITIONnaming 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:aliceownssweep-a, a parent ofs1 - THEN resolving the owners of
s1SHALL includeuser: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.S1has scopesc.S1.and a client asks which groups coversc.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.1mis added to groupsmomentum-btcandmeanrev-eth - THEN
ListTriggersfiltered by either group SHALL returntick.1m, with both groups in itsgroups
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(workersw1,w2, triggertick.1m) is deleted andtick.1malso belongs tomeanrev-eth - THEN
w1andw2SHALL be stopped and deleted - AND
tick.1mSHALL keep firing and belong only tomeanrev-eth - AND the answer SHALL list
tick.1mas kept, withmeanrev-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
aandb, which share workerw, are deleted concurrently - THEN
wSHALL 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 secondDeleteGroupSHALL 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-ais deleted recursively and its childs1also has parentstress - THEN
s1and its members SHALL be kept, withstressas its only parent
Scenario: Deleting a parent without recursive
- WHEN
DeleteGroup{id: "strategies"}is called whilemomentum-btchasstrategiesamong its parents - THEN the call SHALL fail with
FAILED_PRECONDITIONnaming 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
tfrom its only group withRemoveFromGroup - THEN
tSHALL 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 ofaandb - THEN
wSHALL be deleted, andaandbSHALL 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