Files
PaperClipAI/server
DottaandPaperclip 3e8e1efb84 refactor(server): isolate inbound channel message policies (#16230)
## Thinking Path

> - Paperclip helps people manage AI agents for work.
> - Chat channels turn provider messages into shared task workflows.
> - The main service still implements provider details beside common
authorization and persistence.
> - These details belong in the existing channel folders.
> - This pull request moves inbound message filtering, command
rendering, reply metadata, and setup-reply settlement behind explicit
typed functions.
> - The service keeps its shared workflow and selects the provider
implementation directly.

## Linked Issues or Issue Description

Refs: #16192. Stack part 1/5. Base: `master`.

**What existing behavior does this improve?**

The ownership and readability of provider behavior in the chat channel
service.

**Current behavior**

The service implements inbound message filtering, command rendering,
reply metadata, and setup-reply settlement inline.

**Proposed behavior**

Channel modules own these details. The core calls their typed functions.
Runtime and database effects retain their current order.

**Reason and benefit**

Maintainers can find channel behavior in its channel folder without
following a generic provider framework.

**Breaking changes**

None intended. Public service entry points and durable data shapes stay
compatible.

## What Changed

- Extract inbound message filtering, command rendering, reply metadata,
and setup-reply settlement into the existing channel folders.
- Keep shared company scope, authorization, and transaction ownership in
their current workflow.
- Reduce `chat-channels.ts` from 4082 to 3970 lines.

## Verification

- The same 14 selected chat/Photon integration cases passed before and
after extraction, including Telegram forum controls, guidance retries,
Teams setup replies, and Photon conversation reuse.
- Server typecheck passed.
- `node scripts/check-module-boundaries.mjs` passed.
- Full workspace typecheck and build passed on the cumulative stack. All
current-head CI gates passed. Greptile completed at 5/5 with no
findings.
- The full local `pnpm test:run` command exited with three database
fixture-startup hook timeouts. It reported 19,529 passing tests and 250
skipped tests. No assertion failed. Its later test groups did not run
because the driver stops on the first failing group.
- The timed-out files were `environment-custom-images-service.test.ts`,
`generic-mcp-connection.test.ts`, and
`modules/wake-queue/adapters/postgres.test.ts`. All 166 tests in these
files passed in isolation on both baseline `edcfcaf3f6` and stack head
`faaca26d46`, with existing timeouts and assertions. The tests and
database-startup helper are unchanged.
- Provider fixtures prove application integration. They do not prove
live third-party execution.

## Risks

- Incorrect inputs or changed await order could affect provider handling
and recovery.
- Existing integration tests exercise the assembled service before and
after extraction.
- No database migration or API change is included.

## Model Used

OpenAI GPT-6, running in Codex with reasoning, tool use, and code
execution. The exact deployment identifier and context-window size are
not exposed in this session.

## 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
- [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>
2026-10-13 20:44:29 -05:00
..