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: pin manual merges and retain failed auto-merge revocations
[._.]/ Adam Eivy027a0316ff21
diff --git a/server/lib/README.md b/server/lib/README.mdindex 7fdac68b3e..e0247c9013 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -668,6 +668,7 @@ pm` default, `NPM_CONFIG_PREFIX`, nvm/Volta) installed `codex` successfully and| `tombstones.js` | Generic timestamped tombstones (`{ <keyField>, deletedAt }`) that let an otherwise add-only peer merge represent a DELETE, so a record removed on one machine is not resurrected by a peer that still has it (#3530). `normalizeTombstones` / `recordTombstone` / `clearTombstone` / `tombstoneTimestamp` maintain the list; `mergeTombstones` unions it in both directions (newest deletion per key wins) so a delete propagates rather than only defending locally; `isTombstoned(list, key, createdAt)` suppresses a record unless its own creation stamp is strictly NEWER than the deletion; `pruneTombstones(list, records)` drops tombstones a re-created record has superseded (otherwise a stale peer copy keeps reaping it); `supersedingTimestamp(deletedAt)` stamps a re-create that lands in the same millisecond (or behind a skewed peer clock). Comparison goes through `lwwTimestamp.js`, so polarity matches every other sync merge. Key on a field that means the same thing on every machine — locally-minted ids usually do not. `DEFAULT_TOMBSTONE_LIMIT` (200) caps growth. || `untrustedContent.js` | `jevPolicyPatchSchema` validates narrow scorer-management updates. Shared source policies, strict settings schema, data framing and API-only/local-private provider eligibility for untrusted GitHub and messaging content. || `untrustedContentSources.js` | The ingress vocabulary alone — `UNTRUSTED_CONTENT_SOURCES` and `PRIVATE_UNTRUSTED_CONTENT_SOURCES`. Split out of `untrustedContent.js` (which reaches `zod` and `node:crypto`) so the browser can import it: the Abuse Guard panel offers exactly the sources the server screens, instead of restating them and drifting (#7680). |+| `contributionSecurityPolicy.js` | Trusted host-control security policy and strict tool-free GitHub contribution assessment contract. || `uploadLimits.js` | Single source of truth for upload size caps — `JSON_BODY_LIMIT`/`JSON_BODY_LIMIT_BYTES` (the express.json limit applied in `index.js`), `MAX_BASE64_UPLOAD_BYTES` derived from it (base64 ×4/3, so a bigger per-route cap is unreachable), `MAX_SCREENSHOT_BYTES`. Mirrored client-side as `JSON_UPLOAD_MAX_FILE_SIZE`. || `userActionTypes.js` | Closed vocabulary for the operator-action ledger (`user_action_events`, #5594 / #5596): `USER_ACTION_TYPES` (CoS task/feedback/schedule + settings + instance-feature toggles + event-only creative/Brain pointers), `USER_ACTION_ACTORS` (`user` / `mind` / `schedule` / `system`), and the `isUserActionType` / `isUserActionActor` predicates. `recordUserAction` (`services/userActions.js`) throws on a type absent from the list, so a typo fails a test instead of writing a row nothing can filter on. || `uuid.js` | `v4()` thin wrapper over the global `crypto.randomUUID()`. Import-free, so a leaf the browser imports may reach it without a Node built-in — importable, not browser-callable: `randomUUID` needs a secure context there, so client code mints through `client/src/lib/uuid.js`. |@@ -728,5 +729,3 @@ pm` default, `NPM_CONFIG_PREFIX`, nvm/Volta) installed `codex` successfully and| `developmentWorkIdentity.js` | Canonical development task identity and cross-producer ownership matching. || `persistentMindProcessAudit.js` | Bounded process-audit schemas, deterministic observations, measured recovery ratios, and closed-vocabulary synthetic finding renderer. |--| `contributionSecurityPolicy.js` | Trusted host-control security policy and strict tool-free GitHub contribution assessment contract. |diff --git a/server/services/appPullRequestMerge.js b/server/services/appPullRequestMerge.jsindex 4f37901bf1..30ae22fb68 100644--- a/server/services/appPullRequestMerge.js+++ b/server/services/appPullRequestMerge.js@@ -172,6 +172,7 @@ export async function mergeAppPullRequest(app, pullRequest, { method = DEFAULT_Mnumber: pullRequest.number,method,deleteBranch: deleting,+ expectedHeadSha: target.forge === 'github' ? pullRequest.headSha ?? '' : null,timeoutMs: MERGE_TIMEOUT_MS,});if (!result.ok) return result;diff --git a/server/services/appPullRequestMerge.test.js b/server/services/appPullRequestMerge.test.jsindex 6f8f832ea0..c3432c6b25 100644--- a/server/services/appPullRequestMerge.test.js+++ b/server/services/appPullRequestMerge.test.js@@ -13,7 +13,7 @@ import { resolveAppForgeTarget } from '../lib/workTracker.js';import { mergeAppPullRequest } from './appPullRequestMerge.js';const APP = { id: 'app-001', name: 'Widget', repoPath: '/repo' };-const PR = { number: 17, headBranch: 'fix/save-path', baseBranch: 'main' };+const PR = { headSha: 'a'.repeat(40), number: 17, headBranch: 'fix/save-path', baseBranch: 'main' };const githubTarget = () => ({tracker: 'github',@@ -35,12 +35,20 @@ describe('mergeAppPullRequest', () => {// `--repo` keeps gh in remote mode, so `--delete-branch` never checks out a// branch in the user's working tree.expect(execGh).toHaveBeenCalledWith(- ['pr', 'merge', '17', '--repo', 'github.com/acme/widget', '--squash', '--delete-branch'],+ ['pr', 'merge', '17', '--repo', 'github.com/acme/widget', '--squash', '--delete-branch', '--match-head-commit', PR.headSha],expect.any(Number),{ cwd: '/repo', env: { GH_TOKEN: 'x' } },);});+ it('refuses an unknown GitHub head and preserves a head-mismatch failure', async () => {+ expect(await mergeAppPullRequest(APP, { ...PR, headSha: null })).toMatchObject({ ok: false, code: 'invalid-head' });+ expect(execGh).not.toHaveBeenCalled();+ execGh.mockRejectedValue(new Error('Head commit changed'));+ expect(await mergeAppPullRequest(APP, PR)).toMatchObject({ ok: false, code: 'merge-failed' });+ expect(execGh.mock.calls[0][0]).toContain(PR.headSha);+ });+// A `main → release` request's head is a long-lived branch, so an obedient// `--delete-branch` there deletes `main`. An unnamed head is treated the same// way: never delete a branch we cannot identify.@@ -49,7 +57,7 @@ describe('mergeAppPullRequest', () => {['a head equal to the base', { number: 9, headBranch: 'topic', baseBranch: 'topic' }],['an unreadable head', { number: 9, headBranch: '', baseBranch: 'main' }],])('merges but refuses to delete %s', async (_label, pullRequest) => {- const result = await mergeAppPullRequest(APP, pullRequest, { deleteBranch: true });+ const result = await mergeAppPullRequest(APP, { headSha: PR.headSha, ...pullRequest }, { deleteBranch: true });expect(result).toMatchObject({ ok: true, deletedBranch: false });expect(execGh.mock.calls[0][0]).not.toContain('--delete-branch');diff --git a/server/services/issueWatcher.js b/server/services/issueWatcher.jsindex 2ec5ed6d3e..6fa53b78d8 100644--- a/server/services/issueWatcher.js+++ b/server/services/issueWatcher.js@@ -863,7 +863,12 @@ async function processPendingApprovals(app, ctx) {const disabled = await runGh(['pr', 'merge', String(pr.number), '--repo', ctx.repoSpec, '--disable-auto'], ctx).then(() => true, () => false);if (!disabled) {- await keepPendingApproval(app, approval, remaining, 'GitHub auto-merge could not be disabled for security reassessment');+ // An armed remote action must remain tracked even when the ordinary+ // polling budget expires. Notify once, then keep retrying revocation.+ if (!approval.autoMergeRevocationFailed) {+ await notifyPendingApproval(app, approval, 'GitHub auto-merge could not be disabled for security reassessment. Disable it on the PR; PortOS will keep trying.');+ }+ remaining.push({ ...approval, autoMergeRevocationFailed: true });changed = true;continue;}diff --git a/server/services/issueWatcher.test.js b/server/services/issueWatcher.test.jsindex 6bafedc2ec..947ed5ccf3 100644--- a/server/services/issueWatcher.test.js+++ b/server/services/issueWatcher.test.js@@ -919,6 +919,26 @@ describe('processTaskOutput', () => {expect(execGhMock.mock.calls.some(([args]) => args.includes('--disable-auto'))).toBe(true);});+ it('retains an armed legacy auto-merge when revocation fails beyond the normal polling budget', async () => {+ installDefaultGhMock();+ const forgeRead = execGhMock.getMockImplementation();+ execGhMock.mockImplementation((args, ...rest) => {+ if (args.includes('--disable-auto')) throw new Error('Permission denied');+ return forgeRead(args, ...rest);+ });+ apps.set(APP.id, { ...APP, issueWatcherState: { approvedPullRequests: [{+ number: 7, headSha: 'a'.repeat(40), contentFingerprint: screenedPullRequestFingerprint(pullRequest(), DIFF),+ ciPolicy: 'required', autoMergeEnabled: true, ticks: MAX_PENDING_APPROVAL_TICKS,+ }] } });+ await buildTaskInput({ app: apps.get(APP.id) });+ expect(apps.get(APP.id).issueWatcherState.approvedPullRequests).toEqual([+ expect.objectContaining({ number: 7, autoMergeEnabled: true, autoMergeRevocationFailed: true }),+ ]);+ expect(mergePrMock).not.toHaveBeenCalled();+ expect(spawnPrRemediationFollowUpMock).not.toHaveBeenCalled();+ expect(addNotificationMock).toHaveBeenCalledWith(expect.objectContaining({ description: expect.stringContaining('auto-merge could not be disabled') }));+ });+it('keeps pending-CI approvals in the local queue so GitHub cannot bypass reassessment', async () => {installDefaultGhMock({ pr: pullRequest({ statusCheckRollup: [{ status: 'IN_PROGRESS' }] }) });const result = await processTaskOutput({ appId: APP.id, success: true, task: { metadata }, payload: {