@tomflow/chatloop-tools 0.9.49 → 0.9.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.mjs CHANGED
@@ -13,6 +13,7 @@ import {createCliCommandRouter} from './lib/cli-command-router.mjs';
13
13
  let auditPort=null;
14
14
  const auditBacklog=[];
15
15
  let auditDraining=false,auditRetryTimer=null,auditNoOwnerRetries=0,auditLost=0;
16
+ let auditLastLossCode=null,mcpAudit=null;
16
17
  let formObservationLost=0,documentObservationLost=0;
17
18
  const OBSERVER_UUID=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
18
19
  const localError=code=>Object.assign(Error(code),{code});
@@ -34,6 +35,8 @@ async function drainAudit(){
34
35
  auditNoOwnerRetries++<MAX_NO_OWNER_RETRIES)break;
35
36
  auditBacklog.shift(); // unknown telemetry is dropped, not retried
36
37
  auditLost++;
38
+ auditLastLossCode=/^[A-Z][A-Z0-9_]{1,95}$/.test(error?.code||'')?error.code:
39
+ 'TRACE_AUDIT_SINK_FAILED';
37
40
  auditNoOwnerRetries=0;
38
41
  }
39
42
  }
@@ -49,7 +52,9 @@ async function drainAudit(){
49
52
  }
50
53
  }
