Skip to content

feat(notebooks): Persist workflow notebooks and their writer runs - #131536

Open
arslnb wants to merge 3 commits into
codex/workflow-notebook-migrationfrom
codex/workflow-notebook-producer
Open

arslnb wants to merge 3 commits into
codex/workflow-notebook-migrationfrom
codex/workflow-notebook-producer

Conversation

@arslnb

@arslnb arslnb commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Second in the workflow notebook stack. Land the database schema in #131544 first.

A workflow needs to publish its findings incrementally, reuse the same notebook after a retry, and attach the Explorer run that wrote it. This adds the producer side of that contract behind the existing notebook feature and project access checks.

  • Open one notebook per organization and workflow run, or bind an existing notebook selected by the caller. A signed, organization-scoped Seer worker can attach its writer's public run UUID.
  • Store Code Mode widgets, their executed queries or evidence references, and their two-line summaries alongside the ordered blocks. Version checks protect edits, removals, and late summaries. Notebook details return the content revision and the saved rich blocks to readers.
  • Accept metadata and next steps independently for the same completed content revision. The notebook, investigation metadata, and action-request writes reuse the existing stores. Replaying an acknowledged section is idempotent.

Sentry also owns the run and node checkpoint API, recovery scheduling, and retention. The organization endpoints start a workflow through Seer, read its progress from Sentry, and forward commands. A beta monitor launch binds the workflow to a Sentry notebook using the same breached-metric source snapshot as the legacy path.

Deploy this contract before enabling the notebook writer.

Verified the notebook and investigation orchestration test suites and ran the authenticated Seer client against the Django endpoints. The cross-service check exercised creation, attachment, editing, finalization, redelivery, reads, and removal.

@github-actions github-actions Bot added Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components labels Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/notebooks/migrations/0005_workflow_notebooks.py

for 0005_workflow_notebooks in notebooks

--
-- Add field embed to notebookblock
--
ALTER TABLE "notebooks_notebookblock" ADD COLUMN "embed" jsonb NULL;
--
-- Add field embed_source to notebookblock
--
ALTER TABLE "notebooks_notebookblock" ADD COLUMN "embed_source" text NULL;
--
-- Add field embed_summary to notebookblock
--
ALTER TABLE "notebooks_notebookblock" ADD COLUMN "embed_summary" text NULL;
--
-- Create model NotebookWorkflowRun
--
CREATE TABLE "notebooks_notebookworkflowrun" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "date_updated" timestamp with time zone NOT NULL, "date_added" timestamp with time zone NOT NULL, "run_id" uuid NOT NULL, "delivered" jsonb DEFAULT '{}'::jsonb NOT NULL, "notebook_id" bigint NOT NULL, "organization_id" bigint NOT NULL, "writer_run_id" bigint NULL);
ALTER TABLE "notebooks_notebookworkflowrun" ADD CONSTRAINT "notebooks_notebookwo_notebook_id_c08a48c6_fk_notebooks" FOREIGN KEY ("notebook_id") REFERENCES "notebooks_notebook" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "notebooks_notebookworkflowrun" VALIDATE CONSTRAINT "notebooks_notebookwo_notebook_id_c08a48c6_fk_notebooks";
ALTER TABLE "notebooks_notebookworkflowrun" ADD CONSTRAINT "notebooks_notebookwo_organization_id_ee7a5194_fk_sentry_or" FOREIGN KEY ("organization_id") REFERENCES "sentry_organization" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "notebooks_notebookworkflowrun" VALIDATE CONSTRAINT "notebooks_notebookwo_organization_id_ee7a5194_fk_sentry_or";
ALTER TABLE "notebooks_notebookworkflowrun" ADD CONSTRAINT "notebooks_notebookwo_writer_run_id_4ab7d2a6_fk_seer_seer" FOREIGN KEY ("writer_run_id") REFERENCES "seer_seerrun" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "notebooks_notebookworkflowrun" VALIDATE CONSTRAINT "notebooks_notebookwo_writer_run_id_4ab7d2a6_fk_seer_seer";
CREATE UNIQUE INDEX CONCURRENTLY "notebook_unique_workflow_run" ON "notebooks_notebookworkflowrun" ("organization_id", "run_id");
ALTER TABLE "notebooks_notebookworkflowrun" ADD CONSTRAINT "notebook_unique_workflow_run" UNIQUE USING INDEX "notebook_unique_workflow_run";
CREATE INDEX CONCURRENTLY "notebooks_notebookworkflowrun_notebook_id_c08a48c6" ON "notebooks_notebookworkflowrun" ("notebook_id");
CREATE INDEX CONCURRENTLY "notebooks_notebookworkflowrun_organization_id_ee7a5194" ON "notebooks_notebookworkflowrun" ("organization_id");
CREATE INDEX CONCURRENTLY "notebooks_notebookworkflowrun_writer_run_id_4ab7d2a6" ON "notebooks_notebookworkflowrun" ("writer_run_id");

@arslnb
arslnb changed the base branch from master to codex/workflow-notebook-migration November 17, 2026 22:52
@arslnb
arslnb added this pull request to stack #131547 November 17, 2026 22:55
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

decision-model-linter

api

src/sentry/investigations/endpoints/workflow_storage.py

  • warn readsRequestBodyOutsideSerializer = TRUE (0.97): Request body values should be read from a serializer's validated_data. This file reads a value directly from request.data or request.POST.

src/sentry/notebooks/services/executions.py

  • warn makesExistingInputStricter = TRUE (0.86): Rejecting input an endpoint accepted before, or changing a field's default, breaks existing callers, and the API spec often doesn't show it. Make the change backward compatible (keep the field optional, accept the old values, or keep the old default), or treat it as a breaking change and coordinate it.

decision-model-linter: 132 calls on 28 files, 389,404 input tokens, $0.016, model typesafe/jev-1.13-20260917

@arslnb
arslnb marked this pull request as ready for review November 19, 2026 23:29
@arslnb
arslnb requested review from a team as code owners November 19, 2026 23:29

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 75385bd. Configure here.

orchestration.save(update_fields=["projection", "notebook_revision", "date_updated"])
elif section == "metadata":
notebook.update(
title=notebook.title if binding.preserve_title else result["title"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Existing notebook title overwritten on finalize

Medium Severity

Binding a workflow to an existing notebook never sets preserve_title. Metadata delivery then replaces that notebook's title unless someone happens to rename it after the bind. Opening onto a caller-selected notebook is a primary path, so a completed run can silently rename a notebook the user already titled.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 75385bd. Configure here.

block.last_edited_by_id = user_id
if not created:
block.version += 1
block.save()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Workflow text blocks omit markdown display

Medium Severity

Workflow text writes skip display validation and save the model default of {}. Every other text-block path stores {"type": "markdown"}, which the API documents as required. Readers that key off display.type will not treat these blocks as markdown.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 75385bd. Configure here.

@arslnb
arslnb requested a review from a team as a code owner November 20, 2026 20:03
Comment on lines +55 to +57
binding, _ = NotebookWorkflowRun.objects.get_or_create(
organization=organization, run_id=run_id, defaults={"notebook": destination_notebook}
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Low priority since nothing does this today. A rename only sets preserve_title on the bindings that exist at that point. So if someone renames the notebook and a second run then writes to it, the new binding starts at False and the metadata step replaces their title. Defaulting it from the destination here would cover that:

defaults={"notebook": destination_notebook, "preserve_title": destination is not None}

Comment on lines +251 to +252
section = values["section"]
validator = MetadataWrite if section == "metadata" else StepsWrite

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Small suggestion: FinalizerWrite could validate result for its section itself, with MetadataWrite and StepsWrite nested. Then errors come back keyed under result, and the next step items get checked before deliver_finalizer takes the locks.

notebooks: QuerySet[Notebook] = Notebook.objects.filter(
organization=organization, status=requested_status
).filter(Q(source_key__isnull=True) | ~Exists(newer_lineage_revision))
if isinstance(request.access, ServiceAccountAccess) and not request.access.has_all_projects:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Heads up that this changes existing behaviour. A limited service account could read every notebook before, and now it loses the ones outside its projects and the ones with no projects selected. Just want to make sure that's intended.

with notebook_writes(notebook) as writes:
require_workflow_writer(notebook, workflow_run_id, writer_run_id)
blocks = notebook.blocks
stored_key = f"workflow:{key}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It might be helpful to include the run id in the stored key. Suggestions are scoped to the workflow run, but block keys are per notebook, so two runs writing to the same notebook share keys.



@cell_silo_endpoint
class OrganizationNotebookWorkflowWriterEndpoint(OrganizationEndpoint):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This could extend OrganizationNotebooksBaseEndpoint like the endpoint above and keep its own auth and permission classes. That brings the notebooks feature check with it. It would need an extend_schema for the docs build.

@arslnb
arslnb force-pushed the codex/workflow-notebook-producer branch from 75385bd to 098ce32 Compare November 23, 2026 18:33
@arslnb
arslnb requested a review from a team as a code owner November 23, 2026 18:33

This branch was successfully deployed

1 active (outdated) deployment
Preview — 3dacaf2d Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants