Skip to content

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

fix app-manager Git tab counting worktree-locked merged branches as deletable

[._.]/ Adam Eivy464cec73eedd
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index a33b90617b..972fbe5549 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -100,3 +100,4 @@
- **[issue-2535] Paginate the creative-catalog + media list endpoints with the shared `paginateArray` helper.** The primary index `GET`s for creativeDirector (`/`), storyBuilder (`/`), universeBuilder (`/`), moodBoard (`/`), videoTimeline (`/projects`), and loras (`/`) returned unbounded arrays. Each now opts into pagination the moment a client sends `limit`/`offset`, mirroring the `brainCrud` precedent: `isPaginationRequested(req.query)` gates a bounded `{ items, total, limit, offset }` envelope (via the existing `paginateArray` in `server/lib/validation.js`, `defaultLimit: 50`, `maxLimit: 500`), while a request with no pagination params still returns the full array byte-for-byte — so every current client (none of which pass those params to these routes) is unaffected and no client change is required. New route tests assert both the default array and the paginated envelope for each domain (moodBoard gains its first route test). Refs #2535 — CoS tasks (the `?full=1` default-paginated slice) already shipped; privacy vault/orgs/changes/brokers and digital-twin documents remain.
- **[issue-2535] Paginate the remaining privacy + digital-twin list endpoints, completing the sweep.** The last unbounded index `GET`s flagged by #2535 — privacy `/vault`, `/orgs`, `/changes`, `/brokers`, `/broker-cases`, and digital-twin `/documents` — now opt into the shared `paginateArray` envelope exactly like the creative-catalog routes shipped in #2636: `isPaginationRequested(req.query)` gates a bounded `{ items, total, limit, offset }` response (`defaultLimit: 50`, `maxLimit: 500`) the moment a client passes `limit`/`offset`, while a param-less request returns the full array byte-for-byte, so no client change is required. Because the four privacy list-query schemas are `.strict()` (they'd reject unknown keys), a local `paginationQueryFields` fragment (`limit`/`offset` as passthrough strings — `parsePagination` does the parse+clamp) is spread into `privacyVaultListQuerySchema`, `privacyOrgListQuerySchema`, `privacyBrokerListQuerySchema`, and `privacyBrokerCaseListQuerySchema` in `privacyValidation.js`; the `/orgs` handler strips `limit`/`offset` before passing filters to `listOrgs` so pagination never leaks into the service query. New route tests cover the vault/orgs/changes/broker-cases envelopes (filters preserved) and the digital-twin documents envelope. This closes the remaining slice of #2535 (the CoS-tasks default-paginated shape and the creative-catalog/media routes shipped previously).
- **[issue-2642] Require provider/runner provenance before excluding environmental failures from task learning.** Environmental-failure exclusion previously trusted `errorAnalysis.category` alone, but that category is produced by the `analyzeAgentFailure` regex sweep over the failed agent's output tail — so ordinary task output could be misclassified as an infra category (e.g. a failing test whose tail prints "rate limit" tripping the unscoped `/rate.?limit/`) and the run would be silently diverted out of the learning aggregates as an "outage." `analyzeAgentFailure` now stamps an `origin` provenance marker on every classification: `'provider'`/`'runner'` when the match carries a genuine structured signal (an `API Error: NNN` line, a Node error code like `ECONNREFUSED`, a provider token like `overloaded_error`/`not_found_error`, or the structural startup-failure), and `'output-scan'` when it comes only from a loose keyword alternative. Mixed patterns (e.g. `API Error: 429` vs a bare `rate limit`) gate the promotion through a per-pattern `structuredMarker` sub-pattern via the new pure `resolvePatternOrigin` helper. The exclusion gate in `recordTaskCompletion` (`server/services/taskLearning/metrics.js`) now runs through a pure `shouldDivertToEnvironmental(outcomeSuccess, category, origin)` that additionally requires `origin !== 'output-scan'`, so an output-scan false positive counts as a genuine failure while structured signals stay excluded. Back-compat is preserved: an `errorAnalysis` with no `origin` (older records / federated peers) keeps the category-only behavior, and the routing-side signature filter is unchanged (it already fails safe). New unit tests cover the provenance stamping across the classifiers and all three acceptance cases in the gate.
+- **Fix the app-manager Git tab's "Clean N merged" button counting worktree-locked branches, so cleanup deleted zero and toasted "No merged branches to clean up".** `getBranches` marked a local branch `merged: true` from `git branch --merged` alone, but `deleteMergedBranches` (correctly) skips branches checked out in a worktree — `git branch -d` can't delete them. On any install with active CoS-agent/claim worktrees, those merged-but-locked branches inflated the button's count while yielding no deletions. `getBranches` now also returns a `worktree` flag (branch checked out in another worktree), the Git tab's `localMergedCount` counts only `merged && !worktree` so the button reflects what the server will actually delete, and locked branches render a `worktree` badge next to `merged` so the user sees why they linger. Server + client tests cover the count and badge.
diff --git a/client/src/components/apps/tabs/GitTab.jsx b/client/src/components/apps/tabs/GitTab.jsx
index f63120d0d4..af0c7195ab 100644
--- a/client/src/components/apps/tabs/GitTab.jsx
+++ b/client/src/components/apps/tabs/GitTab.jsx
@@ -328,7 +328,10 @@ export default function GitTab({ appId: _appId, appName, repoPath }) {
};
const mergedBranchCount = remoteBranches.filter(rb => rb.merged && !rb.isDefault).length;
- const localMergedCount = branches.filter(b => b.merged).length;
+ // Branches checked out in a worktree can't be locally deleted, so cleanup-merged
+ // skips them — don't count them toward the "Clean N merged" button or it promises
+ // deletions the server refuses.
+ const localMergedCount = branches.filter(b => b.merged && !b.worktree).length;
const handleCleanupMerged = async () => {
if (!repoPath || cleaningUp) return;
@@ -607,6 +610,15 @@ export default function GitTab({ appId: _appId, appName, repoPath }) {
merged
</span>
)}
+ {branch.worktree && (
+ <span
+ className="flex items-center gap-1 text-xs text-gray-400 px-1.5 py-0.5 bg-gray-500/10 rounded shrink-0"
+ title="Checked out in a worktree — can't be deleted until the worktree is removed"
+ >
+ <GitBranch size={10} />
+ worktree
+ </span>
+ )}
{branch.tracking && (
<span className="text-xs text-gray-500 shrink-0">
{branch.ahead > 0 && <span className="text-port-success">+{branch.ahead}</span>}
diff --git a/client/src/components/apps/tabs/GitTab.test.jsx b/client/src/components/apps/tabs/GitTab.test.jsx
index 1e9e5e5251..a109ae9537 100644
--- a/client/src/components/apps/tabs/GitTab.test.jsx
+++ b/client/src/components/apps/tabs/GitTab.test.jsx
@@ -118,3 +118,34 @@ describe('GitTab merged-branch cleanup scoping', () => {
expect(screen.queryByText('Clean 2 merged')).toBeNull();
});
});
+
+describe('GitTab merged branches checked out in worktrees', () => {
+ beforeEach(() => {
+ // Both merged branches are checked out in worktrees, so cleanup-merged would
+ // skip them locally — the button must not advertise them as deletable.
+ api.getBranches.mockResolvedValue({
+ branches: [
+ { name: 'main', current: true, tracking: 'origin/main', ahead: 0, behind: 0, isDefault: true, merged: false, worktree: false },
+ { name: 'claim/issue-1', current: false, tracking: null, ahead: 0, behind: 0, isDefault: false, merged: true, worktree: true },
+ { name: 'claim/issue-2', current: false, tracking: null, ahead: 0, behind: 0, isDefault: false, merged: true, worktree: true },
+ ],
+ });
+ api.getRemoteBranches.mockResolvedValue({ branches: [], defaultBranch: 'main' });
+ });
+
+ it('does not show the local "Clean N merged" button when every merged branch is locked in a worktree', async () => {
+ render(<GitTab appId="x" appName="App" repoPath="/repo" />);
+
+ // The merged branches still render (with their badges) so the user can see them...
+ expect(await screen.findByText('claim/issue-1')).toBeInTheDocument();
+ // ...but there is no phantom cleanup button that would delete zero branches.
+ expect(screen.queryByText(/Clean \d+ merged/)).toBeNull();
+ });
+
+ it('labels worktree-checked-out branches with a worktree badge', async () => {
+ render(<GitTab appId="x" appName="App" repoPath="/repo" />);
+
+ await screen.findByText('claim/issue-1');
+ expect(screen.getAllByText('worktree')).toHaveLength(2);
+ });
+});
diff --git a/server/services/git.js b/server/services/git.js
index 3a3170c18b..77fee55503 100644
--- a/server/services/git.js
+++ b/server/services/git.js
@@ -666,17 +666,18 @@ async function getLocalMergedBranchNames(dir, defaultBranch) {
/**
* Get all local branches with tracking info
- * @returns {Promise<Array<{name: string, current: boolean, tracking: string|null, ahead: number, behind: number, isDefault: boolean, merged: boolean}>>}
+ * @returns {Promise<Array<{name: string, current: boolean, tracking: string|null, ahead: number, behind: number, isDefault: boolean, merged: boolean, worktree: boolean}>>}
*/
export async function getBranches(dir) {
// Get branches with verbose info (includes tracking)
- const [result, { baseBranch }] = await Promise.all([
+ const [result, { baseBranch }, worktreeBranches] = await Promise.all([
execGit(
['branch', '-vv', '--format=%(HEAD)|%(refname:short)|%(upstream:short)|%(upstream:track)'],
dir,
{ ignoreExitCode: true }
),
- getRepoBranches(dir)
+ getRepoBranches(dir),
+ getWorktreeBranches(dir)
]);
const defaultBranch = baseBranch || 'main';
@@ -690,6 +691,11 @@ export async function getBranches(dir) {
.map(b => ({
...b,
isDefault: b.name === defaultBranch,
+ // A branch checked out in another worktree can't be `git branch -d`'d, so
+ // cleanup-merged skips it. Flag it so the UI doesn't advertise it as
+ // deletable (otherwise the "Clean N merged" button promises deletions the
+ // server correctly refuses, and the user gets "No merged branches to clean up").
+ worktree: !b.current && worktreeBranches.has(b.name),
merged: !b.current && !protectedSet.has(b.name) && mergedSet.has(b.name)
}));
}