Split monolithic workbench/server.py into resource route modules and a shared error registry

Open
#424 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
postgresql, python
Domain
backend, testing

Research direction

Read research_multiplier/workbench/server.py to map its route dispatch, duplicated error mappings, security checks, and transaction helpers before extracting modules under research_multiplier/workbench/. Use scripts/architecture_map.py to identify the required module boundaries, then verify the refactor with python scripts/architecture_map.py check, pytest -m offline, tests/offline/test_workbench_server.py, and the PostgreSQL route/workbench regressions.

Written by the indexing model from the issue text.

Description

difficulty:d3 layer:entry priority:p2 status:ready type:refactor

Task difficulty and Agent fit

  • D3 · 8/15. Scope 2, uncertainty 1, impact 2, verification 2, dependencies 1. Behavior-preserving modularization of research_multiplier/workbench/server.py (1,475 lines) into domain route modules and a shared error registry.
  • Recommended configuration. Codex / gpt-6.2-sol / xhigh, 50 and $0.90 per benchmark task. Floor 50 in the Artificial Analysis Coding Agent Index v2.1. Trellin snapshot checked 2026-11-22.
  • Required skills and verification. Python HTTP server refactoring, security boundary preservation, scripts/architecture_map.py, full offline and PostgreSQL workbench route test suites.
  • Scored baseline. c7f731b on main.

Problem

research_multiplier/workbench/server.py has grown to 1,475 lines and concentrates 50+ HTTP routes inside monolithic if/elif chains (_read_api, do_POST, _get_v1, _post_v1) alongside ~18 separate exception-to-HTTP-status maps duplicated across GET, POST, and v1 handlers.

Because nearly every backend feature PR adds or edits routes in server.py (including #341, #363, #364, #370, #371, #376, #404, #405, #406, #408, #414, #416), it has become the primary merge-conflict hotspot across parallel backend work and makes it easy to miss an error branch or security guard when adding a route.

Scope

  • Keep WorkbenchServer lifecycle, session/origin/host security enforcement (_trusted, _authorized), JSON body bounds, Cache-Control: no-store, and transaction helpers (read, write, write_project) in one clear core.
  • Extract domain route registration / dispatch into focused modules under research_multiplier/workbench/ (for example: v1 workspace routes, intake & review routes, squad & agent-work routes, proof/canvas/library routes) so parallel feature work touches isolated route modules.
  • Centralize error-class-to-status mapping (including sanitized DatabaseOperationError and fallback codes) into one table-driven error registry shared by GET and POST paths, eliminating duplicated except / elif self.path == ... branches.
  • Preserve 100% of existing HTTP routes, status codes, JSON shapes, headers, and security invariants (zero behavior changes).
  • Regenerate docs/architecture-map.md and pass python scripts/architecture_map.py check (A1–A3).

Acceptance criteria

  • research_multiplier/workbench/server.py is reduced from its monolithic dispatch/error-mapping structure into focused modules under research_multiplier/workbench/ with a single shared error-mapping registry.
  • Every existing /api/* and /api/v1/* route preserves its exact HTTP method, query/body validation, session/origin checks, status codes, headers, and error payloads.
  • python scripts/architecture_map.py check passes with updated docs/architecture-map.md and zero new layering violations.
  • Full offline suite (pytest -m offline), tests/offline/test_workbench_server.py, and CI PostgreSQL route/workbench regressions pass unchanged.

Related: #11, #226.

Dominant language
Python
Stars
2
Forks
0
Avg merge
56m
Merged PRs (30d)
190

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SAFuDarren/Trellin

All issues in SAFuDarren/Trellin

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.