Skip to content

feat: skip Supermemory for subagents, headless runs and helper prompts by default - #125

Merged
capy-ai[bot] merged 6 commits into
mainfrom
capy/skip-supermemory-for-subagents
Nov 25, 2026
Merged

capy-ai[bot] merged 6 commits into
mainfrom
capy/skip-supermemory-for-subagents

Conversation

@Dhravya

@Dhravya Dhravya commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Dhravya's call (Nov 6): subagents, headless runs and host helper prompts should not hit Supermemory by default. A Pro customer running swarms of one-shot workers had ~60% of his bill in worker captures. This PR covers both OpenCode V1 (opencode-ai) and OpenCode 2 (@opencode/cli). It also adds the Captain's scope additions: orchestrator handling, opening-prompt dedupe and a recall-query repeat skip. It also checks that worktree tags collapse correctly, with no tag changes.

What is detected and how

Class OpenCode V1 (1.19.5) OpenCode 2 (2.2.6)
Subagent session.parentID, read through client.session.get (cached, and primed from session.created/session.updated events). The task tool creates child sessions with parentID (packages/opencode/src/session/session.ts:520). opencode run uses the same field to spot subagents (src/cli/cmd/run.ts:693). session.get().parentID. The subagent tool spawns child sessions (packages/core/src/tool/plugin/subagent.ts), and core plugins skip children the same way (packages/core/src/plugin/warming.ts:117).
Headless The CLI subcommand in process.argv: run or github run. Both host the server and plugins in the CLI process (src/cli/cmd/run.ts "Non-interactive (default)"; src/cli/cmd/github.ts). The TUI runs plugins in a worker of the default $0 [project] command, so it is not matched. Not detectable. opencode run reuses the shared background service when it is up (packages/cli/src/commands/handlers/run.ts), and otherwise spawns serve --stdio with the same command line the TUI's --standalone uses (packages/cli/src/services/standalone.ts). No session field, header or env marks the run. OpenCode 2 run is still treated as interactive.
Helper prompts Title generation calls the LLM directly, outside chat.message (src/session/prompt.ts:193-250, ensureTitle). Compaction creates its user message without chat.message (src/session/compaction.ts:559). Neither reaches recall hooks, and the existing capture already drops summary: true messages. Verified: 0 calls from them (search count = 1 per real prompt). Title is its own hook kind, SessionRequestKind = "primary" | "compaction" | "title" | "generate" (packages/plugin/src/promise/session.ts:66), and the plugin only hooks context and compaction. Verified: 0 calls from title. The plugin's own compaction enrichment still runs for interactive top-level sessions (documented feature) and is skipped for subagents.

Content heuristics are not used anywhere.

Orchestrators (Captain research)

  • Conductor sets CONDUCTOR_WORKSPACE_PATH and CONDUCTOR_SESSION_ID (https://www.conductor.build/docs/reference/environment-variables). Vibe Kanban sets VK_WORKSPACE_ID (BloopAI/vibe-kanban crates/local-deployment/src/container.rs:1367-1368). When one of these is set, the process counts as interactive, even under opencode run.
  • captureOrchestrated (default true; env SUPERMEMORY_CAPTURE_ORCHESTRATED=false) turns recall and capture off for those sessions.
  • Crystal has no env signal (stravu/crystal claudeCodeManager.ts), so its run-style sessions on V1 fall under the headless default unless captureHeadless is set. Claude Squad drives the interactive TUI, so it is unaffected.
  • On OpenCode 2 the plugin reads these env vars from the server process. They therefore apply to --standalone and to run without a background service, which inherit the CLI env. They do not apply to a background service started elsewhere.

Opt-in / opt-out settings

Each setting lives in ~/.config/opencode/supermemory.json(c). Each env var overrides its config field, and true/1/false/0 are accepted.

Setting Default Env Effect
captureSubagents false SUPERMEMORY_CAPTURE_SUBAGENTS true restores recall, capture and compaction memory for child sessions
captureHeadless false SUPERMEMORY_CAPTURE_HEADLESS true restores them for V1 opencode run / github run
captureOrchestrated true SUPERMEMORY_CAPTURE_ORCHESTRATED false skips Conductor / Vibe Kanban sessions
dedupeOpeningPrompt true SUPERMEMORY_DEDUPE_OPENING_PROMPT false always sends repeated opening prompts
dedupeRecallQueries true SUPERMEMORY_DEDUPE_RECALL_QUERIES false always recalls on repeated queries

Container tags, customIds and metadata shapes are unchanged. Only first-turn content changes, and only when dedupeOpeningPrompt fires.

Opening-prompt dedupe and recall-query skip

  • Opening prompt. ~/.supermemory-opencode/opening-prompts.json holds up to 1,000 entries, keyed by sha256(containerTag + whitespace-normalised prompt) and mapped to the session that first captured the prompt. Another session sending the same opening prompt has the first message of its turn-1 batch replaced with [Opening prompt omitted: identical to one already captured from this machine (sha256:…)]. The rest of the conversation is still captured.
    • The owning session keeps sending the full prompt, so retries with the same customId never overwrite stored content with the marker.
    • A prompt is recorded only after a successful capture.
  • Recall query. ~/.supermemory-opencode/recall-queries.json holds up to 500 entries with a 10-minute window, keyed by container tag and lowercased, whitespace-collapsed query. Matching is exact only.
    • It runs through a new skipQuery seam in buildDirectRecallResult, which is the hook point for future recall-skip checks.
    • The profile fetch is unchanged.
  • Both indexes are best-effort: on any file error the plugin falls back to today's behaviour. Simultaneous first captures can race, and a prompt that both workers capture at the same moment is sent twice.

Worktree collapse (verified, no tag changes)

Linked worktrees already resolve through git rev-parse --git-common-dir to the base checkout, so Conductor-style parallel worktrees share the base repo's container, with or without an origin remote. This PR does not change tags.ts. Checked against real git 2.55 repositories:

Layout Directories Tag
no origin, Conductor-style worktrees app, app/sub, conductor/workspaces/app/{tokyo,lima} repo_app__6fad7069f7bdd12e (all)
origin, Conductor-style worktree app2, conductor/workspaces/app2/oslo repo_app2__bdcc5edc12fbd02e (both)
bare repo with origin app5.git, app5-main, app5-feat repo_app5__ee0edee1265913fb (all)

Cross-plugin follow-up: worktrees of a bare repo with no origin. A bare repo has no main checkout, so every worktree hashes its own path and gets its own tag. Examples: app3-main → repo_app3_main__f972104f17bcd4cf and app3-feat → repo_app3_feat__356186b748a0c2ae; in the .bare layout, proj4/main → repo_main__2fa87958050dac2c. This is left unchanged on purpose. OpenCode, Codex and Claude share containers, and Codex (#77) and Claude (#160) also left this case alone. Fixing it in one plugin would split a user's memories away from the other two clients, so the fix needs to land in all three plugins together.

Verification on the real hosts

  • Hosts. opencode-ai@1.19.5 and @opencode/cli@2.2.6 from npm.
  • Model. A local OpenAI-compatible stub (/v1/chat/completions streaming) via an @ai-sdk/openai-compatible custom provider. It answers with fixed text, or with a task (V1) / subagent (OC2) tool call when the prompt contains SPAWN_SUBAGENT.
  • Supermemory. A local recording stub via baseUrl in supermemory.json with a dummy key. It logs every method and path.
  • Baselines. main was built side by side.
  • Interactive. The real TUI, driven in tmux. OC2 used --standalone.
  • Call counts. One prompt costs 18 calls on the legacy API (6 /v4/profile + 11 /v4/search fan-out over read tags + 1 /v3/documents capture). OC2 counts 19 because it re-sends the same customId at shutdown, which is existing behaviour.
Host Scenario main this PR
V1 TUI, plain prompt 18 18
V1 TUI, prompt that spawns a subagent 36 (child 18) 18 (child 0)
V1 opencode run 18 0
V1 run + SUPERMEMORY_CAPTURE_HEADLESS=true – 18
V1 run + subagent + CAPTURE_HEADLESS=true 36 18 (child 0)
V1 … + SUPERMEMORY_CAPTURE_SUBAGENTS=true – 36
V1 … with captureSubagents/captureHeadless: true in the config file – 36
V1 run with CONDUCTOR_WORKSPACE_PATH set – 18 (interactive)
V1 … + SUPERMEMORY_CAPTURE_ORCHESTRATED=false – 0
V1 worker 1 / worker 2, same task prompt (Conductor env) – 18 / 7 (0 searches, capture sends the marker)
V1 worker 3 + DEDUPE_OPENING_PROMPT=false DEDUPE_RECALL_QUERIES=false – 18 (full prompt)
OC2 TUI --standalone, prompt that spawns a subagent 38 (child 19) 19 (child 0)
OC2 run + subagent 38 19
OC2 run + subagent + SUPERMEMORY_CAPTURE_SUBAGENTS=true – 38
OC2 run, plain (headless undetectable) – 19
OC2 run + Conductor env + CAPTURE_ORCHESTRATED=false – 0
OC2 worker 1 / worker 2, same task prompt – 19 / 8

Excerpt from the Supermemory stub log, V1 worker 2:

6 POST /v4/profile
1 POST /v3/documents  {"sessionId":"ses_e4c21918…","content":"[Conversation …:1-1]\n1. [user] [Opening prompt omitted: identical to one already captured from this machine (sha256:c0072520680a)]\n2. [assistant] …"}

Plugin log in the subagent runs: Automatic memory skipped for subagent session: {"sessionID":"ses_e4c23c122ffe…"}. Plugin log in the V1 run: Automatic memory disabled for this process: {"reason":"headless"}.

Repo checks: bun run typecheck, bun test (46 pass, including new session-scope, local-dedupe and V2 subagent tests) and bun run build. A test preload (bunfig.toml → scripts/test-preload.mjs) points os.homedir() at a temp dir, so tests never read or write the developer's ~/.supermemory-opencode or config.

Not detectable

  • OpenCode 2 headless (opencode run, SDK clients of the background service). The host exposes no signal to plugins.
  • OpenCode V1 opencode run --attach <url> and SDK clients of opencode serve. The plugin lives in the server, which cannot see the client's command line.
  • Crystal and Claude Squad orchestrators have no env signal.

Open in Capy

Dhravya and others added 2 commits November 7, 2026 02:43
…s by default

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…#126)

* Re-serve cached recall for repeat queries and expire opening-prompt dedupe after 24h

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Skip values of opencode value flags in headless detection and time out parent lookups

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Accept yes/on/no/off for env flags and document OpenCode 2 run and inherited orchestrator env

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Scope the recall cache to backend and credential, clear it on logout, and write cache files 0600

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore(release): 2.2.0

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
MaheshtheDev and others added 3 commits November 13, 2026 08:50
… logout (#127)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Gate V5 session capture (V1 capture hook and OpenCode 2 compaction, cadence and session-end uploads) with the subagent/headless skip.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

@capy-ai capy-ai Bot 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.

Approving at Mahesh's request. He waived the Capy review ("you can merge the 6 plugin PRs"). Graphity reviewed this head read-only: detection fails safe and no blocking bugs were found.

@capy-ai
capy-ai Bot merged commit b0d7242 into main Nov 25, 2026
2 checks passed
MaheshtheDev added a commit to supermemoryai/supermemory that referenced this pull request Nov 26, 2026
opencode-supermemory 2.3.0 (supermemoryai/opencode-supermemory#125): src/services/session-scope.ts skips subagent and v1 headless sessions, src/services/local-dedupe.ts adds the opening-prompt (200 chars, 24h, legacy capture only) and recall-query (10 min) indexes; flags and env vars in src/config.ts.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
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.

2 participants