Skip to content

SCA: converge the free tier's terminal store on the §1.7 deterministic minimum (S3) - #12726

Merged
Git-on-my-level merged 1 commit into
mainfrom
feat/free-tier-s3-deterministic-minimum
Sep 4, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
feat/free-tier-s3-deterministic-minimum

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

S3 — converge the terminal store on the §1.7 deterministic minimum

Shard S3 of the ratified local-models free-tier program (60-shards.md row S3;
spec 10-backend-plumbing.md §1.7). Branched from main after S4 and S7.

S6 already made the free-tier store terminal and spendless. What it did not do
is make the stored values §1.7's. It reused _build_deferred_structured, whose
title is the first eight words of the first non-empty segment with a bare
'Recording' when the transcript is empty — an algorithm written for the JIT
deferred path, where a later luna enrichment overwrites it. On the free path
nothing overwrites it, so those values are what the user keeps. This PR makes
them the spec's.

What changed

  • backend/utils/conversations/deterministic_minimum.py (new) — §1.7 as a
    pure module. Title = the transcript's first sentence (through the first
    ./!/?) truncated to 60 chars on a word boundary; empty transcript falls
    back to "Recording · 3:14 PM" derived from started_at. The other columns —
    overview '', category other, no action items, no events, no sections —
    already held by accident, because _build_deferred_structured returned a
    Structured with nothing but a title and let the model defaults stand. They
    are now stated and tested rather than inherited, so a change to a default
    cannot silently give a free conversation a fabricated overview or an inferred
    category. The behavioural change in this PR is the title and
    processing_state; the rest is pinning what was already true.

    Same input, same output; started_at is the only clock. The timezone is resolved through a
    provider callable that is invoked only on the empty-transcript branch, so
    the common path costs no lookup, and an unknown zone degrades to UTC rather
    than raising — this path is the fail-closed store and must not be able to
    throw.

  • backend/models/conversation_enums.py — ConversationProcessingState
    (local_pending | none), §1.7 row 5. Absent on every conversation the
    server enriched itself and on every conversation that already carries a
    projection.

  • backend/models/conversation.py — Conversation.processing_state.

  • backend/utils/conversations/process_conversation.py —
    _store_deterministic_minimum builds §1.7's Structured and stamps
    processing_state. _store_deferred_conversation is untouched: the JIT
    placeholder keeps its own algorithm on its own path.

  • backend/utils/free_tier_processing_policy.py — _is_desktop_source
    promoted to public is_desktop_source (private alias kept) so S3's
    "is a projection coming?" answer reads the policy's own source test instead
    of a second copy of it.

  • Regenerated wire types and the app-client OpenAPI surface. Additive only —
    the Swift client's // Total: N methods footer does not move.

Automatic-or-dead check

