Skip to content

feat(dev-api): add /v1/dev/user/ask and omi ask CLI - #11452

Merged
undivisible merged 12 commits into
BasedHardware:mainfrom
aryanorastar:feat/cli-omi-ask-clean2
Aug 25, 2026
Merged

undivisible merged 12 commits into
BasedHardware:mainfrom
aryanorastar:feat/cli-omi-ask-clean2

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

Addressed review (David CR 2026-08-12)

  • IANA timezone validated via ZoneInfo at the API boundary
  • ConversationSearchUnavailableError → 503 (parity with /v1/conversations/search)
  • Transcript-chunk retrieval merged with summary search before RAG

Summary

Clean current-main replacement for #10314. Adds the read-only /v1/dev/user/ask Developer API endpoint and omi ask CLI command, grounded in cited conversation RAG.

Security and cost controls

  • Dedicated fail-closed dev:ask per-key budget (25/hour).
  • Requires conversations:read.
  • Excludes discarded conversations and re-checks locked records after authoritative hydration.
  • Developer-API-key-only route; explicitly excluded from the Firebase app-client OpenAPI contract.

Verification

  • backend/tests/unit/test_dev_ask_endpoint.py: 9 passed locally on tip.
  • Product line-count ratchet passed.
  • CLI / OpenAPI export smoke may still rely on CI where local extras are missing.

Honest gaps

  • Full CLI respx suite and OpenAPI export not re-run locally in this environment; CI is the gate.

Failure-Class: none

Line-Count-Exception: backend/routers/developer.py | 2126 -> 2244 | Adds the read-only developer Ask endpoint with scoped retrieval, rate limiting, and locked/discarded conversation safeguards.

Supersedes stale conflicted #10314 with the same intended implementation on current main.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@aryanorastar

aryanorastar commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

Clean replacement for conflicted #10314 is now open on current main at 8010017501 (10-file delta, +492/-7). The existing approved implementation and security/privacy safeguards are preserved; endpoint tests passed locally and CI is running. @Git-on-my-level @kodjima33 @beastoin please review the replacement after checks complete and make the product/security merge decision.

Edited to remove a stray @nik mention: that handle belongs to an unrelated GitHub user, not @kodjima33. Apologies to anyone it notified.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 10 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread backend/routers/developer.py Resolved
Comment thread backend/routers/developer.py Resolved
Comment thread backend/routers/developer.py Resolved
@Git-on-my-level Git-on-my-level added needs-tests PR introduces logic that should be covered by tests needs-maintainer-review Needs a human maintainer to sign off before merge docs-accuracy Documentation or committed reports need accuracy fixes backend Backend Task (python) labels Aug 12, 2026

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for opening the clean replacement for #10314. The shape is useful, and the PR preserves several important safeguards, but I think the new endpoint should be fixed before merge.

Blocking issues:

  • backend/routers/developer.py: DeveloperAskRequest.timezone is documented as an IANA timezone, but it is accepted as any string and passed directly to qa_rag(..., tz=request.timezone). For a user-facing ask endpoint, invalid or oversized timezone input should be validated at the API boundary (for example with ZoneInfo, returning 422/400 or a deliberate UTC fallback) so relative-date answers do not silently use bad temporal context.
  • backend/routers/developer.py: ask_conversations() calls search_conversations() without catching ConversationSearchUnavailableError. The existing /v1/conversations/search route maps that transient Typesense failure to 503 Search temporarily unavailable; this endpoint would currently bubble the upstream failure into a generic 500 for CLI/API callers.
  • backend/routers/developer.py: retrieval is still only utils.conversations.search.search_conversations(), whose query_by is structured.overview, structured.title. Because this endpoint is supposed to answer questions from conversations, transcript-only facts can be missed before RAG even runs. The backend already has transcript-chunk/search support for other tool surfaces; this endpoint needs equivalent retrieval coverage or a consciously documented narrower contract.

