← Back to Pull requests

Add # references to host objects and free-typed @handles #6

Closed
unknown closed this pull request without merging on Oct 31, 2026 20:15 UTC
View on GitHub
unknown unknown commented on Oct 31, 2026 19:53 UTC
Author

What

Adds pluggable # references from chat messages to host objects (the first host is Comply 100: #B3.2 for requirements, #0001 for risks), and free-typed @handle mentions. These are the two features requested together; the work is split into one ADR per decision.

Details

# references to host objects


  • Resolver hook. huddle.references.ReferenceResolver (one subclass per kind), registered in the new HUDDLE_REFERENCE_RESOLVERS setting and loaded into a cached ReferenceRegistry. A resolver implements search(channel, user, query, *, limit), resolve_code(channel, user, code) and get(channel, user, ids), and can override code / label / url / object_id.

  • Encoding (ChatService.encode, MessageMarkup.encode). #code becomes <#kind:id>. Picked kind:id tokens are used first (if the sender may see them), then free-typed codes go to the resolvers. Unknown or unauthorised codes stay plain text, and a hand-typed <#…> is neutralised just like <@…>.

  • Storage. A new MessageReference model (message, kind, object_id, optional content_type/target), migration 0002, plus for_target() / visible_to() lookups. Rows are kept in step with edits and deletes. The new reference_added(message, reference, target) signal fires after commit, once per newly referenced object.

  • Rendering. ChatRenderer loads a page's reference rows in one query and calls get() once per channel and kind for the viewer. Anything not visible renders as a neutral #unavailable and never leaks its label. MessageView gains text and references.

  • Composer. Typing # after whitespace queries huddle:references (c/<pk>/references/?q=). Picking an option inserts #CODE and adds a hidden references input. The template is components/reference_results.html.

  • API and JSON. Message payloads include references: [{kind, id, code, label, url}], filtered per viewer. The input serializer accepts reference_ids, and there is a new GET /channels/{id}/references/?q=. Websocket JSON mode reuses the payloads.
  • Free-typed @handles


  • An unpicked @handle is matched case-insensitively against mentionable_users(channel), using the display name with spaces removed or the email local part. If more than one user fits, nobody is mentioned. HUDDLE_FREE_TYPED_MENTIONS = False turns this off.
  • Design decisions (ADRs 0007–0009)


  • Conflicts. A picked reference is exact. For a free-typed code, the first resolver in settings order that resolves it wins.

  • DMs and unscoped channels. channel.scope is None is passed to the resolvers, which return nothing if their objects only exist inside a scope (documented).

  • No new ChatPolicy hook. The policy decides chat visibility and resolvers decide host-object visibility. Resolvers are only asked after the policy has admitted the user to the channel.

  • Rows gate rendering. 0.1.0 didn't neutralise <#…>, so a token only becomes a chip if the service recorded a MessageReference row for it. This stops old hand-typed tokens from coming alive when a host adds a resolver.

  • Hosts with no resolvers see the same output as 0.1.0: # stays plain text.

  • Free-typed lookups are capped at 50 codes per message. Chip URLs are only linked for relative, http or https URLs.
  • Testing


  • 145 tests (54 new: tests/test_references.py, tests/test_handles.py) using a toy example app (Project, Ticket, ProjectChatPolicy, TicketResolver). They cover encoding and the no-forging rule, permission at send and at render, unknown codes, DMs, resolver conflicts and picks, edit/delete row sync and the signal, a bulk query-count guard, the autocomplete view, the API payload and search, websocket JSON, and handles including ambiguity.

  • Coverage is 99% (gate 95%). ruff, mypy --strict, tox -f py314 (Django 6.0 + 6.1) and pre-commit run --all-files all pass locally.
  • AI Provenance

  • Tool: Claude Code

  • Model: Claude Opus

  • Prompt/thread: Agent task: build the generic, pluggable # reference mechanism in django-huddle (resolver hook, send-time encoding with no forging, render-time permission re-check, MessageReference storage plus reference_added signal, composer autocomplete, API/JSON payloads) and free-typed @handles with ambiguity handling, as one PR with ADRs, without building Comply 100's resolver.
  • Checklist

  • Addresses exactly one issue or feature (two closely linked composer features, requested as one PR)

  • New or changed behavior has test coverage

  • Diff contains only changes for this task
  • Diff: 577 lines (+432 / -145) across 7 files Reviewer: BenA-SA Review duration: 22m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 577 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.380
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #6"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 49.8% (MEDIUM) · Higher = larger blast radius
    49.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.7% · Safe to merge
    19.7%