Repository navigation
feat(notes): open-loop extraction fields, server-only persistence, card writer (Open loops PR 1) - #23622
Conversation
…rd writer Open loops PR 1 (backend, no UI). The notes call extracts delegations, others' commitments and one observed work defect / errand blocker; the extractions persist in a server-only conversation field and a pure card writer renders self-contained Review cards deterministically. - Fields live on flag-gated schema subclasses (OPEN_LOOPS_ENABLED, default on) so the flag-off prompt bytes and agentic submit tool stay identical. - open_loop_extractions rides the user_corrections protected-JSON write path; fresh-empty parses clear, dedupe reuse keeps prior values. - build_card/build_review_card in utils/open_loops/card.py: template first, optional single gpt-5-nano polish (OPEN_LOOPS_CARD_POLISH_ENABLED, off) with usage tracking; polish failures keep the template. - Daily pass, loop store, task-aware dedupe and Review surfacing follow. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…ractions on agent reprocess Review follow-ups: - a non-list delegated_by_user/commitments_by_others (lone object or word) is wrapped or dropped instead of failing the whole notes parse - the agentic notes path does not request open-loop fields, so it no longer writes an explicit null that wiped earlier one-shot extractions - content excluded from derived consumers stores no open-loop extractions Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b29b4b1127
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| data[OPEN_LOOP_EXTRACTIONS_FIELD] = _protect_json_value(open_loops, uid, level) | ||
| data[OPEN_LOOP_EXTRACTIONS_COMPRESSED_FIELD] = True |
There was a problem hiding this comment.
Handle stored extractions in the portability export path
For standard-protection users, any nonempty extraction is stored as compressed bytes, but prepare_conversation_for_read leaves this new field untouched. iter_all_conversations passes that dictionary directly to services/users/data_export.py, whose _dumps rejects bytes with TypeError. Consequently, one conversation with extracted follow-ups breaks the user's account export. Explicitly decode or exclude the server-only field in the export path rather than relying on the Conversation model, which this path does not use.
Useful? React with 👍 / 👎.
| open_loops = data.get(OPEN_LOOP_EXTRACTIONS_FIELD) | ||
| if open_loops: | ||
| if not isinstance(open_loops, dict): | ||
| raise ValueError('open_loop_extractions must be an object') | ||
| data[OPEN_LOOP_EXTRACTIONS_FIELD] = _protect_json_value(open_loops, uid, level) | ||
| data[OPEN_LOOP_EXTRACTIONS_COMPRESSED_FIELD] = True |
There was a problem hiding this comment.
Migrate existing extractions when enabling enhanced protection
When a standard-protection user migrates to enhanced protection, migrate_conversations_level_batch builds its rewrite payload from transcript segments, speaker scores, and manual assignments only; it never includes open_loop_extractions. The transaction therefore marks the document enhanced while leaving these newly stored conversation quotes as unencrypted compressed bytes. Add this field to the migration's decode-and-reprotect path so existing extractions receive the same protection as newly generated ones.
Useful? React with 👍 / 👎.
| except Exception: # noqa: BLE001 - polish is best-effort by contract | ||
| logger.info('open loop card polish failed; keeping template') | ||
| return card | ||
| if polished is None or not _acceptable(polished): | ||
| return card |
There was a problem hiding this comment.
Record telemetry when polish falls back to the template
When an enabled polisher throws, returns malformed output, or produces an unacceptable card, this path silently changes from model-polished output to the deterministic template: exceptions get only an info log, and rejected results get no signal. The backend guide explicitly requires new fallback branches to call utils.observability.fallback.record_fallback; instrument these outcomes so polish outages and repeated validation failures are visible through the shared operational telemetry.
AGENTS.md reference: backend/AGENTS.md:L318-L318
Useful? React with 👍 / 👎.
| open_loop_out = kwargs.pop('open_loop_out', None) | ||
| if not dedupe_enabled() or hashes is None: | ||
| return generate(prefix, uid=uid, **kwargs) | ||
| return generate(prefix, uid=uid, open_loop_out=open_loop_out, **kwargs) |
There was a problem hiding this comment.
Include the open-loop mode in the notes dedupe fingerprint
With notes deduplication enabled, processing a conversation while OPEN_LOOPS_ENABLED=off and then enabling the feature on the same deployed source produces the same input fingerprint: the effective open-loop mode is absent from the fingerprint inputs. Reprocessing unchanged content consequently reuses the flag-off notes, never calls the new extractor, and leaves open_loop_out empty, so that conversation cannot acquire extractions even through repeated reprocessing. Include open_loops_enabled() in the fingerprint while continuing to exclude the mutable output sink.
Useful? React with 👍 / 👎.
… route overrides CI follow-ups: pin reasoning_effort=minimal on the new gpt-5-nano lane (as conv_folder/conv_discard), list the feature and call site in the endpoint inventory, add its route to the non-dream snapshot, and expect the new open_loop_out kwarg in the shaped-agent routing test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Open loops, PR 1: notes-field extraction + self-contained card writer (backend, no UI)
First PR of the Open loops rebuild. Proactive suggestions become Open loops
surfaced in Review ("Questions for you"): things owed to the user (what they
delegated, what others committed to them), the user's own commitments going
stale, plus one narrow observed work defect / errand blocker. This PR lands
extraction inside the existing notes call, a server-only persistence field, and
the deterministic card writer. No UI, no daily pass, no loop store — later PRs.
A. Notes field
NotesOutput/StructuredExtractiongain optional, default-emptydelegated_by_user,commitments_by_others(
{who, what, by_when?, evidence, work_related?};whomay be"unknown"for passive/unattributed requests) and
observed_issue_or_blocker(
{kind: work_defect|errand_blocker, what, by_when?, evidence, work_related?} | null).Evidence ≤ 20 words by prompt rule, hard-clipped at 300 chars by schema.
OpenLoopNotesOutput,OpenLoopStructuredExtraction,OpenLoopAgentNotesSubmission) selected onlywhile enabled — same pattern as
RichStructuredExtraction— so theflag-off prompt bytes and the agentic
submit_notestool schema staybyte-identical (pinned by
test_shaped_title_prompt_bytes_are_pinned_to_the_literal_fixture).utils/open_loops/prompts.py, adapted from the validatedoffline reference prompts) append after the action-item rules and never
modify them; old model outputs without the fields parse unchanged, and one
malformed entry never costs the note.
(
open_loop_out) toprocess_conversation, which writes a top-levelserver-only
open_loop_extractionsfield on the conversation document —the
relevance_decisionpattern: outside theConversationwire model, soclients never see it.
_prepare_conversation_for_writeprotects it exactlylike
user_corrections: compressed, encrypted for enhanced-protectionusers, with an
open_loop_extractions_compressedmarker; the only reader isdatabase.conversations.get_open_loop_extractions. Write semantics: content→ payload dict; fresh parse with nothing → explicit
null(clears stalevalues on reprocess); dedupe reuse / quiet-minimum / switch off → omitted,
so a Firestore merge keeps prior values.
B. Card writer
backend/utils/open_loops/card.py— pure module.build_card(loop, tz=…)renders deterministically with no model: names who and what in recognizable
words, says where it came from (conversation title + weekday in the user's
timezone) and why now ("due Monday", "no follow-up since Tue"), question +
context ≤ ~180 chars, no internal jargon, no relationship/medical/legal
inference.
build_review_card(…, polisher=…)keeps the same interface with anoptional single polish call (
OPEN_LOOPS_CARD_POLISH_ENABLED, default off,feature key
open_loop_cardon gpt-5-nano withtrack_usage); any failure,malformed JSON, or rule-breaking candidate keeps the template. Example
template output:
Did Maya send the vendor write-up?/From Tuesday's Pricing sync, no follow-up since Tuesday.C. Kill switch
OPEN_LOOPS_ENABLED(ship-on-by-default,config/open_loops.py): off removesthe prompt rules, keeps the flag-off schema/prompt bytes identical, and stops
persisting; already-stored extractions are left in place. Registered in
config/feature-flags.yaml(+ regenerated registry doc) alongside the polishswitch; no runtime-env manifest entry needed (absent = code default on).
Verification
BACKEND_UNIT_TEST_FILE_LIST=<open-loops + notes + action-item + conversation neighborhoods, 162 files> bash backend/test.sh— all green (includes theFirestore-guard/action-item/conversation suites selected for the changed
production files).
test_open_loops_schema.py(parsing/back-compat/scrubbing),test_open_loops_prompt_gating.py(kill-switch prompt gating + sink capturethrough the real one-shot path),
test_open_loops_persistence.py(compressed/encrypted write shape at both protection levels, explicit-clear,
server-only wire exclusion),
test_open_loops_card.py(delegated,owed-by-unknown, stale own task, due-soon/overdue/today, observed defect,
truncation, tz weekday, polish accept/reject).
episode-notes eval (
backend/testing/episode_notes/) is a judge-basedquality comparison requiring explicit keys/endpoints (not run); its hermetic
unit tests ran green as part of the suite. Nothing in this PR changes the
action-item rules; the gating test asserts the action-item rules text is
untouched.
test_action_item_date_validation.pyandtest_conversation_archive_filter_contract.py, the dedupe generate-callassertion, the flag-off prompt pin (now explicitly sets the switch off), and
the QoS two-tier expectation (
open_loop_card).Docs
backend/utils/llm/ARCHITECTURE.md— open-loop extraction in the notes L3 section.backend/utils/open_loops/README.md— storage contract, schema placement, modules.backend/docs/feature-flag-registry.md— regenerated with both switches.Known gaps (later PRs)
submit_notesschema does not requestthe fields yet, so long agent-written meetings extract none (documented in
the README); the one-shot path covers BYOK, short and non-escalated
conversations.
Review source with 2–3 slots/day, and mobile card UI are out of scope here.
utils/open_loops/card.pyis allowlisted in the dead-code ratchet until itscaller (the daily pass) lands.
Failure-Class: none
UI-Evidence: none — backend only
Product invariants named
open-loop extractions are a derived, server-only conversation field. Nothing
in this PR writes to any memory store (Short-term, Long-term, Archive), adds
an intake route, or touches consolidation/promotion; the conversation
processing path only appends fields to the existing notes call and its own
document.
this PR creates no tasks and no Candidates anywhere. The extractions are
storage only — no client surface receives them (the field is outside the
Conversation wire model), and no task/candidate writer is added. The later
Review surfacing PR will re-run this check when it introduces a surface.
Line-Count-Exception: backend/database/conversations.py | 4480 -> 4514 | server-only open_loop_extractions protection in _prepare_conversation_for_write plus the get_open_loop_extractions reader; 34 lines follow the existing user_corrections/translation_materializations protected-JSON pattern
Line-Count-Exception: backend/utils/conversations/process_conversation.py | 3246 -> 3261 | open-loop sink plumbed through _get_structured and persisted as the server-only conversation field next to the existing relevance_decision write, skipped for content excluded from derived consumers; 15 lines
🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 5.5 [email protected]