Skip to content

feat(dev-api): accept folder_id and calendar meeting context in from-segments - #21265

Merged
undivisible merged 3 commits into
BasedHardware:mainfrom
avaldini:feat/dev-from-segments-folder-calendar
Oct 19, 2026
Merged

undivisible merged 3 commits into
BasedHardware:mainfrom
avaldini:feat/dev-from-segments-folder-calendar

Conversation

@avaldini

@avaldini avaldini commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

POST /v1/dev/user/conversations/from-segments now accepts two optional fields:

  • folder_id: files the conversation in one of the user's folders.
  • calendar_meeting_context: the calendar meeting the conversation belongs to.

Integrations that upload their own transcripts often know both already, but today they have no way to pass them:

  • Folder. AI folder assignment guesses from the generated title and overview. The developer API cannot fix it afterwards, because GET /v1/dev/user/folders is read-only and the conversation PATCH only changes title and discarded.
  • Calendar. The summary only sees a meeting from the single calendar connected in the app (_enrich_meeting_context, source 3). Someone who works across several companies has several calendars. The integration can read all of them, but cannot hand Omi the meeting it found.

My setup is the same as in #21250: a self-hosted STT server transcribes the phone's audio and uploads each finished conversation through from-segments. It reads four calendars (personal plus three work accounts), so it knows the meeting and the folder before the upload.

How it works:

  • folder_id
    • It must be one of the user's folders (folders_db.get_folder); otherwise the request gets a 422 before anything is processed.
    • It is set on the conversation on both paths: on the Conversation for the idempotent client_session_id path, and on CreateConversation (new optional field) for the plain path.
    • process_conversation already skips AI assignment when conversation.folder_id is set (not conversation.folder_id guard). That also skips the count refresh the AI path does, so the handler calls update_folder_conversation_count after a successful ingest. A failure there is logged, not raised.
    • It does not stamp folder_user_set. That marker means "a user acted" and protects a row from relevance discard (is_user_curated). A non-null folder_id is already preserved by the processing upsert.
  • calendar_meeting_context
    • It is a bounded input model, DevCalendarMeetingContext in models/calendar_context.py, with:

      • calendar_event_id, title, start_time and duration_minutes;
      • participants (MeetingParticipant);
      • platform, meeting_link and notes.

      Strings, the participant list and the duration have length or range limits.

    • It is converted to CalendarMeetingContext and stored where process_conversation already reads it:

      • CreateConversation.calendar_meeting_context on the plain path;
      • external_data['calendar_meeting_context'] (as model_dump(mode='json'), like store_meeting_context) on the idempotent path.
    • calendar_source is fixed to developer_api, so a caller cannot claim screen_activity, which has its own merge rules. participant_sources is not exposed.

The Firebase-authed POST /v1/conversations/from-segments shares the request model, so it gains the same two optional fields.

Docs and generated artifacts:

  • the endpoint docstring;
  • docs/doc/developer/api/conversations.mdx;
  • docs/api-reference/openapi.json and app-client-openapi.json, regenerated with export_openapi.py --write;
  • the four omiApi.generated.ts files, regenerated with generate_ts_openapi_types.py.

Product invariants affected

none

How it was verified

  • Unit tests:
    • backend/tests/unit/test_developer_from_segments_idempotency.py: 65 passed, including 4 new tests.
    • Every other tests/unit and tests/routers file that mentions CreateConversation, routers.developer, folder_id or calendar_meeting_context passes: 86 files, each run on its own.
    • The exception is tests/unit/test_developer_key.py, which errors with ModuleNotFoundError: No module named 'fake_firestore' both on this branch and on main in my local environment. That is unrelated to this change.
  • tests/unit/test_client_processing_trust_boundary.py passes (51). DevCalendarMeetingContext.to_context builds the context field by field, so no new model_dump site was added.
  • Contracts:
    • export_openapi.py --check passes for the public, app-client and integration-public surfaces.
    • check_app_client_openapi_compatibility.py --base-ref origin/main passes.
    • generate_ts_openapi_types.py --check, generate_swift_openapi_types.py --check and generate_dart_models.py --all --check pass.
    • check_product_invariants.py: no locked invariant requires naming.
  • Formatting: scripts/backend-python-format --check is clean on the changed files. ruff reports the same 3 pre-existing F401s in routers/developer.py as on main.
  • Not verified: the patched backend has not been deployed and called end to end.

Tests

