Files
OpenShell/examples/multi-agent-notepad
Derek Carr 5952a5a23f feat(workspace): add workspace resource model with scoping, membershi… (#2243)
* feat(workspace): implement workspace model (Phase 1 of RFC 0011)

Implements workspace and membership model providing hard isolation
boundaries for multi-player OpenShell deployments.

Workspace CRUD with Kubernetes-style Terminating phase for graceful
deletion. All resources scoped by workspace via ObjectMeta. Membership
RPCs for workspace access control. Persistence migration shifts name
uniqueness to (object_type, workspace, name). Provider profiles support
platform and workspace scoping. Service routing uses workspace-prefixed
DNS labels. Inference routes renamed and workspace-scoped with
DeleteInferenceRoute RPC. Python SDK with WorkspaceClient, two-method
list pattern (workspace-scoped and for_all_workspaces), and workspace
parameter on all methods. CLI workspace flags, TUI workspace cycling.
K8s driver filters unmanaged CRs and uses delete preconditions. Podman
driver uses immutable container IDs. Label serialization fixed across
all put_if call sites.

Signed-off-by: Derek Carr <decarr@redhat.com>

* fix(cli): delegate sandbox upload command to existing upload function

The standalone `sandbox upload` command reimplemented upload logic
inline with two bugs: it used `Path::exists()` which follows symlinks
(rejecting dangling symlinks), and it ran git-aware filtering on
symlink sources. The `run::sandbox_upload()` function already handles
both cases correctly via `sandbox_upload_plan()`. Replace the inline
logic with a call to the existing function.

Signed-off-by: Derek Carr <decarr@redhat.com>

* fix(e2e): shorten sandbox names and fix test compatibility

Shorten the sandbox name in initial_sparse_policy_is_acknowledged_as_loaded
from 'e2e-2159-sparse-enrich' (22 chars) to 'e2e-sparse-enrich' (17 chars)
to comply with MAX_ROUTABLE_NAME_LEN (19 chars).

Also capture stderr in create_keep_with_args so future sandbox creation
failures include the actual CLI error instead of reporting empty output.

Signed-off-by: Derek Carr <decarr@redhat.com>

* test(workspace): add test coverage for workspace CRUD and persistence isolation

Add unit tests for workspace create happy path, get round-trip, get
not-found, get empty-name rejection, already-exists error, and
resolve_workspace not-found. Add persistence test proving cross-workspace
name uniqueness (same name in different workspaces produces separate
records). Add workspace name max-length boundary tests. Fix e2e harness
to include stderr in name-parse-failure error path. Align Python e2e
test_workspace_crud with try/finally pattern. Document provider profile
catalog workspace scoping gap in RFC 0011.

Signed-off-by: Derek Carr <decarr@redhat.com>

* fix(examples): update examples for workspace model compatibility

Shorten sandbox names in demo scripts to fit the 19-character
MAX_ROUTABLE_NAME_LEN limit: policy-demo prefix to pd-, multi-agent
notepad derives a short SANDBOX_TAG from the run ID, governance
interceptor uses gs-PID-RANDOM. Update vscode-remote-sandbox.md SSH
host aliases from openshell-{name} to openshell-{name}.{workspace}
format.

Signed-off-by: Derek Carr <decarr@redhat.com>

* feat(sdk): add workspace-scoped client and workspace CRUD

Add WorkspaceScopedClient modeled after kube::Api::namespaced — captures
workspace once and injects it into every sandbox request. Add workspace
CRUD methods (create, get, list, delete) and list_sandboxes_all_workspaces
on OpenShellClient. Extend SandboxRef with workspace field and add
WorkspaceRef type. Include mock tests for all new operations.

Signed-off-by: Derek Carr <decarr@redhat.com>

* fix(lint): resolve clippy warnings in workspace test assertions

Signed-off-by: Derek Carr <decarr@redhat.com>

* fix(docs): convert indented code blocks to fenced in RFC 0011

Signed-off-by: Derek Carr <decarr@redhat.com>

* fix(lint): resolve clippy warnings and apply cargo fmt across workspace

Auto-format with cargo fmt and fix clippy warnings exposed by the
reformat: unnecessary qualifications, map_unwrap_or, identical match
arms, unused variable prefix, dead code annotations, and let-unit-value
in e2e harness.

Signed-off-by: Derek Carr <decarr@redhat.com>

* fix(workspace): address workspace scoping issues from review

- Add workspace field to settings JSON output (CLI)
- Skip Podman containers missing workspace label instead of defaulting
  to empty string, matching K8s driver behavior
- Add resource_version to list_by_scope SELECT in both SQLite and
  Postgres backends, with regression test
- Gate PolicyLocalContext proposal/lookup routes on workspace readiness,
  returning 503 when workspace is not yet discovered
- Block sandbox and provider creation in TUI all-workspaces mode
- Clear workspace vectors in TUI reset_sandbox_state

Signed-off-by: Derek Carr <decarr@redhat.com>

* fix(workspace): make provider profile catalog workspace-aware

Thread workspace through snapshot_catalog so the
EffectiveProviderProfileCatalog enforces workspace boundaries on both
read and write paths. UserProviderProfileSource now loads platform-scoped
profiles (workspace "") plus the target workspace's profiles, preventing
cross-workspace duplicate profile ID collisions that previously caused
global catalog failures.

Update RFC 0011 to reflect catalog scoping is implemented in Phase 1
rather than deferred to future work.

Signed-off-by: Derek Carr <decarr@redhat.com>

* fix(persistence): include workspace column in atomic policy revision INSERT

put_policy_revision_atomic omitted the workspace column from the INSERT
into the objects table in both SQLite and Postgres backends, causing
atomically-written policy revisions to lose their workspace association.
Add workspace field to AtomicPolicyRevisionWrite and thread it through
both backend INSERT statements, matching the non-atomic put_policy_revision
path which already included it.

Signed-off-by: Derek Carr <decarr@redhat.com>

* fix(proxy): skip ancestor walk when socket owner is the entrypoint

collect_ancestor_identities walked the entire process tree above the
entrypoint when the connecting process was the entrypoint itself,
SHA256-hashing every ancestor binary (IDE, shell, container runtime).
On dev machines with large binaries in the ancestor chain this exceeded
the 30-second test timeout. When start_pid == stop_pid there are no
intermediate ancestors to verify, so return an empty list immediately.

Signed-off-by: Derek Carr <decarr@redhat.com>

* fix(workspace): make provider profile catalog scope-aware

Allow the same profile ID at platform and workspace scopes by
introducing layered catalog entries where workspace profiles shadow
platform profiles. Add source and scope fields to the ProviderProfile
proto and CLI output. Migrate List/Get handlers to the catalog,
fixing divergence with runtime profile resolution.

Signed-off-by: Derek Carr <decarr@redhat.com>

* fix(e2e): align podman e2e labels with centralized driver constants

The podman driver moved its container labels to the centralized
openshell.ai/ prefix, but the e2e test harness and cleanup script
still referenced the old openshell.sandbox-* keys, causing the
local_driver_token_restart test to fail on container lookup.

Signed-off-by: Derek Carr <decarr@redhat.com>

* fix(e2e): align python profile isolation test with scope-aware catalog

Platform profiles are now visible in workspace listings as fallbacks
per the layered catalog design. Update the assertion to match.

Signed-off-by: Derek Carr <decarr@redhat.com>

* fix(workspace): honor profile_workspace in runtime profile resolution

Runtime profile lookups now consult provider.profile_workspace via
get_type_profile_for_scope. Providers created with --global-profile
(profile_workspace="") resolve to the platform profile even when a
workspace profile shadows the same ID. All 6 runtime call sites
updated; type-only call sites remain scope-agnostic.

Signed-off-by: Derek Carr <decarr@redhat.com>

---------

Signed-off-by: Derek Carr <decarr@redhat.com>
2026-07-21 00:59:18 +00:00
..

Multi-Agent Shared Notepad Demo

Run multiple Codex coding agents in parallel OpenShell sandboxes, with a GitHub repository as the durable shared notepad they coordinate through.

Why GitHub as a shared notepad?

Long-running agents that produce artifacts — research notes, memory entries, reports, decision logs — need somewhere durable to write them. The store has to survive individual sandbox death, accept many concurrent writers safely, and stay inspectable after the fact. GitHub provides all three for free:

  • Durable across sandbox restarts. A sandbox can crash mid-run; the committed artifact persists.
  • Concurrency control built in. Every PUT must include the current file SHA, and the branch ref serializes commits. Racing writers see HTTP 409 and retry instead of silently overwriting each other.
  • Auditable. Every write is a commit with author, message, diff, and timestamp. Free observability.
  • Reviewable. Humans review agent output with the same PR/diff tooling they already use for code.
  • No new infra. Most teams already have a GitHub org.

The pattern works best when artifacts are markdown or other text (so diffs are useful) and when write rates are moderate (commits per minute, not per second). For higher rates or structured queries, graduate to a real datastore — see Beyond map/reduce below.

What this demo shows

The simplest useful shape: map/reduce. N worker agents fan out and write one note each; one synthesis agent reads them and writes a summary.

runs/<run-id>/notes/agent-1.md   ← worker 1 writes
runs/<run-id>/notes/agent-2.md   ← worker 2 writes
...
runs/<run-id>/summary.md         ← synthesis agent writes

Each worker gets a different research angle on the same topic. Workers share neither filesystem nor container — only the GitHub repository.

The demo also exercises two OpenShell features:

  • Provider-backed credentials. Sandboxes get placeholders, not the real Codex OAuth tokens or the GitHub token. The proxy resolves them at the network boundary.
  • Scoped network policy. Each sandbox can only GET and PUT paths under /repos/<owner>/<repo>/contents/runs/<run-id>/**.

Files in this example

  • demo.sh — host orchestration. Validates env, creates providers, launches sandboxes, waits for completion. Read this to understand how the run is driven from the host.
  • runner.sh — the script that runs inside each sandbox. Bootstraps Codex OAuth, calls codex exec, and writes the result to GitHub. Read this to understand the agent side.
  • policy.template.yaml — the network policy applied to every sandbox in the run. Renders to a concrete policy with the configured owner, repo, and run id.
  • prompts/worker.md, prompts/synthesis.md — agent instructions.

Prerequisites

  • OpenShell CLI from current main (or set OPENSHELL_BIN to the binary path)
  • A running OpenShell gateway: mise run gateway:docker for local development
  • Local Codex sign-in on the host: codex login
  • gh (GitHub CLI) signed in, or a GitHub PAT with contents:write
  • jq on the host
  • A disposable or demo-only GitHub repository

The demo writes under runs/<run-id>/. Use a repository created specifically for this demo, or one you're comfortable with the demo creating files in.

Quick start

export DEMO_GITHUB_OWNER=<owner>
export DEMO_GITHUB_REPO=<repo>
export DEMO_GITHUB_TOKEN="$(gh auth token)"

bash examples/multi-agent-notepad/demo.sh

gh auth token returns a token with whatever scopes you logged in with — usually broader than contents:write. If you'd rather use a scope-limited PAT, set DEMO_GITHUB_TOKEN to that value instead.

By default the script launches five worker agents and one synthesis agent in the OpenShell base image, where Codex is preinstalled. To run a faster smoke test:

export DEMO_AGENT_COUNT=2
bash examples/multi-agent-notepad/demo.sh

Optional settings:

export DEMO_TOPIC="How should teams evaluate sandboxed coding agents?"
export DEMO_AGENT_COUNT=5
export DEMO_BRANCH=main
export DEMO_RUN_ID="$(date +%Y%m%d-%H%M%S)"
export DEMO_KEEP_SANDBOXES=0

DEMO_RUN_ID is used in sandbox names and policy paths, so keep it lowercase letters, numbers, and -. Use a fresh DEMO_RUN_ID per run unless you intentionally want to overwrite a previous run's files.

DEMO_BRANCH may contain only letters, numbers, ., _, and -.

If a worker fails, the script prints the relevant log tail and keeps full logs in a temporary directory. Set DEMO_KEEP_SANDBOXES=1 to inspect sandboxes after the run; temporary providers are still removed.

How credential protection works

The host script reads your local Codex sign-in and creates a temporary OpenShell provider for the OAuth tokens. It also creates a temporary provider for the GitHub token. Sandboxes receive provider placeholders, not the real credential values.

When codex or curl inside a sandbox sends an authorized request, the OpenShell proxy resolves the placeholder at the network boundary and forwards the request upstream with the real credential. The credential values never sit in the sandbox filesystem.

Network policy

The script renders policy.template.yaml for the configured GitHub repository and run id. The policy allows:

  • Codex traffic to OpenAI and ChatGPT endpoints used by the community base image
  • Limited Codex plugin metadata reads from github.com/openai/plugins.git
  • GitHub REST GET and PUT calls scoped to /repos/<owner>/<repo>/contents/runs/<run-id>/**

The policy does not grant broad GitHub API access.

Beyond map/reduce: memory architecture variants

The pile-and-reduce shape in this demo is one of several useful patterns for using a Git repository as durable agent memory. Each is a different tradeoff between contention, complexity, and what you can ask of the artifact afterwards.

Pile (this demo)

Each agent writes its own file at a unique path. A reducer reads them all and writes a summary.

  • Best for: parallel exploration with bounded fan-in (research, multi-perspective analysis, code review across files).
  • Contention: low. Different files have independent SHAs, so the only source of 409s is branch-ref locking when many commits land at once. The retry loop in put_contents handles it.
  • Extension: hierarchical reduce — k workers per reducer, log(N) levels — for runs that exceed what one synthesis agent can chew through.

Append journal

A long-lived agent (or small team) appends entries to a shared journal.md across many sessions. Useful as chronological memory: "decisions made", "things learned", "open questions".

  • Best for: a single agent or a small group continuously writing an ordered log.
  • Contention: high if many writers; the GET-PUT-409-retry pattern is load-bearing here. For high-write-rate journals, switch to the Git Data API — create blobs concurrently, build one tree, commit once — to avoid branch-ref serialization.
  • Extension: split by month (journal/2026-05.md) to bound file size and spread contention across files.

Indexed memory

Agents read and write keyed entries — memory/<topic>.md per key. Higher- level agents look up "what do we know about X?" by reading the relevant file directly.

  • Best for: keyed memory that survives across runs and is queried by topic.
  • Contention: per-key, which is usually what you want. Hot keys still benefit from the retry loop.
  • Extension: maintain a index.md listing all keys. The index becomes the hot spot — update it lazily, or rebuild it from a directory listing when needed.

When to graduate beyond GitHub

GitHub stops being the right backend when you need sustained write rates above roughly 10/sec, sub-100ms reads, structured queries, or vector search. At that point reach for Postgres, a KV store, or a vector DB. The shape of the agent code stays similar — only the storage primitive changes.