File-by-file notes:

  • .github/scripts/product_file_line_count_ratchet_baseline/backend-routers.json: the ratchet update is consistent with the added developer router lines and includes a specific justification for the new route.
  • backend/dependencies.py: adding get_uid_with_conversations_read_ask() is the right place to enforce conversations:read plus a dedicated billable-endpoint rate-limit policy.
  • backend/route_policy_manifest.yaml: the manifest correctly records /v1/dev/user/ask as developer-api-key auth with conversations:read, dev:ask, and conversations data-domain ownership.
  • backend/routers/developer.py: the read-only locked/discarded filtering is good, but the timezone validation, transient search-error handling, and transcript-search coverage above need changes.
  • backend/scripts/export_openapi.py: explicitly excluding this Developer-API-key-only route from the Firebase app-client OpenAPI contract is the right docs/client-generation boundary.
  • backend/tests/unit/test_dev_ask_endpoint.py: good coverage for grounding, no-context no-LLM behavior, discarded/locked filtering, rate limiting, and app-client OpenAPI exclusion; please add tests for invalid timezone handling, ConversationSearchUnavailableError -> 503, and transcript-only evidence retrieval.
  • backend/utils/rate_limit_config.py: the dedicated dev:ask cap matches the billable qa_rag nature of the endpoint and is no looser than conversation creation.
  • docs/api-reference/openapi.json: the generated public OpenAPI correctly exposes developerApiKey for /v1/dev/user/ask, but this agent-consumed contract will teach SDKs/coding agents that timezone is a free string until the backend schema validates or constrains it.
  • sdks/python-cli/omi_cli/main.py: the omi ask command is straightforward and forwards question, limit, and timezone to the new endpoint while supporting JSON output.
  • sdks/python-cli/tests/test_ask.py: the CLI tests cover normal rendering and JSON mode; adding an option-boundary test for --timezone would be useful once backend validation is defined.

I tried to run the focused backend and CLI tests locally, but this checkout/environment did not have the backend/CLI test dependencies installed (firebase_admin missing for the backend test import, and the CLI test run collected no tests in this environment). CI is green, but the missing cases above are production-path gaps rather than local harness-only failures.

Because this adds a new conversation-RAG Developer API and public OpenAPI/CLI surface, the endpoint also needs human maintainer sign-off for product/security direction after the implementation fixes.

Automated maintainer review.


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

@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.

Dev-API ask endpoint + CLI looks well-scoped with a rate-limit policy and a unit test; new capability, so approve-only. Needs a rebase — conflicts with main.

@aryanorastar

aryanorastar commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level @kodjima33 @beastoin re-review requested on head 6eb509aba1.

Addressed all three current blockers:

  • DeveloperAskRequest.timezone validates bounded IANA timezone names with ZoneInfo.
  • ConversationSearchUnavailableError maps to the established HTTP 503 response.
  • Ask retrieval now merges transcript-chunk IDs via the existing hybrid resolver before hydration/RAG, so transcript-only answers are eligible.

Added regression coverage for invalid timezone, search outage -> 503, and transcript-only retrieval. Focused endpoint suite: 9 passed; Black clean. Please re-review after CI.

Edited to remove a stray @nik mention: that handle belongs to an unrelated GitHub user, not @kodjima33. Apologies to anyone it notified.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level @kodjima33 current-main merge is on head 5a2ecf9dd0 (conflicts were only the routers line-count ratchet; kept main counts + recorded the ask-route +118).

The three earlier blockers remain in place on this tip:

  • IANA ZoneInfo validation for timezone
  • ConversationSearchUnavailableError → 503
  • transcript-chunk IDs merged before RAG

python3 -m pytest backend/tests/unit/test_dev_ask_endpoint.py — 9 passed after the merge. Please re-review / dismiss the stale CHANGES_REQUESTED; @kodjima33 already approved the pre-merge head.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

The latest backend-unit failure is outside the #11452 diff and appears flaky/timing-sensitive on current main: test_agent_vm_protocol.py::test_database_installation_is_offloaded_and_serialized_with_db_use exceeded its timing threshold, and test_agent_vm_startup.py::test_startup_is_idempotent_for_the_same_migration failed. All #11452-specific checks, OpenAPI, CLI matrix, hygiene, and hermetic lanes passed. I cannot rerun the workflow with this token (GitHub requires admin rights); please rerun the failed Backend Unit Tests job. The three endpoint blockers are fixed on the current head.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level re-review on head a9cac744dc after current-main merge.

Your three blockers (IANA timezone, 503 on retrieval failure, transcript retrieval) are on this tip. The previous Backend unit suite red was unrelated test_agent_vm_* flakes on main (0.15s offload bound + SIGPIPE 141), not the ask CLI diff. Merged latest main to retrigger.

Author-side is MERGEABLE. Product/security merge after your dismiss.

@aryanorastar

aryanorastar commented Aug 15, 2026 •

Copy link
Copy Markdown
Collaborator Author

rebase attempt: I replayed the actual PR branch onto current origin/main and resolved the obsolete backend-routers ratchet deletion. The resulting branch is clean, 9 files / +549 lines, and retains the timezone validation, 503 mapping, transcript-chunk retrieval, endpoint tests, and CLI tests. Force-push is currently blocked by the contributor OAuth token lacking the GitHub workflow scope because current main includes .github/workflows/desktop-swift-ci.yml. No remote change was made; please rebase/push from a token with workflow scope, then re-review/dismiss the stale CHANGES_REQUESTED.

@aryanorastar
aryanorastar force-pushed the feat/cli-omi-ask-clean2 branch from a9cac74 to 5a36390 Compare August 15, 2026 04:16
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level @kodjima33 @beastoin the rebased branch is now pushed successfully at 5a36390bf8. GitHub reports MERGEABLE; CI is running. The obsolete backend-routers ratchet conflict was removed, and the ask endpoint safeguards/tests are preserved. Please re-review/dismiss the stale CHANGES_REQUESTED after checks finish.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level @kodjima33 added the required line-count exception to the PR body: backend/routers/developer.py | 2107 -> 2225 | Adds the read-only developer Ask endpoint with scoped retrieval, rate limiting, and locked/discarded conversation safeguards. The prior Hygiene failure was the only PR-specific failure; all endpoint, OpenAPI, CLI, hermetic, and formatting checks passed. Metadata preflight should revalidate this body; please rerun Hygiene if GitHub skips it on the body-only update, then dismiss the stale CHANGES_REQUESTED/re-review current head 5a36390bf8.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level ready for re-review — all three blockers from your CHANGES_REQUESTED (on 80100175) are addressed on tip 5a36390:

  1. Timezone — DeveloperAskRequest.timezone validates via ZoneInfo (length-bounded); invalid → pydantic 422. Test: test_ask_rejects_invalid_timezone.
  2. Typesense outage — ConversationSearchUnavailableError → 503 Search temporarily unavailable. Test: test_ask_maps_search_outage_to_503.
  3. Transcript-only evidence — merges Typesense summary hits with resolve_mcp_conversation_search_ids / search_transcript_chunks via merge_summary_and_transcript_ids. Test: test_ask_merges_transcript_only_hits_before_rag.

Local: pytest tests/unit/test_dev_ask_endpoint.py → 9 passed. CI on tip is green.

Please dismiss CHANGES_REQUESTED / re-approve when you have a moment. kodjima33 already APPROVED.

PR body now declares backend/routers/developer.py | 2111 -> 2225 to
match current main.
@aryanorastar

aryanorastar commented Aug 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

Hygiene follow-up: PR body Line-Count-Exception base bumped to match current main (2111 -> 2225); empty commit 1f0e2aa4e9 retriggers Repo Checks.

Earlier CR items look addressed on tip (IANA ZoneInfo validator, ConversationSearchUnavailableError → 503, transcript+summary merge via merge_summary_and_transcript_ids). Please re-review / dismiss CHANGES_REQUESTED when Hygiene is green.

@aryanorastar

aryanorastar commented Aug 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

Hygiene was still red because the line-count ratchet uses the synthetic merge of tip×main, not tip alone: tip was 2225, merged result is 2229.

Pushed 8657ee85 (merge current main) and updated the PR body to 2111 -> 2229. Ask safeguards still on tip (ZoneInfo / 503 / transcript merge). Local test_dev_ask_endpoint.py re-check running in this tip. Please dismiss CHANGES_REQUESTED when Hygiene is green.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level re-review / dismiss CHANGES_REQUESTED — tip 8657ee85

Verified your three blockers against this tip:

  1. Timezone — DeveloperAskRequest.timezone has a ZoneInfo field_validator (strip, length ≤64, ZoneInfoNotFoundError → 422).
  2. Typesense 503 — ask_conversations() catches ConversationSearchUnavailableError → HTTP 503 Search temporarily unavailable.
  3. Transcript retrieval — after summary search_conversations, merges transcript-chunk hits via resolve_mcp_conversation_search_ids(..., search_transcript_chunks=vector_db.search_transcript_chunks) + merge_summary_and_transcript_ids (Typesense already supplies summary IDs; empty query_vectors stub avoids double-counting Pinecone summary).

Local: tests/unit/test_dev_ask_endpoint.py 9 passed.

Author-side clear — please dismiss CR / re-approve when you have a moment.

@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.

feat(dev-api) /v1/dev/user/ask + omi ask CLI — feature, approve-only per policy

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level @kodjima33

Nik (@kodjima33) has approved this head with write-access (feat(dev-api) /v1/dev/user/ask + omi ask CLI — feature, approve-only per policy).

All three blockers from David’s prior review are verified resolved on tip 8657ee85:

  1. IANA Timezone Validation: DeveloperAskRequest.timezone uses ZoneInfo field validator (bounded length, returns 422 on invalid name). Test: test_ask_rejects_invalid_timezone.
  2. Typesense Outage Parity: ConversationSearchUnavailableError mapped to HTTP 503 Search temporarily unavailable. Test: test_ask_maps_search_outage_to_503.
  3. Transcript-Chunk Hybrid Retrieval: Merges transcript-chunk hits with summary IDs via merge_summary_and_transcript_ids before RAG. Test: test_ask_merges_transcript_only_hits_before_rag.
  4. CI Status: All 18 checks green, 0 conflicts.

@Git-on-my-level Please dismiss the stale CHANGES_REQUESTED review when convenient so this is ready to merge.

