Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix: make sure the context key is always recovered
Gus21e22adc867f
diff --git a/src/cli/daemon/execenv/__tests__/timeline.test.ts b/src/cli/daemon/execenv/__tests__/timeline.test.tsindex 26945dbc6..f761b26e8 100644--- a/src/cli/daemon/execenv/__tests__/timeline.test.ts+++ b/src/cli/daemon/execenv/__tests__/timeline.test.ts@@ -312,27 +312,43 @@ describe("timeline", () => {expect(findResumableSessionId(dir, "user_dm_message", "claude")).toBeNull();});- it("skips failed/running entries and finds the correct completed one", () => {+ it("skips running entries but resumes from failed/killed/completed", () => {+ const threeMinAgo = new Date(Date.now() - 3 * 60 * 1000);+ const twoMinAgo = new Date(Date.now() - 2 * 60 * 1000);+ const oneMinAgo = new Date(Date.now() - 1 * 60 * 1000);+writeEntry(_todayFilename(), makeEntry({task_id: "t_completed",status: "completed",- session_id: "sess_good",- datetime: new Date().toISOString(),+ session_id: "sess_completed",+ datetime: threeMinAgo.toISOString(),}));writeEntry(_todayFilename(), makeEntry({task_id: "t_running",status: "running",session_id: null,- datetime: new Date().toISOString(),+ datetime: oneMinAgo.toISOString(),}));writeEntry(_todayFilename(), makeEntry({task_id: "t_failed",status: "failed",- session_id: "sess_bad",+ session_id: "sess_failed",+ datetime: twoMinAgo.toISOString(),+ }));++ // Most recent non-running entry with a session_id wins (failed, 2min ago)+ expect(findResumableSessionId(dir, "user_dm_message", "claude")).toBe("sess_failed");+ });++ it("resumes from killed sessions", () => {+ writeEntry(_todayFilename(), makeEntry({+ task_id: "t_killed",+ status: "killed",+ session_id: "sess_killed",datetime: new Date().toISOString(),}));- expect(findResumableSessionId(dir, "user_dm_message", "claude")).toBe("sess_good");+ expect(findResumableSessionId(dir, "user_dm_message", "claude")).toBe("sess_killed");});it("searches across midnight boundary (yesterday's file)", () => {diff --git a/src/cli/daemon/execenv/context.ts b/src/cli/daemon/execenv/context.tsindex 4aedc0351..b10614c45 100644--- a/src/cli/daemon/execenv/context.ts+++ b/src/cli/daemon/execenv/context.ts@@ -39,6 +39,7 @@ Your current context is only a fraction of the full timeline of what's your haveThe full context timeline is inside './.context_timeline/YYYY-MM-DD.jsonl'.Each line of a timeline JSONL is a JSON object with these fields:- "task_id" — unique task identifier+- "context_key" — thread identifier, the same context key meaning those tasks are in the same thread.- "session_id" — agent session identifier (null until completion)- "pid" — daemon process ID (present while running, null when done)- "status" — "running", "completed", or "failed"@@ -47,6 +48,7 @@ Each line of a timeline JSONL is a JSON object with these fields:- "prompt" — what the user asked- "agent_responses" — assistant text outputs during execution- "errmsg" — error message (null unless status is "failed")+- "detailed_log" — the running log for this task, including the actually task agent messages with tool-calls and failed logs.those json are sorted by datetime in asc order.## BE HUMANdiff --git a/src/cli/daemon/execenv/timeline.ts b/src/cli/daemon/execenv/timeline.tsindex dbe812deb..cc64c660c 100644--- a/src/cli/daemon/execenv/timeline.ts+++ b/src/cli/daemon/execenv/timeline.ts@@ -233,12 +233,11 @@ export function findResumableSessionId(entries.push(...readJsonl(join(timelineDir, filename)));}- // Sort by datetime descending, pick the first completed matchentries.sort((a, b) => new Date(b.datetime).getTime() - new Date(a.datetime).getTime());for (const entry of entries) {if (- entry.status === "completed" &&+ entry.status !== "running" &&entry.type === type &&entry.provider === provider &&entry.session_id &&@@ -271,7 +270,7 @@ export function findResumableSessionByContextKey(entries.sort((a, b) => new Date(b.datetime).getTime() - new Date(a.datetime).getTime());for (const entry of entries) {if (- entry.status === "completed" &&+ entry.status !== "running" &&entry.context_key === contextKey &&entry.provider === provider &&entry.session_id &&