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

stop a re-aimed ad-hoc run being dropped as a duplicate

Adam Eivy0b76326ccaa9
diff --git a/client/src/components/apps/tabs/CustomTasksSection.test.jsx b/client/src/components/apps/tabs/CustomTasksSection.test.jsx
index eec826d4f9..c5faec2664 100644
--- a/client/src/components/apps/tabs/CustomTasksSection.test.jsx
+++ b/client/src/components/apps/tabs/CustomTasksSection.test.jsx
@@ -289,6 +289,28 @@ describe('CustomTasksSection trigger outcomes', () => {
expect(api.updateCosJob).not.toHaveBeenCalled();
});
+ it('sends no configuration when the card fields were left untouched', async () => {
+ api.getCosJobs.mockResolvedValue({
+ jobs: [{
+ ...task,
+ formFields: [{ key: 'subject', label: 'Subject', type: 'text' }],
+ formValues: { subject: 'Saved subject' }
+ }],
+ dataInputCatalog: []
+ });
+ api.triggerCosJob.mockResolvedValue({ success: true, status: 'queued', started: true });
+
+ render(<CustomTasksSection appId="app-1" appName="Example App" />);
+ await screen.findByText('Example Task');
+ fireEvent.click(screen.getByRole('button', { name: 'Run now' }));
+
+ // "Run as saved" must send nothing rather than echo the card's own copy of
+ // the values: the server merges what it receives over the job it just read,
+ // so echoing them would revert a change made from another surface since
+ // this card rendered.
+ await waitFor(() => expect(api.triggerCosJob).toHaveBeenCalledWith('job-1', {}));
+ });
+
it('blocks an ad-hoc run that leaves a required card field blank', async () => {
api.getCosJobs.mockResolvedValue({
jobs: [{
diff --git a/client/src/components/cos/JobCard.jsx b/client/src/components/cos/JobCard.jsx
index 1e6c3917b8..a1274ca3a8 100644
--- a/client/src/components/cos/JobCard.jsx
+++ b/client/src/components/cos/JobCard.jsx
@@ -15,7 +15,7 @@ import TaskDataInputs from './TaskDataInputs';
import { JobFormFieldsEditor, JobFormValueInputs, missingRequiredJobFormFields } from './JobFormFields';
// Footer actions beside Run now — same shape, quieter than the accent trigger.
-const SECONDARY_ACTION_CLASS = 'flex items-center gap-1.5 px-3 py-1.5 text-sm rounded text-gray-300 hover:text-white hover:bg-port-border/50 transition-colors';
+const SECONDARY_ACTION_CLASS = 'flex items-center gap-1.5 min-h-[44px] px-3 py-1.5 text-sm rounded text-gray-300 hover:text-white hover:bg-port-border/50 transition-colors';
const SCHEDULE_MODE_OPTIONS = [
{ value: 'interval', label: 'Interval' },
@@ -324,8 +324,12 @@ export default function JobCard({
return;
}
// Always an options object, so a caller can forward it to the API wrapper
- // unconditionally; a job with no declared fields sends no configuration.
- onTrigger(job.id, runFormFields.length ? { formValues: runFormValues } : {});
+ // unconditionally. Send a configuration ONLY when the dial was actually
+ // turned: an untouched card would otherwise transmit its own copy of the
+ // saved values, which the server merges over the job it just read — so a
+ // value changed from another surface since this card rendered would be
+ // silently reverted for that run. Sending nothing means "run as saved".
+ onTrigger(job.id, runValuesDirty ? { formValues: runFormValues } : {});
};
const startEditing = () => {
@@ -481,7 +485,7 @@ export default function JobCard({
/>
<p className="text-xs text-gray-500">
{runValuesDirty
- ? 'These values apply to the next Run now only — the saved task is unchanged.'
+ ? 'Run now uses these values until you reset them — the saved task is unchanged.'
: 'Change these and press Run now for a one-off run; Edit changes what the task is saved with.'}
</p>
</div>
diff --git a/client/src/components/cos/tabs/schedule/scheduleConstants.js b/client/src/components/cos/tabs/schedule/scheduleConstants.js
index 8c774b5f79..e82ca04d3e 100644
--- a/client/src/components/cos/tabs/schedule/scheduleConstants.js
+++ b/client/src/components/cos/tabs/schedule/scheduleConstants.js
@@ -119,7 +119,7 @@ export function togglePrReviewerActions(stages, enabled) {
}
export const triggerButtonClass = (disabled) =>
- `flex items-center gap-1 px-3 py-1.5 text-sm rounded transition-colors ${disabled ? 'bg-port-border/30 text-gray-500 cursor-not-allowed' : 'bg-port-accent/20 hover:bg-port-accent/30 text-port-accent'}`;
+ `flex items-center gap-1 min-h-[44px] px-3 py-1.5 text-sm rounded transition-colors ${disabled ? 'bg-port-border/30 text-gray-500 cursor-not-allowed' : 'bg-port-accent/20 hover:bg-port-accent/30 text-port-accent'}`;
export const INTERVAL_BADGE_VARIANT = {
'on-demand': 'gray',
diff --git a/server/lib/README.md b/server/lib/README.md
index 8b03bbf349..b70886678f 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -474,7 +474,7 @@ pm` default, `NPM_CONFIG_PREFIX`, nvm/Volta) installed `codex` successfully and
| `appIdentity.js` | The baseline managed-app id (`PORTOS_APP_ID`) — importable without pulling in the `services/apps.js` graph (pm2, scheduler, settings) behind it. Re-exported by `apps.js`. |
| `appResolver.js` | Fuzzy-match a spoken/typed phrase to a managed app (`{ id, name }`). Tiered exact → prefix → substring, used by voice tools that target a specific app. |
| `autonomousJobIntervals.js` | Autonomous-job cadence vocabulary (pure). `INTERVAL_OPTIONS` (picker rows, `ms: null` for a cadence with no recurrence), `ON_DEMAND_INTERVAL`, `JOB_INTERVAL_VALUES` (every legal stored cadence, incl. `custom`), `resolveIntervalMs(interval, customMs)` → ms or `null` (the no-interval sentinel — never falls through to `DAY`), and `isOnDemandJob(job)` for the three due/next-fire implementations. Lives here so `cosValidation.js` can validate the cadence without a lib → services import; `services/autonomousJobs/constants.js` re-exports it. Separate vocabulary from the scheduled-CoS-task `INTERVAL_TYPES`. |
-| `jobFormFields.js` | A scheduled agent job's own configuration form (pure). `JOB_FORM_FIELD_TYPES` (text/textarea/number/select/checkbox), the `jobFormFieldsSchema` / `jobFormValuesSchema` pair Zod-validates the job payload against, and the prompt projection `formatJobFormValues(fields, values)` / `appendJobFormValues(job, prompt)`. Definitions and values are stored separately so re-aiming a job (a new value) is not an edit to its design (a new field), and the projection iterates DEFINITIONS — a value whose field was deleted is inert. A field the user left blank is omitted rather than passed as an empty line, but a `false` checkbox is a real answer and is kept. Consumed by `services/autonomousJobs/skillTemplates.js`; the values reach the agent as the prompt's `## Run configuration` section. |
+| `jobFormFields.js` | A scheduled agent job's own configuration form (pure). `JOB_FORM_FIELD_TYPES` (text/textarea/number/select/checkbox), the `jobFormFieldsSchema` / `jobFormValuesSchema` pair Zod-validates the job payload against, and the prompt projection `formatJobFormValues(fields, values)` / `appendJobFormValues(job, prompt)`. Definitions and values are stored separately so re-aiming a job (a new value) is not an edit to its design (a new field), and the projection iterates DEFINITIONS — a value whose field was deleted is inert. A field the user left blank is omitted rather than passed as an empty line, but a `false` checkbox is a real answer and is kept. Consumed by `services/autonomousJobs/skillTemplates.js`; the values reach the agent as the prompt's `## Run configuration` section. `describeReaimedValues(fields, saved, run)` names the values a manual run changed, as the one-line description suffix that keeps a re-aimed run from colliding with a differently-aimed twin in `addTask`'s first-line dedupe. |
| `capabilityMap.js` | Pure row builders for Setup & Capabilities, including strict network/provider first-run readiness and optional-integration health rollups; fed by `routes/capabilities.js`. |
| `claimFlowTaskTypes.js` | `CLAIM_FLOW_TASK_TYPES` — the ONE list of task kinds whose prompts own their own `claim/<item>` worktree and push/PR/MR/review lifecycle (#6613). `services/cosTaskGenerator.js` stamps `metadata.claimFlow` from it (WRITE side); `services/agentPromptBuilder.js` reads it back through `isClaimFlowTask()` to pick a run's claim posture (READ side). It lived as two byte-identical copies, so a new claim type added to one silently split the writer from the reader — no error, just a claim run treated as a plain commit-only handoff; `claimFlowTaskTypes.test.js` fails if a local copy reappears. Imports nothing. |
| `chiptuneRender.js` | Deterministic chiptune score → mono PCM → 16-bit WAV buffer (pure Node, no audio deps); `renderScoreToPcm` / `pcmToWavBuffer` / `renderScoreToWav`. |
diff --git a/server/lib/jobFormFields.js b/server/lib/jobFormFields.js
index dce11bce86..d040fe4878 100644
--- a/server/lib/jobFormFields.js
+++ b/server/lib/jobFormFields.js
@@ -152,6 +152,50 @@ export function formatJobFormValues(fields, values) {
return parts.join('\n\n');
}
+// Bounds for the re-aim tag below. A description is a one-line human label, so a
+// pasted brief has to be clipped rather than inlined whole.
+const REAIM_MAX_FIELDS = 3;
+const REAIM_VALUE_CHARS = 40;
+
+/** The comparable form of a value: absent, null, and blank all read the same. */
+const comparableValue = (field, value) => (isSupplied(value) ? renderValue(field, value) : '');
+
+/**
+ * Name the run-configuration values that differ from the job's stored ones, as a
+ * one-line suffix for the task description. Returns `''` when nothing differs.
+ *
+ * This exists because `addTask` rejects a task whose FIRST DESCRIPTION LINE and
+ * target app match one already pending/in_progress/blocked, while
+ * `formatJobFormValues` appends the configuration to the END of the prompt — and
+ * the description is the prompt's first line. Without a discriminator, two
+ * differently-aimed manual runs of one on-demand job produce an identical first
+ * line, so the second is silently rejected as a duplicate of the first and the
+ * caller is told the run was queued. Re-aiming per trigger is the whole point of
+ * an on-demand job, so a re-aimed run is genuinely different work and its
+ * identity has to say so — the same reason that dedupe scopes on the target app.
+ *
+ * Returning `''` for an unchanged configuration is deliberate: running a job
+ * exactly as saved keeps the plain description it has always had, and so still
+ * dedupes against a queued twin (a double-clicked "Run now" is one piece of work).
+ */
+export function describeReaimedValues(fields, savedValues, runValues) {
+ if (!Array.isArray(fields) || fields.length === 0) return '';
+ const changed = fields.filter((field) => field?.key
+ && comparableValue(field, runValues?.[field.key]) !== comparableValue(field, savedValues?.[field.key]));
+ if (changed.length === 0) return '';
+
+ const parts = changed.slice(0, REAIM_MAX_FIELDS).map((field) => {
+ const label = String(field.label || field.key).trim();
+ // Collapse newlines: this rides on the description's FIRST line, and a
+ // multi-line value would push the rest out of the dedupe key entirely.
+ const text = comparableValue(field, runValues?.[field.key]).replace(/\s+/g, ' ').trim();
+ if (!text) return `${label}: (cleared)`;
+ return `${label}: ${text.length > REAIM_VALUE_CHARS ? `${text.slice(0, REAIM_VALUE_CHARS)}…` : text}`;
+ });
+ if (changed.length > REAIM_MAX_FIELDS) parts.push(`+${changed.length - REAIM_MAX_FIELDS} more`);
+ return parts.join(', ');
+}
+
/**
* Append the run configuration to a prompt. Returns the prompt unchanged when
* the job declares no fields or none were filled in, so a job that never uses
diff --git a/server/routes/cosJobRoutes.js b/server/routes/cosJobRoutes.js
index 77d8be33fb..d13d5d3957 100644
--- a/server/routes/cosJobRoutes.js
+++ b/server/routes/cosJobRoutes.js
@@ -13,6 +13,7 @@ import { asyncHandler, ServerError, failValidation } from '../lib/errorHandler.j
import { createCosJobSchema, updateCosJobSchema, triggerCosJobSchema } from '../lib/validation.js';
import { getTaskDataInputCatalog } from '../lib/taskDataInputCatalog.js';
import { generatedJobTaskFields } from '../lib/autonomousJobTask.js';
+import { describeReaimedValues } from '../lib/jobFormFields.js';
const router = Router();
@@ -205,6 +206,16 @@ router.post('/jobs/:id/trigger', asyncHandler(async (req, res) => {
? { ...job, formValues: { ...job.formValues, ...runFormValues } }
: job;
const task = await autonomousJobs.generateTaskFromJob(jobForRun);
+ const generated = generatedJobTaskFields(task);
+ // A re-aimed run is different work, and `addTask` dedupes on the description's
+ // first line + app — which the run configuration, appended to the END of the
+ // prompt, never reaches. Name the changed values there so aiming the same
+ // on-demand job somewhere else isn't swallowed as a duplicate of the run
+ // already queued (and reported to the caller as a success).
+ // Diff the MERGED values the run will actually use, not the request body: a
+ // caller that sends only the field it changed leaves the rest to the stored
+ // values, and diffing the partial body would report those as cleared.
+ const reaimed = runFormValues ? describeReaimedValues(job.formFields, job.formValues, jobForRun.formValues) : '';
// Forward the app scope + git-workflow options from the generated task's
// metadata. addTask maps these top-level keys back onto metadata; without
// them an app-scoped job triggered manually would run in the PortOS root
@@ -215,7 +226,8 @@ router.post('/jobs/:id/trigger', asyncHandler(async (req, res) => {
// no-change-success contract — so a manual trigger queues exactly what the
// scheduled path emits. Shared with the quota-burn lane
// (`quotaBurnInvoke.js`), which layers a different approval posture on top.
- ...generatedJobTaskFields(task),
+ ...generated,
+ ...(reaimed ? { description: `${generated.description} — ${reaimed}` } : {}),
context: `Manually triggered autonomous job: ${job.name}`,
approvalRequired: false
}, 'internal', { suppressDequeue: true });
diff --git a/server/routes/cosJobRoutes.test.js b/server/routes/cosJobRoutes.test.js
index 824c32310f..6f8a19c80b 100644
--- a/server/routes/cosJobRoutes.test.js
+++ b/server/routes/cosJobRoutes.test.js
@@ -565,6 +565,62 @@ describe('CoS Job Routes', () => {
expect(autonomousJobs.updateJob).not.toHaveBeenCalled();
});
+ it('names the re-aimed values in the description so a second aim is not deduped away', async () => {
+ const storedJob = {
+ id: 'j1',
+ type: 'agent',
+ name: 'Review',
+ formFields: [
+ { key: 'subject', label: 'Subject', type: 'text' },
+ { key: 'depth', label: 'Depth', type: 'text' }
+ ],
+ formValues: { subject: 'Saved subject', depth: 'shallow' }
+ };
+ autonomousJobs.getJob.mockResolvedValue(storedJob);
+ autonomousJobs.isShellJob.mockReturnValue(false);
+ autonomousJobs.isScriptJob.mockReturnValue(false);
+ autonomousJobs.generateTaskFromJob.mockResolvedValue({ description: 'Review', priority: 'MEDIUM' });
+ cos.addTask.mockResolvedValue({ id: 'task-1' });
+ cos.forceSpawnTask.mockResolvedValue({ success: true, taskId: 'task-1' });
+
+ await request(app).post('/api/cos/jobs/j1/trigger').send({ formValues: { subject: 'One-off subject' } });
+
+ // addTask dedupes on the description's FIRST LINE + app, and the run
+ // configuration rides at the end of the prompt where that key never
+ // reaches it — so without the changed value named here, aiming this job
+ // somewhere else while the first run is still queued is silently dropped.
+ expect(cos.addTask).toHaveBeenCalledWith(
+ expect.objectContaining({ description: 'Review — Subject: One-off subject' }),
+ 'internal',
+ expect.anything()
+ );
+ });
+
+ it('leaves the description alone when the run matches the saved configuration', async () => {
+ autonomousJobs.getJob.mockResolvedValue({
+ id: 'j1',
+ type: 'agent',
+ name: 'Review',
+ formFields: [{ key: 'subject', label: 'Subject', type: 'text' }],
+ formValues: { subject: 'Saved subject' }
+ });
+ autonomousJobs.isShellJob.mockReturnValue(false);
+ autonomousJobs.isScriptJob.mockReturnValue(false);
+ autonomousJobs.generateTaskFromJob.mockResolvedValue({ description: 'Review', priority: 'MEDIUM' });
+ cos.addTask.mockResolvedValue({ id: 'task-1' });
+ cos.forceSpawnTask.mockResolvedValue({ success: true, taskId: 'task-1' });
+
+ await request(app).post('/api/cos/jobs/j1/trigger').send({ formValues: { subject: 'Saved subject' } });
+
+ // Re-running a job as saved is the SAME piece of work, so it must keep the
+ // plain description and stay dedupable against the run already queued.
+ expect(cos.addTask).toHaveBeenCalledWith(
+ expect.objectContaining({ description: 'Review' }),
+ 'internal',
+ expect.anything()
+ );
+ });
+
it('rejects a malformed one-off run configuration', async () => {
autonomousJobs.getJob.mockResolvedValue({ id: 'j1', type: 'agent', name: 'Review' });
autonomousJobs.isShellJob.mockReturnValue(false);