Skip to content

feat(storage)!: the session log stores the redacted form - #634

Merged
ajianaz merged 1 commit into
developfrom
feat/redacted-session-log
Nov 12, 2026
Merged

ajianaz merged 1 commit into
developfrom
feat/redacted-session-log

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What

#596. The session JSONL stores the redacted form. Every entry payload, and the pinned system prompt, is redacted with the process SecretSet before its line is written. An entry that hid a secret names it, as "redacted": ["NAME"] (names only). A replay from the log reproduces the provider's view exactly. Old raw logs load unchanged.

Why

Owner decision 2026-11-11 (docs/secrets-integrations-design.md §5, §8.1). Logs get exported, summarized into memory and shared, so a secret read once persisted in them. This reverses E11's "the durable log keeps the original".

Changes

  • tole-core/src/storage.rs, at the Storage seam:
    • JsonlStorage::commit redacts each NewEntry payload with SecretSet::redact_value before encoding the line. That redacts every string and object key, in every form the set knows: as is, JSON-escaped, base64 and percent-encoded. A secret that is a bare JSON number becomes the marker string.
    • The committed in-memory Entry is the same redacted form, so memory equals disk.
    • The hidden names go on the wire record, Record::Entry.redacted, with #[serde(default, skip_serializing_if = "Vec::is_empty")]. They are kept per entry id, so compact() writes them back.
    • Old logs have no such field and load unchanged; older binaries ignore it.
    • create_* redacts the pinned system prompt in the header.
    • JsonlStorage::set_secrets sets a per-storage redaction set, for tests and embedders.
    • Nothing new is read from disk, so no new file-read path.
  • tole-core/src/secrets.rs: set_process_secrets / process_secrets.
    • The host installs its set once.
    • Without one, SecretSet::from_env() is built once, cached in a OnceLock, and shared as an Arc clone.
    • The matcher is never rebuilt per entry. When a payload has no match, the append path costs one structural walk; the names are computed only when something was redacted.
    • No new dependency, and it builds with --no-default-features.
  • tole-cli/src/provider_chain.rs: build installs log_secrets: the process set plus each provider's key and base-URL password (primary and reserve), i.e. everything a provider request is redacted with. openai::provider_secrets is now public for this.
  • Docs:
    • a CHANGELOG entry under "Behavior change";
    • the threat-model E11/egress row and the /export paragraph;
    • an implementation note in design §5 (streaming, /export, memory loop, residuals).

Replay exactness: verified, no divergent path found.

  • The turn loop feeds the provider compaction::view(s.entries()), which is the in-memory, redacted entries.
  • So the request a replay rebuilds from the log is built from identical entries, and the provider's own redaction is idempotent on top.
  • The log set is a superset of the provider set (log_secrets), so nothing logged redacted was sent raw, and nothing sent redacted is logged raw.
  • The tests assert both ways: the provider body from the raw entries equals the body from the redacted entries, and the body after reopening the log equals the live body, byte for byte.

Streaming: text deltas only feed the live display. The log gets the assembled assistant message as one entry, so a value split across two chunks is whole there and gets redacted. No partial assistant text is ever committed.

Testing