In backend/tests/unit/test_developer_from_segments_idempotency.py:

  • test_unknown_folder_id_is_rejected_before_processing: a folder that is not the user's gives a 422, and process_conversation is never called.
  • test_folder_and_calendar_reach_create_conversation: goes through the real FastAPI route with a JSON body. It asserts:
    • the CreateConversation handed to processing carries folder_id and the calendar context (title, participant email, parsed start_time, calendar_source == 'developer_api');
    • the folder count is refreshed.
  • test_folder_and_calendar_reach_idempotent_conversation: on the client_session_id path, the processing claim and the Conversation carry folder_id, and external_data['calendar_meeting_context'] holds the context.
  • test_without_folder_id_ai_assignment_stays_in_charge: without the new fields, nothing changes. There is no folder lookup and no count refresh, and folder_id and the context stay None.

In backend/tests/unit/test_meeting_context_resolution.py, added after the first review:

  • test_developer_api_context_merges_with_a_stored_meeting: an uploaded context is the direct source. A stored meeting for the same window keeps the scalar fields, and the uploaded invitees it missed are kept, deduplicated by name and email. They are counted as expected calendar participants.
  • test_developer_api_context_is_used_when_no_stored_meeting_exists: without a stored meeting, the uploaded context wins (event id, title, developer_api source). It is never treated as a screen listing.

UI evidence

UI-Evidence: none -- backend-only change

Failure class (fixes)

Failure-Class: none

Scoped cleanups (optional)

Line-Count-Exception: backend/routers/developer.py | 2655 -> 2690 | two optional request fields and their validation and wiring in the shared from-segments handler; the new input model lives in models/calendar_context.py

…segments

Integrations that send their own transcripts often already know which
folder a conversation belongs to and which calendar meeting it was, but
from-segments has no way to say so: the AI folder assignment guesses
from the generated title, and the summary only sees the one calendar
connected in the app.

folder_id files the conversation in one of the user's folders (unknown
IDs get a 422). Processing already skips AI assignment when a folder is
set, so the handler refreshes that folder's count itself.

calendar_meeting_context takes a bounded subset of CalendarMeetingContext
and stores it where process_conversation already reads it on both the
idempotent and the plain path. calendar_source is fixed to developer_api
so a caller cannot claim screen_activity.
@Git-on-my-level

Copy link
Copy Markdown
Member

Reviewed end to end, including the downstream code this hooks into. The implementation checks out; the open items are product-semantics calls, not defects.

Verified against code on this head:

  • backend/routers/developer.py — the folder 422 pre-check runs before any processing and is uid-scoped (folders_db.get_folder reads users/{uid}/folders/{folder_id}), so a caller cannot reference another user's folder. Both create paths thread folder_id and calendar_meeting_context correctly: the plain path sets them on CreateConversation; the idempotent path sets folder_id on the Conversation and serializes the calendar context into external_data (model_dump(mode='json')). The post-ingest update_folder_conversation_count mirrors what the AI assignment path does, and the try/except-with-log keeps a count-refresh failure from failing the request.
  • backend/models/calendar_context.py — DevCalendarMeetingContext is a clean bounded mirror of CalendarMeetingContext (length caps, max 100 participants, duration 0–1440), and to_context() stamps calendar_source='developer_api'. The screen_activity comment is accurate: that source has its own merge rules in resolve_meeting_context.
  • backend/models/conversation.py — folder_id: Optional[str] on CreateConversation matches the plain-path wiring; the loose Optional[str] here vs the bounded Field on the dev request mirrors how calendar_meeting_context is already split between the two models.
  • backend/utils/conversations/process_conversation.py (existing, not in diff) — confirmed the not conversation.folder_id guard at line 3108 skips AI assignment, and the AI path's count refresh (line 3235) is the one this PR replaces. Also confirmed _enrich_meeting_context consumes the supplied context as the direct source.
  • backend/utils/conversations/meeting_context.py (existing) — stored_meeting_context reads external_data['calendar_meeting_context'] back, so the idempotent path's serialization is genuinely consumed downstream. Note the merge semantics: a developer-supplied context is merged with any stored calendar-backed mapping (each contributing participants the other didn't supply) rather than overriding it — worth a maintainer confirming that's the intended precedence for developer-declared meetings.
  • backend/tests/unit/test_developer_from_segments_idempotency.py — good coverage: unknown-folder 422 before processing (process not called), both create paths assert folder_id/calendar context land correctly, and the no-folder default keeps AI assignment in charge with no refresh. One gap: no test that a supplied context merges with a stored mapping.
  • docs/doc/developer/api/conversations.mdx — accurate against the implementation, including the 422 behavior and required vs optional fields.
  • docs/api-reference/openapi.json, app-client-openapi.json, and the four omiApi.generated.ts copies (web/app, web/admin, web/personas-open-source, desktop/windows) — consistent regens of the same schema; the MeetingParticipant definition added to openapi.json matches the existing model.

