Repository navigation
SCA: converge the free tier's terminal store on the §1.7 deterministic minimum (S3) - #12726
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
There was a problem hiding this comment.
3 issues found across 15 files
Confidence score: 2/5
backend/utils/conversations/deterministic_minimum.pypropagates 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.pycan format fallback titles using a non-UTCstarted_atoffset when_resolve_zonereturnsNone, producing incorrect deterministic titles; convert the timestamp totimezone.utcin that path.backend/tests/unit/test_deterministic_minimum.pydoes not fully enforce its claimed module import-closure guard because_module_import_closureskips relative imports, leaving part of the dependency graph unchecked; include relativeast.ImportFromimports 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 |
There was a problem hiding this comment.
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>
| 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: |
There was a problem hiding this comment.
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>
| if zone is not None: | ||
| moment = moment.astimezone(zone) |
There was a problem hiding this comment.
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>
| 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]>
60ce841 to
35551d4
Compare
S3 — converge the terminal store on the §1.7 deterministic minimum
Shard S3 of the ratified local-models free-tier program (
60-shards.mdrow S3;spec
10-backend-plumbing.md§1.7). Branched frommainafter 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, whosetitle 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 JITdeferred 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 apure module. Title = the transcript's first sentence (through the first
./!/?) truncated to 60 chars on a word boundary; empty transcript fallsback to
"Recording · 3:14 PM"derived fromstarted_at. The other columns —overview
'', categoryother, no action items, no events, no sections —already held by accident, because
_build_deferred_structuredreturned aStructuredwith nothing but a title and let the model defaults stand. Theyare 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_atis the only clock. The timezone is resolved through aprovider 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 theserver 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_minimumbuilds §1.7'sStructuredand stampsprocessing_state._store_deferred_conversationis untouched: the JITplaceholder keeps its own algorithm on its own path.
backend/utils/free_tier_processing_policy.py—_is_desktop_sourcepromoted 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 methodsfooter does not move.Automatic-or-dead check
tests/unit/test_deterministic_minimum.py::test_deterministic_minimum_module_reaches_no_managed_callwalks 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 acopy 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_minimumto_build_deferred_structured.Proof
tests/unit/test_deterministic_minimum.py— 24 passed. Table-driven over§1.7: sentence termination by
./!/?, no-terminator whole-text, blankleading 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_atstill yielding a non-empty title (an emptytitle is what
_get_conversation_objreads as discarded).tests/unit/test_client_processing_acceptance.py— 26 passed, includingfour new coordinator-level assertions with red-proofs in comments:
desktop-without-projection ⇒
local_pending; non-desktop ⇒none;projection in hand ⇒ field absent; stored
structuredis §1.7's row and notthe deferred placeholder's first-eight-words title.
--checkclean: Dart, TS, Swift, app-client OpenAPI.pyrighton every touched backend module: 0 errors.A consequence worth stating plainly
client_processing_mutationwrites exactly one key, and that single-key payloadis 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 readlocal_pending. That is deliberate rather than overlooked: clients checkclient_processingfirst and render the projection regardless. The contract iswritten into the enum's docstring and into
_minimum_processing_state. Thealternative — 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.pyfailed for two reasons, only one ofthem mine:
Mine.
Conversationgainedprocessing_state, so the field-set pin wentred 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) andgoes into
PINNED_CONVERSATION_FIELDS. Separately, my first draft of_minimum_processing_statetook theClientProcessing | Noneand tripped thereference pin. It only ever needed presence, so it now takes a
boolandthe pinned reference set does not have to grow to admit it — the narrower
signature is the better one anyway.
Not mine.
PINNED_CONVERSATION_DUMPShas been red onmainsince25a7d764bc("fold desktop watching and proactive counts into dailysummaries"), which added two
model_dump()calls inutils/llm/external_integrations.py. Both dump aDailySummaryDayStatsPayload, not aConversation— the scanner keys on thecall, 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
mainis red on a test it also runs.Also not mine, and this one needed a judgement.
test_task_intelligence_contract_freeze.pyis red onmainfor the samestructural reason.
44d48884cf("remove the retired onboarding wizardviews") deleted two Swift files that
backend/config/task_intelligence_sources_v1.jsonstill lists asdesktop_manualowner paths. Removing the dead paths then uncovered asecond failure the first was masking:
ProactiveAssistants/ContextReminders/ContextReminderCoordinator.swiftcalls
client.createActionItemandclient.updateActionItemand isregistered nowhere.
Please sanity-check this classification. I registered it under
desktop_manual(policy_class: direct_command), not as a proactivewriter. The directory says
ProactiveAssistants, which is exactly why Iread 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
updateActionItemisreached from
markDone, a button on a card. Neither fires on a timer or onobserved context alone. Under
INV-TASK-2that is a direct command, notautomatic 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
mainwithout any PR seeing it. Three instances turned upin one afternoon — these two and the LLM-endpoint inventory pin, which is what
#12727 is about.
Cut list
non-desktop free conversations still take the legacy path;
processing_stateis
nonefor them because no projection is coming, which is accurate todayand becomes wrong the moment a mobile engine exists. That is S5's decision,
not this PR's.
processing_stateon late projection arrival (see above).local_pending/none. The field is now on the wirein 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.pybeside the source test it reads, so thecoordinator keeps only the call. What is left in
process_conversation.pyisthe 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 istouched. §1.7's
Structuredis server-authored and terminal; nothing on thispath 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.pyis a task-capture authority path.§1.7 makes
action_itemsempty by construction — the minimum proposesnothing 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