Skip to content

fix(engine): a saved step that imports a model or a task, or opens a notebook, from its text requires what it requires - #3619

Queued
jgregoriorincon wants to merge 4 commits into
opengeos:mainfrom
jgregoriorincon:fix/3476-model-notebook-capabilities
Queued

jgregoriorincon wants to merge 4 commits into
opengeos:mainfrom
jgregoriorincon:fix/3476-model-notebook-capabilities

Conversation

@jgregoriorincon

@jgregoriorincon jgregoriorincon commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A saved step that imports a model or a task, or opens a notebook, from its text (model.import, task.import, notebook.open) now requires what that document requires.

Before, no capability read the text or data of these commands. A saved step could import a model or a task, or add a notebook, that uses a setting an older release doesn't know (percent slope, a colorbar's text size, …), and the saved outer document didn't require it, so the older release took the step and could drop the setting without a word.

  • They are read by the walk fix(engine): a saved step that opens a project from its text requires what the project requires #3608 added for opened projects, from the same source the command reads (data before text; a path names a file, which has its own header):
    • model.import: a file the command takes (model::check_file) requires what the model.new it runs requires for that graph or those steps;
    • task.import: a task the command reads requires what its steps require;
    • notebook.open: a notebook the command parses, whose code cells are commands, requires what their lines require. Markdown cells and another language's cells require nothing. The lines are parsed once, not once per check, one command at a time.
  • The walk's limits are shared, whatever the kind of document: 32 levels and 64 MiB of text per walk; past either, or with a data that can't be decoded, the step requires every capability a release knows. What is kept of a text read is now keyed by its kind too, since the same text is another document to another command.

Surfaces: saved tasks, models, scripts and notebooks of the desktop and web apps, rustgis-cli, Python, the Assistant and MCP. Nothing visible changes; a document saved with such a step may carry more entries in its requires header, so an older release refuses it instead of dropping settings.

