@adhdev/daemon-standalone 0.9.82-rc.387 → 0.9.82-rc.389

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-standalone",
3
- "version": "0.9.82-rc.387",
3
+ "version": "0.9.82-rc.389",
4
4
  "description": "ADHDev standalone daemon — embedded HTTP/WS server for local dashboard",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -3901,6 +3901,14 @@ async function meshReviewInbox(ctx, args = {}) {
3901
3901
  }
3902
3902
 
3903
3903
  // src/tools/mesh-tools-session.ts
3904
+ function computeIdleDispatchAckRisk(sessionWasIdle, dispatchPreRecorded, sessionId) {
3905
+ if (!sessionWasIdle || dispatchPreRecorded) return {};
3906
+ return {
3907
+ dispatchAcknowledgementRisk: true,
3908
+ dispatchAcknowledgementRiskReason: "idle_dispatch_prerecord_failed",
3909
+ dispatchAcknowledgementNote: `Session '${sessionId}' was idle at dispatch time and the dispatch row could not be pre-recorded, so its completion may be deduplicated as a prior turn and lost. Use mesh_status to verify; if the session remains idle or the completion never lands, launch a fresh session and retry.`
3910
+ };
3911
+ }
3904
3912
  async function meshPruneStaleDirect(ctx, args = {}) {
3905
3913
  await refreshMeshFromDaemon(ctx);
3906
3914
  const execute = args.execute === true && args.dry_run !== true;
@@ -4218,33 +4226,6 @@ async function meshSendTask(ctx, args) {
4218
4226
  const taskId = (0, import_node_crypto.randomUUID)();
4219
4227
  const dispatchedAt = (/* @__PURE__ */ new Date()).toISOString();
4220
4228
  const coordinatorDaemonId = resolveCoordinatorDaemonId(ctx);
4221
- const dispatchResult = await commandForNode(ctx, node, "agent_command", {
4222
- targetSessionId: args.session_id,
4223
- agentType: resolvedProviderType,
4224
- cliType: resolvedProviderType,
4225
- providerType: resolvedProviderType,
4226
- action: "send_chat",
4227
- message: args.message,
4228
- meshContext: {
4229
- meshId: ctx.mesh.id,
4230
- nodeId: args.node_id,
4231
- taskId,
4232
- ...coordinatorDaemonId ? { coordinatorDaemonId } : {},
4233
- // (3) Originating coordinator session anchor — see the remote-dispatch path above.
4234
- ...ctx.coordinatorSessionId ? { coordinatorSessionId: ctx.coordinatorSessionId } : {}
4235
- }
4236
- });
4237
- const dispatchPayload = unwrapCommandPayload(dispatchResult);
4238
- if (dispatchPayload?.success === false || dispatchResult?.success === false) {
4239
- const source = dispatchPayload?.success === false ? dispatchPayload : dispatchResult;
4240
- return JSON.stringify({
4241
- ...source && typeof source === "object" ? source : {},
4242
- success: false,
4243
- nodeId: args.node_id,
4244
- sessionId: args.session_id,
4245
- error: dispatchPayload?.error || dispatchResult?.error || "agent_command rejected the task"
4246
- });
4247
- }
4248
4229
  try {
4249
4230
  (0, import_daemon_core3.appendLedgerEntry)(ctx.mesh.id, {
4250
4231
  kind: "task_dispatched",
@@ -4272,6 +4253,43 @@ async function meshSendTask(ctx, args) {
4272
4253
  dispatchedToIdleSession: sessionWasIdle,
4273
4254
  dispatchedAt
4274
4255
  });
4256
+ let dispatchPreRecorded = false;
4257
+ try {
4258
+ dispatchPreRecorded = (0, import_daemon_core3.getActiveDirectDispatches)(ctx.mesh.id).some((d) => d.taskId === taskId);
4259
+ } catch {
4260
+ }
4261
+ const dispatchResult = await commandForNode(ctx, node, "agent_command", {
4262
+ targetSessionId: args.session_id,
4263
+ agentType: resolvedProviderType,
4264
+ cliType: resolvedProviderType,
4265
+ providerType: resolvedProviderType,
4266
+ action: "send_chat",
4267
+ message: args.message,
4268
+ meshContext: {
4269
+ meshId: ctx.mesh.id,
4270
+ nodeId: args.node_id,
4271
+ taskId,
4272
+ ...coordinatorDaemonId ? { coordinatorDaemonId } : {},
4273
+ // (3) Originating coordinator session anchor — see the remote-dispatch path above.
4274
+ ...ctx.coordinatorSessionId ? { coordinatorSessionId: ctx.coordinatorSessionId } : {}
4275
+ }
4276
+ });
4277
+ const dispatchPayload = unwrapCommandPayload(dispatchResult);
4278
+ if (dispatchPayload?.success === false || dispatchResult?.success === false) {
4279
+ try {
4280
+ (0, import_daemon_core3.deleteDirectDispatchesByTaskId)(ctx.mesh.id, [taskId]);
4281
+ } catch {
4282
+ }
4283
+ dispatchPreRecorded = false;
4284
+ const source = dispatchPayload?.success === false ? dispatchPayload : dispatchResult;
4285
+ return JSON.stringify({
4286
+ ...source && typeof source === "object" ? source : {},
4287
+ success: false,
4288
+ nodeId: args.node_id,
4289
+ sessionId: args.session_id,
4290
+ error: dispatchPayload?.error || dispatchResult?.error || "agent_command rejected the task"
4291
+ });
4292
+ }
4275
4293
  if (missionId) {
4276
4294
  try {
4277
4295
  (0, import_daemon_core3.recordDirectDispatchTask)(ctx.mesh.id, args.message, {
@@ -4312,11 +4330,10 @@ async function meshSendTask(ctx, args) {
4312
4330
  providerType: resolvedProviderType,
4313
4331
  nodeId: args.node_id,
4314
4332
  sessionId: args.session_id,
4315
- ...sessionWasIdle ? {
4316
- dispatchAcknowledgementRisk: true,
4317
- dispatchAcknowledgementRiskReason: "session_was_idle_at_dispatch",
4318
- dispatchAcknowledgementNote: `Session '${args.session_id}' was idle at dispatch time. If it does not transition to generating, this direct task was not acknowledged. Use mesh_status to verify; if the session remains idle, it may appear as stale direct work \u2014 launch a fresh session and retry.`
4319
- } : {}
4333
+ // DISPATCH-ACK-RISK-STALE: only warn on a GENUINE residual loss risk — an idle
4334
+ // session whose dispatch row did NOT survive pre-record. A successfully
4335
+ // pre-recorded idle dispatch (the NOTIF-DROP / CANON-A path) is not at risk.
4336
+ ...computeIdleDispatchAckRisk(sessionWasIdle, dispatchPreRecorded, args.session_id)
4320
4337
  });
4321
4338
  }
4322
4339
  const task = (0, import_daemon_core3.enqueueTask)(ctx.mesh.id, args.message, {