Skip to content

feat(notes): open-loop extraction fields, server-only persistence, card writer (Open loops PR 1) - #23622

Merged
Git-on-my-level merged 3 commits into
mainfrom
lane/open-loops-notes
Oct 25, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
lane/open-loops-notes

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

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 / StructuredExtraction gain optional, default-empty
    delegated_by_user, commitments_by_others
    ({who, what, by_when?, evidence, work_related?}; who may 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.
  • The fields live on flag-gated subclasses (OpenLoopNotesOutput,
    OpenLoopStructuredExtraction, OpenLoopAgentNotesSubmission) selected only
    while enabled — same pattern as RichStructuredExtraction — so the
    flag-off prompt bytes and the agentic submit_notes tool schema stay
    byte-identical (pinned by test_shaped_title_prompt_bytes_are_pinned_to_the_literal_fixture).
  • Prompt rules (utils/open_loops/prompts.py, adapted from the validated
    offline 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.
  • Persistence: a fresh parse flows through a mutable sink
    (open_loop_out) to process_conversation, which writes a top-level
    server-only open_loop_extractions field on the conversation document —
    the relevance_decision pattern: outside the Conversation wire model, so
    clients never see it. _prepare_conversation_for_write protects it exactly
    like user_corrections: compressed, encrypted for enhanced-protection
    users, with an open_loop_extractions_compressed marker; the only reader is
    database.conversations.get_open_loop_extractions. Write semantics: content
    → payload dict; fresh parse with nothing → explicit null (clears stale
    values 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 an
optional single polish call (OPEN_LOOPS_CARD_POLISH_ENABLED, default off,
feature key open_loop_card on gpt-5-nano with track_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 removes
the 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 polish
switch; 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 the
    Firestore-guard/action-item/conversation suites selected for the changed
    production files).
  • New tests: test_open_loops_schema.py (parsing/back-compat/scrubbing),
    test_open_loops_prompt_gating.py (kill-switch prompt gating + sink capture
    through 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).
  • Notes eval: the repo has no action_items precision/recall harness — the
    episode-notes eval (backend/testing/episode_notes/) is a judge-based
    quality 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.
  • Harness/test-contract updates for the new imports: file-loading stubs in
    test_action_item_date_validation.py and
    test_conversation_archive_filter_contract.py, the dedupe generate-call
    assertion, 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)

  • The agentic notes lane's hand-written submit_notes schema does not request
    the fields yet, so long agent-written meetings extract none (documented in
    the README); the one-shot path covers BYOK, short and non-escalated
    conversations.
  • Daily pass, loop store with expiry, task-aware dedupe (merge, never drop),
    Review source with 2–3 slots/day, and mobile card UI are out of scope here.
  • utils/open_loops/card.py is allowlisted in the dead-code ratchet until its
    caller (the daily pass) lands.

Failure-Class: none
UI-Evidence: none — backend only

Product invariants named

  • INV-MEM-4 (canonical promotion is the sole Long-term authority): the
    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.
  • INV-TASK-2 (capture proposes only where a Suggested surface exists):
    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]

…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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T20:07:54.986248Z a094759 New commits
ℹ️ 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" or "@codex security review".

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]>

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment on lines +383 to +384
data[OPEN_LOOP_EXTRACTIONS_FIELD] = _protect_json_value(open_loops, uid, level)
data[OPEN_LOOP_EXTRACTIONS_COMPRESSED_FIELD] = True

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 Badge 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 👍 / 👎.

Comment on lines +379 to +384
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

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 Badge 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 👍 / 👎.

Comment on lines +300 to +304
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

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 Badge 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 👍 / 👎.

Comment on lines +154 to +156
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)

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 Badge 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]>
@Git-on-my-level
Git-on-my-level merged commit fadc6cd into main Oct 25, 2026
59 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/open-loops-notes branch October 25, 2026 20:18
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