Ask about a run from the row it is on, and stop spending context on health checks when the run was clean

This commit is contained in:
Gmer4Lfe
2026-08-06 21:51:55 -04:00
parent 4347fc5f07
commit f2d0e18f2c
5 changed files with 105 additions and 19 deletions
+35 -16
View File
@@ -265,14 +265,40 @@ $runOutcome = $namedTarget !== ''
. 'last night|duration|how long|rundown|summar\w*|recap|status|results?|outcome)\b/i',
$question);
// Permission first, need second: the capability decides whether live state may be attached at
// all, and only then does the phrasing decide whether this particular question warrants it.
// troubleshoot needs no phrasing test — the operator opened a log to get there.
$diagnostic = $can('health') && ($profile === 'troubleshoot' || $runOutcome || (bool)preg_match(
// The target and its run record are resolved before the diagnostic decision rather than after,
// because whether the run failed is the single most useful input to that decision and it costs
// one small JSON read to know it.
$runTarget = ($can('scoped_log') && $scope !== '') ? $scope : '';
if ($runTarget === '' && $runOutcome) $runTarget = $namedTarget;
$rec = ($runTarget !== '' && vv_ai_scope_ok($runTarget))
? vv_ai_run_record($runTarget)
: ['ok' => false];
// A run that ended, reported ok and exited zero. Anything else — a bad exit, a missing end time,
// no record at all — is not clean and is treated as worth investigating.
$runClean = $rec['ok'] && $rec['status'] === 'ok' && $rec['exit'] === 0 && $rec['end'] !== null;
$kwDiagnostic = (bool)preg_match(
'/\b(why|fail(ed|ing|ure)?|error|broken?|not work|isn.t work|wrong|stuck|hang|'
. 'never runs?|didn.t|won.t|debug|troubleshoot|diagnos)/i',
$question
));
);
// Permission first, need second: the capability decides whether live state may be attached at
// all, and only then does the phrasing decide whether this particular question warrants it.
// troubleshoot needs no phrasing test — the operator opened a log to get there.
//
// A run-outcome question earns live state only when the run was not clean. "How did the daily
// orch go" about a run that exited 0 was pulling in a fleet-wide health sweep and forty recent
// warning lines to answer a question the run record and the log tail already answer completely —
// roughly two thousand tokens taken from the passages to say nothing. When the run did fail, all
// of that is exactly what explains why, so it stays.
$diagnostic = $can('health') && (
$profile === 'troubleshoot'
|| $kwDiagnostic
|| ($runOutcome && !$runClean)
);
$diagBlock = '';
if ($diagnostic) {
@@ -301,19 +327,12 @@ if ($diagnostic) {
// The troubleshooting profile gets the actual tail of the one log the operator is looking at,
// warnings and ordinary lines alike. The fleet-wide WARN/ERROR sweep above cannot answer "why
// did this one stop" — the last line a script printed before dying is usually not labelled.
// The target is whatever the operator has open, and failing that whatever they named in the
// question. The second half is what makes a run-outcome question work from any view: asking how
// the daily orchestrator went while looking at the suggestions list is the ordinary case, not an
// edge one, and requiring them to open the log first is asking them to do the lookup themselves.
$runTarget = ($can('scoped_log') && $scope !== '') ? $scope : '';
if ($runTarget === '' && $runOutcome) $runTarget = $namedTarget;
// $runTarget and $rec were resolved above, where the diagnostic decision needed them. The record
// is emitted before the tail because it states the outcome where the tail only implies it: a log
// ending on a tidy summary block looks identical whether the script exited 0 or was killed on the
// next line, and the difference is the whole answer.
$scopedLog = null;
if ($runTarget !== '' && vv_ai_scope_ok($runTarget)) {
// The record first: it states the outcome, where the tail only implies it. A log that ends
// on a tidy summary block looks identical whether the script exited 0 or was killed on the
// next line, and the difference is the whole answer.
$rec = vv_ai_run_record($runTarget);
if ($rec['ok']) {
$attached['run_record'] = $rec['status'] . ', exit ' . var_export($rec['exit'], true);
$diagBlock .= 'RUN RECORD for ' . $runTarget . " (authoritative — how the last run ended)\n"
@@ -41,6 +41,14 @@ how long did the daily orch take | varaverk | | | run=yes has=run_record
# Works from the AI tab, which sends no scope at all — resolution is from the question, not the page.
how did the daily orch go last run | varaverk | | | target=Orchestrators/daily_sync_maintenance has=run_record
# ── A clean run earns the record and the log, and nothing else ─────────────────────────────────
# The health sweep and the recent-warning lines are ~660 tokens that answer nothing when the run
# exited 0, taken straight out of the passages' budget. They come back the moment it did not.
lets check the daily orch logs and see how it went | varaverk | Scheduler | | diag=no hasnt=health,warnings has=run_record,log_tail
how did the daily orch go | varaverk | | | diag=no hasnt=health,warnings
why did the daily orch fail | varaverk | | | diag=yes has=health,warnings,log_tail
why did the weekly orch fail | varaverk | | | diag=yes has=health,warnings
# ── Definitional questions must NOT be answered with last night's log ──────────────────────────
what does the daily orchestrator do | varaverk | | | target=Orchestrators/daily_sync_maintenance run=no hasnt=run_record,log_tail
how does the daily orch work | varaverk | | | run=no hasnt=run_record,log_tail
@@ -51,6 +59,15 @@ what is the daily orchestrator | varaverk | | | run=no hasnt=run_record
# about, which is indistinguishable from a right answer unless you already knew.
how did sync go | varaverk | | | target=none run=no
what does RSYNC_ENABLED do | varaverk | | | target=none run=no has=conf_keys
# Whole words only. "fail" contains "ai", and ai.log is a real log id — a substring match here
# attached the AI's own log to questions about everything else.
why did this run fail | varaverk | | | target=none
is the mail relay working again | varaverk | | | target=none
# ── The Recent Activity buttons: one click from a row to an answer about that run ──────────────
# Both open the log first, so the dock is scoped to troubleshoot against that script's log id.
Why did this run fail? | troubleshoot | Orchestrators/daily_sync_maintenance | | diag=yes has=log_tail,run_record
How did this run go? | troubleshoot | Orchestrators/weekly_sync_maintenance | | has=log_tail,run_record
# ── General Chat holds nothing, and hands Varaverk questions up rather than deferring ──────────
how was your day | chat | | | profile=chat caps=none hasnt=health,log_tail,incidents,conf_keys