Warning, /swf-testbed/docs/decision-box.md is written in an unsupported language. File is not indexed.
0001 # ePIC Decision Box
0002
0003 `swf_testbed_decision_box` implements the site-specific dataset control pattern
0004 for prompt processing:
0005
0006 - one full open Rucio dataset per run, containing all STF file DIDs
0007 - one open processing dataset per site, such as `group.daq:run.123.E1_BNL`
0008 - the prompt-processing decision box decides which site dataset(s) receive each file DID
0009 - PanDA/JEDI consumes the site-specific datasets with `runUntilClosed=True`
0010
0011 The implementation is part of `swf-testbed` and uses Rucio for dataset
0012 creation, file attachment, and dataset closure.
0013
0014 ## Flow
0015
0016 
0017
0018 In the diagram, `Data agent -> Processing agent` is the `stf_ready`
0019 notification. The dotted arrows from the full run dataset to the BNL/JLAB
0020 subset datasets mean the subset datasets contain the same STF file DIDs selected
0021 from the full dataset.
0022
0023 ## Dataset Ownership
0024
0025 The data agent owns the full run dataset:
0026
0027 ```text
0028 group.daq:swf.<run>.run
0029 ```
0030
0031 It creates the full dataset on `run_imminent` and attaches every STF file DID
0032 to it on `stf_gen`.
0033
0034 The data agent also owns the site-specific processing datasets used by the
0035 decision box:
0036
0037 ```text
0038 group.daq:run.<run>.E1_BNL
0039 group.daq:run.<run>.E1_JLAB
0040 ```
0041
0042 It creates those datasets on `run_imminent`, after creating the full run
0043 dataset. They are logical subsets of the full run dataset: the decision box
0044 attaches the same STF file DID, not a PFN copy, to only the site dataset(s)
0045 selected by policy. The data agent records the decision metadata in
0046 swf-monitor for the processing agent to consume.
0047
0048 If `decision_box_site_dataset_template` is unset, the package default is to
0049 derive site datasets from the full run dataset, for example
0050 `group.daq:swf.<run>.run.E1_BNL`.
0051
0052 ## Prompt Processing Integration
0053
0054 `swf-testbed/agents/data_agent.py` uses this package when
0055 `[prompt_processing].decision_box_enabled = true`.
0056
0057 In that mode the data agent:
0058
0059 - creates the site-specific processing datasets
0060 - applies decisions for each `stf_gen` message after attaching the STF DID to
0061 the full run dataset
0062 - attaches the same STF DID to the selected site-specific datasets
0063 - records the decision in the STF row metadata
0064 - sends one site-specific `stf_ready` message the first time a site-specific
0065 dataset receives an STF DID
0066 - closes the site-specific processing datasets on `end_run`
0067
0068 `swf-testbed/agents/prompt_processing_agent.py` does not mutate those input
0069 datasets. It submits a `runUntilClosed=True` PanDA task only for the site named
0070 in each `stf_ready` message, then uses the data-agent decision metadata to
0071 claim and poll STF processing status. If no STF is selected for a site during a
0072 run, no empty task is submitted for that site.
0073
0074 The prompt-processing workflow config enables the Rucio-backed decision box:
0075
0076 ```toml
0077 decision_box_enabled = true
0078 decision_box_policy = "round-robin"
0079 decision_box_sites = ["E1_BNL", "E1_JLAB"]
0080 decision_box_rucio_scope = "group.daq"
0081 decision_box_site_dataset_template = "run.{run_number}.{site_name}"
0082 ```
0083
0084 With this template, a full run dataset such as `group.daq:swf.102741.run`
0085 produces site-specific processing datasets such as
0086 `group.daq:run.102741.E1_BNL` and `group.daq:run.102741.E1_JLAB`. These logical
0087 work-partition datasets do not match broad `group.daq:swf*` Rucio rules.
0088
0089 The decision box expects the same Rucio client and `rucio_comms` environment
0090 used by the existing data agent.
0091
0092 When the decision box is disabled, prompt processing falls back to one PanDA
0093 task over the full run dataset. That legacy task uses
0094 `non_decision_box_site`, which defaults to `E1_BNL` and can be overridden by
0095 `SWF_NON_DECISION_BOX_SITE`.
0096
0097 ## Policy Modes
0098
0099 - `round-robin`: alternate assignments across the configured sites
0100 - `hash`: deterministic assignment based on the file DID
0101 - `both`: assign each file to all configured sites
0102 - `none`: do not attach the file to any site-specific processing dataset
0103 - `explicit`: use the sites supplied in the incoming message fields
0104
0105 Policies implement `DecisionPolicy._choose_sites(context)` and return a
0106 `SiteAssignment`. The `DecisionContext` contains the file DID, run dataset,
0107 run number, configured sites, sequence number, original message fields, stored
0108 run conditions, and optional policy metadata. This keeps the placeholder
0109 policies small while giving future experiment policies access to detector state,
0110 run configuration, operator input, or other decision inputs without changing the
0111 dataset mutation service.
0112
0113 ## PanDA Submission Shape
0114
0115 The processing tasks consume the site datasets, not the full run dataset:
0116
0117 ```text
0118 --site E1_BNL --inDS group.daq:run.101871.E1_BNL runUntilClosed=True
0119 --site E1_JLAB --inDS group.daq:run.101871.E1_JLAB runUntilClosed=True
0120 ```
0121
0122 Use split settings such as `nFilesPerJob=1` and `nChunksToWait=1` when files
0123 should be released promptly.