Not in this PR: a style, layer or map given inline (#3589), and steps given inline to task.new, task.addStep and task.editStep.

Testing

  • New tests in crates/engine/src/tests/capabilities_inline_project.rs and project_capabilities.rs, written first and seen failing (each step required nothing): a model with a graph, a web tool with steps and a task, by text and by data; a .rgisnb and a Jupyter notebook of RustGIS commands; a project opened by a notebook cell; the history and a project's notebooks; refused files, Markdown and Python cells and a path requiring nothing; undecodable data, the depth limit and the byte budget; one text read as a notebook and as a project.
  • Cost, measured once in an unoptimized build: a notebook of 19 MB of command lines walks in 1.5 s; a project holding the same cells takes 10 s, as before this change. A 1.7 MB web tool walks in 8 ms.
  • cargo fmt --check, clippy on rustgis-engine, doctests, the layering check and cargo xtask schema --check pass. nextest: all of rustgis-engine passes; 8 failures are in other crates (7 in rustgis-geolibre, line_strokes_editor_edits_one_class in the rustgis-ui-egui smoke tests) and fail the same on main (256cd3095) without this change. That full run was before the last commits (task.import, reading a notebook one command at a time, comment wrapping); after the code ones, the capability tests, hostile_params_never_panic, clippy and fmt passed again.

UI evidence

No visible UI change.

Related issue

Closes #3476

Summary by CodeRabbit

  • Bug Fixes
    • Capability requirements are now identified more accurately when saved steps open or import projects, models, tasks, or notebooks, including documents and scripts opened from within them.
    • Unreadable or unsupported content, and content that exceeds processing limits, continues to require all known capabilities.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Saved-step capability discovery now follows inline projects, models, tasks, and notebooks opened or imported from step text. It collects capabilities from executable commands and nested documents, with document kind included in the cache key. Tests cover source forms, nesting, rejected inputs, and shared limits.

Changes: Saved-step capability discovery

Layer / File(s) Summary
Parse opened document kinds
crates/engine/src/cmd/notebook.rs, crates/engine/src/project_capabilities.rs
The notebook parser is crate-visible. Opened projects, models, tasks, and command-language notebooks are parsed by kind, and executable command capabilities are collected.
Traverse, cache, and validate opened documents
crates/engine/src/project_capabilities.rs, crates/engine/src/tests/capabilities_inline_project.rs
The saved-step walk selects inline document sources and includes document kind in digest keys. Tests cover nested documents, source forms, rejected inputs, and shared depth and byte limits.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant SavedStep
  participant collect_opened_project
  participant OpenedReads
  participant opened_capabilities
  participant commands_capabilities
  SavedStep->>collect_opened_project: select opened document source
  collect_opened_project->>OpenedReads: check kind-qualified digest
  OpenedReads->>opened_capabilities: evaluate uncached document
  opened_capabilities->>commands_capabilities: collect executable command capabilities
  commands_capabilities->>collect_opened_project: follow nested opened documents
Loading

Possibly related issues

  • Issue 2818: The changes cover capability discovery for saved task.import steps and nested documents, matching the reported gap for imported tasks and models.
  • Issue 3462: The changes include project.openText documents in capability discovery, addressing the reported missing layout capability check.
  • Issue 3598: The project.openText path now evaluates opened project text for capabilities, which matches the issue’s missing capability checks for inline projects.

Suggested reviewers: giswqs, mavrick-f, elpidioassinaturas

Merge Risk: Minimal · up to fcf62

This change makes saved model, task and notebook imports record the capabilities they need, so older releases refuse them instead of silently dropping settings. Nothing in the supplied evidence points to a concrete defect, and the change looks ready to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a saved step that imports a model or task, or opens a notebook, from text now requires the capabilities of that document. This matches the raw summary, which adds capa…
Description check Passed The description follows the template. It has Summary, Testing, UI evidence, and Related issue sections. The Summary explains the change and its motivation, and the Testing section lists new tests, per…
Linked Issues check Passed [#3476] Requires saved projects to require capabilities used by inline documents. Head code in crates/engine/src/project_capabilities.rs adds collect_opened_project, opened_capabilities and `com…
Out of Scope Changes check Passed All changed areas serve the capability walk for opened documents. The changes are: parse in crates/engine/src/cmd/notebook.rs changed to pub(crate) so the walk can reuse it; the walk in `project…
Full details: Title check

Explanation

The title names the main change: a saved step that imports a model or task, or opens a notebook, from text now requires the capabilities of that document. This matches the raw summary, which adds capability discovery for model.import, task.import, and notebook.open. The title uses the conventional fix(engine) prefix. It is long at 118 characters, but it is specific and accurate.

Full details: Description check

Explanation

The description follows the template. It has Summary, Testing, UI evidence, and Related issue sections. The Summary explains the change and its motivation, and the Testing section lists new tests, performance numbers, and the checks run. The UI evidence section states no visible UI change, as the template allows. The Related issue section links Closes #3476. The Summary is dense, but all required information is present.

Full details: Linked Issues check

Explanation

[#3476] Requires saved projects to require capabilities used by inline documents. Head code in crates/engine/src/project_capabilities.rs adds collect_opened_project, opened_capabilities and commands_capabilities. These read the text (or base64 data) of project.openText, project.fromTemplate, model.import, task.import and notebook.open, then merge the capabilities of the opened content into the saved project's required list. Opened::Project reads a project through Project::from_peer_raw and recurses. Opened::Model, Opened::Task and Opened::Notebook read through the same checks as their commands. OpenedReads caches each text by depth and kind, so each text is read once per walk. The per-step read matches the issue's expected behavior. Tests in crates/engine/src/tests/capabilities_inline_project.rs and project_capabilities.rs cover these cases, per the PR description. The PR says it does not claim project.fromTemplate or project.openText. The head code's doc comments and dispatch list both commands, so the walk covers them. The reproduction (colorbar text_size without layout-colorbar-labels) is not traced in the code. The truncated collect_opened_project body and the test bodies were not read, so the behavior is taken from the doc comments, the dispatch code and the PR's test list. No coding requirement is unmet on the evidence read.

Full details: Out of Scope Changes check

Explanation

All changed areas serve the capability walk for opened documents. The changes are: parse in crates/engine/src/cmd/notebook.rs changed to pub(crate) so the walk can reuse it; the walk in project_capabilities.rs; and capability tests in crates/engine/src/tests/capabilities_inline_project.rs and project_capabilities.rs. The PR states that inline styles, layers and maps (#3589) and inline steps to task.new, task.addStep and task.editStep are not in scope, and the code changes do not reach those areas. No unrelated change was found in the evidence read. The diff of project_capabilities.rs could not be read through the diff tool because the changed blobs are missing from the checkout, so this verdict rests on the file read and the PR summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit reads a notebook page,
Then checks each model, task, and stage.
Through nested text, the clues run deep,
While kind-specific keys their records keep.
The saved steps now count what commands require.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: c51dc8b5-323f-4cbf-8328-d71753f1e6c3
Commits

Reviewing files that changed from the base of the PR and between d75248d and fcf62a4.

Files selected for processing: 3

  • crates/engine/src/cmd/notebook.rs
  • crates/engine/src/project_capabilities.rs
  • crates/engine/src/tests/capabilities_inline_project.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@jgregoriorincon
jgregoriorincon marked this pull request as ready for review December 2, 2026 19:27
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Code review

I read the full diff (3 files, about 305 added and 29 removed lines), the changed walk in project_capabilities.rs, and the commands it mirrors: model.import, task.import, notebook.open, read_text/inline_text_within, check_file, check_format, parse, run_cells, and script_commands. No prior review threads exist on this PR, so no earlier concerns were skipped.

Bugs: none found. The walk matches what each command reads: data before text, the same refusals (check_file, check_format, language().is_none()), and the same line grammar. Dropping unparseable script lines is safe because script_commands refuses the whole script before any line runs. Failures over-require, which is the safe direction. The RefCell borrows don't overlap on the recursion path, and non-test code has no unwrap/expect.

Security: none found.

Performance:

  • The notebook arm (project_capabilities.rs:254) parses the whole notebook and runs every capability check on every code line, on each save, on the UI thread, with no Cancel check. The PR gives a time figure for an unoptimized build but no peak memory. Nested parsed trees stay alive during recursion, so the peak can be a multiple of the 64 MiB budget. Confidence: medium. Inline comment posted.

Quality:

  • commands_capabilities (project_capabilities.rs:273) repeats the loop in task_capabilities (lines 168–174) and emits names in a different order. The sets match, but there are two copies of the predicate loop. Confidence: high on the duplication, low impact. Inline comment posted.
  • The PR's scope exclusion of inline steps on task.new, task.addStep and task.editStep is acknowledged and not counted as a finding.

AGENTS.md: no rule break found. The change adds tests for both clean and lossy input, and the PR description covers the surfaces it reaches. The twin routes are covered: project.openText and project.fromTemplate are walked, and layout.import, presentation.import, and the style and map imports are checked at the leaf level (project_capabilities.rs ~769, 770, 568, 623). report.open routes through report.existingTemplate.

Earlier concerns left alone: 0 (no prior threads).

Change size

Compared with main (merge base 256cd30 to PR head fcf62a4), covering the whole PR.

Measure Value
Files changed 3 (0 added, 3 modified, 0 removed, 0 renamed)
Size before 355.9 KB
Size after 368.9 KB
Total size change +12.9 KB
Path Before After Change
crates/engine/src/tests/capabilities_inline_project.rs 4.4 KB 11.6 KB +7.2 KB
crates/engine/src/project_capabilities.rs 319.8 KB 325.5 KB +5.7 KB
crates/engine/src/cmd/notebook.rs 31.8 KB 31.8 KB +11 B

@jgregoriorincon
jgregoriorincon marked this pull request as draft December 2, 2026 19:33
@jgregoriorincon
jgregoriorincon marked this pull request as ready for review December 2, 2026 19:58
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Code review

I found no new bugs, security issues, or AGENTS.md breaks in this PR. I read the full diff, the three changed files, and the code it depends on: the model.import, task.import and notebook.open commands, read_text/inline_text, script_line, run_cells, and check_file/check_format. I had no shell, so I did not build or run the tests. The findings below come from reading the code.

Bugs: none found.

  • Where the walk reads the text, the order matches the command: data before text, and a path is not read. Each command's refusal is mirrored, so an unreadable or refused document requires nothing and the command refuses it too. Confidence: high.
  • Notebook cells run one at a time through run_script, which refuses a script over MAX_SCRIPT_LINES before any command runs. The walk's per-cell take(MAX_SCRIPT_LINES) therefore over-reads and does not under-require. Dropping script.*, ui.* and notebook.run lines is also safe, because script_commands refuses the whole cell on them. Confidence: high.
  • notebook.open's clamp() only repairs what parse already refuses, so the walk sees the same cells. Confidence: medium-high.

Security: none found.

Performance: nothing new beyond the notebook memory and time concern already raised (see below).

Quality: nothing new beyond the duplicated task loop already raised (see below). Confidence: low. I did not find another point worth a comment.

AGENTS.md: no breaks found.

  • No unwrap, expect or panic appears in non-test code.
  • The notebook arm's cell-line checks run through script_line, and script_line already refuses script.*, ui.* and notebook.run.
  • No command or parameter was added, so command-surface.txt needs no update.
  • The saved requires shape is unchanged, so the schema needs no update.

Twins checked:

Already raised, left alone (2 concerns):

  • Notebook memory and time on the UI thread. The author replied with measurements, and the reply is not fully answered in the PR description.
  • The duplicated task predicate loop and its order. The author replied and declined the refactor.

Change size

Compared with the base branch, the whole PR: merge base 256cd30 to PR head fcf62a4.

Measure Value
Files changed 3 (0 added, 3 modified, 0 removed, 0 renamed)
Size before 355.93 KB
Size after 368.87 KB
Total size change +12.94 KB
Path Before After Change
crates/engine/src/tests/capabilities_inline_project.rs 4.37 KB 11.60 KB +7.23 KB
crates/engine/src/project_capabilities.rs 319.76 KB 325.45 KB +5.70 KB
crates/engine/src/cmd/notebook.rs 31.81 KB 31.82 KB +11 B

@jgregoriorincon
jgregoriorincon marked this pull request as draft December 3, 2026 01:00
auto-merge was automatically disabled December 3, 2026 01:00

Pull request was converted to draft

@jgregoriorincon
jgregoriorincon marked this pull request as ready for review December 3, 2026 01:00
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3619/
Web app https://preview.rustgis.app/pr-3619/app/
Commit fcf62a4

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

@jgregoriorincon
jgregoriorincon added this pull request to the merge queue Dec 3, 2026

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.

[Bug]: Saved steps that open or import an inline document don't require most layout capabilities

1 participant