judge: Pool-Ziele und Ketten aus mehreren Judge-Schritten
Der Judge-Ziel darf ein Pool sein; die Mitglieder behalten ihr eigenes "as" und werden in Pool-Reihenfolge versucht. Mehrere `judge every N` Klauseln einer Regel bilden eine Kette: die Zahlen sind kumulativ, müssen aufsteigend sein, und nach dem letzten Schritt beginnt der Zähler wieder bei 0. Beispiel: every 5 ds41flash, every 10 claude-openai0 -> 5. Call DeepSeek, 10. Call Claude, 15./20. wieder DeepSeek/Claude. /v1/models nimmt die engere Grenze über Worker und alle Judge-Schritte. Absteigende Ketten und Judge-Ziele ohne Modell werden beim Laden abgelehnt; die Meldung nennt den Schritt. Tests: 364 OK, 0 FAIL. tests/run.sh definiert wieder fail(); der MCP-Lastabschnitt konnte einen Fehlschlag sonst verschlucken.
This commit is contained in:
1 parent
584c622ed6
commit
725edf784a
10 files changed
+333
-101
No files matched your search
@@ -140,7 +140,7 @@ req for "*" pass peer1, cloud
|
||||
```
|
||||
req [for <model-glob>] [path <glob>] [need >N | <N | N]
|
||||
[check hooks|none] [retry <seconds>]
|
||||
[judge every N <endpoint> as <model> [cache 5m|1h|off]]
|
||||
[judge every N <endpoint|pool> [as <model>] [cache 5m|1h|off]]...
|
||||
( pass <endpoint>[,<endpoint>...] [as <model>] | block )
|
||||
```
|
||||
|
||||
@@ -155,13 +155,18 @@ req [for <model-glob>] [path <glob>] [need >N | <N | N]
|
||||
`pass peer-a as "qwen3.8-flash-next-q1m", peer-b, cloud` sends the local id to the
|
||||
peers and the requested id to the cloud.
|
||||
- `block` — refuse with `403`.
|
||||
- `judge every N <endpoint> as <model> [cache 5m|1h|off]` — before `pass`: every Nth
|
||||
request of a conversation is sent to that endpoint with the same body. The rule's
|
||||
normal targets stay as fallback, so a rate-limited or offline judge still leaves the
|
||||
worker serving the turn. A judge turn is never answered from junction's response
|
||||
cache. `cache 1h` adds an Anthropic `cache_control` marker to the last message; the
|
||||
provider then caches tools, system prompt and the conversation prefix up to that
|
||||
message. `5m` is cheaper to write, `off` sends no marker. See below.
|
||||
- `judge every N <endpoint|pool> [as <model>] [cache 5m|1h|off]` — before `pass`:
|
||||
at request N of a conversation that endpoint or pool gets the same body. The clause
|
||||
may repeat; the counts are **cumulative inside one chain** and must be ascending.
|
||||
After the last step the conversation counter starts again at 0. Example: `every 5
|
||||
deepseek` then `every 10 claude` means the 5th call goes to DeepSeek, the 10th to
|
||||
Claude, then the chain restarts and the 15th/20th are next. A pool member's own `as`
|
||||
wins; a rule-level `as` is its fallback. The rule's normal targets stay as fallback,
|
||||
so a rate-limited or offline judge still leaves the worker serving the turn. A judge
|
||||
turn is never answered from junction's response cache. `cache 1h` adds an Anthropic
|
||||
`cache_control` marker to the last message; the provider then caches tools, system
|
||||
prompt and the conversation prefix up to that message. `5m` is cheaper to write,
|
||||
`off` sends no marker. See below.
|
||||
|
||||
No matching rule → `503 no_matching_rule`: an unmatched request is a config gap, not
|
||||
something to quietly send to a cloud.
|
||||
@@ -170,22 +175,30 @@ something to quietly send to a cloud.
|
||||
|
||||
A rule with an exact model name and a `judge` clause becomes a virtual model in
|
||||
`/v1/models`. The client asks for the virtual name; the worker does the turns, and
|
||||
every Nth request of the same conversation goes to the judge instead:
|
||||
the chain decides which requests go to which judge:
|
||||
|
||||
```
|
||||
req for "qwen3.6-35b-judged" balance round-robin check none \
|
||||
judge every 5 ds41flash cache off \
|
||||
judge every 10 claude-openai0 as "claude-opus-5-5" cache 1h \
|
||||
pass qwen3.6-35b as "/models/unsloth/Qwen3.6-35B-A3B-MTP-GGUF/Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf"
|
||||
```
|
||||
|
||||
The judge gets the **whole** body, including every previous assistant message, so it
|
||||
can see what the worker did and correct it. The count is per conversation and per
|
||||
rule, not global. A conversation is identified by `x-junction-session`,
|
||||
`x-session-id`, `x-conversation-id` or `x-opencode-session` if the client sends one;
|
||||
otherwise junction hashes the first system and first user message, which do not change
|
||||
when a turn is appended. Requests are counted, not user-visible turns: an agent turn
|
||||
with three tool round-trips counts three times. Use a session header and a larger N
|
||||
when that matters.
|
||||
The 5th call of a conversation goes to the `ds41flash` pool (DeepSeek), the 10th to
|
||||
Claude Opus, then the counter resets: the 15th and 20th are next. The judge gets the
|
||||
**whole** body, including every previous assistant message, so it can see what the
|
||||
worker did and correct it. The count is per conversation and per rule, not global. A
|
||||
conversation is identified by `x-junction-session`, `x-session-id`,
|
||||
`x-conversation-id` or `x-opencode-session` if the client sends one; otherwise
|
||||
junction hashes the first system and first user message, which do not change when a
|
||||
turn is appended. Requests are counted, not user-visible turns: an agent turn with
|
||||
three tool round-trips counts three times. Use a session header and a larger N when
|
||||
that matters.
|
||||
|
||||
`cache` writes an Anthropic-style `cache_control` marker on the last message.
|
||||
Anthropic and gateways that translate the marker honour it. DeepSeek and other
|
||||
OpenAI-compatible providers cache repeated prefixes automatically; there `cache off`
|
||||
is right, and the marker would only be noise.
|
||||
|
||||
If the judge fails, the same request is offered to the rule's normal targets. The
|
||||
fallback gets the original body, without the judge's cache marker. `/v1/models` lists
|
||||
|
||||
@@ -215,8 +215,15 @@ req path "/v1/models" check none pass peer1, peer2, opencode-go
|
||||
# the Anthropic OpenAI-compatible endpoint, not kind anthropic):
|
||||
#
|
||||
# req for "qwen-judged" balance round-robin check none \
|
||||
# judge every 5 ds41flash cache off \
|
||||
# judge every 10 claude-openai as "claude-opus-5-5" cache 1h \
|
||||
# pass peer1 as "qwen3.8"
|
||||
#
|
||||
# The judge clauses form a chain: the 5th call goes to the DeepSeek pool, the
|
||||
# 10th to Claude, then the counter resets to 0 (15th/20th next). Counts must be
|
||||
# ascending. A pool is allowed as the judge; its members keep their own "as".
|
||||
# "cache" is for Anthropic-style cache_control; DeepSeek/OpenAI-compatible
|
||||
# providers cache prefixes automatically, so leave it off there.
|
||||
|
||||
# Anything unseen is refused rather than silently sent to the opencode-go.
|
||||
req for "*" block
|
||||
+84
-25
@@ -887,25 +887,35 @@ static int parse_rule(char **w, int n, int lineno, j_rule *r, char *err, size_t
|
||||
snprintf(r->strip, sizeof r->strip, "%s", w[i + 1]);
|
||||
i += 2;
|
||||
} else if (!strcmp(k, "judge")) {
|
||||
/* judge every N endpoint as "model" [cache 5m|1h|off]
|
||||
* Muss vor "pass" stehen: "pass" nimmt den Rest der Zeile als Ziele. */
|
||||
/* judge every N endpoint|pool [as "model"] [cache 5m|1h|off]
|
||||
* Repeatable; the counts are cumulative and the chain resets after its
|
||||
* last step. Muss vor "pass" stehen: "pass" nimmt den Rest der Zeile. */
|
||||
if (i + 3 >= n || strcmp(w[i + 1], "every")) goto bad;
|
||||
if (r->judge_count >= J_MAX_JUDGES) {
|
||||
snprintf(err, errlen, "line %d: more than %d judge steps",
|
||||
lineno, J_MAX_JUDGES);
|
||||
return -1;
|
||||
}
|
||||
long every = 0;
|
||||
if (as_long(w[i + 2], &every) || every < 1) goto bad;
|
||||
r->judge_every = (int)every;
|
||||
snprintf(r->judge_target, sizeof r->judge_target, "%s", w[i + 3]);
|
||||
int j = r->judge_count;
|
||||
r->judges[j].every = (int)every;
|
||||
r->judges[j].cache = 0;
|
||||
r->judges[j].as[0] = '\0';
|
||||
snprintf(r->judges[j].target, sizeof r->judges[j].target, "%s", w[i + 3]);
|
||||
i += 4;
|
||||
if (i + 1 < n && !strcmp(w[i], "as")) {
|
||||
snprintf(r->judge_as, sizeof r->judge_as, "%s", w[i + 1]);
|
||||
snprintf(r->judges[j].as, sizeof r->judges[j].as, "%s", w[i + 1]);
|
||||
i += 2;
|
||||
}
|
||||
if (i + 1 < n && !strcmp(w[i], "cache")) {
|
||||
if (!strcmp(w[i + 1], "1h")) r->judge_cache = 2;
|
||||
else if (!strcmp(w[i + 1], "5m")) r->judge_cache = 1;
|
||||
else if (!strcmp(w[i + 1], "off")) r->judge_cache = 0;
|
||||
if (!strcmp(w[i + 1], "1h")) r->judges[j].cache = 2;
|
||||
else if (!strcmp(w[i + 1], "5m")) r->judges[j].cache = 1;
|
||||
else if (!strcmp(w[i + 1], "off")) r->judges[j].cache = 0;
|
||||
else goto bad;
|
||||
i += 2;
|
||||
}
|
||||
r->judge_count++;
|
||||
} else if (!strcmp(k, "block")) {
|
||||
r->block = 1;
|
||||
i++;
|
||||
@@ -1381,28 +1391,77 @@ int j_config_load(const char *path, j_config *cfg, char *err, size_t errlen)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (r->judge_every > 0) {
|
||||
if (!r->judge_target[0] || !r->judge_as[0]) {
|
||||
snprintf(err, errlen,
|
||||
"line %d: judge needs 'every N endpoint as \"model\"'", r->line);
|
||||
return -1;
|
||||
}
|
||||
int found_judge = 0;
|
||||
for (int e = 0; e < cfg->endpoint_count; e++)
|
||||
if (!strcmp(cfg->endpoints[e].name, r->judge_target)) {
|
||||
if (r->judge_count > 0) {
|
||||
int max_judge_slots = 0;
|
||||
for (int j = 0; j < r->judge_count; j++) {
|
||||
if (j > 0 && r->judges[j].every <= r->judges[j - 1].every) {
|
||||
snprintf(err, errlen,
|
||||
"line %d: judge steps must be ascending (%d after %d)",
|
||||
r->line, r->judges[j].every, r->judges[j - 1].every);
|
||||
return -1;
|
||||
}
|
||||
const char *target = r->judges[j].target;
|
||||
if (!target[0]) {
|
||||
snprintf(err, errlen,
|
||||
"line %d: judge needs 'every N endpoint|pool [as \"model\"]'",
|
||||
r->line);
|
||||
return -1;
|
||||
}
|
||||
int found_judge = 0;
|
||||
int judge_slots = 0;
|
||||
for (int e = 0; e < cfg->endpoint_count; e++) {
|
||||
if (strcmp(cfg->endpoints[e].name, target)) continue;
|
||||
found_judge = 1;
|
||||
judge_slots = 1;
|
||||
if (!r->judges[j].as[0]) {
|
||||
snprintf(err, errlen,
|
||||
"line %d: judge needs 'every N endpoint as \"model\"'",
|
||||
r->line);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!found_judge) {
|
||||
snprintf(err, errlen, "line %d: judge passes to unknown endpoint '%s'",
|
||||
r->line, r->judge_target);
|
||||
return -1;
|
||||
if (!found_judge) {
|
||||
for (int p = 0; p < cfg->pool_count; p++) {
|
||||
if (strcmp(cfg->pools[p].name, target)) continue;
|
||||
found_judge = 1;
|
||||
judge_slots = cfg->pools[p].count;
|
||||
for (int c = 0; c < cfg->pools[p].count; c++) {
|
||||
if (!cfg->pools[p].target_as[c][0] && !r->judges[j].as[0]) {
|
||||
snprintf(err, errlen,
|
||||
"line %d: judge pool member %s needs a model",
|
||||
r->line, cfg->pools[p].targets[c]);
|
||||
return -1;
|
||||
}
|
||||
int member = 0;
|
||||
for (int e = 0; e < cfg->endpoint_count; e++)
|
||||
if (!strcmp(cfg->endpoints[e].name, cfg->pools[p].targets[c])) {
|
||||
member = 1;
|
||||
break;
|
||||
}
|
||||
if (!member) {
|
||||
snprintf(err, errlen,
|
||||
"line %d: judge pool member passes to unknown endpoint '%s'",
|
||||
r->line, cfg->pools[p].targets[c]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found_judge) {
|
||||
snprintf(err, errlen,
|
||||
"line %d: judge passes to unknown endpoint or pool '%s'",
|
||||
r->line, target);
|
||||
return -1;
|
||||
}
|
||||
if (judge_slots > max_judge_slots) max_judge_slots = judge_slots;
|
||||
}
|
||||
/* The judge is inserted in front of the rule's targets at runtime. */
|
||||
if (r->target_count + 1 > J_MAX_TARGETS) {
|
||||
/* One judge step is inserted in front of the targets at runtime. */
|
||||
if (r->target_count + max_judge_slots > J_MAX_TARGETS) {
|
||||
snprintf(err, errlen,
|
||||
"line %d: judge needs one more target slot (max %d)",
|
||||
r->line, J_MAX_TARGETS);
|
||||
"line %d: judge needs %d more target slots (max %d)",
|
||||
r->line, max_judge_slots, J_MAX_TARGETS);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-7
@@ -54,6 +54,7 @@
|
||||
#define J_MAX_KEY_ENVS 8
|
||||
#define J_MAX_MODEL_PATTERNS 32
|
||||
#define J_MAX_POOLS 16
|
||||
#define J_MAX_JUDGES 4
|
||||
#define J_MAX_MCP 16
|
||||
#define J_MAX_CACHE_PEERS 8
|
||||
/* Endliche Latenzgrenzen in Sekunden; dazu kommt der +Inf-Eimer. */
|
||||
@@ -259,13 +260,17 @@ typedef struct {
|
||||
/* Präfix, das vor dem Weiterleiten vom Modellnamen fällt: `strip "local/"` macht aus
|
||||
* local/qwen3.6-35b das qwen3.6-35b, das die Box kennt. */
|
||||
char strip[J_NAME_MAX];
|
||||
/* Sampled escalation: `judge every N endpoint as "model" [cache 1h]`.
|
||||
* Every Nth request of a conversation goes to this endpoint instead of the
|
||||
* rule's targets; if it fails, the rule's targets still serve as fallback. */
|
||||
int judge_every; /* 0 = off */
|
||||
int judge_cache; /* 0 = off, 1 = 5m, 2 = 1h */
|
||||
char judge_target[J_NAME_MAX];
|
||||
char judge_as[J_GLOB_MAX];
|
||||
/* Sampled escalation chain: `judge every N endpoint|pool [as "model"] [cache ...]`
|
||||
* may repeat. The counts are cumulative inside the chain; after the last step
|
||||
* the conversation counter starts again at 0. The step's target is inserted
|
||||
* in front of the rule's targets; if it fails, those still serve as fallback. */
|
||||
struct {
|
||||
int every;
|
||||
int cache; /* 0 = off, 1 = 5m, 2 = 1h */
|
||||
char target[J_NAME_MAX];
|
||||
char as[J_GLOB_MAX];
|
||||
} judges[J_MAX_JUDGES];
|
||||
int judge_count;
|
||||
int target_count;
|
||||
int line;
|
||||
} j_rule;
|
||||
|
||||
+17
-6
@@ -49,10 +49,16 @@ static uint64_t fnv1a(uint64_t h, const void *data, size_t len)
|
||||
return h;
|
||||
}
|
||||
|
||||
int j_judge_tick(uint64_t conversation, int rule_line, int every)
|
||||
static int step_for_count(unsigned count, const int *steps, int nsteps)
|
||||
{
|
||||
if (every <= 0) return 0;
|
||||
if (every == 1) return 1;
|
||||
for (int i = 0; i < nsteps; i++)
|
||||
if ((unsigned)steps[i] == count) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int j_judge_tick(uint64_t conversation, int rule_line, const int *steps, int nsteps)
|
||||
{
|
||||
if (nsteps <= 0) return -1;
|
||||
|
||||
uint64_t key = conversation ? conversation : 1;
|
||||
key ^= (uint64_t)(unsigned)rule_line * 0x9e3779b97f4a7c15ULL;
|
||||
@@ -71,9 +77,12 @@ int j_judge_tick(uint64_t conversation, int rule_line, int every)
|
||||
if (s->key == key) {
|
||||
s->count++;
|
||||
s->last = now;
|
||||
int hit = (s->count % (unsigned)every) == 0;
|
||||
int step = step_for_count(s->count, steps, nsteps);
|
||||
/* After the last step the chain is complete; the next request starts
|
||||
* at 0 and the first step is due again N calls later. */
|
||||
if (step == nsteps - 1) s->count = 0;
|
||||
pthread_mutex_unlock(&g_slots_mu);
|
||||
return hit;
|
||||
return step;
|
||||
}
|
||||
if (s->key == 0 || now - s->last > JUDGE_IDLE_S) {
|
||||
if (free_slot < 0) free_slot = (int)ix;
|
||||
@@ -88,8 +97,10 @@ int j_judge_tick(uint64_t conversation, int rule_line, int every)
|
||||
s->key = key;
|
||||
s->count = 1;
|
||||
s->last = now;
|
||||
int step = step_for_count(1, steps, nsteps);
|
||||
if (step == nsteps - 1) s->count = 0;
|
||||
pthread_mutex_unlock(&g_slots_mu);
|
||||
return 0;
|
||||
return step;
|
||||
}
|
||||
|
||||
static uint64_t hash_messages(const char *body, const char *end, uint64_t h, int *any);
|
||||
|
||||
+6
-4
@@ -13,10 +13,12 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* Returns 1 when this request is the judge turn. `conversation` comes from
|
||||
* j_judge_conversation(); `rule_line` keeps counters of different rules apart.
|
||||
* every <= 0 disables, every == 1 sends everything to the judge. */
|
||||
int j_judge_tick(uint64_t conversation, int rule_line, int every);
|
||||
/* Returns the index of the judge step for this request, or -1 for the worker.
|
||||
* `steps` are the cumulative counts inside the chain (strictly ascending), e.g.
|
||||
* {5, 10}: the 5th request is step 0, the 10th is step 1, then the counter
|
||||
* starts again at 0. `conversation` comes from j_judge_conversation();
|
||||
* `rule_line` keeps counters of different rules apart. */
|
||||
int j_judge_tick(uint64_t conversation, int rule_line, const int *steps, int nsteps);
|
||||
|
||||
/* Stable conversation id: session header if present, else the first 4 KiB of the
|
||||
* body (the part that does not change when a turn is appended), plus the vkey.
|
||||
|
||||
+45
-21
@@ -3566,37 +3566,61 @@ static void handle_client(j_conn *client)
|
||||
* offline, budget) still falls back to the worker instead of failing the turn.
|
||||
* An oversized context already moved to ctx_fallback; leave that decision alone. */
|
||||
int judge_turn = 0;
|
||||
if (rule->judge_every > 0 && !ctx_fallback_used && rq.body && model[0]) {
|
||||
int judge_slots = 0;
|
||||
if (rule->judge_count > 0 && !ctx_fallback_used && rq.body && model[0]) {
|
||||
int steps[J_MAX_JUDGES];
|
||||
for (int j = 0; j < rule->judge_count; j++) steps[j] = rule->judges[j].every;
|
||||
char sess[J_HDR_VALUE];
|
||||
const char *session = request_session(&rq.hdrs, sess, sizeof sess);
|
||||
uint64_t conversation = j_judge_conversation(rq.body, vk ? vk->name : "", session);
|
||||
if (j_judge_tick(conversation, rule->line, rule->judge_every)) {
|
||||
if (rule_copy.target_count + 1 > J_MAX_TARGETS) {
|
||||
int step = j_judge_tick(conversation, rule->line, steps, rule->judge_count);
|
||||
if (step >= 0) {
|
||||
const char *target = rule->judges[step].target;
|
||||
const char *judge_as = rule->judges[step].as;
|
||||
int cache = rule->judges[step].cache;
|
||||
const j_pool *judge_pool = find_pool(target);
|
||||
int slots = judge_pool ? judge_pool->count : 1;
|
||||
if (rule_copy.target_count + slots > J_MAX_TARGETS) {
|
||||
jlog("judge_skipped", "rule_line=%d reason=target_limit", rule->line);
|
||||
} else {
|
||||
if (rule->judge_cache > 0 &&
|
||||
j_judge_cache_body(rq.body, rule->judge_cache == 2,
|
||||
&judge_body, &judge_len) != 0) {
|
||||
if (cache > 0 &&
|
||||
j_judge_cache_body(rq.body, cache == 2, &judge_body, &judge_len) != 0) {
|
||||
judge_body = NULL;
|
||||
judge_len = 0;
|
||||
}
|
||||
for (int k = rule_copy.target_count; k > 0; k--) {
|
||||
snprintf(rule_copy.targets[k], sizeof rule_copy.targets[k], "%s",
|
||||
rule_copy.targets[k - 1]);
|
||||
snprintf(rule_copy.target_as[k], sizeof rule_copy.target_as[k], "%s",
|
||||
rule_copy.target_as[k - 1]);
|
||||
for (int k = rule_copy.target_count - 1; k >= 0; k--) {
|
||||
snprintf(rule_copy.targets[k + slots],
|
||||
sizeof rule_copy.targets[k + slots], "%s",
|
||||
rule_copy.targets[k]);
|
||||
snprintf(rule_copy.target_as[k + slots],
|
||||
sizeof rule_copy.target_as[k + slots], "%s",
|
||||
rule_copy.target_as[k]);
|
||||
}
|
||||
snprintf(rule_copy.targets[0], sizeof rule_copy.targets[0], "%.*s",
|
||||
(int)sizeof rule_copy.targets[0] - 1, rule->judge_target);
|
||||
snprintf(rule_copy.target_as[0], sizeof rule_copy.target_as[0], "%.*s",
|
||||
(int)sizeof rule_copy.target_as[0] - 1, rule->judge_as);
|
||||
rule_copy.target_count++;
|
||||
if (judge_pool) {
|
||||
for (int c = 0; c < judge_pool->count; c++) {
|
||||
snprintf(rule_copy.targets[c], sizeof rule_copy.targets[c], "%.*s",
|
||||
(int)sizeof rule_copy.targets[c] - 1,
|
||||
judge_pool->targets[c]);
|
||||
const char *m = judge_pool->target_as[c][0] ? judge_pool->target_as[c]
|
||||
: judge_as;
|
||||
snprintf(rule_copy.target_as[c], sizeof rule_copy.target_as[c],
|
||||
"%.*s", (int)sizeof rule_copy.target_as[c] - 1, m);
|
||||
}
|
||||
} else {
|
||||
snprintf(rule_copy.targets[0], sizeof rule_copy.targets[0], "%.*s",
|
||||
(int)sizeof rule_copy.targets[0] - 1, target);
|
||||
snprintf(rule_copy.target_as[0], sizeof rule_copy.target_as[0], "%.*s",
|
||||
(int)sizeof rule_copy.target_as[0] - 1, judge_as);
|
||||
}
|
||||
rule_copy.target_count += slots;
|
||||
rule_copy.balance = J_BALANCE_FIRST;
|
||||
judge_turn = 1;
|
||||
jlog("judge", "rule_line=%d every=%d endpoint=%s model=%s cache=%s "
|
||||
"conv=%016llx",
|
||||
rule->line, rule->judge_every, rule->judge_target, rule->judge_as,
|
||||
judge_body ? (rule->judge_cache == 2 ? "1h" : "5m") : "off",
|
||||
judge_slots = slots;
|
||||
jlog("judge", "rule_line=%d step=%d every=%d target=%s slots=%d model=%s "
|
||||
"cache=%s conv=%016llx",
|
||||
rule->line, step, rule->judges[step].every, target, slots,
|
||||
judge_as[0] ? judge_as : "pool",
|
||||
judge_body ? (cache == 2 ? "1h" : "5m") : "off",
|
||||
(unsigned long long)conversation);
|
||||
}
|
||||
}
|
||||
@@ -3890,7 +3914,7 @@ static void handle_client(j_conn *client)
|
||||
/* Welcher Rumpf geht raus? Ein Ziel mit eigenem Kürzen bekommt den kurzen,
|
||||
* ein großes den vollen. Der Judge bekommt den vollen Rumpf mit dem
|
||||
* Cache-Marker; fällt er aus, sieht der Worker wieder den normalen Rumpf. */
|
||||
int judge_target = judge_turn && t == 0;
|
||||
int judge_target = judge_turn && t < judge_slots;
|
||||
int judge_body_used = judge_target && judge_body != NULL;
|
||||
const char *send_body = judge_body_used ? judge_body
|
||||
: ((ep_compresses && comp_body) ? comp_body : out_body);
|
||||
|
||||
+34
-10
@@ -306,6 +306,13 @@ static j_endpoint *find_ep(const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const j_pool *find_pool_cfg(const char *name)
|
||||
{
|
||||
for (int i = 0; i < CFG.pool_count; i++)
|
||||
if (!strcmp(CFG.pools[i].name, name)) return &CFG.pools[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Ist das ein "einfacher" Modellname (kein Globjoker), der als virtuelle/alias
|
||||
* Kette in Regeln auftaucht? Wir nutzen Regeln mit exakt passendem model_glob. */
|
||||
long j_models_effective_limit(const char *model, int which)
|
||||
@@ -322,7 +329,7 @@ long j_models_effective_limit(const char *model, int which)
|
||||
if (strcmp(r->model_glob, model) != 0) continue;
|
||||
/* Pfadspezifische Regeln (z.B. /v1/models) sind keine Modellalias-Ketten. */
|
||||
if (r->path_glob[0] && strcmp(r->path_glob, "*") != 0) continue;
|
||||
int is_chain = (r->target_count > 1) || r->judge_every > 0;
|
||||
int is_chain = (r->target_count > 1) || r->judge_count > 0;
|
||||
for (int t = 0; !is_chain && t < r->target_count; t++)
|
||||
if (r->target_as[t][0]) is_chain = 1;
|
||||
if (!is_chain) continue;
|
||||
@@ -339,14 +346,31 @@ long j_models_effective_limit(const char *model, int which)
|
||||
if (best <= 0 || lim < best) best = lim;
|
||||
}
|
||||
}
|
||||
if (r->judge_every > 0 && r->judge_target[0]) {
|
||||
j_endpoint *ep = find_ep(r->judge_target);
|
||||
if (ep) {
|
||||
const char *em = r->judge_as[0] ? r->judge_as : model;
|
||||
long lim = j_models_limit(ep, em, which);
|
||||
if (lim <= 0) lim = ep->context;
|
||||
if (which == 1 && lim <= 0) lim = 0;
|
||||
if (lim > 0 && (best <= 0 || lim < best)) best = lim;
|
||||
for (int j = 0; j < r->judge_count; j++) {
|
||||
const char *target = r->judges[j].target;
|
||||
const char *judge_as = r->judges[j].as;
|
||||
if (!target[0]) continue;
|
||||
const j_pool *jp = find_pool_cfg(target);
|
||||
if (jp) {
|
||||
for (int c = 0; c < jp->count; c++) {
|
||||
j_endpoint *ep = find_ep(jp->targets[c]);
|
||||
if (!ep) continue;
|
||||
const char *em = jp->target_as[c][0] ? jp->target_as[c]
|
||||
: (judge_as[0] ? judge_as : model);
|
||||
long lim = j_models_limit(ep, em, which);
|
||||
if (lim <= 0) lim = ep->context;
|
||||
if (which == 1 && lim <= 0) lim = 0;
|
||||
if (lim > 0 && (best <= 0 || lim < best)) best = lim;
|
||||
}
|
||||
} else {
|
||||
j_endpoint *ep = find_ep(target);
|
||||
if (ep) {
|
||||
const char *em = judge_as[0] ? judge_as : model;
|
||||
long lim = j_models_limit(ep, em, which);
|
||||
if (lim <= 0) lim = ep->context;
|
||||
if (which == 1 && lim <= 0) lim = 0;
|
||||
if (lim > 0 && (best <= 0 || lim < best)) best = lim;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -470,7 +494,7 @@ int j_models_patch_list(const char *json, size_t len, char **out, size_t *out_le
|
||||
if (r->block || r->target_count <= 0) continue;
|
||||
if (!r->model_glob[0] || strchr(r->model_glob, '*') || strchr(r->model_glob, '?')) continue;
|
||||
if (r->path_glob[0] && strcmp(r->path_glob, "*") != 0) continue;
|
||||
int is_chain = (r->target_count > 1) || r->judge_every > 0;
|
||||
int is_chain = (r->target_count > 1) || r->judge_count > 0;
|
||||
for (int t = 0; !is_chain && t < r->target_count; t++) if (r->target_as[t][0]) is_chain = 1;
|
||||
if (!is_chain) continue;
|
||||
const char *name = r->model_glob;
|
||||
|
||||
+94
-10
@@ -15,16 +15,22 @@ JJ=$((PORT+271))
|
||||
JP=$((PORT+272))
|
||||
JF=$((PORT+273))
|
||||
JP2=$((PORT+274))
|
||||
JP3=$((PORT+275))
|
||||
JJ2=$((PORT+276))
|
||||
JP4=$((PORT+277))
|
||||
|
||||
tests/stub $JW "WORKER" > "$TMP/judge_worker.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
tests/stub $JJ "JUDGE" > "$TMP/judge_judge.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
tests/stub $JJ2 "JUDGE2" > "$TMP/judge_judge2.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
STUB_STATE="$TMP/judge_bad.state" tests/stub $JF "BADJUDGE" --fail-n 100 \
|
||||
> "$TMP/judge_bad.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
wait_port $JW 10 || bad "the judge worker stub did not come up"
|
||||
wait_port $JJ 10 || bad "the judge stub did not come up"
|
||||
wait_port $JJ2 10 || bad "the second judge stub did not come up"
|
||||
wait_port $JF 10 || bad "the failing judge stub did not come up"
|
||||
|
||||
cat > "$TMP/judge.conf" <<CFG
|
||||
@@ -41,11 +47,11 @@ PIDS+=($!)
|
||||
wait_port "$JP" 10 || bad "the judge instance did not come up"
|
||||
|
||||
SYS="You are a careful reviewer. Keep the answer short and check the previous step."
|
||||
judge_body() { # judge_body <first-user> <last-user>
|
||||
python3 - "$SYS" "$1" "$2" <<'PY'
|
||||
judge_body() { # judge_body <model> <first-user> <last-user>
|
||||
python3 - "$SYS" "$2" "$3" "$1" <<'PY'
|
||||
import json, sys
|
||||
print(json.dumps({
|
||||
"model": "qwen-judged",
|
||||
"model": sys.argv[4],
|
||||
"messages": [
|
||||
{"role": "system", "content": sys.argv[1]},
|
||||
{"role": "user", "content": sys.argv[2]},
|
||||
@@ -55,11 +61,11 @@ print(json.dumps({
|
||||
}))
|
||||
PY
|
||||
}
|
||||
judge_ask() { # judge_ask <port> <first-user> <last-user>
|
||||
judge_ask() { # judge_ask <port> <model> <first-user> <last-user>
|
||||
curl -s -D "$TMP/judge_h.txt" -o "$TMP/judge_b.txt" -m 20 \
|
||||
-X POST -H 'Content-Type: application/json' \
|
||||
-H 'anthropic-version: 2025-01-01' \
|
||||
-d "$(judge_body "$2" "$3")" \
|
||||
-d "$(judge_body "$2" "$3" "$4")" \
|
||||
"http://127.0.0.1:$1/v1/chat/completions"
|
||||
JNAME=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Stub-Name: //p')
|
||||
JCACHE=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Stub-Cache-Control: //p')
|
||||
@@ -71,7 +77,7 @@ judge_ask() { # judge_ask <port> <first-user> <last-user>
|
||||
# Unterhaltung A: 3., 6., 9. … Anfrage geht an den Judge.
|
||||
A=("W" "W" "J" "W" "W" "J")
|
||||
for i in 1 2 3 4 5 6; do
|
||||
judge_ask "$JP" "$SYS" "conversation A, turn $i"
|
||||
judge_ask "$JP" "qwen-judged" "$SYS" "conversation A, turn $i"
|
||||
if [ "${A[$((i-1))]}" = "J" ]; then
|
||||
[ "$JNAME" = "JUDGE" ] && ok "turn $i goes to the judge" \
|
||||
|| bad "turn $i should go to the judge, got '$JNAME'"
|
||||
@@ -94,13 +100,13 @@ for i in 1 2 3 4 5 6; do
|
||||
done
|
||||
|
||||
# Unterhaltung B beginnt bei 1, obwohl A schon beim Judge war.
|
||||
judge_ask "$JP" "A different system prompt for B." "conversation B, turn 1"
|
||||
judge_ask "$JP" "qwen-judged" "A different system prompt for B." "conversation B, turn 1"
|
||||
[ "$JNAME" = "WORKER" ] && ok "a second conversation starts with the worker" \
|
||||
|| bad "conversation B inherited A's counter: $JNAME"
|
||||
judge_ask "$JP" "A different system prompt for B." "conversation B, turn 2"
|
||||
judge_ask "$JP" "qwen-judged" "A different system prompt for B." "conversation B, turn 2"
|
||||
[ "$JNAME" = "WORKER" ] && ok "the second turn of B is still the worker" \
|
||||
|| bad "conversation B's second turn hit the judge too early"
|
||||
judge_ask "$JP" "A different system prompt for B." "conversation B, turn 3"
|
||||
judge_ask "$JP" "qwen-judged" "A different system prompt for B." "conversation B, turn 3"
|
||||
[ "$JNAME" = "JUDGE" ] && ok "the third turn of B goes to the judge" \
|
||||
|| bad "conversation B's third turn did not reach the judge"
|
||||
|
||||
@@ -128,7 +134,7 @@ CFG
|
||||
./junction --config "$TMP/judge_fb.conf" > "$TMP/judge_fb.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
wait_port "$JP2" 10 || bad "the judge-fallback instance did not come up"
|
||||
judge_ask "$JP2" "$SYS" "fallback turn"
|
||||
judge_ask "$JP2" "qwen-judged" "$SYS" "fallback turn"
|
||||
[ "$JNAME" = "WORKER" ] && ok "a failing judge falls back to the worker" \
|
||||
|| bad "the failed judge did not fall back: '$JNAME'"
|
||||
[ "$JCACHE" = "0" ] && ok "the worker fallback does not receive the judge's cache marker" \
|
||||
@@ -138,6 +144,79 @@ contains "$(cat "$TMP/judge_fb.log")" "upstream_error endpoint=badjudge" \
|
||||
contains "$(cat "$TMP/judge_fb.log")" "served_by endpoint=worker" \
|
||||
"the fallback is visible in the log"
|
||||
|
||||
# Ein Pool als Judge: das erste Mitglied fällt aus, das zweite bedient den Turn.
|
||||
cat > "$TMP/judge_pool.conf" <<CFG
|
||||
listen 127.0.0.1:$JP3
|
||||
queue_timeout 10
|
||||
retry_num 0
|
||||
models allow "vm-pool" "WORKER" "JUDGE" "BADJUDGE"
|
||||
endpoint worker { base http://127.0.0.1:$JW/v1; context 8000; timeout 10 }
|
||||
endpoint judge { base http://127.0.0.1:$JJ/v1; context 12000; timeout 10 }
|
||||
endpoint badjudge { base http://127.0.0.1:$JF/v1; context 12000; timeout 10; cooldown 1 }
|
||||
pool judgepool badjudge as "bad-model", judge as "judge-model"
|
||||
req for "vm-pool" judge every 1 judgepool cache off pass worker as "worker-model"
|
||||
CFG
|
||||
./junction --config "$TMP/judge_pool.conf" > "$TMP/judge_pool.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
wait_port "$JP3" 10 || bad "the judge-pool instance did not come up"
|
||||
judge_ask "$JP3" "vm-pool" "$SYS" "pool judge turn"
|
||||
[ "$JNAME" = "JUDGE" ] && ok "a judge pool falls through to its second member" \
|
||||
|| bad "the judge pool did not reach the second member: '$JNAME'"
|
||||
[ "$JMODEL" = "judge-model" ] && ok "the judge pool member keeps its own model" \
|
||||
|| bad "the pool judge saw model '$JMODEL'"
|
||||
[ "$JCACHE" = "0" ] && ok "cache off sends no marker to the pool judge" \
|
||||
|| bad "the pool judge received cache_control"
|
||||
contains "$(cat "$TMP/judge_pool.log")" "target=judgepool slots=2" \
|
||||
"the judge log names the pool and its slot count"
|
||||
contains "$(cat "$TMP/judge_pool.log")" "failed endpoint=badjudge" \
|
||||
"the first judge pool member's failure is logged"
|
||||
contains "$(cat "$TMP/judge_pool.log")" "served_by endpoint=judge" \
|
||||
"the second judge pool member served the turn"
|
||||
|
||||
# Eine Kette: 3. Call -> DeepSeek-Judge, 5. Call -> Claude-Judge, dann wieder
|
||||
# bei 0. Der 8. Call ist der 3. nach dem Reset, der 10. der 5.
|
||||
cat > "$TMP/judge_chain.conf" <<CFG
|
||||
listen 127.0.0.1:$JP4
|
||||
queue_timeout 10
|
||||
models allow "vm-chain" "WORKER" "JUDGE" "JUDGE2"
|
||||
endpoint worker { base http://127.0.0.1:$JW/v1; context 8000; timeout 10 }
|
||||
endpoint judge { base http://127.0.0.1:$JJ/v1; context 8000; timeout 10 }
|
||||
endpoint judge2 { base http://127.0.0.1:$JJ2/v1; context 8000; timeout 10 }
|
||||
pool judgea judge as "judge-a-model"
|
||||
req for "vm-chain" judge every 3 judgea cache off judge every 5 judge2 as "judge-b-model" cache 1h pass worker as "worker-model"
|
||||
CFG
|
||||
./junction --config "$TMP/judge_chain.conf" > "$TMP/judge_chain.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
wait_port "$JP4" 10 || bad "the judge-chain instance did not come up"
|
||||
CHAIN=("W" "W" "A" "W" "B" "W" "W" "A" "W" "B")
|
||||
for i in 1 2 3 4 5 6 7 8 9 10; do
|
||||
judge_ask "$JP4" "vm-chain" "$SYS" "chain turn $i"
|
||||
want=${CHAIN[$((i-1))]}
|
||||
case "$want" in
|
||||
W) [ "$JNAME" = "WORKER" ] && ok "chain call $i stays on the worker" \
|
||||
|| bad "chain call $i should be the worker, got '$JNAME'" ;;
|
||||
A) [ "$JNAME" = "JUDGE" ] && ok "chain call $i goes to the deepseek judge" \
|
||||
|| bad "chain call $i should be the deepseek judge, got '$JNAME'"
|
||||
[ "$JMODEL" = "judge-a-model" ] && ok "chain call $i uses judge-a model" \
|
||||
|| bad "chain call $i model '$JMODEL'"
|
||||
[ "$JCACHE" = "0" ] && ok "chain call $i sends no marker to deepseek" \
|
||||
|| bad "chain call $i carried cache_control for deepseek" ;;
|
||||
B) [ "$JNAME" = "JUDGE2" ] && ok "chain call $i goes to the claude judge" \
|
||||
|| bad "chain call $i should be the claude judge, got '$JNAME'"
|
||||
[ "$JMODEL" = "judge-b-model" ] && ok "chain call $i uses judge-b model" \
|
||||
|| bad "chain call $i model '$JMODEL'"
|
||||
[ "$JCACHE" = "1" ] && ok "chain call $i carries the claude cache marker" \
|
||||
|| bad "chain call $i had no cache_control for claude" ;;
|
||||
esac
|
||||
done
|
||||
contains "$(grep 'step=0 every=3 target=judgea' "$TMP/judge_chain.log" | head -1)" \
|
||||
"step=0" "the chain log names the deepseek step"
|
||||
contains "$(grep 'step=1 every=5 target=judge2' "$TMP/judge_chain.log" | head -1)" \
|
||||
"step=1" "the chain log names the claude step"
|
||||
CHAIN_A_CALLS=$(grep -c 'target=judgea' "$TMP/judge_chain.log")
|
||||
[ "$CHAIN_A_CALLS" = "2" ] && ok "the chain reset after its last step and started again" \
|
||||
|| bad "the chain did not reset: $CHAIN_A_CALLS deepseek judge calls"
|
||||
|
||||
# Konfigurationsfehler müssen laut sein.
|
||||
printf 'endpoint e {\n base http://127.0.0.1:9995/v1\n}\nreq for "vm" judge every 2 missing as "m" pass e\n' \
|
||||
> "$TMP/judge_bad_endpoint.conf"
|
||||
@@ -153,3 +232,8 @@ printf 'endpoint e {\n base http://127.0.0.1:9995/v1\n}\nreq for "vm" judge ever
|
||||
> "$TMP/judge_no_as.conf"
|
||||
OUT=$(./junction --config "$TMP/judge_no_as.conf" 2>&1)
|
||||
contains "$OUT" "judge needs" "a judge without a model is rejected"
|
||||
|
||||
printf 'endpoint e {\n base http://127.0.0.1:9995/v1\n}\nreq for "vm" judge every 10 e as "m" judge every 5 e as "m" pass e\n' \
|
||||
> "$TMP/judge_order.conf"
|
||||
OUT=$(./junction --config "$TMP/judge_order.conf" 2>&1)
|
||||
contains "$OUT" "judge steps must be ascending" "a descending judge chain is rejected"
|
||||
+4
-1
@@ -23,6 +23,9 @@ trap cleanup EXIT
|
||||
|
||||
ok() { printf ' OK %s\n' "$1"; }
|
||||
bad() { printf ' FAIL %s\n' "$1"; FAILED=1; }
|
||||
# Ältere Abschnitte rufen fail(); ohne diese Funktion blieb ein Fehlschlag
|
||||
# unbemerkt und die Suite meldete PASS.
|
||||
fail() { bad "$1"; }
|
||||
contains() { case "$1" in *"$2"*) ok "$3";; *) bad "$3 (missing '$2')";; esac; }
|
||||
|
||||
# Auf den Listener warten statt zu schlafen. Unter Last (parallel kompiliert, ein
|
||||
@@ -68,7 +71,7 @@ log_has() {
|
||||
# answer requests with somebody else's config), so fail loudly and early.
|
||||
# 8157 gehört auf dieser Maschine dem Hermes-Gateway — der Port wird von keinem
|
||||
# Test benutzt, also darf er die Suite nicht aufhalten.
|
||||
for port in 8361 8362 8363 8364 8357 8358 8359 8360 8355 8356 8347 8348 8349 8350 8351 8352 8353 8354 8345 8346 8335 8336 8337 8338 8339 8340 8341 8342 8375 8376 8377 8378 8385 8386 8387 8388 8389 8395 8396 8397 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8150 8151 8152 8153 8154 8155 8156 8158 8159 8160 8161 8162 8163 8164 8165 8166 8365 8366 8405 8406 8407 8408 8409 8167 8168 8170 8171 8172 8173 8175 8180 8181 8194 8176 8177 8185 8186 8187 8188 8189 8190 9443 9990 9991 9992 9993 9994 9995 9996; do
|
||||
for port in 8361 8362 8363 8364 8357 8358 8359 8360 8355 8356 8347 8348 8349 8350 8351 8352 8353 8354 8345 8346 8335 8336 8337 8338 8339 8340 8341 8342 8375 8376 8377 8378 8385 8386 8387 8388 8389 8395 8396 8397 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8150 8151 8152 8153 8154 8155 8156 8158 8159 8160 8161 8162 8163 8164 8165 8166 8365 8366 8405 8406 8407 8408 8409 8410 8411 8412 8167 8168 8170 8171 8172 8173 8175 8180 8181 8194 8176 8177 8185 8186 8187 8188 8189 8190 9443 9990 9991 9992 9993 9994 9995 9996; do
|
||||
if ss -tln 2>/dev/null | grep -q ":$port "; then
|
||||
echo "port $port is busy — a leftover junction/stub is still running:"
|
||||
ss -tlnp 2>/dev/null | grep ":$port " | sed 's/^/ /'
|
||||
|
||||
Reference in new issue
Block a user