oliver-zehentleitner / maity

clean-up: G4 resume and briefing view: shared builders for what an agent is told, one rules call, fewer repeated reads in the packet

Sign in to report

tsk-xvj1ytw9tm08 Open

From the clean-up audit tsk-hgnbapyw7hnh (uncovered files, G4 Members, projects, joins and briefing), read at 9dfd4b65. Line numbers are at that SHA. Paths are under hub/src/maity_hub/.

1. Duplication / design: the resume packet and the briefing view build the same parts twice

  • Kind: duplication, design.
  • Files:
  • me block: routes/me_session.py:605-623 (_packet), :433-439 (_isolated_packet), routes/briefing_view.py:108-123 (_me).
  • project head {id, full_name, slug, name, state}: me_session.py:441-447, :664-669; briefing_view.py:167-173.
  • the isolated agent's small packet: me_session.py:421-448 and briefing_view.py:159-174.
  • setup: me_session.py:739-742 (_setup_block) and briefing_view.py:192, :223.
  • guide.of(..., restricted=told.id in restricted.resolve(...)): me_session.py:634-640 and briefing_view.py:201-207.
  • keep_the_why: me_session.py:690-699 and briefing_view.py:224-227. me_session.py:120 KEEP_THE_WHY_INSTRUCTION = rules.KEEP_THE_WHY is an alias used once (:698); briefing_view uses rules.KEEP_THE_WHY.
  • What is wrong: §19.3.1 (docs/api.md:23815) says the view is computed "as a resume of that membership would compute them now". hub/context/memory.md entry 2b6f40c8 says the view calls the same pieces as the packet (memory.compact_block, preferences.texts, guide.of, rules.generate). The parts above are not such pieces: each is written twice, and only test_briefing_view.py:158 holds one part (the Keep the Why instruction) equal.
  • Proposal: a small domain module (for example told.py) with me_block(conn, agent, owner, credential), project_head(conn, project), isolated_packet(...), setup_block(conn, project), guide_block(conn, project, membership, bridging) and keep_the_why_block(...). Both routes build from it. Keep the context entry's rule: no reuse of _packet itself. Drop KEEP_THE_WHY_INSTRUCTION. Add a test that the shared parts are equal for one membership.
  • Effort: M. Risk: low to medium (the packet shape is pinned by test_resume and test_contract_shapes).

2. Design / duplication: arbiter_text lives in a route module, and the rules call is written three times

  • Kind: design, duplication.
  • Files: routes/projects.py:1628-1635 (arbiter_text), imported by routes/me_session.py:72 and routes/briefing_view.py:40. The call rules.generate(project, trust, role, arbiter_text(conn, project), supervised=..., bridging=bool(bridges.views(conn, [id])[id]["bridging_for"])) is at routes/projects.py:1612-1620, routes/me_session.py:489-496 and routes/briefing_view.py:213-220.
  • What is wrong: two route modules import a third for a rules helper. The three calls must agree on what the rules say to a member.
  • Proposal: move arbiter_text into rules.py; add rules.for_member(conn, project, membership, *, supervised) that computes the arbiter text and the bridging flag. The three routes call it (the resume passes its bridging_for, which it needs anyway).
  • Effort: S. Risk: low (test_rules_review, test_resume).

3. Debt (repeated reads): _packet reads the same rows several times

  • Kind: slow path on a hot route (every resume).
  • Files: routes/me_session.py: the caller's credential row is read by _credential at :614 and :632 and again inline at :693-696; namespace.full_name(conn, project) runs at :647, :666 and :716 (each a query).
  • Proposal: read the credential and the full name once at the top of _packet and pass them on.
  • Effort: S. Risk: none.

Order

  • Item 3 together with, or after, tsk-tnmcav72bhg9 item 2 (packet built outside the project lock); both move the same code.
  • Item 1 after item 2 (it uses rules.for_member).

Covered elsewhere

  • Unbounded _requests_block (me_session.py:752-756 loads every request of the project): tsk-tnmcav72bhg9 item 3.
  • in_set written inline at briefing_view.py:206 and me_session.py:639: tsk-5whysgm79amz item 11.
  • Preferences N+1 in packet and texts: tsk-kwfr5gs7tz82 item 5.
  • §19.3.1 lists discuss_first, agent and the soul outline with rollback_of, which the view does not build yet: contract ahead of code, on tsk-ssd3gcxvnrkm (layered briefings) and tsk-d2jhza7mv0jh (soul versions).
  • Searched: arbiter_text, briefing_view, KEEP_THE_WHY_INSTRUCTION.

Effort sum: M + 2S, about 5 points.