tests/unit/test_deterministic_minimum.py::test_deterministic_minimum_module_reaches_no_managed_call
walks the module's real static import closure from the file on disk and
asserts nothing in it reaches a model client or contains get_llm(. It is not a
copy of the import list — route the minimum through anything that can spend and
it goes red. That is what lets the minimum be the deny-fallback for
authorize_managed_compute: it cannot itself spend.

Paired with test_minimum_structured_is_the_spec_row_not_the_deferred_placeholder,
whose red-proof is reverting _store_deterministic_minimum to
_build_deferred_structured.

Proof

  • tests/unit/test_deterministic_minimum.py — 24 passed. Table-driven over
    §1.7: sentence termination by ./!/?, no-terminator whole-text, blank
    leading segments, multi-segment join, whitespace collapse, word-boundary
    truncation, single-token hard cut, empty-transcript fallback, started_at
    (not the wall clock) as the only time source, user-zone rendering, unknown
    zone → UTC, no timezone lookup when the transcript has text, naive datetime
    read as UTC, missing started_at still yielding a non-empty title (an empty
    title is what _get_conversation_obj reads as discarded).
  • tests/unit/test_client_processing_acceptance.py — 26 passed, including
    four new coordinator-level assertions with red-proofs in comments:
    desktop-without-projection ⇒ local_pending; non-desktop ⇒ none;
    projection in hand ⇒ field absent; stored structured is §1.7's row and not
    the deferred placeholder's first-eight-words title.
  • Generators re-run and --check clean: Dart, TS, Swift, app-client OpenAPI.
  • pyright on every touched backend module: 0 errors.

A consequence worth stating plainly

client_processing_mutation writes exactly one key, and that single-key payload
is pinned by the trust-boundary test. So when a projection arrives after the
terminal persist (the normal case — local inference finishes after upload), it
does not clear processing_state, and a projected conversation can still read
local_pending. That is deliberate rather than overlooked: clients check
client_processing first and render the projection regardless. The contract is
written into the enum's docstring and into _minimum_processing_state. The
alternative — a second mutation that writes both fields — would widen the
ingress-owned payload that S4 deliberately pinned to one key.

Two trust-boundary pins repaired on the way through

test_client_processing_trust_boundary.py failed for two reasons, only one of
them mine:

  1. Mine. Conversation gained processing_state, so the field-set pin went
    red and demanded a classification. It is not projection-family: it is
    server-authored and carries no client text, so it stays out of
    PROJECTION_FAMILY_FIELDS (the integration redactor must not strip it) and
    goes into PINNED_CONVERSATION_FIELDS. Separately, my first draft of
    _minimum_processing_state took the ClientProcessing | None and tripped the
    reference pin. It only ever needed presence, so it now takes a bool and
    the pinned reference set does not have to grow to admit it — the narrower
    signature is the better one anyway.

  2. Not mine. PINNED_CONVERSATION_DUMPS has been red on main since
    25a7d764bc ("fold desktop watching and proactive counts into daily
    summaries"), which added two model_dump() calls in
    utils/llm/external_integrations.py. Both dump a
    DailySummaryDayStatsPayload, not a Conversation — the scanner keys on the
    call, not the receiver's type — so neither can carry client_processing.
    Reviewed and pinned here with that reasoning in a comment, because this
    branch cannot be green while main is red on a test it also runs.

  3. Also not mine, and this one needed a judgement.
    test_task_intelligence_contract_freeze.py is red on main for the same
    structural reason. 44d48884cf ("remove the retired onboarding wizard
    views") deleted two Swift files that
    backend/config/task_intelligence_sources_v1.json still lists as
    desktop_manual owner paths. Removing the dead paths then uncovered a
    second failure the first was masking:
    ProactiveAssistants/ContextReminders/ContextReminderCoordinator.swift
    calls client.createActionItem and client.updateActionItem and is
    registered nowhere.

    Please sanity-check this classification. I registered it under
    desktop_manual (policy_class: direct_command), not as a proactive
    writer. The directory says ProactiveAssistants, which is exactly why I
    read it rather than assumed: the create runs inside a user-invoked reminder
    flow on the user's own text — its failure strings are tool replies ("Bring
    the document to the front and ask again") — and updateActionItem is
    reached from markDone, a button on a card. Neither fires on a timer or on
    observed context alone. Under INV-TASK-2 that is a direct command, not
    automatic capture. If context reminders are meant to propose rather than
    write, the manifest entry is wrong and the code is what should change.

The second and third share a cause worth naming beyond this PR: neither change
touched a file that selects the test it broke, so the unit-test selector never
ran it. An exact-set pin whose subject files are wider than its selection
trigger can go red on main without any PR seeing it. Three instances turned up
in one afternoon — these two and the LLM-endpoint inventory pin, which is what
#12727 is about.

Cut list

  • Extending §1.7 past the desktop source. S6's gate is desktop-only, so
    non-desktop free conversations still take the legacy path; processing_state
    is none for them because no projection is coming, which is accurate today
    and becomes wrong the moment a mobile engine exists. That is S5's decision,
    not this PR's.
  • Clearing processing_state on late projection arrival (see above).
  • Any client rendering of local_pending / none. The field is now on the wire
    in Swift, Dart and TS; S9/W4 consume it.

Line-count ratchet

The §1.7 builder is a new module and the processing-state decision lives in
free_tier_processing_policy.py beside the source test it reads, so the
coordinator keeps only the call. What is left in process_conversation.py is
the structured build, the state assignment, one import, and the docstring that
says why this store is not _build_deferred_structured.

Line-Count-Exception: backend/utils/conversations/process_conversation.py | 2882 -> 2904 | §1.7 builder and the processing-state decision were both placed outside this file; the +22 is the call site, one import, and the docstring distinguishing the terminal store from the deferred placeholder

Product invariants

  • INV-MEM-4 — no memory promotion, admission, or Long-term authority path is
    touched. §1.7's Structured is server-authored and terminal; nothing on this
    path forms, promotes, or admits a memory, and the module's import closure is
    asserted to reach no model client at all.
  • INV-TASK-2 — process_conversation.py is a task-capture authority path.
    §1.7 makes action_items empty by construction — the minimum proposes
    nothing and writes no task. That is strictly less capture than the placeholder
    it replaces.

Failure class

No fix: commits in this range.

Failure-Class: none

🤖 Generated with Claude Code

@mintlify

mintlify Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
omi 🟢 Ready View Preview Sep 4, 2026, 7:36 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

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

3 issues found across 15 files

Confidence score: 2/5

  • backend/utils/conversations/deterministic_minimum.py propagates a provider exception when timezone lookup fails for an empty transcript, preventing terminal storage; catch the provider error and continue with the UTC fallback.
  • backend/utils/conversations/deterministic_minimum.py can format fallback titles using a non-UTC started_at offset when _resolve_zone returns None, producing incorrect deterministic titles; convert the timestamp to timezone.utc in that path.
  • backend/tests/unit/test_deterministic_minimum.py does not fully enforce its claimed module import-closure guard because _module_import_closure skips relative imports, leaving part of the dependency graph unchecked; include relative ast.ImportFrom imports in the traversal.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/tests/unit/test_deterministic_minimum.py">

<violation number="1" location="backend/tests/unit/test_deterministic_minimum.py:201">
P2: The "automatic-or-dead" guardrail claims it walks "the closure of the module as loaded," but `_module_import_closure` only follows absolute imports: `ast.ImportFrom` is skipped when `node.level != 0` (line 201), imports resolving to package directories (no matching `*.py`, e.g. `import utils` followed by `utils.llm.clients.get_llm` attribute access) are dropped, and the follow-on `get_llm(` text scan only runs over files already in the closure. Any model-client path reachable through a relative import or a package-level import therefore evades both the forbidden-name check and the text scan, so the test gives false confidence if a future dependency introduces such a chain. Resolve relative imports against the importing module's package (track each file's package while walking) and include package `__init__.py` files so the closure matches what Python actually loads.</violation>
</file>

<file name="backend/utils/conversations/deterministic_minimum.py">

<violation number="1" location="backend/utils/conversations/deterministic_minimum.py:96">
P2: When `started_at` carries a non-UTC offset and no valid `tz_name` is supplied, the fallback title uses that offset instead of UTC. Convert to `timezone.utc` whenever `_resolve_zone` returns `None`.</violation>

<violation number="2" location="backend/utils/conversations/deterministic_minimum.py:131">
P1: When the empty-transcript timezone lookup fails, `deterministic_minimum_title` propagates the provider exception and prevents terminal storage. Catch provider errors and continue with the UTC fallback.</violation>
</file>

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

Re-trigger cubic

sentence = first_sentence(transcript_text(conversation))
if sentence:
return truncate_on_word_boundary(sentence)
tz_name = tz_name_provider() if tz_name_provider is not None else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: When the empty-transcript timezone lookup fails, deterministic_minimum_title propagates the provider exception and prevents terminal storage. Catch provider errors and continue with the UTC fallback.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/utils/conversations/deterministic_minimum.py, line 131:

<comment>When the empty-transcript timezone lookup fails, `deterministic_minimum_title` propagates the provider exception and prevents terminal storage. Catch provider errors and continue with the UTC fallback.</comment>

<file context>
@@ -0,0 +1,158 @@
+    sentence = first_sentence(transcript_text(conversation))
+    if sentence:
+        return truncate_on_word_boundary(sentence)
+    tz_name = tz_name_provider() if tz_name_provider is not None else None
+    return fallback_title(
+        getattr(conversation, 'started_at', None),
</file context>
Suggested change
tz_name = tz_name_provider() if tz_name_provider is not None else None
try:
tz_name = tz_name_provider() if tz_name_provider is not None else None
except Exception:
tz_name = None

names: list[str] = []
if isinstance(node, ast.Import):
names = [alias.name for alias in node.names]
elif isinstance(node, ast.ImportFrom) and node.module and node.level == 0:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: The "automatic-or-dead" guardrail claims it walks "the closure of the module as loaded," but _module_import_closure only follows absolute imports: ast.ImportFrom is skipped when node.level != 0 (line 201), imports resolving to package directories (no matching *.py, e.g. import utils followed by utils.llm.clients.get_llm attribute access) are dropped, and the follow-on get_llm( text scan only runs over files already in the closure. Any model-client path reachable through a relative import or a package-level import therefore evades both the forbidden-name check and the text scan, so the test gives false confidence if a future dependency introduces such a chain. Resolve relative imports against the importing module's package (track each file's package while walking) and include package __init__.py files so the closure matches what Python actually loads.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/tests/unit/test_deterministic_minimum.py, line 201:

<comment>The "automatic-or-dead" guardrail claims it walks "the closure of the module as loaded," but `_module_import_closure` only follows absolute imports: `ast.ImportFrom` is skipped when `node.level != 0` (line 201), imports resolving to package directories (no matching `*.py`, e.g. `import utils` followed by `utils.llm.clients.get_llm` attribute access) are dropped, and the follow-on `get_llm(` text scan only runs over files already in the closure. Any model-client path reachable through a relative import or a package-level import therefore evades both the forbidden-name check and the text scan, so the test gives false confidence if a future dependency introduces such a chain. Resolve relative imports against the importing module's package (track each file's package while walking) and include package `__init__.py` files so the closure matches what Python actually loads.</comment>

<file context>
@@ -0,0 +1,227 @@
+            names: list[str] = []
+            if isinstance(node, ast.Import):
+                names = [alias.name for alias in node.names]
+            elif isinstance(node, ast.ImportFrom) and node.module and node.level == 0:
+                names = [node.module]
+            for name in names:
</file context>

Comment on lines +96 to +97
if zone is not None:
moment = moment.astimezone(zone)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: When started_at carries a non-UTC offset and no valid tz_name is supplied, the fallback title uses that offset instead of UTC. Convert to timezone.utc whenever _resolve_zone returns None.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/utils/conversations/deterministic_minimum.py, line 96:

<comment>When `started_at` carries a non-UTC offset and no valid `tz_name` is supplied, the fallback title uses that offset instead of UTC. Convert to `timezone.utc` whenever `_resolve_zone` returns `None`.</comment>

<file context>
@@ -0,0 +1,158 @@
+    if moment.tzinfo is None:
+        moment = moment.replace(tzinfo=timezone.utc)
+    zone = _resolve_zone(tz_name)
+    if zone is not None:
+        moment = moment.astimezone(zone)
+    # %-I is a GNU/BSD extension; both CI and Cloud Run are POSIX. Strip the
</file context>
Suggested change
if zone is not None:
moment = moment.astimezone(zone)
moment = moment.astimezone(zone or timezone.utc)

…lly names

S6 made the free-tier store terminal and spendless. It did not make the stored
values the spec's: it reused `_build_deferred_structured`, whose title is the
first eight words of the first non-empty segment and a bare `'Recording'` when
the transcript is empty. That algorithm was written for the JIT deferred path,
where a later enrichment overwrites it. On the free path nothing overwrites it,
so those eight words are what the user keeps.

§1.7 is now a pure module. The title is the transcript's first sentence cut to
60 characters on a word boundary, falling back to `"Recording · 3:14 PM"` from
`started_at` — the only clock it reads. Overview is empty, not a placeholder
sentence that looks like content. Category is `other`, because inferring one
needs a model. The timezone is resolved through a callable invoked only on the
empty-transcript branch, and an unknown zone degrades to UTC rather than
raising: this is the fail-closed store and it must not be able to throw.

`Conversation.processing_state` says why `structured` is the minimum —
`local_pending` when a capable client is expected to deliver a projection,
`none` when nothing is coming. It is absent when a projection is already in
hand. It does not get cleared when one arrives later, because
`client_processing_mutation` writes exactly one key and that is pinned; clients
resolve it by reading `client_processing` first, and the enum's docstring is
the contract.

The check that makes this stick walks the module's real static import closure
and asserts nothing in it can reach a model client. That is what lets the
minimum be the deny-fallback for `authorize_managed_compute`: it cannot itself
spend.

Two trust-boundary pins needed repair. `Conversation` gaining a field is one of
them, and it is not projection-family — it is server-authored and carries no
client text, so the integration redactor must not strip it. The other was
already red on main: `25a7d764bc` added two `model_dump()` calls in
`external_integrations.py` that dump a stats payload rather than a conversation,
and no file it touched selects the test that pins them.

Co-Authored-By: Claude Opus 5 <[email protected]>
@Git-on-my-level
Git-on-my-level force-pushed the feat/free-tier-s3-deterministic-minimum branch from 60ce841 to 35551d4 Compare September 4, 2026 08:29
@Git-on-my-level
Git-on-my-level merged commit 614c89d into main Sep 4, 2026
44 checks passed
@Git-on-my-level
Git-on-my-level deleted the feat/free-tier-s3-deterministic-minimum branch September 4, 2026 10:06

This branch was successfully deployed

1 active deployment
staging - docs — 35551d41 Deployed Sep 4, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant