Skip to content

SCA-4852 Key paid listen-finalization notes across retries - #26643

Open
Git-on-my-level wants to merge 5 commits into
mainfrom
sca4852-serving
Open

Git-on-my-level wants to merge 5 commits into
mainfrom
sca4852-serving

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Routes managed Python listen-finalization notes through the v2 keyed gateway. The operation key and protocol pin survive redelivery and new dispatch generations. Changed input gets a new key. Admission defaults off.

Worker 2 reported 382 passing tests on the exact head. One development chart render skipped because Helm was unavailable. Firestore emulator scenarios verified a single dispatch and rollup increment after an injected crash or lost response, a new dispatch for changed input, and refusal to settle after a blocking deletion marker.

Custody review must resolve physical expiry of sealed results before activation. Rollback to a pre-v2 image requires draining or quarantining pinned work. Go handback still needs qualification.

Release READBACK must include daily all-job volume, added Firestore reads and writes, committed-result POST collisions, and provider dispatches per logical operation. Cost approved up to 2M combined added reads and writes per UTC day.

View guided diff Turn on auto-fix

Product invariants affected

  • INV-MEM-4. The dispatch change comes before the existing canonical memory intake and promotion authority.
  • INV-TASK-2. Keyed notes replay feeds the existing Candidate path for extracted tasks.

Line-Count-Exception: backend/database/conversation_finalization_jobs.py | 3812 -> 3818 | Store and return the protocol pin at the existing durable job transaction boundary.
Line-Count-Exception: backend/database/firestore_index_registry.py | 2422 -> 2423 | Make the sealed-result field index exemption part of the generated manifest.
Line-Count-Exception: backend/utils/conversations/process_conversation.py | 3550 -> 3552 | Bind the notes operation to the selected conversation's content revision.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T06:26:26.068793Z c1e18d6 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.

@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: da9aa7222e

ℹ️ 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 +55 to +58
request_identity = json.dumps(
[job_id, _input_revision.get(), body], sort_keys=True, separators=(',', ':'), allow_nan=False
)
key = str(UUID(bytes=sha256(request_identity.encode()).digest()[:16], version=4))

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 Freeze volatile prompt inputs before deriving the retry key

When NOTES_PACKET_V2_MODE serves a pinned finalization job, build_notes_packet() in backend/utils/llm/notes_packet.py inserts current_local_iso from datetime.now(timezone.utc) into the prompt. Hashing the entire request body therefore generates a different idempotency key on every redelivery, even when the job and content revision are unchanged. If the first gateway response is lost or the worker crashes before checkpointing notes, the retry buys another completion instead of replaying the committed result. Persist and reuse the request's volatile inputs across retries so both the key and gateway fingerprint remain stable.

Useful? React with 👍 / 👎.

Comment on lines +154 to +160
if v2_trace is None:
schedule_attempt_trace(context, attempt_trace)
elif v2_trace.attempts:
(attempt,) = v2_trace.attempts
if v2_trace.notes_accounting_event is None:
idempotency.V2_POST_OUTCOMES.labels(keyed_request.environment, 'provider_dispatch').inc()
v2_trace.notes_accounting_event = build_accounting_event(context, attempt)

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 Persist the v2 accounting trace when invocation is canceled

If a v2 request is canceled during provider execution, the executor records a canceled attempt and _create_chat_completion() calls account() before re-raising CancelledError. This new branch only puts the accounting event in memory, while idempotency.complete() exits at await invoke(...) without ever submitting store.finish(). Unlike the previous schedule_attempt_trace() behavior, the provider attempt is consequently absent from accounting and user-day rollups; only the pending claim survives. Add a cancellation settlement path that durably records the attempt while retaining the indeterminate replay fence.

Useful? React with 👍 / 👎.

@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: f65c6317b4

ℹ️ 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 +20 to +21
def admit_v2_notes() -> bool:
return os.getenv('LISTEN_FINALIZATION_NOTES_V2_ADMISSION', '').strip().lower() == 'on'

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 Document the pinned finalization protocol and rollout contract

This introduces a listen-finalization admission flag and a persisted protocol pin that remains active after admission is turned off, but the commit contains neither a pipeline change note nor an update to the pipeline's env/wire contract. Operators therefore lack the documented distinction between stopping new admissions and stopping already-pinned work, which matters when rolling back to a gateway or worker image without v2 support. Add the rollout and rollback guidance under backend/docs/listen_pusher_pipeline/changes/ and document the flag default and persisted protocol in the pipeline contract, as required by backend/AGENTS.md.

AGENTS.md reference: backend/AGENTS.md:L164-L164

Useful? React with 👍 / 👎.

@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: d8394ec00e

ℹ️ 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".

if recap_telemetry.active():
keyed = finalization_notes and notes_operation_active()
if keyed:
from utils.llm.gateway_client import GatewayContextChatOpenAI

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 Move the gateway client import to module scope

The new keyed-notes branch adds a function-local import, violating the explicit backend requirement that all imports live at module scope. Import GatewayContextChatOpenAI once at the top of the module and reuse it in both branches rather than adding another deferred import.

AGENTS.md reference: backend/AGENTS.md:L167-L167

Useful? React with 👍 / 👎.

@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: c1e18d6621

ℹ️ 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 +125 to +126
return await idempotency.complete(
request, caller, _resolve_credentials(request, caller), invoke, v2=request.url.path == NOTES_V2_ROUTE

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 Accommodate multimodal notes payloads on the keyed route

When admission is enabled, notes requests exceeding 1 MiB now fail with HTTP 413 because this route uses idempotency.complete(), whose _request_body() enforces MAX_REQUEST_BYTES = 1024 * 1024. The existing notes pipeline can attach four base64 JPEG screenshots: screen_frame_evidence.load_notes_frame_images() bounds image dimensions to 1024 pixels but imposes no encoded-byte budget, and meeting_notes_rich_prompts.screen_frames_message() includes every loaded image alongside the transcript. These supported multimodal requests can exceed the new limit even though the ordinary completion route accepted them. Every redelivery encounters the same rejection, preventing finalization. Give the v2 route a suitable bounded payload allowance or explicitly reconcile the notes payload budget with this limit.

Useful? React with 👍 / 👎.

Comment on lines +652 to +653
if notes_operation_active() and not v3_models.active():
manager = isolated_notes_model(model, finalization_notes=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.

P2 Badge Deduplicate backend token accounting for replayed notes

If the first delivery finishes the LangChain invocation but fails before saving the notes checkpoint, the next delivery replays the stored completion, including its original token usage. However, the isolated model preserves the LLMUsageCallback installed by get_or_create_omi_gateway_llm(), so on_llm_end() calls record_llm_usage() again; that function unconditionally increments tokens and call counts in users/{uid}/llm_usage. Thus one provider completion is counted multiple times in the user-facing /v1/users/me/llm-usage summary, even though the new gateway accounting correctly records only one attempt. Make the backend usage write idempotent by operation identity rather than accounting each replay as another provider call.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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