mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-16 11:59:26 +01:00
## Thinking Path > - Paperclip runs agents and connects their work to chat services. > - Discord command registration uses a shared worker and saved deadlines. > - A task drain can hold that worker while registration is already due. > - The coordinator can keep a 30-second fallback after the drain ends. > - This change refreshes the command owner on drain release or observed expiry. > - Normal admission, earliest-time and provider retry checks still apply. ## Linked Issues or Issue Description Refs: #17557, #21562. Related: #15532 checks credential reads when registration is not due. This change handles resumption of due work in the separate command worker. **What happened?** A due command registration can wait for the coordinator's fallback after a task drain ends. The worker retains the request but has no drain-release subscription. This delays command work and its return to an idle state. **Expected behavior** Resume due command work when admission returns. Preserve future earliest times and provider failure backoffs. Leave an empty or stopped worker idle. **Steps to reproduce** 1. Register the normal command worker while an idle task drain is active. 2. Retain a due registration and capture the coordinator's fallback. 3. Release the drain, or observe its expiry, before that fallback. 4. Check that the due endpoint is checked before the fallback. Both regression cases fail before this change. **Paperclip version or commit** Main base `3c15acd3fc1b200ef0e36ac904a03cd5fcba00c0`. **Deployment mode** Built from source. The focused tests use the real coordinator and command owner with controlled registration operations. They do not contact Discord. ## What Changed - Subscribe the command owner to normal drain changes and observed expiry. - Wake it only when current admission allows work and its existing next time is due. - Remove both subscriptions through the normal worker stop callback. - Add eight controls for release, expiry, another closed gate, future earliest time, provider backoff, empty state and both stop paths. ## Verification Local checks used the integrated branch that exposed this contract gap. This main port contains the same two tested file afterimages. Its admission, scheduler and fairness modules match those local inputs. Main's coordinator and DB modules have other changes. Fresh CI on `aec6ecc65717aa6372bad526e044ec4aa3888bec` now qualifies this main context. - Both release and expiry cases fail at the intended missing endpoint-check assertion before the product change. No setup or timeout failure is used as causal proof. - All eight focused cases pass after the change. No case is excluded. - The complete normal Server typecheck and affected-file program checks pass on the integrated branch. - Normal committed Source SDK verification passes on this main branch. - Exact-head main CI passes, including typecheck, build, the general and serialized suites, and all eight new controls (142 ms) in server shard 2/12. [CI run](https://github.com/paperclipai/paperclip/actions/runs/43565579653). A full local repository build and suite were not run in this checkout. - Greptile reviewed the exact head at 5/5 with no actionable findings. The complete edited summary and all paginated review threads were inspected; no unresolved threads remain. Run the focused controls with: ```sh pnpm --filter @paperclipai/server exec vitest run src/services/chat-channels/discord/command-work.test.ts --maxWorkers=1 --no-file-parallelism --retry=0 ``` The existing admission-drain contract remains accurate. This fix adds no configuration or command, so no documentation change is required. Full transport sleep acceptance and deployed suspension are separate claims. ## Risks A release event can request an earlier pass for already due work. The existing `canRun`, earliest-time, batching and per-item backoff checks remain active. Both worker stop and coordinator stop must remove the subscriptions; the controls cover each path. No scheduler policy, claim or provider deadline changes. ## Model Used OpenAI `gpt-6.1-sol` assisted with implementation and independent review. The Codex managing agent performed technical review and verification. The host does not expose its exact runtime model ID or context-window size. Work used source inspection, code edits and local test execution. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes (not required: the existing contract remains accurate) - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge Co-authored-by: Paperclip <noreply@paperclip.ing>