Repository navigation
Make ZenFlow standalone with authoritative Firestore persistence - #2
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 52e9c8f18b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (req.method === 'GET' && ['/events', '/audit/download'].includes(req.path)) { | ||
| options.failed(); next(); unlock(); return; | ||
| } | ||
| res.once('finish', () => { if (!responding) { options.failed(); unlock(); } }); |
There was a problem hiding this comment.
Normalize streaming routes before acquiring the workspace lock
An authenticated GET /api/events/ reaches the SSE handler because Express uses non-strict routing, but /events/ does not match this exemption. The request therefore retains the process-wide workspace lock for the lifetime of the stream, blocking subsequent workspace API requests. Disconnecting does not recover it either: the SSE handler cleans up on close, while this middleware only unlocks on finish. Normalize trailing slashes consistently with the authorization middleware and ensure aborted streams release their lock.
Useful? React with 👍 / 👎.
| }) as Response['json']; | ||
| // SSE and read-only downloads own their stream after the handler starts. | ||
| if (req.method === 'GET' && ['/events', '/audit/download'].includes(req.path)) { | ||
| options.failed(); next(); unlock(); return; |
There was a problem hiding this comment.
Retain snapshot isolation through the SSE authorization handshake
When an SSE connection overlaps another mutation, next() enters the asynchronous second createApiSecurity middleware in server.ts, but this immediately releases the workspace lock without waiting for authorization or snapshot serialization. A subsequent mutation can replace and modify the global store while that verification is pending, so the SSE handler's initial snapshot can publish uncommitted changes. If the database commit then fails, rollback sends no corrective event and the connected browser retains data that was never saved. Keep the handshake under the lock or serialize a request-local committed snapshot instead of reading the mutable global store afterward.
AGENTS.md reference: AGENTS.md:L12-L12
Useful? React with 👍 / 👎.
| // Preserve original task metadata for recovery, excluding saved credentials. | ||
| const backup = Object.fromEntries(Object.entries({ ...doc.data(), id: doc.id }) | ||
| .filter(([key]) => !/apikey|secret|token/i.test(key))); | ||
| batch.set(this.db.doc(`workspace_backups/native-v1/${collection}/${doc.id}`), backup); |
There was a problem hiding this comment.
Preserve existing migration backups when retrying startup
If startup fails after any migration batch commits but before the completion marker is written, the next startup processes those documents again. Their integration metadata has already been deleted, and this unconditional batch.set overwrites the original backup with the cleaned document, permanently losing the metadata retained for recovery. This also occurs if deleting the retired webhook registry fails after all document batches succeed. Make backup creation and per-document migration restart-safe without replacing an existing original backup.
AGENTS.md reference: AGENTS.md:L13-L13
Useful? React with 👍 / 👎.
| app.use('/api', (req, res, next) => { | ||
| if (['/auth/session', '/health'].includes(req.path)) return next(); | ||
| return createApiSecurity({ getStore: () => store, verify: verifyIdentity })(req, res, next); |
There was a problem hiding this comment.
Rate-limit session requests before loading the workspace
Anonymous requests to /api/auth/session bypass the initial security gate and enter workspaceMiddleware, which reads every user and task before the session handler checks the origin, token, or rate limit. Since authLimiter is registered after this database middleware, even requests exceeding its 20-per-minute allowance still incur a full snapshot read and occupy the shared request queue. An unauthenticated client can therefore exhaust Firestore read quotas and delay legitimate operations without obtaining a valid identity. Apply the session rate limiter and reject invalid authentication inputs before loading the workspace.
AGENTS.md reference: AGENTS.md:L1003-L1003
Useful? React with 👍 / 👎.
| }); | ||
|
|
||
| // API: Get entire state with ETag conditional validation (HTTP 304 Not Modified) | ||
| app.get('/api/state', (req: Request, res: Response) => { | ||
| maybeArchive(); | ||
| autoArchiveDoneTasks(); |
There was a problem hiding this comment.
Bound automatic archival before committing state reads
If at least 250 tasks are eligible for automatic archival, /api/state and /api/tasks modify all of them and create one audit record per task before responding. The new commit limit then rejects the operation because 250 task writes plus 250 audit writes and the revision require 501 writes. Rollback leaves every task eligible, so every subsequent state/tasks read repeats the same failure and returns 503 rather than recovering. Bound each archival sweep to the available write budget or perform bounded archival transactions separately so a backlog cannot prevent workspace reads.
AGENTS.md reference: AGENTS.md:L479-L479
Useful? React with 👍 / 👎.
| const keydown = (event: KeyboardEvent) => { if (event.key === 'Escape') onClose(); }; | ||
| window.addEventListener('keydown', keydown); | ||
| return () => window.removeEventListener('keydown', keydown); | ||
| }, [isOpen, onClose, refreshFirestoreStatus]); |
There was a problem hiding this comment.
Separate modal initialization from the unstable close callback
Opening Workspace & Compliance starts a continuous status-fetch loop: App.tsx passes an inline onClose, while refreshFirestoreStatus() updates the provider's firestoreStatus with a newly parsed object. That context update rerenders DashboardContent, creates another onClose, and reruns this effect, issuing another refresh and clearing the audit logs again. Each successful response perpetuates the loop, repeatedly reading the entire Firestore workspace through /api/firestore/status and preventing loaded audit history from remaining visible. Separate the opening/reset effect from the Escape listener or stabilize the parent's close callback.
Useful? React with 👍 / 👎.
Removes ClickUp synchronization, webhooks, API proxies, credentials and UI mapping/destination controls. Members, tasks, timers, activity history and audit records persist in Firestore; atomic commits complete before success responses and SSE, and failed writes roll back.
Includes a private metadata backup and migration that preserves native IDs, ownership and parent links. Local JSON/NDJSON storage and browser credential upload are removed. Migrated 28 historical audit records to Firestore and retired repository data files. Railway health probes Firestore.
Validation: 24 local tests, strict TypeScript and production build passed. Linux CI passed the complete rule-denial suite plus Firestore/Auth emulator migration, atomicity/conflict, compiled-server CRUD, delegation, audit export, restart and deletion-recovery checks. Production preflight recorded 4 members and 139 tasks for post-deploy comparison. See docs/READINESS.md for write limits, read costs and recovery.