Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: CoS PRs use commit subject as title and drop duplicate Summary heading
[._.]/ Adam Eivy1c98262f3ff6
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 3d565e6d76..8d144a81c2 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -453,6 +453,26 @@## Fixed+- **CoS-spawned PRs — concise title + no double "Summary" heading.** Two+ related bugs in the PR-creation path:+ - The PR title was the raw user task description (e.g. "on the+ settings/backup page, we should have a button to run the backup. Also,+ we should show default…"), truncated at 100 chars. New helper+ `git.suggestPRTitle()` picks the oldest commit subject on the branch as+ the title (the agent already wrote a conventional `feat:`/`fix:` commit+ message that summarizes the change far better than the prompt), falling+ back to the description's first line when no commits are found. Used in+ both the worktree-PR path and the JIRA-ticket PR path (where the+ `${jiraTicketId}: ` prefix is preserved).+ - The PR body rendered "Summary" twice — `generatePRDescription` wraps the+ extracted agent summary in `## Summary`, but agents often write their own+ `## Summary` heading at the top of their final message. `extractAgentSummary`+ now strips a leading `Summary` / `## Summary` / `Summary:` heading before+ returning, so the wrapping section is the only one in the rendered PR.+ - Tests: 2 new `extractAgentSummary` cases for the heading-strip behavior;+ `cleanupAgentWorktree.test.js` mock updated to stub `suggestPRTitle`.+ Full server suite (4,549 tests) green.+- **CoS orphan handler — no more duplicate `[Auto-Fix]` investigation tasks.**When `cleanupOrphanedAgents` swept up two stale "running" agents that shared ataskId, `handleOrphanedTask` ran once per agent. The first call blocked thediff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.jsindex 718fb2af83..489b6377d2 100644--- a/server/services/agentLifecycle.js+++ b/server/services/agentLifecycle.js@@ -1048,8 +1048,11 @@ export async function handleAgentCompletion(agentId, exitCode, success, durationconst jiraPrBody = await git.generatePRDescription(workspace, targetBranch, jiraBranch, outputBuffer);const jiraPrBodyWithRef = `Resolves ${jiraTicketRef}\n\n${jiraPrBody}`;+ const baseTitle = await git.suggestPRTitle(workspace, targetBranch, jiraBranch, task.description);+ const jiraPrTitle = `${jiraTicketId}: ${baseTitle}`.substring(0, 100);+const prResult = await git.createPR(workspace, {- title: `${jiraTicketId}: ${(task.description || 'CoS automated task').substring(0, 100)}`,+ title: jiraPrTitle,body: jiraPrBodyWithRef,base: targetBranch,head: jiraBranch@@ -1217,9 +1220,7 @@ export async function cleanupAgentWorktree(agentId, success, { openPR = false, rif (!targetBranch) {targetBranch = await git.getDefaultBranch(sourceWorkspace, { allowRemote: false }).catch(() => null) || 'main';}- const taskDesc = description || 'CoS automated task';- const firstLine = taskDesc.split(/[\r\n]/).find(l => l.trim()) || taskDesc;- const prTitle = firstLine.trim().substring(0, 100) || 'CoS automated task';+ const prTitle = await git.suggestPRTitle(worktreePath, targetBranch, worktreeBranch, description);const prBody = await git.generatePRDescription(worktreePath, targetBranch, worktreeBranch, agentOutput);diff --git a/server/services/cleanupAgentWorktree.test.js b/server/services/cleanupAgentWorktree.test.jsindex 3fa2718d27..2290ef6658 100644--- a/server/services/cleanupAgentWorktree.test.js+++ b/server/services/cleanupAgentWorktree.test.js@@ -159,6 +159,7 @@ vi.mock('./git.js', () => ({getDefaultBranch: vi.fn().mockResolvedValue('main'),createPR: vi.fn(),generatePRDescription: vi.fn(),+ suggestPRTitle: vi.fn(),deleteBranch: vi.fn().mockResolvedValue(undefined),requestCopilotReview: vi.fn().mockResolvedValue({ success: true }),resolveForgeForRepo: vi.fn().mockResolvedValue({ cli: 'gh', env: process.env, host: 'github.com', owner: null, account: null }),@@ -207,6 +208,11 @@ describe('cleanupAgentWorktree - openPR path', () => {git.generatePRDescription.mockImplementation(() =>Promise.resolve('Automated PR created by PortOS Chief of Staff.\n\n## Summary\n\nImplemented the requested feature with new API endpoints and UI components.'));+ // suggestPRTitle echoes the fallback (task description) by default; specific+ // tests can override to simulate a real commit-derived title.+ git.suggestPRTitle.mockImplementation((_dir, _base, _head, fallback) =>+ Promise.resolve((fallback || 'CoS automated task').split(/[\r\n]/)[0].trim().substring(0, 100) || 'CoS automated task')+ );});it('should run PR flow when openPR is true and success is true', async () => {diff --git a/server/services/git.js b/server/services/git.jsindex c3275a1345..663b69b60d 100644--- a/server/services/git.js+++ b/server/services/git.js@@ -635,6 +635,37 @@ export async function generatePRDescription(dir, baseBranch, headBranch, agentOureturn 'Automated PR created by PortOS Chief of Staff.';}+/**+ * Suggest a concise PR title from the branch's commits, falling back to a+ * provided text (typically the task description).+ *+ * The CoS task description is often verbose user prose (e.g. "on the+ * settings/backup page, we should have a button to run the backup. Also, we+ * should show default exclusions"). Commit subjects on the branch are far+ * better titles because the agent wrote them as conventional-commit summaries+ * of the actual change.+ *+ * Picks the OLDEST commit on the branch when present — for multi-commit+ * branches that include follow-ups like "address review:" or "/simplify"+ * cleanups, the first commit is usually the main feature/fix.+ *+ * @param {string} dir - Working directory (repo root or worktree)+ * @param {string} baseBranch - Base branch the PR will target+ * @param {string} headBranch - Branch the PR will be opened from+ * @param {string} fallbackText - Used when no commits are found+ * @returns {Promise<string>} PR title (<= 100 chars)+ */+export async function suggestPRTitle(dir, baseBranch, headBranch, fallbackText) {+ const comparison = await getBranchComparison(dir, baseBranch, headBranch).catch(() => null);+ if (comparison?.commits?.length) {+ const oldest = comparison.commits[comparison.commits.length - 1];+ const subject = oldest?.message?.trim();+ if (subject) return subject.substring(0, 100);+ }+ const firstLine = (fallbackText || '').split(/[\r\n]/).find(l => l.trim()) || '';+ return firstLine.trim().substring(0, 100) || 'CoS automated task';+}+/*** Extract a meaningful implementation summary from raw agent output.* Agents typically end their output with a summary of what was implemented.@@ -670,6 +701,15 @@ export function extractAgentSummary(output) {while (summaryLines.length && !summaryLines[0].trim()) summaryLines.shift();while (summaryLines.length && !summaryLines[summaryLines.length - 1].trim()) summaryLines.pop();+ // Strip a leading "Summary" heading the agent may have written itself+ // (e.g. "## Summary", "# Summary", "Summary:"). Without this, the PR body+ // ends up with two stacked "Summary" headings — generatePRDescription wraps+ // the extracted text in its own "## Summary" section.+ while (summaryLines.length && /^\s*(#{1,6}\s*)?summary\s*:?\s*$/i.test(summaryLines[0])) {+ summaryLines.shift();+ while (summaryLines.length && !summaryLines[0].trim()) summaryLines.shift();+ }+const summary = summaryLines.join('\n').trim();// Must have meaningful content (at least a sentence)diff --git a/server/services/git.test.js b/server/services/git.test.jsindex f771844a23..83a3859188 100644--- a/server/services/git.test.js+++ b/server/services/git.test.js@@ -232,5 +232,36 @@ describe('extractAgentSummary', () => {expect(summary).toContain('All tests pass');expect(summary).not.toContain('🔧');});++ it('strips leading "## Summary" heading so the PR body does not double it up', () => {+ const output = [+ '🔧 Using Edit tool',+ ' → /path/to/file.js',+ '',+ '## Summary',+ '',+ 'Added a Run Backup Now button and default-exclusions display.',+ 'All tests pass.'+ ].join('\n');++ const summary = extractAgentSummary(output);+ expect(summary).not.toMatch(/^#{1,6}?\s*summary/i);+ expect(summary?.split('\n')[0]).toContain('Added a Run Backup Now button');+ });++ it('strips leading "Summary:" (no markdown prefix) too', () => {+ const output = [+ '🔧 Using Edit tool',+ ' → /path/to/file.js',+ '',+ 'Summary:',+ '',+ 'Added a Run Backup Now button and default-exclusions display.',+ 'All tests pass.'+ ].join('\n');++ const summary = extractAgentSummary(output);+ expect(summary?.split('\n')[0]).toContain('Added a Run Backup Now button');+ });});