All run locally on 8dd59e2 (develop e76d90e), with CARGO_TARGET_DIR set and CARGO_INCREMENTAL=0.

  • cargo test --workspace --no-fail-fast passes: 1571 passed, 0 failed (85 suites), on the final head.
    • An earlier run had 12 tole-cli failures (in config, config_trust and compaction_host). They came from stale /tmp dirs left by a previous run whose pid was reused ("File exists", another test's user.toml), not from this change.
    • cargo test -p tole-cli then passed (700) and the final full run is clean.
  • cargo test -p tole-core --no-default-features passes: 551 passed; cargo check -p tole-core --no-default-features --tests passes.
  • cargo test -p tole-cli --no-default-features passes: 464 passed. With --features shell-tools added: 627 passed.
  • cargo fmt --all -- --check passes.
  • cargo clippy -D warnings passes for --workspace --all-targets, -p tole-core --no-default-features --all-targets, -p tole-cli --no-default-features and -p tole-cli --no-default-features --features shell-tools.
  • cora review --no-llm --staged: "No issues found".

New tests in crates/tole-core/tests/redacted_log.rs. The secret s3cr3t/v"al+0596 makes every encoded form differ.

  • no_form_of_a_secret_reaches_the_log_and_each_entry_names_what_it_hid:
    • the secret appears in user text, in tool-call arguments (percent-encoded), in a tool result (JSON-escaped inside JSON text, base64, raw), in an error and in assistant text;
    • none of its forms reaches the file, or memory;
    • each of those entries carries redacted: ["TOLE_T596_TOKEN"], and a clean entry has no field.
  • replay_from_the_log_reproduces_the_provider_view_exactly:
    • provider body from the raw entries == the live body;
    • the reopened entries == the committed entries;
    • the replayed body == the live body.
  • an_old_raw_log_loads_unchanged_and_only_new_lines_are_redacted:
  • a_secret_split_across_streamed_chunks_is_redacted_in_the_committed_message.
  • a_whole_turn_logs_only_redacted_text_and_feeds_the_provider_the_same: through run_turn, the tool ran with the model's raw arguments, while the log and every transcript the provider was handed hold no form of the secret.
  • the_pinned_system_prompt_is_stored_redacted.
  • provider_chain::tests::the_log_redacts_every_secret_the_providers_are_shown_redacted: both providers' keys and URL passwords are in the log set.

Red/green: each rule was broken on purpose, the named test failed, and it passed again once restored. All 7 breaks were caught:

Broken rule Caught by
commit writes the raw payload forms, turn, chunks and old-log tests
names not recorded forms test
empty redacted field written forms test
header system prompt left raw system-prompt test
per-storage set ignored forms, turn, chunks and old-log tests
log set lacks the reserve provider provider_chain test
log set lacks the provider keys and URL password provider_chain test

Decisions to check

  • Crash resume re-runs logged arguments. A tool still runs with the arguments the model sent. A crash-resumed intent (Resume::ReExecute) reads its arguments from the log, so it re-runs with the redacted form. The model only ever saw redacted text, so raw values in arguments should be rare.
  • Registers are not redacted. Register cells (model, mission, pending intent, reasoning effort) are control state and are stored as they are; the docs say so.
  • compact() keeps old raw lines raw. It rewrites entries verbatim (the audit log is never altered). For an old raw session, its raw lines stay raw after compaction. A fork of an old session is redacted, because it re-commits.
  • Embedders without a process set. An embedder that installs no process set gets the environment's set, built once on first use. Secrets set in the environment later, in the same process, are not picked up until set_process_secrets is called.
  • tole export does not exist. The TUI /export renders the in-memory entries, so a new session exports redacted, and an old session's raw lines export as they are.

Size: 501 changed lines (489 added, 12 removed) across 8 files.

Related Issues

Closes #596 (secrets epic #594; follows #595, #631 and #632).

Checklist

  • Branch name follows convention (feat/redacted-session-log)
  • Branch is from develop
  • Commit messages follow Conventional Commits
  • No secrets or credentials committed
  • One logical change per PR

Owner decision 2026-11-11 (#596, design secrets-integrations §5, §8.1);
reverses E11's "the durable log keeps the original".

JsonlStorage::commit redacts every entry payload with the process
SecretSet before the line is encoded: structurally, every string and
key, in every form the set knows (as is, JSON-escaped, base64,
percent-encoded; a secret that is a bare number becomes the marker
string). The pinned system prompt is redacted the same way. An entry
that hid a secret carries "redacted": ["NAME"] on the wire, names
only, absent otherwise. The committed in-memory entry is that same
redacted form and the provider is fed from it, so the log stores what
the provider saw and a replay rebuilds the same request.

The set is the process set (secrets::set_process_secrets), built once;
the CLI installs everything a provider request is redacted with, both
providers' keys and URL passwords included (provider_chain::log_secrets).
Without one, the environment's set, built once and cached. Old raw logs
load unchanged and are never rewritten; only new lines are redacted.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 9e5b92e into develop Nov 12, 2026
19 of 20 checks passed
ajianaz added a commit that referenced this pull request Nov 13, 2026
…ssion log is redacted since #634 (#673)

The rule that told the reviewer the durable log keeps the original text and not to flag missing redaction on durable log writes was wrong since #596 and #634 (the session log stores the redacted form): it is replaced by a rule that says so and asks the reviewer to flag any durable write (session log, ledger, usage record) that can carry a secret without going through the redaction. The subprocess rule's stale file name uteke_search.rs is now uteke.rs. The api_key rule (OpenAiConfig.api_key is filled from the environment) and the loop-guard rule (LOOP_TRIP_AFTER = 3) were re-verified against the code and are unchanged.

Closes #668
@ajianaz
ajianaz deleted the feat/redacted-session-log branch November 20, 2026 08:37
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.

feat(storage): store the redacted form in the session log

2 participants