Skip to content

Add support for creating stateless backends#150

Merged
StpMax merged 45 commits into
mainfrom
feat/stateless_backend_creation
Jun 12, 2026
Merged

Add support for creating stateless backends#150
StpMax merged 45 commits into
mainfrom
feat/stateless_backend_creation

Conversation

@StpMax

@StpMax StpMax commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds the ability to generate, launch, and publish artifacts with a real backend process — not just static HTML. Introduces two new artifact types (fullstack-stateless-app, fullstack-stateful-app), a launch_backend tool, and fullstack-aware publishing with datasource-secret resolution.

NOTE: In the future, fullstack artifacts generation is planned to be moved to a separate tool. This will enable us to ensure that the artifact code contains all the necessary code required for publishing. Work on this is being conducted in a separate branch feat/stateless_backend_creation_tool.

Core changes

Backend launching

  • New core/artifacts/backend_launcher.py — standalone helper (decoupled via a ScratchpadPoolLike Protocol so cowork can reuse it): installs requirements.txt into the scratchpad venv, picks a free port, spawns backend.py --port N , runs an HTTP→TCP readiness probe, and idempotently reaps any prior process for the slug.
  • New launch_backend tool wiring it into a ChatSession; tracked backends are reaped in session.close().
  • ScratchpadRuntime.venv_python() / LocalScratchpadRuntime.ensure_venv() / ScratchpadManager.venv_python() expose the venv interpreter to auxiliary processes.

Artifact metadata

  • New DatasourceRef model + port and datasources fields on Artifact.
  • set_artifact_primary tool/handler/store-method generalized to update_artifact (primary + port + datasources), using an _UNSET sentinel so only passed fields change.
  • Added schemaVersion field (+ METADATA_SCHEMA_VERSION constant) to version the on-disk layout for future migrations; legacy files load as v1.

Publishing

  • publisher.publish() detects fullstack artifacts and bundles backend.py + static/ + requirements.txt, resolving DS_*__FIELD secrets from the local vault into the JSON body (secrets travel beside the zip, not inside it). Sends python_version.
  • /publish now lists/selects both HTML reports and fullstack artifacts; explicitly publishing a fullstack app's static/index.html correctly publishes the whole bundle instead of the orphaned frontend.
  • .py/.txt added to credential-scrubbed extensions.

Prompts

  • New universal ARTIFACTS contract and BACKEND_GENERATION guidance; output_context replaced by output_dir threaded through the session config.

Fixes

  • scrub_credentials now uses word-boundary regex (avoids over-eager substring redaction of short secrets) while keeping the empty-value guard (a registered-but-unset secret var no longer corrupts output).

@entelligence-ai-pr-reviews

entelligence-ai-pr-reviews Bot commented May 8, 2026

Copy link
Copy Markdown

Confidence Score: 5/5 - Safe to Merge

Safe to merge — this PR adds support for creating stateless backends and has passed automated review without any identified issues. The implementation appears clean with no logic bugs, security concerns, or correctness problems flagged by the review system. No pre-existing unresolved comments carry over into this PR's scope.

Key Findings:

  • No review comments were generated during automated analysis, indicating no detectable logic, security, or correctness issues in the stateless backend creation support.
  • The PR is focused in scope — adding stateless backend support — which limits the blast radius of any potential undetected edge cases.
  • Absence of any flagged null-checks, missing validations, or race conditions in the new backend lifecycle code suggests standard defensive patterns are being followed.

@torrmal

torrmal commented May 8, 2026

Copy link
Copy Markdown
Contributor

this is good, we need to make sure tihs work all the way to this repo https://github.com/mindsdb/cowork
as that one assumes the artifacts hav e aspecific location, etc.
in that cowork repo, it would be amazing if there was a proxy endpoint for scratchpad:server endpoints, so all requests from the artifact are going thorugh an endpoint that later we can secure with some sort of authentication for sharing,
@StpMax

@StpMax StpMax marked this pull request as ready for review June 1, 2026 13:23
@entelligence-ai-pr-reviews

entelligence-ai-pr-reviews Bot commented Jun 1, 2026

Copy link
Copy Markdown

EntelligenceAI PR Summary

This PR adds fullstack (FastAPI) artifact support to Anton, extending publishing, backend lifecycle management, LLM prompts, and the artifact metadata model.

  • anton/core/artifacts/backend_launcher.py: New module for launching artifact backend subprocesses with venv provisioning, port allocation, process reaping, and readiness probing
  • anton/core/artifacts/models.py / store.py: Artifact model gains schemaVersion, port, datasources; set_primary replaced by generic update() with _UNSET sentinel for partial updates
  • anton/core/backends/ (base.py, local.py, manager.py): New venv_python() and ensure_venv() methods expose scratchpad interpreter to external callers
  • anton/core/llm/prompts.py / prompt_builder.py: Adds ARTIFACTS_PROMPT and BACKEND_GENERATION_PROMPT; removes output_context field, injects output_dir directly into prompt build pipeline
  • anton/core/tools/tool_defs.py / tool_handlers.py: set_artifact_primary replaced by update_artifact; new launch_backend tool added with full lifecycle handling
  • anton/core/session.py: Tracks spawned backends in _tracked_backends; adds graceful teardown via _reap_tracked_backends(); propagates output_dir through config
  • anton/publisher.py: Fullstack publish path added with zip bundling, datasource secret collection, and enriched request payload
  • anton/utils/datasources.py: scrub_credentials() uses regex word-boundary assertions to prevent partial credential matches
  • Tests: Updated across four test files to use store.update(), pass output_dir="", and align with new artifacts directory structure

Confidence Score: 5/5 - Safe to Merge

Safe to merge — this PR adds support for creating stateless backends and has passed automated review with zero issues identified across all analysis dimensions. The implementation appears clean with no logic bugs, security concerns, or correctness problems flagged by either heuristic analysis or line-by-line review. No pre-existing unresolved comments are associated with this change.

Key Findings:

  • Automated heuristic analysis found zero critical, significant, high-risk, or medium-severity issues across the entire changeset.
  • No review comments were generated during the current review pass, indicating the code follows expected patterns and conventions without obvious correctness or safety gaps.
  • No pre-existing unresolved review threads are carried into this PR, meaning there is no accumulated technical debt or deferred concerns to consider.
  • The PR scope — adding stateless backend creation support — is a well-defined, bounded feature addition that did not trigger any security or data-integrity warning patterns.

Comment thread anton/core/artifacts/backend_launcher.py
Comment thread anton/core/tools/tool_handlers.py Outdated
Comment thread anton/core/artifacts/backend_launcher.py Outdated
@StpMax StpMax requested review from ZoranPandovski and ea-rus June 1, 2026 13:50

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

I've addded few comments but otherwise ready to merge

return uuid.uuid4().hex[:8]


_UNSET = object()

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.

Can we use pydantic dataclass instead of _UNSET ?

Comment thread anton/core/artifacts/backend_launcher.py
Comment thread anton/core/tools/tool_defs.py
Comment thread anton/core/llm/prompts.py
Comment thread anton/core/llm/prompt_builder.py
@StpMax StpMax added this pull request to the merge queue Jun 12, 2026
Merged via the queue into main with commit 202d2fd Jun 12, 2026
5 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants