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

address review (claude): allow un-scoping a job to global + enforce openPR⇒useWorktree

Adam Eivy64f73714d7bf
diff --git a/client/src/components/apps/tabs/CustomTasksSection.jsx b/client/src/components/apps/tabs/CustomTasksSection.jsx
index a469e75d7b..7bc159b047 100644
--- a/client/src/components/apps/tabs/CustomTasksSection.jsx
+++ b/client/src/components/apps/tabs/CustomTasksSection.jsx
@@ -91,8 +91,16 @@ function scheduleSummary(job) {
function TaskForm({ form, setForm, onSave, onCancel, saveLabel }) {
const update = (key, val) => setForm(f => ({ ...f, [key]: val }));
+ // Toggle a git-workflow flag while preserving the system-wide invariant that
+ // openPR implies useWorktree (matches toggleAppMetadataOverride used elsewhere):
+ // turning openPR on forces useWorktree on; turning useWorktree off forces openPR off.
const toggleMeta = (field) =>
- setForm(f => ({ ...f, taskMetadata: { ...f.taskMetadata, [field]: !f.taskMetadata?.[field] } }));
+ setForm(f => {
+ const meta = { ...f.taskMetadata, [field]: !f.taskMetadata?.[field] };
+ if (field === 'openPR' && meta.openPR) meta.useWorktree = true;
+ if (field === 'useWorktree' && !meta.useWorktree) meta.openPR = false;
+ return { ...f, taskMetadata: meta };
+ });
return (
<div className="space-y-3 bg-port-card border border-port-accent/50 rounded-lg p-4">
diff --git a/client/src/components/cos/tabs/JobsTab.jsx b/client/src/components/cos/tabs/JobsTab.jsx
index dff803dd58..2ce9ade9ff 100644
--- a/client/src/components/cos/tabs/JobsTab.jsx
+++ b/client/src/components/cos/tabs/JobsTab.jsx
@@ -87,8 +87,11 @@ function normalizeJobPayload(formData) {
payload.command = null;
payload.triggerAction = null;
}
- // Empty app picker selection ('') → undefined so the server treats it as a global job.
- if (!payload.appId) payload.appId = undefined;
+ // Empty app picker selection ('') → null so a PUT actively un-scopes the job
+ // back to global (undefined would be dropped from JSON and updateJob would
+ // preserve the old scope). The schema maps '' → null too; sending null directly
+ // is unambiguous across create and update.
+ if (!payload.appId) payload.appId = null;
if (payload.scheduleMode === 'cron') {
payload.cronExpression = payload.cronExpression?.trim() || null;
payload.scheduledTime = null;
diff --git a/server/lib/validation.js b/server/lib/validation.js
index 65da5ddb49..36de31ffdf 100644
--- a/server/lib/validation.js
+++ b/server/lib/validation.js
@@ -725,8 +725,11 @@ export const createCosJobSchema = z.object({
promptTemplate: z.string().optional(),
command: z.string().optional(),
triggerAction: z.preprocess(v => v === '' ? undefined : v, z.string().optional()),
- // Optional managed-app scope (empty string from the UI picker → undefined → global job).
- appId: z.preprocess(v => v === '' ? undefined : v, z.string().optional()),
+ // Optional managed-app scope. Empty string from the UI picker → null so a PUT
+ // can actively un-scope a job back to global (updateJob only skips `undefined`,
+ // so undefined would silently preserve the old scope). Absent key stays
+ // undefined (preserve existing on PUT, default null on create).
+ appId: z.preprocess(v => v === '' ? null : v, z.string().nullable().optional()),
// Optional git-workflow options for app-scoped agent jobs.
taskMetadata: z.object({
useWorktree: z.boolean().optional(),
diff --git a/server/routes/cosJobRoutes.test.js b/server/routes/cosJobRoutes.test.js
index f922370849..4e52c4ffe4 100644
--- a/server/routes/cosJobRoutes.test.js
+++ b/server/routes/cosJobRoutes.test.js
@@ -218,7 +218,7 @@ describe('CoS Job Routes', () => {
);
});
- it('should coerce empty-string appId to undefined (global job)', async () => {
+ it('should coerce empty-string appId to null (global job)', async () => {
autonomousJobs.createJob.mockResolvedValue({ id: 'j1' });
const response = await request(app)
@@ -227,7 +227,7 @@ describe('CoS Job Routes', () => {
expect(response.status).toBe(200);
expect(autonomousJobs.createJob).toHaveBeenCalledWith(
- expect.objectContaining({ appId: undefined })
+ expect.objectContaining({ appId: null })
);
});
});
@@ -253,6 +253,22 @@ describe('CoS Job Routes', () => {
expect(response.status).toBe(404);
});
+
+ it('un-scopes a job to global when the client sends empty appId', async () => {
+ autonomousJobs.updateJob.mockResolvedValue({ id: 'j1', appId: null });
+
+ // The Global picker sends appId:'' (or null); the schema maps '' → null so
+ // updateJob actually clears the scope (it only skips `undefined`).
+ const response = await request(app)
+ .put('/api/cos/jobs/j1')
+ .send({ name: 'Now Global', appId: '' });
+
+ expect(response.status).toBe(200);
+ expect(autonomousJobs.updateJob).toHaveBeenCalledWith(
+ 'j1',
+ expect.objectContaining({ appId: null })
+ );
+ });
});
describe('POST /api/cos/jobs/:id/toggle', () => {
diff --git a/server/services/autonomousJobs/skillTemplates.js b/server/services/autonomousJobs/skillTemplates.js
index e59cb61719..3c4fbd389a 100644
--- a/server/services/autonomousJobs/skillTemplates.js
+++ b/server/services/autonomousJobs/skillTemplates.js
@@ -156,7 +156,7 @@ async function generateTaskFromJob(job) {
autonomyLevel: job.autonomyLevel,
// App-scoped jobs carry the target app id so prepareAgentWorkspace resolves
// the agent's workspace to the app's repoPath. Absent = runs in PortOS root.
- ...(job.appId ? { app: job.appId } : {}),
+ ...(job.appId != null ? { app: job.appId } : {}),
// Forward git-workflow options so an app-scoped task can isolate via a
// worktree and open a PR (same metadata flags the built-in task types use).
...(meta.useWorktree != null ? { useWorktree: meta.useWorktree } : {}),