Skip to content

chore(sandbox): delete the TypeScript daemon, Go is the only one - #5575

Merged
pedrofrxncx merged 1 commit into
mainfrom
chore/remove-ts-daemon
Aug 3, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
chore/remove-ts-daemon

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Aug 2, 2026 •

Copy link
Copy Markdown
Collaborator

What

Deletes packages/sandbox/daemon/** — the TypeScript sandbox daemon. ~24k lines
out. The Go daemon (packages/sandbox/daemon-go/) has been what every sandbox
claims since #5484 → #5569; this removes the losing half.

Kept, because none of it is the daemon:

Was Now
daemon/daemon*.e2e*.ts daemon-e2e/ — the black-box conformance suite, no longer living inside one implementation. Default target is daemon-go/bin/daemon; DAEMON_E2E_CMD still swaps in any binary.
daemon/e2e-stub/stub-daemon.mjs daemon-e2e/stub-daemon.mjs (used by the native stub-seam nightly).
daemon/org-fs/* orgfs/ — org-fs client + WebDAV (Studio-side) and the privileged mounter sidecar, which is its own image and stays TypeScript. repo-link.ts/thread-links.ts deleted (Go's internal/orgfs owns them).
daemon/types.ts, daemon/config-store/types.ts, daemon/events/types.ts daemon-protocol.ts — the config + SSE wire types the daemon client and web UI consume, trimmed to what crosses the wire.

Also removed as newly-dead: sync detachMount (only the deleted exit hook and
the deleted link-daemon called it), node-pty (nothing imports it — it existed
because the TS bundle marked it external), the daemon @opentelemetry exporter
deps, the ./daemon/routes/dispatch and ./org-fs/detach-mount package exports,
buildSandboxDaemon() in the server bundler, and rg/where from knip's
ignoreBinaries.

One image

The Dockerfile's ts/go targets collapse into a single stage.
release-studio-sandbox.yaml publishes only studio-sandbox-go; the
studio-sandbox name is frozen at 1.35.3 (its last TS tag) and stays pullable
for rollback. The image-bump dispatch to deco-apps-cd now names
studio-sandbox-go so tag bumps keep landing.

CI

  • sandbox-daemon.yml: the two daemon-e2e jobs become one — Go build + vet +
    go test -race + the suite — keeping the daemon-e2e job name so branch
    protection is unaffected. docker-smoke builds and boots one image.
  • daemon-e2e-windows.yml deleted: it gated packages/sandbox/daemon/**, a
    subtree that no longer exists, by running the TS bundle under Bun on Windows.
  • native.yml / release-orgfs-sidecar.yaml: path filters and test globs
    repointed.

Docs (Go is the daemon)

Testing

  • bun test packages/sandbox/daemon-e2e/ → 184 pass, 0 fail against
    daemon-go/bin/daemon with DAEMON_E2E_CMD unset (proves the new default).
  • go build, go vet ./... clean.
  • bun run --workspaces check clean; bun run lint 0 errors; knip clean.
  • docker build -f deploy/helm/sandbox-env/orgfs-sidecar/Dockerfile . succeeds
    from the new orgfs/ path; full sandbox image build succeeds.
  • packages/sandbox unit tests: 235 pass.

Prod cutover — MUST land first: decocms/deco-apps-cd#193

Prod runs chart sandbox-env-0.9.63, which renders two templates:
studio-sandbox-prod (image.repository, still …/studio-sandbox = TS) and
studio-sandbox-prod-go. Prod claims the TS one for almost everything —
Studio prod is 4.158.7 (cut Aug 1), which predates #5568, so the deployed
resolver is still opt-in (flags?.sandbox_go_daemon ? "go" : "ts"):

$ kubectl -n agent-sandbox-system get pods
studio-sandbox-prod-7696k     …/studio-sandbox:1.35.3       claimed   <- TS
studio-sandbox-prod-w8tdk     …/studio-sandbox:1.35.3       claimed   <- TS
studio-sandbox-prod-zx9d8     …/studio-sandbox:1.35.3       claimed   <- TS
studio-sandbox-prod-go-tvj77  …/studio-sandbox-go:1.35.2    spare, idle 4h20m

So merging this PR without the cutover would stop publishing the image tag prod
actually pulls. decocms/deco-apps-cd#193 is the one-line fix (both envs):

image:
  repository: ghcr.io/decocms/studio/studio-sandbox-go   # was …/studio-sandbox

Both templates then run the Go image, so every claim and both warm pools are Go
regardless of Studio version or org flag — no chart bump, no Studio deploy.
Bumping the chart to 0.10.x afterwards deletes the redundant -go template (and
the -go-suffixed pod names) — order per its Chart.yaml note: Studio first.

Follow-up

daemon-go/ keeps its name in this PR — renaming it to daemon/ would conflict
with every open PR touching it (#5339, #4428). Worth doing once those land.
Same for the -go image suffix, once prod has settled on it.


Summary by cubic

Removed the TypeScript sandbox daemon and standardized on the Go daemon. One image (studio-sandbox-go), one implementation (packages/sandbox/daemon-go/), and the e2e suite now targets the built Go binary.

  • Refactors

    • Deleted packages/sandbox/daemon/** and related deps; kept non-daemon pieces: packages/sandbox/daemon-e2e/ (black-box HTTP/SSE), packages/sandbox/orgfs/ (client/WebDAV + privileged sidecar), and packages/sandbox/daemon-protocol.ts (wire types).
    • Image: Dockerfile collapses to a single stage; only ghcr.io/decocms/studio/studio-sandbox-go is published. studio-sandbox is frozen at its last TS tag for rollback.
    • CI: unified daemon e2e job (Go build + vet + go test -race + suite), removed daemon-e2e-windows.yml, repointed path filters, and dropped buildSandboxDaemon() from the server bundler.
    • Docs: packages/sandbox/README.md now states "Go is the daemon", added packages/sandbox/daemon-go/README.md, and updated references across Rust comments/specs.
  • Migration

    • Before merging, switch image.repository in decocms/deco-apps-cd (stg and prod) to ghcr.io/decocms/studio/studio-sandbox-go so all claims run the Go image regardless of org flags.
    • Optional follow-up: bump the chart to 0.10.x to remove the now-redundant -go template.

Written for commit 1b741a9. Summary will update on new commits.

Review in cubic

The Go daemon has been the implementation every sandbox claims since #5484/
#5569; the TS daemon was still building, still shipping in a second image and
still claiming half the docs. Delete it (~24k lines) and keep only what is not
the daemon:

- `daemon-e2e/` — the black-box HTTP/SSE conformance suite, moved out of the
  implementation it used to live inside. Its default target is now
  `daemon-go/bin/daemon` instead of the TS bundle; `DAEMON_E2E_CMD` still
  swaps in any other binary.
- `orgfs/` — the org-fs client/WebDAV plus the privileged mounter sidecar,
  which is its own image and stays TypeScript. Dead `detachMount` (the sync
  twin, only reachable from the deleted daemon's exit hook) removed with it.
- `daemon-protocol.ts` — the config + SSE wire types Studio's daemon client and
  web UI consume, previously reached into the daemon source.

One image, one daemon: the Dockerfile's `ts`/`go` targets collapse into a
single stage and `studio-sandbox-go` is the only image published — the
`studio-sandbox` name is frozen at 1.35.3 (its last TS tag) and stays pullable
for rollback. The image also drops the node-pty install that existed only
because the TS bundle marked it external.

CI: the two daemon-e2e jobs become one (Go, keeping the `daemon-e2e` job name),
docker-smoke builds and boots one image, and daemon-e2e-windows.yml — a gate on
a subtree that no longer exists — is deleted.

Docs say Go: sandbox README rewritten (it still described the Bun daemon and
the removed desktop link), a README for daemon-go, CONTRIBUTING rule #4 and
AGENTS gotcha #8 rewritten, and every `packages/sandbox/daemon/...` pointer in
the Rust local-api parity comments repointed at its Go or daemon-e2e successor.
@pedrofrxncx
pedrofrxncx merged commit 0318d04 into main Aug 3, 2026
29 checks passed
@pedrofrxncx
pedrofrxncx deleted the chore/remove-ts-daemon branch August 3, 2026 00:48
decocms Bot pushed a commit that referenced this pull request Aug 3, 2026
PR: #5575 chore(sandbox): delete the TypeScript daemon, Go is the only one
Bump type: patch

- decocms (apps/api/package.json): 4.160.2 -> 4.160.3
- @decocms/native (apps/native/package.json): 4.160.2 -> 4.160.3
- @decocms/harness (packages/harness/package.json): 2.8.3 -> 2.8.4
- @decocms/sandbox (packages/sandbox/package.json): 1.35.3 -> 1.35.4
- @decocms/shared (packages/shared/package.json): 0.13.2 -> 0.13.3
- deploy/helm/sandbox-env (chart 0.10.3) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.35.4

Deploy-Scope: server
viktormarinho added a commit that referenced this pull request Aug 3, 2026
… hosts them

#5575 deleted the TS sandbox daemon, which was the last runtime that
registered `claudeCodeHarnessFactory`/`codexHarnessFactory`; the preceding
commit dropped the cluster's unreachable registration. That left the whole TS
CLI harness implementation with zero production consumers — the live one is
Rust (`apps/native/crates/harness`), which is a port, not a consumer.

Deleted: packages/harness/src/{codex,claude-code/index,resolve-executable,
model/index}, cli-session-error, cli-stream-metadata, the ./claude-code and
./codex export subpaths, and the ai-sdk-provider-{claude-code,codex-cli} deps.

Kept: claude-code/model/agent-tiers.ts + chat-tier.ts (apps/web and apps/api
import `resolveAgentTier` to build the model picker), and cli-harness.ts's
`cliProviderName` (the read side of CLI session resume).

Knip could not see any of this: packages/harness's exports map has a "./*"
glob, so every src file looks like a public entrypoint.

- cli-import-boundary.test.ts deleted: it read claude-code/index.ts and
  codex/index.ts off disk, so it fails ENOENT once they are gone.
- cli-harness.test.ts covered only `isCliHarness`, which was dead. Repointed
  to `cliProviderName` — the surviving export, and a cross-language contract
  with the Rust crate that had no test at all.
- cli-message-prep.ts lost `prepCliMessages` (CLI-only) and kept
  `extractUserText` (decopilot). Renamed to extract-user-text.ts so the
  filename stops describing code that is gone.
viktormarinho added a commit that referenced this pull request Aug 3, 2026
… on the package (#5573)

* chore(harness): drop the unreachable cluster registration of the CLI harnesses

`assertHarnessRunsInCluster` throws for claude-code/codex at the dispatch
gate, and `dispatchRunAndWait` throws again on any non-decopilot id — so the
factories the barrel registered could never be reached by a lookup. Local CLI
runs happen in the Tauri app's Rust harness crate; cloud-CLI is unimplemented.

Also removes `buildSandboxDaemon()` from the server bundler: it built
packages/sandbox's daemon bundle + typegen tarball on every API build for
host/runner.ts's text-import, and that file no longer exists (#5570). The
sandbox image workflow runs its own `bun run --cwd=packages/sandbox build`,
so the image is unaffected.

* chore(harness): drop the source-text assertions from the registration test

Asserting a file's source does not contain a symbol tests the deletion, not
the behavior. The registry lookup is already covered by the gate's own tests.

* chore(harness): delete the TypeScript CLI harnesses, now that nothing hosts them

#5575 deleted the TS sandbox daemon, which was the last runtime that
registered `claudeCodeHarnessFactory`/`codexHarnessFactory`; the preceding
commit dropped the cluster's unreachable registration. That left the whole TS
CLI harness implementation with zero production consumers — the live one is
Rust (`apps/native/crates/harness`), which is a port, not a consumer.

Deleted: packages/harness/src/{codex,claude-code/index,resolve-executable,
model/index}, cli-session-error, cli-stream-metadata, the ./claude-code and
./codex export subpaths, and the ai-sdk-provider-{claude-code,codex-cli} deps.

Kept: claude-code/model/agent-tiers.ts + chat-tier.ts (apps/web and apps/api
import `resolveAgentTier` to build the model picker), and cli-harness.ts's
`cliProviderName` (the read side of CLI session resume).

Knip could not see any of this: packages/harness's exports map has a "./*"
glob, so every src file looks like a public entrypoint.

- cli-import-boundary.test.ts deleted: it read claude-code/index.ts and
  codex/index.ts off disk, so it fails ENOENT once they are gone.
- cli-harness.test.ts covered only `isCliHarness`, which was dead. Repointed
  to `cliProviderName` — the surviving export, and a cross-language contract
  with the Rust crate that had no test at all.
- cli-message-prep.ts lost `prepCliMessages` (CLI-only) and kept
  `extractUserText` (decopilot). Renamed to extract-user-text.ts so the
  filename stops describing code that is gone.

* docs(harness): correct the README for a package with one harness

The overview still advertised Claude Code and Codex harnesses, a codex usage
example, and "portable between the API and sandbox daemon" as the boundary
rationale — all three are gone. Restates the real one: apps/web and
packages/sandbox are lint-barred from apps/api/src, so the contracts the three
share have to live outside the API.

* chore(harness): enumerate the exports map so knip can see this package

packages/harness's exports ended in "./*": ["./src/*.ts", "./src/*/index.ts"],
so every file under src/ looked like a public entry point and knip could never
report anything here as unused. That is how ~2k lines of dead CLI harness code
stayed invisible until it was grepped by hand.