Reviewer note on BasedHardware#11452 asked for an option-boundary test once backend
timezone validation was defined. It now is (DeveloperAskRequest rejects
non-IANA values), so this pins the CLI half of the contract: the default
is UTC and an explicit --timezone is forwarded verbatim rather than
pre-screened client-side, where a second IANA list would drift from the
server's ZoneInfo database.

Verified the test guards rather than decorates: hardcoding "UTC" in
main.py's request body fails it (assert 'UTC' == 'Asia/Kolkata'); restored
and the file's 3 tests pass.
@aryanorastar

aryanorastar commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level all three blocking items from your review are resolved, plus the one non-blocking note. Flagging because the request-changes is still on file and now predates the fixes.

1. timezone accepted as any string — DeveloperAskRequest now carries a @field_validator("timezone") that constructs ZoneInfo(value) and raises timezone must be a valid IANA timezone on ZoneInfoNotFoundError, so FastAPI returns 422 at the API boundary instead of letting a bad value reach qa_rag(..., tz=...). Test: test_ask_rejects_invalid_timezone.

2. ConversationSearchUnavailableError bubbling to 500 — the search_conversations() call is wrapped and mapped to 503 Search temporarily unavailable, matching /v1/conversations/search. Test: test_ask_maps_search_outage_to_503.

3. Transcript-only facts missed before RAG — retrieval is no longer summary-only. ask_conversations now runs resolve_mcp_conversation_search_ids against vector_db.search_transcript_chunks alongside the summary search and merges via merge_summary_and_transcript_ids(transcript_ids, summary_ids, request.limit) — the existing transcript-chunk surface you pointed at, not a new one. Test: test_ask_merges_transcript_only_hits_before_rag.

Non-blocking note, now closed — you said a CLI --timezone option-boundary test would be useful once backend validation is defined. It is, so I added it in 1419e44e: it pins that the default is UTC and an explicit --timezone is forwarded verbatim rather than pre-screened client-side, since a second IANA list in the CLI would drift from the server's ZoneInfo database.

I checked that test guards rather than decorates — hardcoding "UTC" into the request body in main.py fails it:

E       AssertionError: assert 'UTC' == 'Asia/Kolkata'

Restored, and tests/test_ask.py passes (3 tests).

On your local-harness note: firebase_admin missing is environmental — the backend cases above run in CI's backend unit suite, which is green on this head. The CLI tests need respx and an editable install of sdks/python-cli, which is what I used.

The human sign-off you reserved for the new Developer API / public OpenAPI / CLI surface is still open and is the right call. Please dismiss the stale request-changes when you next pass.


On the two red Swift checks — resolved, no longer applicable. They were main's own omi_inline_userdefaults_key violations in OnboardingPersistenceClearingTests.swift, inherited through the merge ref because desktop-swiftlint lints the whole tree rather than the changed paths. main fixed them itself in 822d3738a7, so #12035 was closed as superseded. The separate backend collection error that was also reddening this branch is fixed by #12057, now merged.

Current head 9ccb8dfbeb merges both, and every check is green — 20 successful, 0 failing, 0 pending. @kodjima33 has re-approved on this exact head.

So the only thing standing between this and mergeable is the CHANGES_REQUESTED review, which is still pinned to 8010017501 — eleven days and fifteen commits behind the current tip, and predating all three fixes above. Please dismiss or re-review when you next pass; the human product/security sign-off you reserved for the new Developer API surface is a separate and still-open call, and I am not asking you to make that one here.

Edited to replace the stale paragraph about the two red Swift checks: both root causes have since landed on main, so the checks are green and #12035 is closed as superseded. Verified the three blocking fixes are still present on 9ccb8dfbeb before rewriting.

Desktop Swift Static & Test Contracts failed on
SuggestedTasksStoreTests.testNotMineAndAlreadyHandledPersistReasonAndResolveCandidate,
a task-intelligence test in a subsystem this PR does not touch. The same CI
window produced two other unrelated Swift test failures on other PRs, each a
different test. No code change.

@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.

Re-approved on latest commit: dev-api /v1/dev/user/ask + omi ask CLI — read-only, budget-gated (25/hr), scoped to conversations:read; feature (not bug fix) so approve-only per policy, not merge. CI green.

@undivisible
undivisible dismissed Git-on-my-level’s stale review August 25, 2026 09:02

Stale CR on 8010017 (13+ days / 15 commits old). Tip 9ccb8df addresses all three blockers: ZoneInfo timezone validation, ConversationSearchUnavailableError→503, and transcript-id merge before RAG. kodjima33 approved the current head.

@undivisible
undivisible merged commit 0c9cf73 into BasedHardware:main Aug 25, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) docs-accuracy Documentation or committed reports need accuracy fixes needs-maintainer-review Needs a human maintainer to sign off before merge needs-tests PR introduces logic that should be covered by tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants