Skip to content

feat: Let a user keep one session out of the recording #1923

Open
1 of 2 issues completed
Open

Description

@michaljacovi

Part of #1920.

Problem

On a laptop the archive is on by default (#1639), and its switch is global:
session.archive.enabled. To keep one sensitive session out, a user has to
turn the whole archive off, or delete the session afterwards
(DELETE /v1/sessions/{id}). listener.skip_hosts works per host, not per
session. Opt-out per session is what lets people leave recording on.

Proposal

  • When a session's requests carry an opt-out marker, nothing of that session
    is written to the archive. The proxy still forwards it and runs its
    plugins.
  • The session id comes from the existing headers (core/session/idheader.go).

Proposal (agreed with Hai, 2026-11-17): how the user sets it

Modelled on context-guru:

  • An env var at launch (CORTEX_RECORD=off) that becomes a request header
    on every call of that session.
  • Optionally, a mid-session /no-record that stops recording and deletes
    what was already written. It needs a "stop recording this session" call
    into Cortex.

The exact shape of that call is a design detail for this issue's PR. It must
respect #1856's anti-goal of no API route that accepts events from a
caller: it only stops the archive for one session.

Open questions

  • Does an opted-out session still count in the cost ledger? Ledger rows carry
    no content, so we'd keep them.
  • Is it shown in agentop at all (live only, marked "not recorded")?

Out of scope

  • Per-project or per-user defaults: a follow-up once the per-session switch
    exists.

Assisted-By: Claude (Anthropic AI) [email protected]

Sub-issues

Sub-issues

1 of 2 Issues completed
Loading 2 sub-issues

Activity

  1. self-assigned this
    on Nov 17, 2026
  2. added
    enhancement
    laptop
    on Nov 17, 2026
  3. michaljacovi commented on Nov 17, 2026

    @michaljacovi
    ContributorAuthor

    Design before the first PR. Three PRs, each useful on its own.

    PR 1: the proxy honours X-Cortex-Record: off (named like the other X-Cortex-* headers)

    • ResolveClient pins Context.NoRecord() from the headers before any plugin runs, and removes the header from pctx.Headers. So plugins never see it, and SyncRequestHeaders doesn't forward it. sessionevent copies it into a new SessionEvent.NoRecord. Only off counts; anything else records.
    • The archive makes it sticky per session: from the first flagged event on, it withholds every event of that session, including header-less ones filed by process or client affinity (attribution.go). In a test session, Claude Code's Datadog and event_logging calls landed in the session without the header. Events archived before the first flagged one are erased. Flagged requests queue no capture.
    • The proxy still forwards the session and runs every plugin. The cost ledger and usage keep their rows, which carry no content.
    • The live view keeps the session in memory, with noRecord on its summary.

    Finding: import after a restart. WriteSession refuses a live session only while the archive or this run's numbering knows the id (archive/import.go). An opted-out session leaves nothing in the archive. So after a restart, agentop import would bring it in from Claude Code's transcript. The fix: the archive keeps a content-free marker for the id (a session.json with noRecord: true and no segments). It survives restarts, and the import refuses that id. prune keeps the marker for retention_days after the session's last event, then removes it like any expired session.

    PR 2: launch-time switch. CORTEX_RECORD=off agentop exec claude (or --no-record) appends the header to the child's ANTHROPIC_CUSTOM_HEADERS. Checked: Claude Code sends it on every inference call, main and subagent (3 of 3). A settings-file env block overrides the process env, so exec checks for an ANTHROPIC_CUSTOM_HEADERS there and warns. Claude Code first; the other agents later.

    PR 3: mid-session /no-record. A UserPromptSubmit hook blocks the prompt (so it never reaches the model) and calls a new loopback-only POST /v1/sessions/{id}/no-record. That sets the same mark and erases what was already written, through the existing delete path. It accepts no events, like DELETE /v1/sessions/{id}.

    Questions:

    1. Is an event field plus the archive's sticky marker the right shape? Its other effect is that DELETE /v1/sessions (clear all) also clears the markers, so a later import could bring those sessions in.
    2. Is a content-free marker in the archive OK? It records only that the id opted out, and lives retention_days.
    3. Should the live store also drop parsed content for an opted-out session, or keep it for plugins as today?
    4. Praxis mode (cortex-gateway → /v1/ingest): in PR 1, or a follow-up?

    Not covered: Claude Code's startup calls go to pending:claude-code before the session id is known, so they're recorded as today. They are bootstrap calls (/api/claude_cli/bootstrap and two others), not the conversation.

    Assisted-By: Claude (Anthropic AI) [email protected]

  4. michaljacovi commented on Nov 18, 2026

    @michaljacovi
    ContributorAuthor

    Update to the design above, after two rounds of review on the PR 1 branch. Three changes, and one note on praxis mode.

    1. Own session only. The flag counts only when the request names its own session with a session-id header. A request that names none is filed by fallback (to the active session or default), and honouring its flag there would stop someone else's recording. Such a request is recorded as usual; the header is still stripped. A header can also name a shared bucket (default, or a pending: one), so the opt-out applies only to ids that session.IsConversation accepts.

    2. Never backwards. The earlier text said events archived before the first flagged one are erased. They are no longer erased: what the archive already holds for the session stays, and the opt-out applies from the first flagged event on. The session-id header is client-asserted, so a request naming another session must not be able to erase that session's history. Erasing stays explicit: DELETE /v1/sessions/{id}, and /no-record in PR 3.

    3. The marker is stricter. Any marked session refuses an import, with or without replace, including one whose events were imported first. The first flagged event persists the marker at once (also while the archive is paused), so a restart before the next event keeps it. Renames carry it.

    Praxis mode. The gateway records a hopped request, and its rows come back through /v1/ingest without the flag (the header is stripped before the hop). PR 1 handles that in Go: before it hops a request that withholds its session, the forward proxy marks the session in the store, which stamps that session's later events, ingested rows included. The store also tells the archive at once, so the archive's marker exists from the hop on, even if the store later evicts the session. A cleaner later option is a noRecord field in attribution.Wire that cortex-gateway copies into each row's event. That needs a change in praxis/. Would you prefer that as a follow-up?

    The four questions above still stand, with question 1 now about the store stamp for ingested rows next to the archive's marker.

    Assisted-By: Claude (Anthropic AI) [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementlaptop

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions