Skip to content

feat(agent-server): Canvas Extensions installation persistence [3/4] - #4364

Merged
VascoSch92 merged 2 commits into
OpenHands:mainfrom
VascoSch92:extension-canvas-3
Aug 6, 2026
Merged

VascoSch92 merged 2 commits into
OpenHands:mainfrom
VascoSch92:extension-canvas-3

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

Adding installation persistence for canvas-extension.


AGENT:

Why

Part of the Canvas Extensions backend build-out (#4348). Issue #4350 identified two concrete bugs in reusing the shared openhands.sdk.extensions.installation framework (also used by Plugins/Skills) as-is for Canvas Extensions: InstallationInfo.enabled defaults to True, and neither InstallationManager.install() (on a genuinely new install) nor its self-healing directory discovery override that default. A freshly installed or newly discovered canvas extension would come back enabled, when Canvas Extensions require explicit opt-in.

This branch also carries #4349 (requested_ref tracking) forward -- it was implemented directly on extension-canvas-2 but never had its own PR, since it's small, independent SDK work with no canvas-extensions-specific surface.

Note for reviewers: this branch is stacked on top of #4361 (still open, not yet merged), so the diff below currently includes #4348's manifest/containment files again alongside the new work. Those shrink out of this diff automatically once #4361 merges into main.

Summary

  • Add openhands-agent-server/openhands/agent_server/canvas_extensions/installed.py: a thin wrapper around the shared InstallationManager, following the same shape as openhands/sdk/plugin/installed.py, with on-disk layout at ~/.openhands/canvas-extensions/installed/<name>/.
  • Force enabled=False on every write path that creates a new tracked entry (fresh install, self-healing discovery) via an explicit post-write correction, while correctly preserving the prior enabled state on a legitimate force-reinstall of an already-tracked extension. Hardened against a stale/tampered .installed.json entry with no matching directory being treated as "already installed."
  • Wire up resolve_entrypoint() containment checking (built in Canvas Extensions: manifest model, validation, and entrypoint containment #4348 but never called) at manifest load time, so both install and discovery enforce it.
  • Add MANIFEST_FILENAME (Final[str]) constant to manifest.py.
  • update_canvas_extension() deliberately not added -- that's the install(force=True)/.update() anti-pattern issue Canvas Extensions: staged install + atomic swap + two-step refresh (check/apply) #4351 (staged install + atomic swap) exists to replace, not something to introduce here.

Issue Number

#4350

How to Test

uv run pytest tests/agent_server/canvas_extensions -v

77 tests pass (25 for the new persistence module, plus the existing manifest/containment suites). Coverage includes the three regression scenarios named in #4350 (fresh install lands disabled, a smuggled enabled: true stale-metadata record is ignored, a manually-placed directory is discovered disabled), force-reinstall state preservation in both directions, mixed-state handling across multiple extensions in one listing call, and rejection/skip paths for malformed manifests, mismatched manifest names, and entrypoint containment escapes at both install and discovery time.

Mutation-tested the two highest-stakes correctness properties directly: neutering the force-disable correction fails 5 of the new tests; disabling the pre-existing/new-entry distinction fails the mixed-state and force-reinstall tests specifically. Confirms the tests exercise real logic, not just happy-path assertions.

uv run pre-commit run --files <changed files> passes (ruff format/lint, pyright, import-dependency-rules, tool-subclass-registration).

Video/Screenshots

N/A -- backend persistence module only, no UI or HTTP route in this PR (REST API surface is #4352, blocked on this one).

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

Scoped to #4350 (+ carrying forward the already-implemented #4349). Everything else in the epic remains separate, already-filed tickets: staged install/atomic swap (#4351, blocked on this), REST API surface (#4352), OpenAPI/typescript-client (#4354), audit logging (#4355), manifest API-scope + reserved names (#4356), adversarial fuzz suite (#4357).

@VascoSch92
VascoSch92 changed the base branch from main to extension-canvas-2 August 4, 2026 11:10
@VascoSch92
VascoSch92 marked this pull request as ready for review August 4, 2026 11:11

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This review was created by an AI agent (OpenHands) on behalf of the repository maintainers.

Summary

Reviewed the Canvas Extensions manifest and entrypoint-containment module (openhands-agent-server/openhands/agent_server/canvas_extensions/). All 52 tests pass locally. The PR introduces the manifest schema (CanvasExtensionManifest, CanvasExtensionPage, CanvasExtensionContributes) and the security-critical resolve_entrypoint() containment primitive.

Security Analysis

The entrypoint containment is well-designed with defense-in-depth:

  1. Syntactic field validation (_validate_entrypoint) rejects empty strings, absolute paths, and .. path components at model construction time.
  2. Filesystem-level containment (resolve_entrypoint) resolves symlinks via Path.resolve() and checks is_relative_to(root) — catching symlink escapes, symlinked-directory escapes, symlinked package roots, and the pathlib root / "/abs" footgun. The is_file() check additionally rejects directories, dangling symlinks, and symlink cycles (confirmed by the adversarial test suite).
  3. package_root.resolve() is called before joining — correctly normalizing a symlinked package root before containment is evaluated.

The function returns the fully-resolved path (symlinks already eliminated), which is the TOCTOU-safe path to serve. The docstring correctly states this must be called immediately before serving — follow-up ticket #4352 (REST API surface) should ensure it serves the returned resolved candidate path directly, not a re-read through root / entrypoint, to avoid a symlink-swap TOCTOU window between resolution and read.

Correctness

  • The candidate != root guard on line 154 is functionally redundant (is_relative_to returns True when paths are equal, so not is_relative_to(root) is already False), but it documents the . edge case explicitly. Not a bug — behavior is identical with or without it.
  • Name/contribution-id validation reuses validate_extension_name() from the SDK rather than duplicating the kebab-case regex — consistent with DRY and the repo's reuse-over-duplicate guidance.
  • Duplicate page id/path detection runs via field_validator on pages and correctly fires through model_validate(dict) (the real JSON ingestion path), verified by test_duplicate_page_contribution_ids_rejected_through_full_manifest.
  • model_copy(update=...) in the containment tests correctly bypasses field validators (Pydantic v2 design) to test resolve_entrypoint in isolation — this is appropriate for adversarial testing of the defense-in-depth layer.

Test Coverage

The adversarial test suite is thorough: textual traversal (4 variants), symlinked file/directory/package-root escapes, symlink cycles, the absolute-path footgun, entrypoint-as-directory, missing entrypoint, and a legitimate in-package symlink that must still resolve. Manifest validation covers required fields, wrong types, duplicate ids/paths, and invalid name/id/path patterns. No gaps identified.

Risk Assessment

Low risk. This PR adds a new self-contained module with no changes to existing code paths — no Agent, Conversation, or existing agent-server routes are modified. The import of openhands.sdk.extensions.installation.utils.validate_extension_name is permitted by the repo's import dependency rules (agent-server to sdk is allowed). The module is not yet wired to any HTTP route (that is #4352), so there is no attack surface exposed in this PR. The security-critical containment logic is sound and well-tested.

Material Findings

No material issues found. The two style-level suggestions from the prior review (comment on line 42, redundant guard on line 154) are non-material and I have no additional inline findings to add.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

Posted a GitHub PR review on PR #4364 (commit 62ae3b2) as all-hands-bot with event COMMENT (review id 4853810343).

Review summary:

The PR adds a thin wrapper around the shared InstallationManager to enforce disabled-by-default semantics for Canvas Extensions. The design and test coverage are strong, but two findings were raised:

  1. Material — load_installed_canvas_extensions bypasses the force-disable correction (inline at installed.py:173): This function delegates directly to manager.load_installed(), whose internal list_installed() → sync() → discover_untracked() creates newly-discovered entries with enabled=True (the default). Since this path never calls _force_disable_new, a manually-dropped extension directory will be discovered and loaded as enabled — contradicting the PR's core disabled-by-default guarantee. The existing discovery test only covers list_installed_canvas_extensions, not this function.

  2. Low — _force_disable_new doesn't check manager.disable() return value (inline at installed.py:96): If disable() returns False, info.enabled is set to False in memory while disk remains enabled=True, a returned-state-vs-persisted-state discrepancy.

Risk assessment: Medium. Both inline comments were accepted by the GitHub review API.

This comment was posted by an AI agent (OpenHands).

@VascoSch92 VascoSch92 changed the title feat(agent-server): Canvas Extensions installation persistence [3/4] feat(agent-server): Canvas Extensions installation persistence Aug 5, 2026
@VascoSch92 VascoSch92 changed the title [3/4] feat(agent-server): Canvas Extensions installation persistence feat(agent-server): Canvas Extensions installation persistence [3/4] Aug 5, 2026

@smolpaws smolpaws 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.

🐾 Hi, I'm smolpaws — a feline OpenHands agent doing a review pass to help. Reviewed this layer against its base (extension-canvas-2).

Verdict: well-reasoned layer, but the disabled-by-default guarantee has one real gap — it isn't enforced on the load path.

The module's stated promise (docstring) is: every newly created entry, whether from install() or from self-healing directory discovery, lands enabled=False until explicitly enabled. install_canvas_extension and list_installed_canvas_extensions enforce that via _force_disable_new. But:

1. load_installed_canvas_extensions() bypasses the guarantee (installed.py:173).
It calls manager.load_installed() directly — no _force_disable_new, no _tracked_names pre-check (unlike list_installed_canvas_extensions at :166). Chain: load_installed() → list_installed() → session.sync() → discover_untracked(), which builds entries with InstallationInfo.enabled defaulting to True, persists them, then load_installed() returns every enabled one.

So a directory dropped straight into the installed dir — exactly the case your list_installed_canvas_extensions docstring says "also lands disabled" — is loaded enabled on the first load_installed_canvas_extensions() call, and stays enabled because enabled: true is now written to .installed.json. This contradicts both the module docstring and that function's own docstring.

Note load_installed() returns manifests (T), not InstallationInfo, so you can't just reuse _force_disable_new here — you'd want to run the disciplined discover-and-disable pass first, then load only what's still enabled.

2. Minor — the disable is a second write, not atomic with discovery (installed.py:166).
_force_disable_new calls manager.disable(), which does a separate full metadata load/sync/save per discovered entry, on top of the sync list_installed() already ran. Two consequences: (a) discovering N dirs triggers ~N extra directory re-scans + manifest re-parses per list call — correct but wasteful; (b) the "flip to disabled" write is separate from the "discovered as enabled" write, so a reader racing between them can briefly observe the entry enabled. Eventually-consistent, not atomic.

What's sharp: the _tracked_names reasoning — a stale metadata record with no matching directory must not count as "already installed," or a real install would inherit its enabled state as if it were a force-reinstall. That's a subtle correctness point and you got it right. Tests are thorough too.

Fixing #1 is the one I'd want resolved before this ships as the "disabled-by-default" layer. 🐾

@enyst enyst left a comment

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.

Seem this little detail might be worth a quick pass?

So a directory dropped straight into the installed dir — exactly the case your list_installed_canvas_extensions docstring says "also lands disabled" — is loaded enabled on the first load_installed_canvas_extensions() call, and stays enabled because enabled: true is now written to .installed.json. This contradicts both the module docstring and that function's own docstring.

@VascoSch92
VascoSch92 changed the base branch from extension-canvas-2 to main August 6, 2026 09:17
@all-hands-bot

Copy link
Copy Markdown
Collaborator

🤖 OpenHands is reviewing this PR.

Head commit: d0aec32ae27ab308267a7778a46656d9f1d3e1fe
View the conversation: https://oss-agent-canvas.ngrok.dev/conversations/f4e81fb7-8238-4932-878d-04c0b48775e4

This comment was posted by an AI agent (OpenHands).

…sabled-by-default guarantee

InstallationManager.install() and its self-healing directory discovery
both default a freshly created tracked entry to enabled=True. Canvas
Extensions require any newly created entry -- from an explicit install
or from discovery -- to land disabled until explicitly enabled, so this
wraps the shared manager and corrects that as an explicit post-write
step, without touching the shared framework used by Plugins/Skills.
…alled_canvas_extensions

load_installed_canvas_extensions() called InstallationManager.load_installed()
directly, skipping the force-disable pass that list_installed_canvas_extensions()
applies to newly discovered entries. A directory dropped straight into the
installed dir was loaded (and persisted) as enabled on first load, contradicting
the module's disabled-by-default guarantee.
@VascoSch92
VascoSch92 enabled auto-merge (squash) August 6, 2026 09:24
@VascoSch92
VascoSch92 merged commit ca9652b into OpenHands:main Aug 6, 2026
28 checks passed
@github-actions github-actions Bot mentioned this pull request Aug 6, 2026
5 of 7 tasks
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.

4 participants