Two items for a maintainer before merge:

  1. folder_user_set is deliberately not stamped, so a developer-preset folder does not mark the conversation user-curated (is_user_curated) and it stays eligible for relevance discard. The PR body explains the reasoning ("a user acted"); whether an explicit integration instruction should carry the same protection is a product call.
  2. No backend test workflow appears to have run on this PR (only the static reviewer check), so the added unit tests haven't been exercised by CI yet.

Leaving for human maintainer review on those two points — good, well-scoped contribution overall.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added backend Backend Task (python) needs-maintainer-review Needs a human maintainer to sign off before merge labels Oct 12, 2026
…red meeting

From the review: the from-segments calendar context is the direct source in
resolve_meeting_context. A stored meeting for the same window keeps the scalar
fields and the uploaded invitees it missed are kept (deduplicated); without one,
the uploaded context wins and is never read as a screen listing.
@avaldini

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review. Both points:

Merge test. Added in f37b6d8, in test_meeting_context_resolution.py:

  • test_developer_api_context_merges_with_a_stored_meeting: an uploaded context is the direct source. A stored meeting for the same window keeps the scalar fields, and the uploaded invitees it missed are kept, deduplicated by name and email, as expected calendar participants.
  • test_developer_api_context_is_used_when_no_stored_meeting_exists: without a stored meeting, the uploaded context wins and is never read as a screen listing.

Both pass locally, alongside the from-segments and trust-boundary suites.

folder_user_set. I left it unset on purpose. Today the marker means "a person moved this conversation". is_user_curated uses it to exempt a row from relevance discard, and sync assignment uses it to keep the row as a separate target. An integration that sets folder_id only knows where the conversation belongs, not whether it is worth keeping. So short noise captures (a "mic check", one filler line) should still be discarded as usual. Meanwhile a non-null folder_id already survives processing upserts, so the folder is not lost.

If you would rather treat an explicit API folder like a manual move, it is a one-line change: stamp folder_user_set in both create paths. I'm happy to switch it.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avaldini feat(dev-api) folder_id/calendar context -- feature, approve-only

@Git-on-my-level

Copy link
Copy Markdown
Member

Reviewed the from-segments folder_id + calendar_meeting_context change end to end against the current backend. Verification notes: (1) backend/routers/developer.py — the folder_id ownership check (folders_db.get_folder(uid, folder_id) -> 422) runs before any processing and get_folder is scoped to users/{uid}/folders, so no cross-tenant exposure; the post-ingest update_folder_conversation_count is wrapped in try/except and logged, matching the existing pattern for count refreshes. (2) backend/models/calendar_context.py — DevCalendarMeetingContext.to_context() stamps calendar_source='developer_api'; since CalendarMeetingContext.calendar_source is free-form and resolve_meeting_context only special-cases screen_activity, the uploaded context merges with a stored meeting exactly as the tests describe (stored meeting wins scalars, uploaded invitees are kept deduplicated). (3) backend/models/conversation.py + process_conversation — folder_id on CreateConversation survives the final persist via the conversation.dict() spread, and the existing not conversation.folder_id guard skips AI assignment; the idempotent path stores the context in external_data, which process_conversation already hoists into the summary context, so both paths are covered. (4) backend/tests/unit/test_developer_from_segments_idempotency.py and test_meeting_context_resolution.py — good coverage of the 422, both ingest paths, the no-folder default, and merge semantics. (5) docs + generated TS/OpenAPI artifacts (omiApi.generated.ts x4, openapi.json x2, conversations.mdx) are consistent downstream updates. The choice not to stamp folder_user_set (explained in the PR body) is a sound call given it gates relevance discard. A human maintainer has already approved this head; remaining step before merge is a green CI run. Thanks for the careful PR body and tests.

(Automated maintainer review on behalf of the Omi maintainers; the merge decision stays with a human maintainer.)


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@avaldini

Copy link
Copy Markdown
Contributor Author

Thanks for the approval! CI hasn't run on this branch yet: the workflow runs are waiting on "Approve and run workflows" (first-time contributor from a fork). Could a maintainer approve them so the checks can run?

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-scoped dev-API feature (folder_id + calendar meeting context on from-segments). Feature, not a bug fix, so approve-only per policy — no merge.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution and removed needs-maintainer-review Needs a human maintainer to sign off before merge labels Oct 14, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Verified this end to end against the current head — the wiring holds together nicely:

  • backend/routers/developer.py: folder_id ownership is validated per-user via folders_db.get_folder(uid, ...) and rejected with a 422 before any processing, so there's no cross-tenant path. Both create paths (plain CreateConversation and the idempotent client_session_id flow) carry the folder and calendar fields consistently.
  • backend/models/calendar_context.py: DevCalendarMeetingContext keeps tight input bounds (title ≤500, notes ≤10000, participants ≤100, duration 0–1440) and to_context() correctly tags calendar_source='developer_api' — good separation between the API input model and the internal CalendarMeetingContext.
  • The subtle part checks out: the idempotent path stashes the context in external_data['calendar_meeting_context'], and process_conversation rehydrates that dict back into a CalendarMeetingContext; with folder_id preset, the not conversation.folder_id guard skips AI assignment, and the manual update_folder_conversation_count in the handler mirrors what the AI path does (failures logged, not raised — right call).
  • Tests cover the important branches: unknown-folder 422 before processing, both create paths, the no-folder default, and the merge semantics where a stored meeting wins scalar fields while uploaded participants are deduped by name/email.
  • docs/doc/developer/api/conversations.mdx matches the actual behavior (including the 422), and the OpenAPI/omiApi.generated.ts updates are consistent regenerations of the new schema. One note: the "Generated Files" check was skipped on this PR, so regeneration consistency was verified by inspection rather than CI — worth a glance if that check normally gates your merges.

Thanks for the thorough PR description — the rationale for skipping folder_user_set was particularly helpful context. No concerns from this review; human approval is already on record.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@avaldini

Copy link
Copy Markdown
Contributor Author

Thanks! On the Generated Files note: that job is the Flutter codegen check (build_runner / gen-l10n), and this PR doesn't touch app/, so it's skipped by path. The regenerated OpenAPI specs and TypeScript clients are covered by the OpenAPI Contract job (export_openapi.py --check, generate_ts_openapi_types.py --check), which passed on this head.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New optional dev-API fields - new capability, not bug fix - approve-only; CI green.

@undivisible
undivisible merged commit 024e682 into BasedHardware:main Oct 19, 2026
59 of 60 checks passed
Git-on-my-level added a commit that referenced this pull request Oct 19, 2026
Five unit files fail on current main. Each one passed on its own PR's base
and broke when main moved underneath it; none is a product regression.

- test_request_context.py (#19738): tested the JIT budget surface that
  #22209 removed from llm_gateway/gateway/request_context.py. Keep the
  request-id tests; drop the tests for removed code.
- test_users_joan_followup_tombstone_guard.py (#19867): called
  delete_person_endpoint, but the joan followup route is
  delete_followup_question_endpoint.
- test_developer_from_segments_idempotency.py (#21265): process fakes
  rejected the trigger=CLIENT_FINALIZE kwarg the router passes since #19788.
- test_external_tools_sanitization.py (#19406): the stubbed utils package
  lacked utils.generated_compute (#21488) and utils.model_text. Stub the
  default-off gate as disabled and load the stdlib-only model_text for real.
- test_batch_upload_storage.py: the database.vector_db stub lacked
  delete_action_item_vectors_batch, which merge_conversations imports since
  #15953.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level added a commit that referenced this pull request Oct 19, 2026
)

* fix(backend): restore pyright-clean main after #22207 and #22326

Main's backend unit shards fail the enforced pyright lane:

- database/desktop_previews.py (#22207): 16 reportUnnecessaryIsInstance
  errors. The runtime guards stay; they move into validators that take
  `object` (_payload, _string, _expected_generation, _datetime), so the
  checks are meaningful to pyright. Public signatures, error messages and
  check order are unchanged.
- utils/sync/pipeline.py:process_segment (#22326 on top of #22452):
  "code is too complex to analyze". Behaviour-neutral split: the two
  identical cap-hold defer blocks become one hold_for_cap closure, and the
  final-pass / speaker-identification block moves to
  _assign_segment_speakers with the same exception handling.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): repair unit tests that drifted from main across merges

Five unit files fail on current main. Each one passed on its own PR's base
and broke when main moved underneath it; none is a product regression.

- test_request_context.py (#19738): tested the JIT budget surface that
  #22209 removed from llm_gateway/gateway/request_context.py. Keep the
  request-id tests; drop the tests for removed code.
- test_users_joan_followup_tombstone_guard.py (#19867): called
  delete_person_endpoint, but the joan followup route is
  delete_followup_question_endpoint.
- test_developer_from_segments_idempotency.py (#21265): process fakes
  rejected the trigger=CLIENT_FINALIZE kwarg the router passes since #19788.
- test_external_tools_sanitization.py (#19406): the stubbed utils package
  lacked utils.generated_compute (#21488) and utils.model_text. Stub the
  default-off gate as disabled and load the stdlib-only model_text for real.
- test_batch_upload_storage.py: the database.vector_db stub lacked
  delete_action_item_vectors_batch, which merge_conversations imports since
  #15953.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants