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: share upstream owner and full-name checks across the watchdog and process audit (#12691)

[._.]/68503a9644be
diff --git a/server/lib/README.md b/server/lib/README.md
index 882b87f5cd..26895adff7 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -467,7 +467,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `gitForge.js` | `parseGitRemote`, `parseGitHubOwnerFromRemote`, `pickGhAccountForOwner`, `detectForgeCli`, `parsePullRequestUrl` — GitHub/GitLab remote + PR/MR URL parsers and forge/account selectors used by `git.js`. Pure except that `parseGitRemote` canonicalizes an ssh `Host` alias through `sshHostAlias.js`. |
| `sshHostAlias.js` | `resolveSshHostAlias`, `parseSshHostAliases` — resolves a personal SSH `Host` alias (`git@github-acme:…`, backed by `HostName github.com` in `~/.ssh/config`) to the host a remote actually connects to. Every remote-URL host parser (`gitForge.parseGitRemote`, `gitRemote.parseGitRemoteUrl`, `workTracker.hostFromOriginUrl`) canonicalizes through it, so multi-account checkouts classify as GitHub instead of an unreachable unknown host. |
| `gitOutputParsers.js` | `parseStatus`, `parseDiffStat`, `parseBranchVerboseLine`, `parseSubmoduleStatusLine`/`SUBMODULE_STATUS_RE`, `extractAgentSummary` — pure parsers turning git command output into structured data for `git.js`. `extractAgentSummary` anchors on `agentOutputMarkers`' completion marker so a TUI agent's PR body carries its sentinel summary, not the lifecycle telemetry above it. `isBenignConcurrentFetchRefRace(stderr)` reads a non-zero `git fetch` as a SUCCESS when its only failure is a lost compare-and-swap whose refs already hold the fetched commits — the routine outcome when the Git tab, `getRemoteBranches`, and CoS agent worktrees fetch one `.git` at once. |
-| `gitRemote.js` | `getOriginInfo`, `classifyOriginRemote`, `parseGitRemoteUrl`, `readRemoteUrl`, `UPSTREAM_OWNER`/`UPSTREAM_REPO` — safely reads and classifies checkout remotes against PortOS or a caller-supplied canonical upstream. Used by self-update and managed integrations to detect forks. |
+| `gitRemote.js` | `getOriginInfo`, `classifyOriginRemote`, `parseGitRemoteUrl`, `readRemoteUrl`, `isUpstreamOwner`, `isUpstreamFullName`, `UPSTREAM_OWNER`/`UPSTREAM_REPO` — safely reads and classifies checkout remotes against PortOS or a caller-supplied canonical upstream. Used by self-update and managed integrations to detect forks. |
| `gitStaleLock.js` | `gitLockPathFromError`, `isStaleGitLock`, `clearStaleGitLock`, `clearStaleGitLocksIn`, `STALE_GIT_LOCK_MIN_AGE_MS` — recognizes the `*.lock` a KILLED git process left behind and removes it so the caller can retry. A lock under `.git/modules/<submodule>/` is shared by every worktree of the repo, so one dead process wedges submodule checkout install-wide with a bogus "another git process is running". Removal requires a `.lock` path under a `.git` directory (so a malformed message cannot aim the unlink at `yarn.lock`) that is older than 30 minutes — 3x the longest git command PortOS runs (`worktreeManager.WORKTREE_ADD_TIMEOUT_MS`, pinned by a test), which is what keeps it from deleting a LIVE competitor's lock. The threshold is deliberately not a parameter. `clearStaleGitLock(message)` is the reactive form, wired into `services/gitSubmodules.js#updateSubmodule` and `worktreeManager.addWorktreeWithRetry`; `clearStaleGitLocksIn(gitDir)` sweeps ahead of `update.sh`/`update.ps1`, the most likely producer. `scripts/doctor.js` reports one as the blocker. |
| `repoLinkFields.js` | `deriveRepoLinkFields(url)` / `normalizeRepoLinkFields(link)` / `linkIsRepo(link)` / `repoLinkLabel(link)` — the repository metadata a Brain link carries, plus the dual-write/tolerant-read shim that keeps the pre-multi-host `isGitHubRepo` field names readable across federated peers. |
| `repoUrl.js` | `parseRepoUrl(url)` → `{ host, provider, owner, repo }` / `isRepoUrl(url)` / `repoCloneUrl(parsed)` / `repoBrowseUrl(parsed)` / `parseGitHubUrl(url)` / `isGitHubRepoUrl(url)` — authoritative "is this a clonable repo URL?" rule, with per-host behavior (subgroup nesting, clone layout) in the `REPO_HOSTS` table. Re-exported by `client/src/lib/repoUrl.js` so the Brain capture boxes reveal the post-clone agent options for exactly the URLs the server will clone. |
diff --git a/server/lib/gitRemote.js b/server/lib/gitRemote.js
index 8008651c82..90d6b9b901 100644
--- a/server/lib/gitRemote.js
+++ b/server/lib/gitRemote.js
@@ -6,6 +6,18 @@ export const UPSTREAM_OWNER = 'atomantic';
export const UPSTREAM_REPO = 'PortOS';
export const UPSTREAM_FULL_NAME = `${UPSTREAM_OWNER}/${UPSTREAM_REPO}`;
+/** Return whether an owner or owner/repository name identifies PortOS upstream. */
+export function isUpstreamOwner(fullNameOrOwner) {
+ if (typeof fullNameOrOwner !== 'string') return false;
+ const owner = fullNameOrOwner.trim().split('/')[0];
+ return owner.toLowerCase() === UPSTREAM_OWNER.toLowerCase();
+}
+
+/** Return whether a full owner/repository name identifies PortOS upstream. */
+export function isUpstreamFullName(fullName) {
+ return typeof fullName === 'string' && fullName.trim().toLowerCase() === UPSTREAM_FULL_NAME.toLowerCase();
+}
+
/**
* Strip any `://user:token@` credentials from a URL so a PAT embedded in an
* https remote can't leak into API responses, logs, or telemetry. SCP-style
diff --git a/server/lib/gitRemote.test.js b/server/lib/gitRemote.test.js
index efac2f5c3a..eaf7c25dbd 100644
--- a/server/lib/gitRemote.test.js
+++ b/server/lib/gitRemote.test.js
@@ -17,9 +17,22 @@ import {
redactRemoteUrlCredentials,
UPSTREAM_OWNER,
UPSTREAM_REPO,
- UPSTREAM_FULL_NAME
+ UPSTREAM_FULL_NAME,
+ isUpstreamOwner,
+ isUpstreamFullName
} from './gitRemote.js';
+describe('upstream identity helpers', () => {
+ it('matches upstream owners and full names case-insensitively', () => {
+ expect(isUpstreamOwner('Atomantic/PortOS')).toBe(true);
+ expect(isUpstreamOwner('ATOMANTIC')).toBe(true);
+ expect(isUpstreamOwner('other/PortOS')).toBe(false);
+ expect(isUpstreamFullName('Atomantic/PortOS')).toBe(true);
+ expect(isUpstreamFullName(' ATOMANTIC/PORTOS ')).toBe(true);
+ expect(isUpstreamFullName('atomantic/other')).toBe(false);
+ });
+});
+
describe('parseGitRemoteUrl', () => {
it('parses SCP-style SSH URLs', () => {
expect(parseGitRemoteUrl('[email protected]:atomantic/PortOS.git')).toEqual({
diff --git a/server/services/developmentWatchdog.js b/server/services/developmentWatchdog.js
index a785e24243..7142ac17e0 100644
--- a/server/services/developmentWatchdog.js
+++ b/server/services/developmentWatchdog.js
@@ -6,11 +6,13 @@ import { normalizePersistentMindCapabilities } from '../lib/persistentMindCapabi
import { getDomainMode } from '../lib/domainAutonomy.js';
import { DEVELOPMENT_ACTIVE_STATUSES, sameDevelopmentWork } from '../lib/developmentWorkIdentity.js';
import { safeJSONParse } from '../lib/jsonIo.js';
+import { isUpstreamOwner, UPSTREAM_OWNER } from '../lib/gitRemote.js';
let scanTail = Promise.resolve();
const tasksFrom = data => [...data.user.tasks, ...data.cos.tasks];
const ownershipTask = (app, pr) => ({ metadata: { app: app.id, reviewLoopPRUrl: pr.url } });
const parseGithubJson = value => safeJSONParse(value, null, { allowArray: false });
+const forgeAccountFor = (target, app) => isUpstreamOwner(target?.fullName) ? UPSTREAM_OWNER : app.forgeAccount;
function reviewFollowUpPrNumber(task, target) {
const metadata = task?.metadata || {};
@@ -98,11 +100,11 @@ async function inspectApp(app, tasks, localReviewTasks = [], activeAgentTaskIds
};
// Other forge support remains explicit rather than silently using GitHub semantics.
if (tracker !== 'github' || !target?.repoSpec) { row.blockers.push('unsupported-forge'); return row; }
- const account = target.fullName?.split('/')[0]?.toLowerCase() === 'atomantic' ? 'atomantic' : app.forgeAccount;
- if (account === 'atomantic' && app.forgeAccount && app.forgeAccount !== 'atomantic') { row.blockers.push('conflicting-forge-account-pin'); return row; }
+ const account = forgeAccountFor(target, app);
+ if (account === UPSTREAM_OWNER && app.forgeAccount && app.forgeAccount !== UPSTREAM_OWNER) { row.blockers.push('conflicting-forge-account-pin'); return row; }
const exec = await resolveForgeExecOptions(app.repoPath, { forgeAccount: account });
const login = (await execGh(['api', 'user', '--hostname', target.apiHost, '--jq', '.login'], undefined, exec)).trim();
- if (account === 'atomantic' && login !== 'atomantic') { row.blockers.push('required-forge-account-unavailable'); return row; }
+ if (account === UPSTREAM_OWNER && login !== UPSTREAM_OWNER) { row.blockers.push('required-forge-account-unavailable'); return row; }
// Every downstream resolver receives the same explicit account pin.
const pinned = { ...app, forgeAccount: account };
const { metadata: preview } = await resolveClaimWorkMetadata(pinned, 'claim-issue');
@@ -260,7 +262,7 @@ async function dispatch(app, decision) {
const { resolveAppForgeTarget } = await import('../lib/workTracker.js');
const { target } = await resolveAppForgeTarget(app);
const { resolveForgeExecOptions } = await import('./forgeExecOptions.js');
- const exec = await resolveForgeExecOptions(app.repoPath, { forgeAccount: target.fullName.startsWith('atomantic/') ? 'atomantic' : app.forgeAccount });
+ const exec = await resolveForgeExecOptions(app.repoPath, { forgeAccount: forgeAccountFor(target, app) });
const { execGh } = await import('./github.js');
const { parseBlockingIssueNumbers } = await import('./blockedIssueReconcile.js');
const body = await execGh([decision.kind === 'pr' ? 'pr' : 'issue', 'view', String(item.number), '--repo', target.repoSpec, '--json', 'body'], undefined, exec)
diff --git a/server/services/developmentWatchdog.test.js b/server/services/developmentWatchdog.test.js
index aa4f5af9fe..5475df5d38 100644
--- a/server/services/developmentWatchdog.test.js
+++ b/server/services/developmentWatchdog.test.js
@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
-const m = vi.hoisted(() => ({ state: null, tasks: [], prs: [], backlog: [], peers: [], adds: [], updates: [], save: vi.fn(), branch: '', account: 'atomantic', nextPrs: null, prReads: 0, prStates: {}, dependencies: [], dependencyOpen: false, execGhFailureOn: null, invalidGhJsonOn: null, issueTruncated: false, readiness: { shouldRun: true }, requests: [], duplicate: false, prepare: vi.fn(), record: vi.fn(), execution: vi.fn(), metadata: vi.fn() }));
+const m = vi.hoisted(() => ({ state: null, tasks: [], prs: [], backlog: [], peers: [], adds: [], updates: [], save: vi.fn(), branch: '', account: 'atomantic', fullName: 'atomantic/example', execOptions: [], nextPrs: null, prReads: 0, prStates: {}, dependencies: [], dependencyOpen: false, execGhFailureOn: null, invalidGhJsonOn: null, issueTruncated: false, readiness: { shouldRun: true }, requests: [], duplicate: false, prepare: vi.fn(), record: vi.fn(), execution: vi.fn(), metadata: vi.fn() }));
vi.mock('./cosState.js', () => ({ loadState: async () => m.state, saveState: m.save, withStateLock: async fn => fn(), isImprovementEnabled: state => state.config.improvementEnabled }));
vi.mock('./apps.js', () => ({ getActiveApps: async () => [{ id: 'app', name: 'Example', repoPath: '/example' }] }));
vi.mock('./cosTaskStore.js', () => ({ getAllTasks: async () => ({ user: { tasks: [] }, cos: { tasks: m.tasks } }), updateTask: async (id, updates, type, options) => {
@@ -11,7 +11,7 @@ vi.mock('./cosTaskStore.js', () => ({ getAllTasks: async () => ({ user: { tasks:
return task;
}, addTask: async task => { if (m.duplicate) return { id: 'existing', duplicate: true }; const result = { ...task, id: 'queued', status: 'pending' }; m.tasks.push(result); m.adds.push(result); return result; } }));
vi.mock('./instances.js', () => ({ getPeers: async () => m.peers }));
-vi.mock('../lib/workTracker.js', () => ({ resolveAppForgeTarget: async () => ({ tracker: 'github', target: { fullName: 'atomantic/example', repoSpec: 'github.com/atomantic/example', apiHost: 'github.com' } }) }));
+vi.mock('../lib/workTracker.js', () => ({ resolveAppForgeTarget: async () => ({ tracker: 'github', target: { fullName: m.fullName, repoSpec: `github.com/${m.fullName}`, apiHost: 'github.com' } }) }));
vi.mock('./appPullRequests.js', () => ({ listAppPullRequests: async () => ({ pullRequests: ++m.prReads > 1 && m.nextPrs ? m.nextPrs : m.prs, transient: false }) }));
vi.mock('./perpetualWork.js', async importOriginal => ({ ...(await importOriginal()), detectActionableWork: async () => ({ count: m.backlog.length, items: m.backlog }), listConfiguredForgeIssues: async () => ({ ok: true, truncated: m.issueTruncated, issues: m.backlog.map(i => ({ number: Number(i.ref), labels: [], assignees: [] })) }) }));
vi.mock('./cosTaskClaimWork.js', () => ({
@@ -33,7 +33,7 @@ vi.mock('./github.js', () => ({ execGh: async args => {
if (args[0] === m.invalidGhJsonOn) return 'not json';
return JSON.stringify({ body: '', state: m.dependencyOpen ? 'OPEN' : 'CLOSED', labels: m.dependencyOpen ? [{ name: 'in-progress' }] : [] });
}, getPullRequestState: async number => m.prStates[String(number)] || { status: 'unavailable', state: null } }));
-vi.mock('./forgeExecOptions.js', () => ({ resolveForgeExecOptions: async () => ({}) }));
+vi.mock('./forgeExecOptions.js', () => ({ resolveForgeExecOptions: async (_path, options) => { m.execOptions.push(options); return {}; } }));
vi.mock('./forgeActorTrust.js', () => ({ createGithubActorTrust: async () => ({ isTrusted: async () => true }) }));
vi.mock('../lib/execGit.js', () => ({ execGit: async () => ({ stdout: m.branch }) }));
vi.mock('../lib/peerHttpClient.js', () => ({ peerFetch: async () => { throw new Error('offline'); } }));
@@ -49,7 +49,7 @@ import { readPersistentMindMaintenanceContext } from './persistentMindMaintenanc
beforeEach(() => {
m.state = { config: { improvementEnabled: true, persistentMindMaintainer: { enabled: true, appIds: ['app'] }, persistentMindCapabilities: { readPortos: true, createTasks: true }, maxConcurrentAgents: 3 }, agents: {} };
- m.tasks = []; m.prs = []; m.backlog = []; m.peers = []; m.adds = []; m.updates = []; m.branch = ''; m.account = 'atomantic'; m.save.mockClear(); m.nextPrs = null; m.prReads = 0; m.prStates = {}; m.dependencies = []; m.dependencyOpen = false; m.execGhFailureOn = null; m.invalidGhJsonOn = null; m.issueTruncated = false;
+ m.tasks = []; m.prs = []; m.backlog = []; m.peers = []; m.adds = []; m.updates = []; m.branch = ''; m.account = 'atomantic'; m.fullName = 'atomantic/example'; m.execOptions = []; m.save.mockClear(); m.nextPrs = null; m.prReads = 0; m.prStates = {}; m.dependencies = []; m.dependencyOpen = false; m.execGhFailureOn = null; m.invalidGhJsonOn = null; m.issueTruncated = false;
m.readiness = { shouldRun: true }; m.requests = []; m.duplicate = false;
m.metadata.mockReset().mockResolvedValue({ metadata: {} });
m.prepare.mockReset().mockResolvedValue({
@@ -214,6 +214,16 @@ it('keeps explicit live claim and open dependency evidence out of dispatch', asy
expect(receipt.decisions[0].reason).toBe('open-dependency'); expect(m.adds).toEqual([]);
});
+it.each(['atomantic/PortOS', 'Atomantic/PortOS'])('pins both watchdog forge lookups to upstream for %s', async fullName => {
+ m.fullName = fullName;
+ m.prs = [{ ...orphan, headBranch: 'fix' }];
+ m.dependencies = [10];
+
+ await runDevelopmentWatchdog({ force: true });
+
+ expect(m.execOptions.slice(0, 2).map(options => options?.forgeAccount)).toEqual(['atomantic', 'atomantic']);
+});
+
it('treats a slashdo /do:next branch (next/issue-<num>) as a live external claim, not an orphan (#8161)', async () => {
// Before #8161, issueNumberFromRef (perpetualWork.js, via planIds.extractSlugFromRef)
// only recognized claim/ and cos/.../ prefixes, so a next/issue-<num> PR fell through
diff --git a/server/services/persistentMindProcessAudit.js b/server/services/persistentMindProcessAudit.js
index 2101416808..b2514cdb2a 100644
--- a/server/services/persistentMindProcessAudit.js
+++ b/server/services/persistentMindProcessAudit.js
@@ -11,6 +11,7 @@ import { PROCESS_AUDIT_LIMITS as LIMITS, processAuditFingerprint, processAuditSi
processAuditNextSchema, processAuditReadSchema, processAuditOutcomeSchema, processAuditFixSchema } from '../lib/persistentMindProcessAudit.js';
import { loadState } from './cosState.js';
import { readPersistentMindManagedApps } from './persistentMindManagedApps.js';
+import { isUpstreamFullName } from '../lib/gitRemote.js';
// Access projections must not load the archived-job graph merely to read grants.
const loadAgentIndex = async () => (await import('./cosAgentIndex.js')).loadAgentIndex();
@@ -272,7 +273,7 @@ export async function recordProcessAuditOutcome(raw, context = {}) {
const { listAppIssues } = await import('./appIssues.js');
const listed = await listAppIssues(app);
if (listed.transient) throw new Error('Tracker unreadable; nothing filed');
- const cleanupState = args.template === 'recovery-loop' && app.fullName === 'atomantic/PortOS'
+ const cleanupState = args.template === 'recovery-loop' && isUpstreamFullName(app.fullName)
&& anchors.includes('server/services/agentRepoStateVerification.js')
? await cleanupFixState(app, await getAgentRecord(receipt.agentId)) : null;
if (cleanupState === 'unknown') {
@@ -330,7 +331,7 @@ export async function readPendingProcessAudit(appId) {
return { appId, pending: page.records.filter(record => !Object.values(store.receipts).some(receipt => receipt.agentId === record.id && receipt.outcome)).length,
truncated: !!page.nextCursor || page.missingMetadata > 0 || page.unknownApp > 0, missingMetadata: page.missingMetadata, unattributedJobs: page.unknownApp, nextCursor: page.nextCursor, checkpoint: store.checkpoints[appId] || null, metrics: processAuditMetrics(page.records),
fixes: Object.values(store.findings).filter(finding => finding.sourceAppId === appId && finding.fix).map(finding => ({ revision: finding.fix.revision, cleanObservations: finding.fix.cleanObservations, recurrences: finding.fix.recurrences })),
- knownCleanupFix: app.fullName === 'atomantic/PortOS' ? { revision: KNOWN_CLEANUP_FIX, url: 'https://github.com/atomantic/PortOS/pull/7817', recurrence: 'unknown-until-comparable-post-fix-evidence' } : null };
+ knownCleanupFix: isUpstreamFullName(app.fullName) ? { revision: KNOWN_CLEANUP_FIX, url: 'https://github.com/atomantic/PortOS/pull/7817', recurrence: 'unknown-until-comparable-post-fix-evidence' } : null };
}
/** Safe automatic-wake projection: no transcript prose, job identifiers or task titles. */