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: surface a JIRA sprint-fetch failure from the API instead of answering 200 with an empty list (#3437)

[._.]/ Adam Eivy14b76b05a75f
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index b6e8f31ba6..b7704b08d8 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -8,7 +8,7 @@
## Fixed
-- **[issue-3437] A failed JIRA sprint-ticket fetch no longer reads as "No tickets assigned to you".** Expanding a JIRA-enabled app row substituted `[]` for a thrown request and cached it, so an unreachable instance, an expired token, or a wrong project key all rendered as an authoritative empty sprint — and because the `!jiraTickets[id]` guard was satisfied by that cached empty array, the page never retried for the rest of its life. Failure now records a message in a parallel `ticketErrors` map and leaves the ticket entry unset (the `null = not fetched` vs `[] = fetched-and-empty` sentinel rule), so the panel renders three distinct states — loading, "Couldn't load sprint tickets — <message>" with a **Retry** button, and the genuine empty case — and both Retry and a re-expand re-issue the request. A successful empty result is still cached, since JIRA calls are slow and rate-limited. The fetch passes `{ silent: true }` now that this path owns its error UI. The app-detail Overview tab ran the same swallow-into-`[]` fetch on mount and gets the same treatment.
+- **[issue-3437] A failed JIRA sprint-ticket fetch no longer reads as "No tickets assigned to you".** Expanding a JIRA-enabled app row substituted `[]` for a thrown request and cached it, so an unreachable instance, an expired token, or a wrong project key all rendered as an authoritative empty sprint — and because the `!jiraTickets[id]` guard was satisfied by that cached empty array, the page never retried for the rest of its life. Failure now records a message in a parallel `ticketErrors` map and leaves the ticket entry unset (the `null = not fetched` vs `[] = fetched-and-empty` sentinel rule), so the panel renders three distinct states — loading, "Couldn't load sprint tickets — <message>" with a **Retry** button, and the genuine empty case — and both Retry and a re-expand re-issue the request. A successful empty result is still cached, since JIRA calls are slow and rate-limited. The fetch passes `{ silent: true }` now that this path owns its error UI. The server was swallowing it too — `GET /api/jira/instances/:id/my-sprint-tickets/:key` called the soft `getMyCurrentSprintTickets` wrapper and answered `200 []` for an unreachable instance, so no client fix alone could have worked; the route now calls the strict `fetchMyCurrentSprintTickets` and returns 502 `JIRA_FETCH_FAILED` (non-UI callers that genuinely want a soft failure keep the wrapper). The app-detail Overview tab ran the same swallow-into-`[]` fetch on mount and gets the same treatment.
- **[issue-3436] Archiving an app no longer reports success when the request failed.** `handleArchive` / `handleUnarchive` on `/apps` swallowed the failure with `.catch(() => null)` and then fired their success toast unconditionally — so a failed archive showed the red "Request failed" toast from `request()` immediately followed by a green "<app> archived", and the last one read won. The user was told an app was excluded from CoS scheduling when it was not. Both handlers now gate the toast on a response, matching `handleBuild` in the same file, and update the row's archived state locally on success instead of waiting for the `apps:changed` round-trip. The app-detail Overview tab carried the identical bug and is fixed with it.
- **[issue-3435] A running app Update no longer vanishes when you collapse the row or leave `/apps`, and can't be dispatched twice.** The Update / Standardize flow (git pull → npm install → setup → PM2 restart, minutes long) rendered its step log *inside* the expanded row, and the hook tracking it held `isOperating` / `steps` in page state whose unmount tore down the socket listeners — so collapsing the row or navigating away left a long-running operation with no indicator anywhere, and the second dispatch that invited ran a concurrent `npm install` against the same checkout. The server now owns the in-flight set: a module-level map keyed by app id rejects a second `app:update` / `app:standardize` for an app already operating (a re-entrancy guard, not a lock), buffers the steps emitted so far, and broadcasts progress with `io.emit` instead of replying only to the socket that dispatched. Clients rehydrate from `app:operations:active` — pushed on connect and on demand via `app:operations:list` — so a page that mounts mid-operation restores the whole log. `/apps` renders that state in a sticky page-level banner naming the app (`Updating <app>…`) above the list instead of inside the row, and a row blocked only by another app's operation now reads `Update (busy)` rather than being silently greyed out. Operations are tracked per app id, so two apps operating from different tabs each get their own banner instead of one shadowing the other, and the app-detail Overview tab passes its own `appId` so it still reports only its own operation. The guard also matches on `repoPath`, since two app records can point at the same checkout; a refused dispatch is flagged `duplicate` so the client toasts it without marking the healthy run failed; and a completion carrying `success: false` now reads as a failure instead of "Operation complete".
- **A successful `branch-cleanup` run is no longer recorded as a failure.** The task deletes merged branches in the app's live checkout — its prompt `cd`s to the repo path and runs `git branch -d` / `git push --delete` — but it was the only git/gh coordinator type shipping with no `taskMetadata` at all, so `applyAppWorktreeDefault` filled `useWorktree`/`openPR` from the app's `defaultOpenPR: true`. Every run got a CoS-managed worktree it never touched (one that holds the very refs it was trying to delete) and a PR expectation it could never satisfy, and finalization scored the completed run `pr-missing`. The four non-committing coordinator types — `branch-cleanup`, `branch-reconcile`, `issue-reconcile`, `jira-status-report` — now share one documented `taskMetadata` posture: `useWorktree`/`openPR` explicitly `false` (not merely absent, which is what let the app defaults in) *and* locked via `MANAGED_AGENT_OPTIONS` so a per-app override can't re-attach them, plus `worktreeChangesExpected: false`, because a clean tree is the success shape for a branch deletion or a posted report and the TUI idle-complete gate must not read it as "the model produced no work". `jira-status-report` was hit by the same bug for a subtler reason: its `readOnly: true` skips worktree *creation* but the finalize-time PR-claim check reads `metadata.openPR` directly, so a posted report still scored `pr-missing`. A guard test now iterates `NON_COMMITTING_COORDINATOR_TASK_TYPES` — the set that already grants these types their commit-criterion exemption — so a future coordinator type can't be added to one list and not the other. Existing installs pick all of this up on the next schedule load: the taskMetadata deep-merge backfills the new keys and `enforceManagedAgentOptions` rewrites any stored `true`.
diff --git a/server/routes/jira.js b/server/routes/jira.js
index 109fbc703d..eea87e1528 100644
--- a/server/routes/jira.js
+++ b/server/routes/jira.js
@@ -221,10 +221,20 @@ router.post('/instances/:instanceId/tickets/:ticketId/transition', asyncHandler(
* Get tickets assigned to current user in active sprint for a project
*/
router.get('/instances/:instanceId/my-sprint-tickets/:projectKey', asyncHandler(async (req, res) => {
- const tickets = await jiraService.getMyCurrentSprintTickets(
+ // STRICT variant on purpose (#3437): the UI has to tell "the fetch failed"
+ // apart from "the sprint is empty", and the swallow-to-[] wrapper made that
+ // impossible — an unreachable instance rendered as "No tickets assigned to
+ // you" with no retry. Non-UI callers that genuinely prefer a soft failure
+ // (voice/character context) keep using getMyCurrentSprintTickets.
+ const tickets = await jiraService.fetchMyCurrentSprintTickets(
req.params.instanceId,
req.params.projectKey
- );
+ ).catch(err => {
+ throw new ServerError(`JIRA sprint fetch failed: ${err.message}`, {
+ status: 502,
+ code: 'JIRA_FETCH_FAILED'
+ });
+ });
res.json(tickets);
}));
diff --git a/server/routes/jira.test.js b/server/routes/jira.test.js
new file mode 100644
index 0000000000..483cff4595
--- /dev/null
+++ b/server/routes/jira.test.js
@@ -0,0 +1,84 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import express from 'express';
+import { request } from '../lib/testHelper.js';
+
+vi.mock('../services/jira.js', () => ({
+ getInstances: vi.fn(),
+ upsertInstance: vi.fn(),
+ deleteInstance: vi.fn(),
+ testConnection: vi.fn(),
+ getProjects: vi.fn(),
+ createTicket: vi.fn(),
+ updateTicket: vi.fn(),
+ addComment: vi.fn(),
+ getTransitions: vi.fn(),
+ deleteTicket: vi.fn(),
+ transitionTicket: vi.fn(),
+ getMyCurrentSprintTickets: vi.fn(),
+ fetchMyCurrentSprintTickets: vi.fn(),
+ getBoardColumns: vi.fn(),
+ getActiveSprints: vi.fn(),
+ getBoards: vi.fn(),
+ getIssue: vi.fn(),
+ searchEpics: vi.fn()
+}));
+vi.mock('../services/jiraReports.js', () => ({
+ listReports: vi.fn(),
+ generateReport: vi.fn(),
+ generateAllReports: vi.fn(),
+ getLatestReport: vi.fn(),
+ getReport: vi.fn()
+}));
+vi.mock('../services/apps.js', () => ({ getAppById: vi.fn() }));
+
+import * as jiraService from '../services/jira.js';
+import { errorMiddleware } from '../lib/errorHandler.js';
+import jiraRoutes from './jira.js';
+
+function makeApp() {
+ const app = express();
+ app.use(express.json());
+ app.use('/api/jira', jiraRoutes);
+ app.use(errorMiddleware);
+ return app;
+}
+
+describe('GET /instances/:instanceId/my-sprint-tickets/:projectKey', () => {
+ let app;
+ beforeEach(() => {
+ app = makeApp();
+ vi.clearAllMocks();
+ });
+
+ it('returns the sprint tickets', async () => {
+ jiraService.fetchMyCurrentSprintTickets.mockResolvedValue([{ key: 'EX-1', summary: 'Example ticket' }]);
+
+ const r = await request(app).get('/api/jira/instances/jira-1/my-sprint-tickets/EX');
+
+ expect(r.status).toBe(200);
+ expect(r.body).toEqual([{ key: 'EX-1', summary: 'Example ticket' }]);
+ });
+
+ it('returns an empty sprint as an empty list, not an error', async () => {
+ jiraService.fetchMyCurrentSprintTickets.mockResolvedValue([]);
+
+ const r = await request(app).get('/api/jira/instances/jira-1/my-sprint-tickets/EX');
+
+ expect(r.status).toBe(200);
+ expect(r.body).toEqual([]);
+ });
+
+ it('surfaces a fetch failure instead of answering 200 with an empty list (#3437)', async () => {
+ // The swallow-to-[] wrapper made an unreachable instance indistinguishable
+ // from an empty sprint, so the UI stated "No tickets assigned to you".
+ jiraService.fetchMyCurrentSprintTickets.mockRejectedValue(new Error('connect ECONNREFUSED'));
+
+ const r = await request(app).get('/api/jira/instances/jira-1/my-sprint-tickets/EX');
+
+ expect(r.status).toBe(502);
+ expect(r.body.code).toBe('JIRA_FETCH_FAILED');
+ expect(r.body.error).toContain('connect ECONNREFUSED');
+ // The soft wrapper must not be what the UI route calls.
+ expect(jiraService.getMyCurrentSprintTickets).not.toHaveBeenCalled();
+ });
+});