51
54
  const recordApi=event=>{
52
- if(auditBacklog.length>=MAX_AUDIT_BACKLOG){auditLost++;return;}
55
+ if(auditBacklog.length>=MAX_AUDIT_BACKLOG){
56
+ auditLost++;auditLastLossCode='TRACE_AUDIT_BACKLOG_OVERFLOW';return;
57
+ }
53
58
  auditBacklog.push(event);
54
59
  if(auditPort){
55
60
  if(auditRetryTimer){clearTimeout(auditRetryTimer);auditRetryTimer=null;}
@@ -61,12 +66,15 @@ const apiAspect=createApiAspect('@tomflow/chatloop-tools',{sink:recordApi});
61
66
  // is delivered. Drain only *after* that reply; never delay an API or replay it.
62
67
  async function drainCliTelemetry(timeoutMs=300){
63
68
  const deadline=Date.now()+Math.max(0,Math.min(timeoutMs,750));
64
- const aspectFlushed=await apiAspect.drain(Math.max(0,deadline-Date.now()));
69
+ // The MCP AOP's separate queue must also drain before EOF exits.
70
+ const budget=Math.max(0,deadline-Date.now());
71
+ const [aspectFlushed,mcpFlushed]=await Promise.all([apiAspect.drain(budget),
72
+ mcpAudit?.drain(budget)??Promise.resolve(true)]);
65
73
  while(auditBacklog.length||auditDraining){
66
74
  if(Date.now()>=deadline)return false;
67
75
  await new Promise(resolve=>setTimeout(resolve,Math.min(10,deadline-Date.now())));
68
76
  }
69
- return aspectFlushed&&auditLost===0;
77
+ return aspectFlushed&&mcpFlushed&&auditLost===0;
70
78
  }
71
79
  const INTERNAL_DRAIN=Symbol.for('chat-loop.telemetry.drain.internal');
72
80
  // The CLI and Supervisor executable import only this package root.
@@ -179,7 +187,8 @@ async function runtime(){
179
187
  const health={...result.traceHealth,
180
188
  writerStatus:result.traceHealth.status,
181
189
  formObservationLost,documentObservationLost,
182
- apiObservationLost:auditLost};
190
+ apiObservationLost:auditLost,
191
+ ...(auditLost?{apiObservationLastErrorCode:auditLastLossCode}:{})};
183
192
  if((formObservationLost>0||documentObservationLost>0||auditLost>0)
184
193
  &&health.status==='OK')health.status='TRACE_DEGRADED';
185
194
  return {...result,traceHealth:health};
@@ -244,14 +253,17 @@ async function runtime(){
244
253
  phase:event.phase,
245
254
  ...(event.durationMs!==null?{durationMs:event.durationMs}:{}),
246
255
  ...(event.errorCode?{errorCode:event.errorCode}:{})
247
- },900).then(reply=>{
248
- if(reply?.status!=='OK')throw Object.assign(Error('TRACE_RECORD_FAILED'),
249
- {code:'TRACE_RECORD_FAILED'});
256
+ },3000).then(reply=>{
257
+ // A transport ACK is not proof that the Writer persisted this span.
258
+ if(reply?.status!=='OK'||!OBSERVER_UUID.test(reply.eventId||'')){
259
+ const code=/^[A-Z][A-Z0-9_]{1,95}$/.test(reply?.error?.code||'')
260
+ ?reply.error.code:'TRACE_RECORD_FAILED';
261
+ throw localError(code);
262
+ }
250
263
  return reply;
251
264
  });
252
265
  void drainAudit();
253
- const mcpAudit=createApiAspect('@tomflow/chatloop-tools',
254
- {sink:recordApi});
266
+ mcpAudit=createApiAspect('@tomflow/chatloop-tools',{sink:recordApi});
255
267
  // Only declared providers may create a per-tool observation wrapper.
256
268
  // Unknown tool names must not grow a process-lifetime cache.
257
269
  const declaredToolNames=new Set(providerDefinitions.flatMap(p=>p.names));
package/lib/control.mjs CHANGED
@@ -100,7 +100,10 @@ const verifiedBusinessReply=(reply,request)=>{
100
100
  return reply;
101
101
  };
102
102
  export async function talk(request,timeout=12000){
103
- const hello=await send({action:'__ping'},1200);
103
+ // The owner handshake is still required for every IPC call. Only skip the
104
+ // unrelated Writer health snapshot: telemetry calls already have their own
105
+ // persisted receipt and health is queried explicitly via __trace_health.
106
+ const hello=await send({action:'__ping',omitTraceHealth:true},1200);
104
107
  if(hello.contract!==CONTRACT||hello.version!==VERSION||hello.packageVersion!==PACKAGE_VERSION||
105
108
  hello.registrySignature!==registry().map(t=>t.id+':'+t.enabled).join('|'))
106
109
  throw Object.assign(new Error('Version or registry mismatch'),{code:'INCOMPATIBLE_VERSION'});
@@ -293,7 +293,8 @@ async function main(){
293
293
  let work;
294
294
  try{work=req?.action==='__ping'?
295
295
  Promise.resolve({contract:CONTRACT,version:VERSION,packageVersion:PACKAGE_VERSION,registrySignature:catalog.map(t=>t.id+':'+t.enabled).join('|'),ownerNonce:nonce,
296
- managerPid:process.pid,traceHealth:traceHealth()}):req?.action==='__trace_health'
296
+ managerPid:process.pid,
297
+ ...(req.omitTraceHealth===true?{}:{traceHealth:traceHealth()})}):req?.action==='__trace_health'
297
298
  ?Promise.resolve(req.contract===CONTRACT
298
299
  &&REQUEST_ID.test(req.requestId||'')
299
300
  ?{contract:CONTRACT,requestId:req.requestId,
@@ -220,8 +220,11 @@ export async function runTraceDiagnose(args){
220
220
  globalWarnings.push('FORM_TRACE_OBSERVATION_LOSS');
221
221
  if(health?.documentObservationLost>0)
222
222
  globalWarnings.push('DOCUMENT_TRACE_OBSERVATION_LOSS');
223
- if(health?.apiObservationLost>0)
223
+ if(health?.apiObservationLost>0){
224
224
  globalWarnings.push('MCP_API_TRACE_OBSERVATION_LOSS');
225
+ result.globalApiObservationLoss={count:health.apiObservationLost,
226
+ lastErrorCode:health.apiObservationLastErrorCode||'UNVERIFIED'};
227
+ }
225
228
  if(globalWarnings.length)result.globalObservationWarnings=globalWarnings;
226
229
  if(result.writerHealth==='TRACE_DEGRADED'){
227
230
  result.gaps.push(health?.errorCode
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.9.49",
6
+ "version": "0.9.51",
7
7
  "type": "module",
8
8
  "description": "Chat Loop local tools: MCP gateway, isolated bundled tunnel-client and unified CLI",
9
9
  "bin": {