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

Fail closed when CoS task state is unreadable before queueing a PR review

Adam Eivya1b78fee73e8
diff --git a/server/routes/apps/pullRequests.js b/server/routes/apps/pullRequests.js
index 43c7f8aec9..ecf5fad379 100644
--- a/server/routes/apps/pullRequests.js
+++ b/server/routes/apps/pullRequests.js
@@ -278,6 +278,15 @@ router.post('/:id/pull-requests/:number/review', loadApp, asyncHandler(async (re
}
const [tasks, requests] = await Promise.all([readActiveTasks(), readPendingOnDemandRequests()]);
+ // Fail CLOSED on an unreadable task store, matching /resolve: `reviewActionFor`
+ // reads a null task list as "no run in flight", so queueing anyway would spend a
+ // second model-abuse scan and code review on a public PR already being reviewed.
+ if (tasks === null) {
+ throw new ServerError('Could not inspect existing CoS actions before queueing this review', {
+ status: 503,
+ code: 'AGENT_ACTION_UNAVAILABLE',
+ });
+ }
const existing = reviewActionFor({ number }, tasks, requests, app.id);
if (existing) {
res.json({ appId: app.id, appName: app.name, number, reviewAction: existing, duplicate: true });
diff --git a/server/routes/apps/pullRequests.test.js b/server/routes/apps/pullRequests.test.js
index 5e8e5e80ea..4db8b15dba 100644
--- a/server/routes/apps/pullRequests.test.js
+++ b/server/routes/apps/pullRequests.test.js
@@ -283,6 +283,16 @@ describe('app pull-request routes', () => {
expect(triggerOnDemandTask).not.toHaveBeenCalled();
});
+ it('fails closed when CoS task state cannot be read before queueing a review', async () => {
+ getAllTasks.mockRejectedValue(new Error('task store unavailable'));
+
+ const response = await request(app).post('/api/apps/app-001/pull-requests/17/review');
+
+ expect(response.status).toBe(503);
+ expect(response.body.code).toBe('AGENT_ACTION_UNAVAILABLE');
+ expect(triggerOnDemandTask).not.toHaveBeenCalled();
+ });
+
it('returns the in-flight pr-reviewer run instead of queuing a second one', async () => {
getAllTasks.mockResolvedValue({
user: { tasks: [] },