Replaces the glob with the 56 subpaths actually imported (plus "."), generated
from the real import specifiers across apps/ and packages/ and verified to
resolve. No consumer changes: bun run check passes in all 15 workspaces.

Knip now reports on this package, and immediately found two things the glob was
hiding:
- no-background-tasks-prompt.ts — a system-prompt fragment whose own doc says
  "shared across CLI harnesses (claude-code, codex)"; orphaned when those were
  deleted. Removed.
- THOUGHT_SIGNATURE_SEPARATOR — used only inside its own module. Narrowed to
  module-private.

No guard test: a missing entry is already a compile error (TS2307) on
bun run check. Documented in the README, since that message reads as "file
missing" when the file is merely unexported.
viktormarinho added a commit that referenced this pull request Aug 3, 2026
…arness registry

Final step of the harness-package teardown (#5573 deleted the dead TS CLI
harnesses; #5577 moved the wire contracts to @decocms/shared/harness). After
those, the package was 9.5k lines consumed by apps/api alone — its stated
reason to exist (portability into the desktop daemon's bundle) died with the
link daemon (#5570) and the TS sandbox daemon (#5575).

The move:
- packages/harness/src → apps/api/src/harnesses/lib (git mv, history kept).
  58 api files rewritten from "@decocms/harness/X" to "@/harnesses/lib/X".
  All the lib's deps were already in apps/api's manifest; the workspace
  package, its README, tsconfig and dependency edges are gone.
- The leaf discipline survives as a directory rule: ban-cross-tree-imports
  now applies its harness clauses (no @/ imports, no @/core/studio-context,
  no @aws-sdk/*) to apps/api/src/harnesses/lib/, and no-cross-tree.test.ts
  moved with the tree and still guards it. The engine stays a leaf; only the
  package wrapper is gone.

The registry collapse (spec §5.4, executed at last):
- InProcessSandboxClient absorbs localDispatch and hard-wires
  decopilotHarnessFactory — the registry it consulted was a Map with one
  entry, populated by an import side effect. registry.ts, localDispatch, the
  orphaned lib barrel and their registration tests are deleted; the client's
  tests now assert the real factory's contract (eager CLI guard, lazy stream)
  instead of stubbing a seam.
- apps/api/src/harnesses/index.ts keeps one side effect: registering the
  cluster environment builder the factory requires.

Fallout knip caught once the package boundary stopped hiding it:
- buildRepoEnvironmentPrompt: dead (nothing builds that prompt block). Deleted.
- CHAT_MODES: only its derived type is consumed. Narrowed to module-private.

DBOS workflow-source snapshot re-baselined (import-specifier text is hashed;
apps/api/scripts/update-workflow-source-snapshot.ts, 8 hashes).

Infra: sandbox-daemon.yml change filter, release-changes test fixtures, root
README workspace table, bundle-server-script comment.
viktormarinho added a commit that referenced this pull request Aug 3, 2026
…arness registry (#5578)

Final step of the harness-package teardown (#5573 deleted the dead TS CLI
harnesses; #5577 moved the wire contracts to @decocms/shared/harness). After
those, the package was 9.5k lines consumed by apps/api alone — its stated
reason to exist (portability into the desktop daemon's bundle) died with the
link daemon (#5570) and the TS sandbox daemon (#5575).

The move:
- packages/harness/src → apps/api/src/harnesses/lib (git mv, history kept).
  58 api files rewritten from "@decocms/harness/X" to "@/harnesses/lib/X".
  All the lib's deps were already in apps/api's manifest; the workspace
  package, its README, tsconfig and dependency edges are gone.
- The leaf discipline survives as a directory rule: ban-cross-tree-imports
  now applies its harness clauses (no @/ imports, no @/core/studio-context,
  no @aws-sdk/*) to apps/api/src/harnesses/lib/, and no-cross-tree.test.ts
  moved with the tree and still guards it. The engine stays a leaf; only the
  package wrapper is gone.

The registry collapse (spec §5.4, executed at last):
- InProcessSandboxClient absorbs localDispatch and hard-wires
  decopilotHarnessFactory — the registry it consulted was a Map with one
  entry, populated by an import side effect. registry.ts, localDispatch, the
  orphaned lib barrel and their registration tests are deleted; the client's
  tests now assert the real factory's contract (eager CLI guard, lazy stream)
  instead of stubbing a seam.
- apps/api/src/harnesses/index.ts keeps one side effect: registering the
  cluster environment builder the factory requires.

Fallout knip caught once the package boundary stopped hiding it:
- buildRepoEnvironmentPrompt: dead (nothing builds that prompt block). Deleted.
- CHAT_MODES: only its derived type is consumed. Narrowed to module-private.

DBOS workflow-source snapshot re-baselined (import-specifier text is hashed;
apps/api/scripts/update-workflow-source-snapshot.ts, 8 hashes).

Infra: sandbox-daemon.yml change filter, release-changes test fixtures, root
README workspace table, bundle-server-script comment.
viktormarinho added a commit that referenced this pull request Aug 3, 2026
…5579)

* chore: delete the dead auth-config.json tail and the stray EFS RFC

Auth moved to AUTH_* environment variables (auth-env.ts) — core/config.ts even
warns that a config-file 'auth' key is ignored. Nothing reads auth-config.json
anymore, but its tail survived everywhere:

- auth-config.json at the repo root: snuck in via #5575 (a sandbox-daemon PR),
  tracked ever since, read by nothing. Deleted.
- apps/api/auth-config.example.json, tests/resilience/auth-config.test.json:
  referenced by nothing. Deleted.
- .github/workflows/e2e.yml wrote the file before every run — for nothing.
  Step deleted.
- .cursor/worktrees.json copied a file that does not exist. Line deleted.
- apps/api/src/auth/index.ts's header claimed the exact opposite of reality
  ('file-based, not environment variables'). Fixed, with the .gitignore entry,
  the AGENTS.md config line, and config.example.json's pointer.
- deploy/helm/studio/README.md documented a configmap-auth.yaml template that
  does not exist in templates/. Section removed, following ones renumbered.

efs-spec.md (an L2 golden-cache RFC draft) also landed at the root in #5575.
Deleted — it was never referenced by anything in the repo.

Not touched: decostudio-alias/ stays at the root on purpose — it is the
published npm alias (decostudio → decocms) with its own publish workflow, and
it must stay OUT of the workspaces globs so its 'decocms': '*' dependency
resolves against the registry instead of being workspace-linked. spec/001.md's
auth-config mentions are a historical design document and were left alone.

* docs(helm): stop documenting authConfig values the chart renders to nothing

The chart has had no template consuming .Values.configMap.authConfig or
secret.authConfigSecretName since configmap-auth.yaml was deleted (#3048,
env-var auth) — but the README and examples/secrets-example.yaml kept
documenting both, including a second Secret with camelCase keys
(googleClientId, resendApiKey) the server never reads. This is an active
trap: the real prod values in deco-apps-cd carry a full authConfig block
(google, resend, magic-link) that renders to nothing — auth there actually
works because the ExternalSecret feeds AUTH_* keys via envFrom.

README now shows the real mechanism (AUTH_* in meshConfig/Secret, schema in
apps/api/src/auth/auth-env.ts) and the example Secret carries AUTH_* keys.

* chore(api): delete apps/api/spec — a stale v1 design document

001.md described the file-based auth-config.json design that #3048/#5120
replaced with AUTH_* env vars, plus a pre-split architecture; nothing links to
it except its README entry and one step of the add-mcp-tools skill, both
removed (the skill's 'Document in Spec' step told contributors to document new
tools in a file that described a system that no longer exists).
monitoring-share-plugin.md was referenced by nothing at all.

* chore: delete .cursorindexingignore

Stale editor config from 2024 (last touched in #1218); the paths it excluded
no longer exist in the repo.
guitavano added a commit that referenced this pull request Aug 4, 2026
…5676)

* fix(sandbox): restore port-sniffer phrase gate + cross-chunk carry

The Go daemon's port sniffer (default since #5568, TS daemon deleted in
#5575) was an incomplete port of the TypeScript one: it dropped two
safeguards, so a Vite dev server that binds a non-config port (e.g. 5173)
is no longer detected. `getDevPort()` then falls back to the configured
`application.port` (3000) — the daemon proxies/probes 127.0.0.1:3000,
gets connection-refused forever, serves "Server is starting…" and never
leaves the `starting` lifecycle phase. The preview is stuck on the boot
skeleton even though `vite dev` is ready.

Restore both safeguards from the TS sniffer:

- **Phrase gate.** The bind URL must be preceded by `Local:` / `Listening
  on` on the same line. Without it, a bare `http://localhost:3000` line
  (a framework echoing the injected PORT, a proxied fetch, a sibling
  process) hijacks the lock before Vite's real `Local: http://localhost:5173/`.

- **Cross-chunk carry.** PTY reads aren't line-buffered, so the bind line
  can split across chunks. Carry a bounded, ANSI-stripped tail per source
  and match the concatenation. Also require a `/` or whitespace after the
  port so a split mid-number ("...:51" | "73/") waits instead of locking
  the truncated "51".

Tests cover both failure modes (bare-3000 hijack, split bind line).

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(sandbox): lock on any non-digit terminator, consume ANSI ESC

Review of the previous commit found the `[/\s]` trailing requirement
regressed the no-trailing-slash frameworks (next, bun) it claimed to
support: the ANSI stripper matches the bracket body but not the ESC, so a
colored `http://localhost:3000\x1b[0m\n` strips to `...:3000\x1b\n` — the
ESC sits between the port and the newline, `[/\s]` rejects it, and the
port is never sniffed (silently falling back to the wrong configured
port — the exact failure the sniffer exists to prevent).

- Require a non-digit terminator (`[^\d]`) instead of `[/\s]`. Still fixes
  the mid-number split (a buffer ending on digits has no following char →
  waits), but locks on any non-digit — `/`, `)`, `,`, whitespace,
  newline, or a leftover ESC — matching the eager TS behavior for the
  frameworks a strict `[/\s]` would have dropped.
- Make ansiPattern consume the ESC when present (`\x1b?`) so a stripped
  color code leaves nothing between the port and its terminator.

Tests: colored no-trailing-slash, non-slash terminator, Reset clears
carry, sibling URL before the banner (line-bound `[^\n]*?`), and
per-source carry isolation.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
guitavano added a commit that referenced this pull request Aug 4, 2026
…en absent (#5687)

* feat(sandbox): regenerate blocks.gen.json in the Go daemon's /read when absent

`.deco/blocks.gen.json` is the runtime's merge of every `.deco/blocks/*.json`;
most repos gitignore it (a multi-MB single line that conflicts on every content
PR and is regenerated on dev cold-start), so a fresh sandbox has the block
sources but not the merged artifact. The web CMS reads it via the daemon's
/read proxy (readCommittedJson -> use-decofile) so the Blocks UI is editable
before the dev server boots.

The TypeScript daemon synthesized this merge on the fly in /read (added in
#5084) but the behavior was dropped when that daemon was deleted (#5575) and
never ported to Go — so on main today /read 400s and the CMS shows "decofile
unavailable" until the dev server is up. Restore it in Go:

- decofile.GenerateFromBlocks / GenerateFromBlocksDeduped: deterministic,
  byte-spliced merge keyed by the decode-until-stable filename stem (fixes the
  double-encoded-stem bug the old decode-once path had), single-flight
  coalesced so concurrent cold reads share one multi-MB build.
- fs.Read falls back to the merge only when the absent path's basename is
  blocks.gen.json; every other absent file still 400s.
- Go unit tests for the merge + a black-box daemon-e2e spec.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* review: harden the decofile /read fallback

Addresses a multi-perspective review of the fallback:

- security: gate the fallback on a relative path. An absolute body.Path
  bypasses SafePath, so allowing it would turn the merge into an arbitrary
  sibling-blocks/ directory glob; the CMS only ever sends relative paths.
  Proven by a routes unit test that points an absolute path at the real repo's
  gen artifact and asserts it still 400s while the relative form merges.
- robustness: defer the singleflight cleanup so a panic in the merge can't
  leave a stale in-flight entry that wedges every future reader of that dir.
- testing: cover the riskiest path — pretty-printed multi-line blocks round-
  tripping through the consumer's stripLineNumbers (inlined in the e2e, unit-
  asserted no merged line starts with a line-number prefix) — plus a concurrent
  -race test for the coalescer.
- cleanup: unexport generateFromBlocks (only the deduped wrapper calls it),
  splice via bytes.TrimSpace to drop a per-block string copy, and broaden the
  package doc to cover generation alongside validation.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
nicacioliveira pushed a commit that referenced this pull request Aug 7, 2026
The cross-node golden tier was written in TypeScript (#5351, #5399) and deleted
with that daemon in #5575, before it ever ran in a deployed config. Nothing
replaced it: the Go daemon logged "GOLDEN_CACHE_REMOTE is set but this daemon
implements the node-local golden tier only" and installed from scratch. Since
then the bucket, the mountpoint PV/PVC and the env var were all provisioned
(decocms/terraform-eks-cluster#88/#92, decocms/deco-apps-cd#203), so prod has
the volume mounted at /golden-cache with nothing on either end of it.

This ports restore, publish and prune to Go, keyed identically to L1 (same
credential-stripped repo hash, same lockfile hash) so the two tiers can never
disagree about what a key means.

Orchestrator wiring: L1 reflink → L2 extract → install. An L2 hit leaves
pendingGolden set, so the healthy-boot transition seeds THIS node's L1 from the
extracted tree and the next pod here gets the reflink instead of another
extract. That transition also runs the L2 publish, which no-ops on an existing
key, so the two are safe together.

Two deliberate departures from the TypeScript original:

- The pipe is os.Pipe, not `bash -c` with pipefail. Both children get one real
  kernel fd pair, so a multi-GB tree never traverses this process — which
  matters because the health probe must keep answering (Studio tears the pod
  down on a single miss), and because a relayed copy is what truncated this
  transfer in the TS version. Using os/exec's StdoutPipe would reintroduce that
  relay. This also drops the bash dependency and the shell quoting it needed.
- No shell means no `set -o pipefail`; both children's exit codes are checked
  explicitly instead, consumer first because its stderr is the line that
  explains a corrupt archive.

Unchanged from the original, because they are load-bearing: an archive rather
than a tree (per-operation metadata latency is fatal across ~100k files);
extract into staging then rename, so an interrupted tar cannot leave a partial
node_modules that later code reads as complete; write straight to the final key
rather than temp+rename, because a blob store has no rename and does not need
one; read the archive back before reporting success, because publish no-ops on
an existing key so a corrupt one would be permanent.

zstd is already in the sandbox image (packages/sandbox/image/Dockerfile) — it
survived the TS deletion. main.go now warns when it is missing rather than
warning that the tier is unimplemented.

Testing: real files, real tar/zstd, no mocks. Publish on one root and restore on
another (the point of the tier), an ~8 MB payload past any pipe buffer (the case
that caught a truncating implementation in TS, where a 1 KB fixture passed),
dormant-when-unconfigured as the discriminating counterpart, truncated and
corrupt archives failing closed with no partial tree and no staging left behind,
idempotent publish, and prune by TTL and per-repo cap. `go build ./...`,
`go vet`, `gofmt` clean; full internal/setup suite passes.

NOT validated on a real pod, and it cannot be yet: the tenant mount is
read-only, so publish always fails there and the store stays empty. Restoring
needs something to have published — a trusted seeder with the writable mount is
the remaining piece, tracked separately.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
nicacioliveira pushed a commit that referenced this pull request Aug 10, 2026
The cross-node golden tier was written in TypeScript (#5351, #5399) and deleted
with that daemon in #5575, before it ever ran in a deployed config. Nothing
replaced it: the Go daemon logged "GOLDEN_CACHE_REMOTE is set but this daemon
implements the node-local golden tier only" and installed from scratch. Since
then the bucket, the mountpoint PV/PVC and the env var were all provisioned
(decocms/terraform-eks-cluster#88/#92, decocms/deco-apps-cd#203), so prod has
the volume mounted at /golden-cache with nothing on either end of it.

This ports restore, publish and prune to Go, keyed identically to L1 (same
credential-stripped repo hash, same lockfile hash) so the two tiers can never
disagree about what a key means.

Orchestrator wiring: L1 reflink → L2 extract → install. An L2 hit leaves
pendingGolden set, so the healthy-boot transition seeds THIS node's L1 from the
extracted tree and the next pod here gets the reflink instead of another
extract. That transition also runs the L2 publish, which no-ops on an existing
key, so the two are safe together.

Two deliberate departures from the TypeScript original:

- The pipe is os.Pipe, not `bash -c` with pipefail. Both children get one real
  kernel fd pair, so a multi-GB tree never traverses this process — which
  matters because the health probe must keep answering (Studio tears the pod
  down on a single miss), and because a relayed copy is what truncated this
  transfer in the TS version. Using os/exec's StdoutPipe would reintroduce that
  relay. This also drops the bash dependency and the shell quoting it needed.
- No shell means no `set -o pipefail`; both children's exit codes are checked
  explicitly instead, consumer first because its stderr is the line that
  explains a corrupt archive.

Unchanged from the original, because they are load-bearing: an archive rather
than a tree (per-operation metadata latency is fatal across ~100k files);
extract into staging then rename, so an interrupted tar cannot leave a partial
node_modules that later code reads as complete; write straight to the final key
rather than temp+rename, because a blob store has no rename and does not need
one; read the archive back before reporting success, because publish no-ops on
an existing key so a corrupt one would be permanent.

zstd is already in the sandbox image (packages/sandbox/image/Dockerfile) — it
survived the TS deletion. main.go now warns when it is missing rather than
warning that the tier is unimplemented.

Testing: real files, real tar/zstd, no mocks. Publish on one root and restore on
another (the point of the tier), an ~8 MB payload past any pipe buffer (the case
that caught a truncating implementation in TS, where a 1 KB fixture passed),
dormant-when-unconfigured as the discriminating counterpart, truncated and
corrupt archives failing closed with no partial tree and no staging left behind,
idempotent publish, and prune by TTL and per-repo cap. `go build ./...`,
`go vet`, `gofmt` clean; full internal/setup suite passes.

NOT validated on a real pod, and it cannot be yet: the tenant mount is
read-only, so publish always fails there and the store stays empty. Restoring
needs something to have published — a trusted seeder with the writable mount is
the remaining piece, tracked separately.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
aka-sacci-ccr added a commit that referenced this pull request Aug 11, 2026
* fix(sandbox): port submodule credentials to the Go daemon

#4885 shipped per-host submodule PATs, with the daemon half in
`packages/sandbox/daemon/setup/clone.ts`. The Go port (#5484) omitted that
half, and #5575 deleted the TypeScript daemon — so since then the Studio
side has resolved the secret, redacted it, and shipped it in the config
payload, while the daemon dropped it on unmarshal and never ran
`git submodule update`. A repo with private submodules clones with empty
submodule directories and the dev server dies on unresolved imports.

Ports the deleted implementation:

- `git.repository.submoduleCredentials` on the Go config, carried through
  `mergeRepository` (absent keeps current, so a clone-URL-only credential
  refresh doesn't drop the PATs).
- Host validation (mirrors `SUBMODULE_HOST_RE`), dedupe by host,
  percent-encoded credentials-file lines, per-host SSH→HTTPS `insteadOf`
  rewrites, and `submodule update --init --recursive --depth 1` — funnelled
  through `finalize` so both acquisition paths and both branch cases get it.
- Opt-in and best-effort throughout: no-op without credentials or a
  `.gitmodules`; a fetch failure warns and leaves the checkout intact.
- The token stays on the git-only channel: a 0600 temp file outside the repo,
  deleted after the fetch, never in argv, env, or the repo's `.git/config`,
  and redacted from both `/_sandbox/config` responses (the copy is what the
  browser sees; the live store keeps the token for the clone step).

Tests: Go unit tests for the pure argv/credentials-line functions and the
best-effort paths, config merge + classify, and route redaction; a
`daemon.submodules.e2e.test.ts` black-box suite asserting the fetch is
attempted with the rewrite applied, the clone survives an unreachable
submodule, an invalid host is skipped, and no response echoes the token.
Verified the e2e fails against the pre-fix wiring.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(sandbox): persist no-op config patches, and let a deleted credential revoke

Review of the submodule-credentials port surfaced two defects on the config
plane, both of which made the feature partially unusable, plus three smaller
ones. Each had a test pinning the broken behavior as correct; those are
inverted here.

- `Store.apply` returned on a `KindNoOp` transition WITHOUT writing the merged
  config. "No-op" classifies the side effect (no re-clone, no restart), not the
  write — so a patch carrying a field `Classify` has no arm for, which is
  exactly submodule credentials, was answered 200 with a receipt echoing the
  new value while the store kept the old one. Guarded on non-nil so an inert
  patch still can't claim an unclaimed daemon.

- `submoduleCredentials` is now always sent, empty array included. The daemon
  reads an absent field as "keep current", and both `buildConfigPayload` and
  `readValidatedSubmoduleCredentials` collapsed "the user deleted their last
  row" into "never configured" — so a revoked PAT stayed live in the pod for
  its lifetime, and a re-bootstrapped pod kept the previous config's tokens.
  The `[]`-clears path the merge documents was unreachable from its only
  producer.

- The credentials file moves from a random `os.CreateTemp` name in the shared
  /tmp to a deterministic path in the daemon's own tmp dir, swept at boot. A
  SIGKILL between the write and the `defer os.Remove` strands a live PAT on
  disk, and only a name the next boot can predict is sweepable.

- The submodule fetch runs through `runStep`, not `runNetworkStep`. `--recursive`
  emits aggregate output, so one dead submodule host matches the transient-error
  list and bought 4 full recursive passes plus 9s of sleeps ahead of install and
  the dev server, for a step whose failure is already tolerated.

- Two comments claimed protection the runtime doesn't provide: 0600 does not
  hide the file from tenant code (every process in the pod shares one uid — the
  control is lifetime), and `/config` redaction is defense in depth against a
  remote reader, not a boundary against in-pod code.

Tests: the two that pinned the bugs are inverted; the redaction tests now
assert 200 + a cloneUrl round-trip so they can't pass on an empty response;
`cloneLog` throws instead of returning "" so the e2e's absence assertions
can't pass vacuously; the e2e proves the SSH→HTTPS rewrite positively (the
URL git actually dialed) rather than by the absence of an ssh error. New:
credentials-file write failure, deletion after a failed fetch, per-host token
pairing, the boot sweep, and an e2e for revocation.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: decobot <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

1 participant