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:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user