Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

feat: expose scheduler.maxBatchSize as an operator config key (PIN-192)

Luigi Agosti679d1f1fab71
diff --git a/docs/reference/config.md b/docs/reference/config.md
index ff945389..47fd2aa2 100644
--- a/docs/reference/config.md
+++ b/docs/reference/config.md
@@ -312,7 +312,8 @@ Current nested file-config shape:
"maxInflight": 20,
"maxPerAgentInflight": 10,
"resultTTLSec": 300,
- "workerCount": 4
+ "workerCount": 4,
+ "maxBatchSize": 50
},
"observability": {
"activity": {
@@ -547,9 +548,10 @@ Rationale: humanized input is useful for compatibility with pages that react poo
- `profiles`
- `multiInstance`
- `timeouts`
+- `scheduler`
- `observability`
-They do not expose every field in those sections, and they do not support `scheduler.*`.
+They do not expose every field in those sections.
Use `pinchtab config patch` or edit `config.json` directly for fields such as:
@@ -560,7 +562,6 @@ Use `pinchtab config patch` or edit `config.json` directly for fields such as:
- `security.allowClipboard`
- `security.idpi.scanTimeoutSec`
- `security.idpi.shieldThreshold`
-- `scheduler.*`
- `observability.activity.events.*`
## Common Examples
diff --git a/docs/reference/scheduler.md b/docs/reference/scheduler.md
index 1f473e8b..efa4e79b 100644
--- a/docs/reference/scheduler.md
+++ b/docs/reference/scheduler.md
@@ -30,7 +30,8 @@ The scheduler is off by default. Dashboard mode registers the task routes only w
"maxInflight": 20,
"maxPerAgentInflight": 10,
"resultTTLSec": 300,
- "workerCount": 4
+ "workerCount": 4,
+ "maxBatchSize": 50
}
}
```
@@ -45,6 +46,7 @@ The scheduler is off by default. Dashboard mode registers the task routes only w
| `maxPerAgentInflight` | `10` | max concurrently executing tasks per agent |
| `resultTTLSec` | `300` | retention time for terminal task snapshots |
| `workerCount` | `4` | number of worker goroutines |
+| `maxBatchSize` | `50` | max tasks one `POST /tasks/batch` may submit; a larger batch is refused with `batch_too_large` |
## Task Object
@@ -425,7 +427,7 @@ Each task definition supports the same fields as a single task submit (`action`,
| --- | --- |
| missing `agentId` | `400 Bad Request` |
| empty `tasks` array | `400 Bad Request` |
-| more than 50 tasks | `400 Bad Request` with `batch_too_large` code |
+| more tasks than `scheduler.maxBatchSize` (default 50) | `400 Bad Request` with `batch_too_large` code |
| invalid JSON body | `400 Bad Request` |
Partial failure: if some tasks are rejected by admission (queue full), the accepted tasks are still submitted. The response includes each task's status individually.
diff --git a/internal/config/config_file_json.go b/internal/config/config_file_json.go
index 7122ce30..27f45997 100644
--- a/internal/config/config_file_json.go
+++ b/internal/config/config_file_json.go
@@ -157,6 +157,7 @@ type schedulerFileConfigJSON struct {
MaxPerAgentFlight *int `json:"maxPerAgentInflight"`
ResultTTLSec *int `json:"resultTTLSec"`
WorkerCount *int `json:"workerCount"`
+ MaxBatchSize *int `json:"maxBatchSize"`
}
type observabilityFileConfigJSON struct {
diff --git a/internal/config/config_file_marshal.go b/internal/config/config_file_marshal.go
index b8b84215..067e2879 100644
--- a/internal/config/config_file_marshal.go
+++ b/internal/config/config_file_marshal.go
@@ -281,6 +281,7 @@ func (fc FileConfig) MarshalJSON() ([]byte, error) {
MaxPerAgentFlight: fc.Scheduler.MaxPerAgentFlight,
ResultTTLSec: fc.Scheduler.ResultTTLSec,
WorkerCount: fc.Scheduler.WorkerCount,
+ MaxBatchSize: fc.Scheduler.MaxBatchSize,
},
Observability: observabilityFileConfigJSON{
Activity: activityConfigJSON{
diff --git a/internal/config/config_load.go b/internal/config/config_load.go
index ceaa1fdf..14577df9 100644
--- a/internal/config/config_load.go
+++ b/internal/config/config_load.go
@@ -806,6 +806,9 @@ func applySchedulerConfig(cfg *RuntimeConfig, s SchedulerFileConfig) {
if s.WorkerCount != nil {
cfg.Scheduler.WorkerCount = *s.WorkerCount
}
+ if s.MaxBatchSize != nil {
+ cfg.Scheduler.MaxBatchSize = *s.MaxBatchSize
+ }
}
func applyAutoSolverConfig(cfg *RuntimeConfig, a AutoSolverFileConfig) {
diff --git a/internal/config/config_types.go b/internal/config/config_types.go
index 72562ef6..e160040d 100644
--- a/internal/config/config_types.go
+++ b/internal/config/config_types.go
@@ -188,6 +188,7 @@ type SchedulerConfig struct {
MaxPerAgentFlight int `json:"maxPerAgentInflight,omitempty"`
ResultTTLSec int `json:"resultTTLSec,omitempty"`
WorkerCount int `json:"workerCount,omitempty"`
+ MaxBatchSize int `json:"maxBatchSize,omitempty"`
}
// AutoSolverConfig holds autosolver runtime settings.
@@ -495,6 +496,7 @@ type SchedulerFileConfig struct {
MaxPerAgentFlight *int `json:"maxPerAgentInflight,omitempty"`
ResultTTLSec *int `json:"resultTTLSec,omitempty"`
WorkerCount *int `json:"workerCount,omitempty"`
+ MaxBatchSize *int `json:"maxBatchSize,omitempty"`
}
type ObservabilityFileConfig struct {
diff --git a/internal/config/editor_get.go b/internal/config/editor_get.go
index 759e62b2..be280d5e 100644
--- a/internal/config/editor_get.go
+++ b/internal/config/editor_get.go
@@ -506,6 +506,8 @@ func getSchedulerField(s *SchedulerFileConfig, field string) (string, error) {
return formatIntPtr(s.ResultTTLSec), nil
case "workerCount":
return formatIntPtr(s.WorkerCount), nil
+ case "maxBatchSize":
+ return formatIntPtr(s.MaxBatchSize), nil
default:
return "", fmt.Errorf("unknown field scheduler.%s", field)
}
@@ -660,6 +662,7 @@ func addSettledDefaults(resolved *FileConfig, cfg *RuntimeConfig) {
MaxPerAgentFlight: intPtrIfPositive(cfg.Scheduler.MaxPerAgentFlight),
ResultTTLSec: intPtrIfPositive(cfg.Scheduler.ResultTTLSec),
WorkerCount: intPtrIfPositive(cfg.Scheduler.WorkerCount),
+ MaxBatchSize: intPtrIfPositive(cfg.Scheduler.MaxBatchSize),
}
if resolved.InstanceDefaults.TabPolicy == nil {
resolved.InstanceDefaults.TabPolicy = &TabPolicyDefaults{}
diff --git a/internal/config/editor_set.go b/internal/config/editor_set.go
index 1844a286..16fa7433 100644
--- a/internal/config/editor_set.go
+++ b/internal/config/editor_set.go
@@ -782,6 +782,8 @@ func setSchedulerField(s *SchedulerFileConfig, field, value string) error {
return setIntPtrField(&s.ResultTTLSec, "scheduler.resultTTLSec", value)
case "workerCount":
return setIntPtrField(&s.WorkerCount, "scheduler.workerCount", value)
+ case "maxBatchSize":
+ return setIntPtrField(&s.MaxBatchSize, "scheduler.maxBatchSize", value)
default:
return fmt.Errorf("unknown field scheduler.%s", field)
}
diff --git a/internal/config/scheduler_defaults.go b/internal/config/scheduler_defaults.go
index 90abbaa0..0da1158d 100644
--- a/internal/config/scheduler_defaults.go
+++ b/internal/config/scheduler_defaults.go
@@ -14,6 +14,7 @@ func DefaultSchedulerConfig() SchedulerConfig {
MaxPerAgentFlight: 10,
ResultTTLSec: 300,
WorkerCount: 4,
+ MaxBatchSize: 50,
}
}
@@ -36,6 +37,7 @@ func finalizeSchedulerConfig(cfg *RuntimeConfig) {
{&s.MaxPerAgentFlight, defaults.MaxPerAgentFlight},
{&s.ResultTTLSec, defaults.ResultTTLSec},
{&s.WorkerCount, defaults.WorkerCount},
+ {&s.MaxBatchSize, defaults.MaxBatchSize},
} {
if *knob.value <= 0 {
*knob.value = knob.fallback
diff --git a/internal/config/scheduler_defaults_test.go b/internal/config/scheduler_defaults_test.go
index c268aa05..491584d1 100644
--- a/internal/config/scheduler_defaults_test.go
+++ b/internal/config/scheduler_defaults_test.go
@@ -22,6 +22,7 @@ func TestSchedulerKeysAnswerTheDeclaredDefaults(t *testing.T) {
"scheduler.maxPerAgentInflight": strconv.Itoa(defaults.MaxPerAgentFlight),
"scheduler.resultTTLSec": strconv.Itoa(defaults.ResultTTLSec),
"scheduler.workerCount": strconv.Itoa(defaults.WorkerCount),
+ "scheduler.maxBatchSize": strconv.Itoa(defaults.MaxBatchSize),
} {
if got := effectiveValue(t, path); got != want {
t.Errorf("%s = %q, want %q", path, got, want)
@@ -30,12 +31,13 @@ func TestSchedulerKeysAnswerTheDeclaredDefaults(t *testing.T) {
}
func TestSchedulerKeysKeepWhatTheFileSets(t *testing.T) {
- writeConfigForGet(t, `{"scheduler":{"maxInflight":7,"strategy":"strict-fifo","workerCount":9}}`)
+ writeConfigForGet(t, `{"scheduler":{"maxInflight":7,"strategy":"strict-fifo","workerCount":9,"maxBatchSize":5}}`)
for path, want := range map[string]string{
- "scheduler.maxInflight": "7",
- "scheduler.strategy": "strict-fifo",
- "scheduler.workerCount": "9",
+ "scheduler.maxInflight": "7",
+ "scheduler.strategy": "strict-fifo",
+ "scheduler.workerCount": "9",
+ "scheduler.maxBatchSize": "5",
} {
if got := effectiveValue(t, path); got != want {
t.Errorf("%s = %q, want the configured %q", path, got, want)
@@ -46,7 +48,7 @@ func TestSchedulerKeysKeepWhatTheFileSets(t *testing.T) {
// A configured zero has always meant "use the default" for these knobs — never
// unlimited. The reader must say so too, or it reports a queue size nothing enforces.
func TestSchedulerZeroMeansTheDefaultEverywhere(t *testing.T) {
- writeConfigForGet(t, `{"scheduler":{"maxQueueSize":0,"maxPerAgent":0,"maxInflight":0,"maxPerAgentInflight":0,"resultTTLSec":0,"workerCount":0}}`)
+ writeConfigForGet(t, `{"scheduler":{"maxQueueSize":0,"maxPerAgent":0,"maxInflight":0,"maxPerAgentInflight":0,"resultTTLSec":0,"workerCount":0,"maxBatchSize":0}}`)
defaults := DefaultSchedulerConfig()
cfg, _, err := LoadConfig()
diff --git a/internal/config/scheduler_wire_twin_test.go b/internal/config/scheduler_wire_twin_test.go
new file mode 100644
index 00000000..540b4f30
--- /dev/null
+++ b/internal/config/scheduler_wire_twin_test.go
@@ -0,0 +1,102 @@
+package config
+
+import (
+ "encoding/json"
+ "reflect"
+ "strings"
+ "testing"
+)
+
+// The standing defect class this section is exposed under: SchedulerFileConfig is the type
+// `config set` writes into, and fileConfigJSON.Scheduler is a SEPARATE hand-maintained twin
+// that MarshalJSON copies into. A field present on the first and missing from the second
+// makes `config set` report success and write nothing.
+//
+// Derived from the type rather than listed, so a scheduler key added later is covered with
+// no edit here: every declared field is set through the editor, marshaled the way a save
+// does it, and read back out of the JSON.
+func TestEverySchedulerKeySurvivesTheWireTwin(t *testing.T) {
+ fields := reflect.VisibleFields(reflect.TypeOf(SchedulerFileConfig{}))
+ if len(fields) == 0 {
+ t.Fatal("SchedulerFileConfig declares no fields; this guard would pass vacuously")
+ }
+
+ var file SchedulerFileConfig
+ want := map[string]any{}
+ checked := 0
+ for _, field := range fields {
+ key, _, _ := strings.Cut(field.Tag.Get("json"), ",")
+ if key == "" || key == "-" {
+ continue
+ }
+ value, expected, ok := schedulerProbeValueFor(field.Type)
+ if !ok {
+ t.Errorf("%q has type %s, which this guard cannot drive — extend it rather than skipping the field", key, field.Type)
+ continue
+ }
+ if err := setSchedulerField(&file, key, value); err != nil {
+ t.Errorf("config set scheduler.%s: %v", key, err)
+ continue
+ }
+ want[key] = expected
+ checked++
+ }
+ if checked == 0 {
+ t.Fatal("no field was driven; the guard is not exercising the editor")
+ }
+
+ raw, err := json.Marshal(FileConfig{Scheduler: file})
+ if err != nil {
+ t.Fatalf("marshal: %v", err)
+ }
+ var onDisk struct {
+ Scheduler map[string]any `json:"scheduler"`
+ }
+ if err := json.Unmarshal(raw, &onDisk); err != nil {
+ t.Fatalf("unmarshal: %v", err)
+ }
+
+ for key, expected := range want {
+ got, present := onDisk.Scheduler[key]
+ if !present || got == nil {
+ t.Errorf("scheduler.%s was accepted by config set and is absent from the saved file; the wire twin is missing it, so the write reports success and changes nothing", key)
+ continue
+ }
+ if got != expected {
+ t.Errorf("scheduler.%s saved as %v, want %v", key, got, expected)
+ }
+ }
+}
+
+// The other half: a key the file sets must reach the runtime and then the reader, so the
+// value an operator writes is the value in effect rather than one the loader dropped.
+func TestSchedulerMaxBatchSizeReachesTheRuntimeFromTheFile(t *testing.T) {
+ writeConfigForGet(t, `{"scheduler":{"maxBatchSize":5}}`)
+
+ cfg, _, err := LoadConfig()
+ if err != nil {
+ t.Fatalf("LoadConfig() error = %v", err)
+ }
+ if cfg.Scheduler.MaxBatchSize != 5 {
+ t.Errorf("runtime maxBatchSize = %d, want the configured 5", cfg.Scheduler.MaxBatchSize)
+ }
+ if got := effectiveValue(t, "scheduler.maxBatchSize"); got != "5" {
+ t.Errorf("scheduler.maxBatchSize reads %q, want the configured 5", got)
+ }
+}
+
+func schedulerProbeValueFor(t reflect.Type) (string, any, bool) {
+ if t.Kind() == reflect.Pointer {
+ t = t.Elem()
+ }
+ switch t.Kind() {
+ case reflect.Bool:
+ return "true", true, true
+ case reflect.String:
+ return "strict-fifo", "strict-fifo", true
+ case reflect.Int:
+ return "7", float64(7), true
+ default:
+ return "", nil, false
+ }
+}
diff --git a/internal/scheduler/scheduler.go b/internal/scheduler/scheduler.go
index c4511ad9..15006b24 100644
--- a/internal/scheduler/scheduler.go
+++ b/internal/scheduler/scheduler.go
@@ -32,10 +32,9 @@ type Config struct {
// DefaultConfig returns safe defaults. The knobs an operator can set live in
// internal/config, which owns their defaults and reports them through `config get`;
-// only the two this package does not expose as config keys are written here.
+// only the one this package does not expose as a config key is written here.
func DefaultConfig() Config {
out := ConfigFromRuntime(config.DefaultSchedulerConfig())
- out.MaxBatchSize = 50
out.WatcherInterval = 30 * time.Second
return out
}
@@ -53,6 +52,7 @@ func ConfigFromRuntime(s config.SchedulerConfig) Config {
MaxPerAgentFlight: s.MaxPerAgentFlight,
ResultTTL: time.Duration(s.ResultTTLSec) * time.Second,
WorkerCount: s.WorkerCount,
+ MaxBatchSize: s.MaxBatchSize,
}
}
diff --git a/internal/scheduler/scheduler_defaults_test.go b/internal/scheduler/scheduler_defaults_test.go
index d16a60a5..4ba33ea8 100644
--- a/internal/scheduler/scheduler_defaults_test.go
+++ b/internal/scheduler/scheduler_defaults_test.go
@@ -27,7 +27,7 @@ func TestDefaultConfigTakesTheOperatorKnobsFromTheConfigPackage(t *testing.T) {
want := ConfigFromRuntime(config.DefaultSchedulerConfig())
got := DefaultConfig()
- got.MaxBatchSize, got.WatcherInterval = want.MaxBatchSize, want.WatcherInterval
+ got.WatcherInterval = want.WatcherInterval
if got != want {
t.Errorf("DefaultConfig() operator knobs = %+v, want %+v from config.DefaultSchedulerConfig()", got, want)
}
@@ -50,6 +50,7 @@ var schedulerKnobFields = []string{
"ResultTTL",
"ResultTTLSec",
"WorkerCount",
+ "MaxBatchSize",
}
var knobLiteralAssignment = regexp.MustCompile(`\b(` + strings.Join(schedulerKnobFields, "|") + `)\s*[:=]\s*("|\d|-\d)`)
@@ -112,3 +113,22 @@ func TestSchedulerDefaultsAreSpelledInOnePlace(t *testing.T) {
}
}
}
+
+// Exposing the knob must not move the value it produces, and the value must arrive
+// through the one conversion site rather than a second path. 50 is spelled out here
+// rather than read from the config package: comparing two derived sides holds whatever
+// both are changed to, and "the default is unchanged" is the claim being pinned.
+func TestBatchSizeIsUnchangedAndComesThroughTheConversionSite(t *testing.T) {
+ if got := DefaultConfig().MaxBatchSize; got != 50 {
+ t.Errorf("default maxBatchSize = %d, want the 50 this package produced before the knob was exposed", got)
+ }
+
+ runtime := config.DefaultSchedulerConfig()
+ runtime.MaxBatchSize = 5
+ if got := ConfigFromRuntime(runtime).MaxBatchSize; got != 5 {
+ t.Errorf("a configured maxBatchSize of 5 converted to %d; the conversion drops it, so config set writes a value nothing enforces", got)
+ }
+ if got := New(ConfigFromRuntime(runtime), nil).cfg.MaxBatchSize; got != 5 {
+ t.Errorf("the running scheduler enforces %d, want the configured 5", got)
+ }
+}
diff --git a/internal/schema/config.json b/internal/schema/config.json
index cc05c4b9..e21b8a86 100644
--- a/internal/schema/config.json
+++ b/internal/schema/config.json
@@ -777,6 +777,9 @@
},
"workerCount": {
"$ref": "#/definitions/nonNegativeNullableInteger"
+ },
+ "maxBatchSize": {
+ "$ref": "#/definitions/nonNegativeNullableInteger"
}
}
},