mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-27 11:22:03 +00:00
fix(photon): intercept console.log so 'stream interrupted' bursts escalate
spectrum-ts routes stream telemetry through @photon-ai/otel's createLogger,
which sends severity>=ERROR to console.error and WARN/INFO to console.log.
The two lines the health monitor keys off land on different channels:
log.error("stream persistently failing") -> console.error (caught), but
log.warn("stream interrupted; reconnecting") -> console.log (was missed).
The original interception patched console.error only, so the recovering->
degraded escalation counter never saw the interrupt bursts that are the
primary silent-inbound symptom. Verified live against spectrum-ts 3.1.0 +
@photon-ai/otel: 3 real log.warn('stream interrupted') calls now escalate
to degraded -> process.exit(75) -> adapter reconnect.
Adds a shared classifyStreamLog() fed by both console.error and console.log,
plus a regression test asserting both channels are intercepted.
This commit is contained in:
parent
b60260c61a
commit
7f1c278db8
2 changed files with 44 additions and 8 deletions
|
|
@ -168,22 +168,41 @@ function markStreamRecovering(reason) {
|
|||
}
|
||||
}
|
||||
|
||||
function classifyStreamLog(text) {
|
||||
if (!text.includes("[spectrum.stream]")) return;
|
||||
const reason = text.split("\n", 1)[0];
|
||||
if (text.includes("persistently failing")) {
|
||||
markStreamDegraded(reason);
|
||||
} else if (text.includes("stream interrupted")) {
|
||||
markStreamRecovering(reason);
|
||||
}
|
||||
}
|
||||
|
||||
// spectrum-ts routes its stream telemetry through @photon-ai/otel's
|
||||
// createLogger, which sends severity >= ERROR to console.error and
|
||||
// everything else (WARN/INFO) to console.log. The two lines we key off
|
||||
// land on *different* channels: `log.error("stream persistently failing")`
|
||||
// -> console.error, but `log.warn("stream interrupted; reconnecting")`
|
||||
// -> console.log. Patch both so the recovering/degraded counters see the
|
||||
// interrupt bursts, not just the terminal "persistently failing" line.
|
||||
const originalConsoleError = console.error.bind(console);
|
||||
console.error = (...args) => {
|
||||
const text = args
|
||||
.map((arg) => (arg && arg.stack ? arg.stack : String(arg)))
|
||||
.join(" ");
|
||||
if (text.includes("[spectrum.stream]")) {
|
||||
const reason = text.split("\n", 1)[0];
|
||||
if (text.includes("persistently failing")) {
|
||||
markStreamDegraded(reason);
|
||||
} else if (text.includes("stream interrupted")) {
|
||||
markStreamRecovering(reason);
|
||||
}
|
||||
}
|
||||
classifyStreamLog(text);
|
||||
originalConsoleError(...args);
|
||||
};
|
||||
|
||||
const originalConsoleLog = console.log.bind(console);
|
||||
console.log = (...args) => {
|
||||
const text = args
|
||||
.map((arg) => (arg && arg.stack ? arg.stack : String(arg)))
|
||||
.join(" ");
|
||||
classifyStreamLog(text);
|
||||
originalConsoleLog(...args);
|
||||
};
|
||||
|
||||
if (!projectId || !projectSecret || !sharedToken) {
|
||||
console.error(
|
||||
"photon-sidecar: PHOTON_PROJECT_ID, PHOTON_PROJECT_SECRET and " +
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue