@vibe-lark/larkpal 0.1.65 → 0.1.67

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.
Files changed (2) hide show
  1. package/dist/main.mjs +30 -3
  2. package/package.json +1 -1
package/dist/main.mjs CHANGED
@@ -3774,6 +3774,7 @@ function serializeChatRun(run) {
3774
3774
  lastToolName: run.lastToolName,
3775
3775
  idleSeconds,
3776
3776
  adapterBusy: run.status === "running" ? run.adapterBusy : false,
3777
+ processStatus: run.processStatus,
3777
3778
  staleReason: run.staleReason
3778
3779
  };
3779
3780
  }
@@ -3922,11 +3923,36 @@ async function reconcileRunWithAdapter(run, messageStore, processManager) {
3922
3923
  const processInfo = processManager.getProcessInfo(run.sessionId);
3923
3924
  const adapterBusy = processManager.isSessionBusy?.(run.sessionId) ?? processInfo?.status === "running";
3924
3925
  run.adapterBusy = adapterBusy;
3926
+ run.processStatus = processInfo?.status;
3925
3927
  const idleMs = Date.now() - run.lastEventAt;
3926
3928
  let staleReason;
3927
- if (!adapterBusy) staleReason = processInfo ? `runtime process is ${processInfo.status}` : "runtime adapter reports session is not busy";
3928
- else if (idleMs >= getStaleRunIdleMs()) staleReason = `run idle for ${Math.floor(idleMs / 1e3)}s`;
3929
+ if (!adapterBusy) {
3930
+ if (!processInfo) staleReason = "runtime adapter reports session is not busy";
3931
+ else if (processInfo.status === "stopped" || processInfo.status === "crashed" || processInfo.status === "stopping") staleReason = `runtime process is ${processInfo.status}`;
3932
+ else if (idleMs >= getStaleRunIdleMs()) staleReason = `run idle for ${Math.floor(idleMs / 1e3)}s while runtime process is ${processInfo.status}`;
3933
+ } else if (idleMs >= getStaleRunIdleMs()) staleReason = `run idle for ${Math.floor(idleMs / 1e3)}s`;
3929
3934
  if (!staleReason) return;
3935
+ let cleanupRequired = false;
3936
+ if (!adapterBusy && (processInfo?.status === "running" || processInfo?.status === "starting")) {
3937
+ cleanupRequired = true;
3938
+ try {
3939
+ await processManager.stopProcess(run.sessionId);
3940
+ log$30.warn("[stream] stale run 已触发 runtime process 清理", {
3941
+ sessionId: run.sessionId,
3942
+ runId: run.runId,
3943
+ staleReason,
3944
+ processStatus: processInfo.status
3945
+ });
3946
+ } catch (err) {
3947
+ log$30.error("[stream] stale run 清理 runtime process 失败", {
3948
+ sessionId: run.sessionId,
3949
+ runId: run.runId,
3950
+ staleReason,
3951
+ processStatus: processInfo.status,
3952
+ error: err instanceof Error ? err.message : String(err)
3953
+ });
3954
+ }
3955
+ }
3930
3956
  const error = `Chat run became stale: ${staleReason}`;
3931
3957
  log$30.warn("[stream] activeRun 与 runtime 状态不一致,标记为 stale", {
3932
3958
  sessionId: run.sessionId,
@@ -3934,7 +3960,8 @@ async function reconcileRunWithAdapter(run, messageStore, processManager) {
3934
3960
  staleReason,
3935
3961
  idleMs,
3936
3962
  adapterBusy,
3937
- processStatus: processInfo?.status
3963
+ processStatus: processInfo?.status,
3964
+ cleanupRequired
3938
3965
  });
3939
3966
  if (await markRunTerminal(run, messageStore, "failed", {
3940
3967
  finalStatus: "stale",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-lark/larkpal",
3
- "version": "0.1.65",
3
+ "version": "0.1.67",
4
4
  "description": "LarkPal - Lark/Feishu bot service",
5
5
  "type": "module",
6
6
  "main": "./dist/main.mjs",