fix: encapsulate mutable draining/drainScheduled flags in render-queue.ts #1140

Closed
opened 2026-05-13 21:28:08 +00:00 by claude-desktop · 0 comments
Collaborator

As a developer maintaining the agent-env-sync pipeline, I want the mutable draining and drainScheduled flags in render-queue.ts to be encapsulated, so that the queue state is self-contained and the control flow is obvious to a reader unfamiliar with the module.

Current state

  • apps/server/src/infrastructure/agent-env-sync/render-queue.ts lines 75 and 82 expose two bare let flags at module scope
  • The drain loop at lines 88–121 reads/writes these flags with no guard primitive
  • JavaScript single-threading prevents races today, but the pattern is fragile if Bun workers are ever introduced

Fix

  • Wrap queue state (pending items + draining + drainScheduled) in a single closure or class exported as a singleton
  • All state mutations go through the closure/class methods — no bare module-level lets

Out of scope

  • Changing the queue's public API (enqueue, drain)
  • Parallelising renders (single-queue behaviour preserved)

References

  • apps/server/src/infrastructure/agent-env-sync/render-queue.ts:75,82
  • Codebase audit 2026-05-13
As a developer maintaining the agent-env-sync pipeline, I want the mutable `draining` and `drainScheduled` flags in `render-queue.ts` to be encapsulated, so that the queue state is self-contained and the control flow is obvious to a reader unfamiliar with the module. ### Current state - `apps/server/src/infrastructure/agent-env-sync/render-queue.ts` lines 75 and 82 expose two bare `let` flags at module scope - The drain loop at lines 88–121 reads/writes these flags with no guard primitive - JavaScript single-threading prevents races today, but the pattern is fragile if Bun workers are ever introduced ### Fix - [ ] Wrap queue state (pending items + `draining` + `drainScheduled`) in a single closure or class exported as a singleton - [ ] All state mutations go through the closure/class methods — no bare module-level `let`s ### Out of scope - Changing the queue's public API (`enqueue`, `drain`) - Parallelising renders (single-queue behaviour preserved) ### References - `apps/server/src/infrastructure/agent-env-sync/render-queue.ts:75,82` - Codebase audit 2026-05-13
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/agent-hooks#1140
No description provided.