Skip to content

fix(config): bound the incognito end grace period - #1

Open
LuisQin01 wants to merge 18 commits into
Loveca:feat/incognito-chatfrom
LuisQin01:feat/8353-incognito
Open

LuisQin01 wants to merge 18 commits into
Loveca:feat/incognito-chatfrom
LuisQin01:feat/8353-incognito

Conversation

@LuisQin01

@LuisQin01 LuisQin01 commented Nov 22, 2026 •

Copy link
Copy Markdown

Related to bytedance#8353.

Why

The feature branch accepts an arbitrarily large incognito.end_grace_seconds. When a user explicitly ends a chat, the Gateway calculates the grace deadline before applying the thread's absolute lifetime cap. With a 10,000-year grace, the configuration loads successfully but the deadline calculation raises OverflowError.

What changed

Validate the end grace against the existing 365-day upper bound for incognito lifetimes. The accepted range is 0–31,536,000 seconds, inclusive. The default is one hour. A grace longer than the configured thread lifetime is still valid within this range, and the thread still expires at its absolute deadline. Operators using a grace above 365 days will need to lower it. The sample configuration and user guide document the range.

Surface area

  • Backend configuration validation, operator documentation and tests.

Bug fix verification

Ran the existing incognito configuration suite with the new regression cases against the feature branch. Both the just-over-limit case and the 10,000-year case failed because the model accepted the value. With the patch applied to a fresh copy of the same files, all eight tests passed.

Test footprint

The existing configuration suite gains 14 lines and removes one. Its boundary test now covers zero and exactly 365 days. One parameterized test covers both rejected values.

Validation

  • Isolated configuration suite on Python 3.12 with Pydantic 2.12.5: 8 passed (before the fix: 2 failed, 6 passed).
  • Fixed-clock checks using the existing deadline helper passed for default grace, zero grace and one-year grace capped by a seven-day lifetime.
  • Ruff lint and format checks passed for both changed Python files. The full Gateway suite was not run.

Loveca and others added 18 commits November 16, 2026 00:38
…e contracts

The create and end routes read the incognito configuration inline, and the
strict blocking-I/O suite turned the create-path read into a 503 for every
thread creation. Both reads now run through asyncio.to_thread, and ordinary
creates skip the config read entirely.

List incognito_thread_not_schedulable in the scheduled-task error contract
with its en-US and zh-CN translations, update the migration-chain assertion
for the new head, and follow the renamed admission-pin helper in its test.
The router auth stub now stamps an auth source only when a test opts in, so
legacy fixtures that persist rows without a user_id keep the unfiltered
run/event reads they were written for.
Incognito runs now keep every durable write the agent would normally make
outside the incognito boundary. A single server-owned helper,
is_incognito_runtime, reads the marker pinned at admission; passive memory
capture, the compaction flush and the memory_add/update/delete tools stop
before touching the memory backend. Read paths (injection and memory_search)
still work, so the chat can use what the user already taught DeerFlow.

Large tool outputs and viewed images still land in the thread's own outputs
tree, but no copy enters the shared blob store; view_image records the image
without a blob_ref and the middleware resolves it from actual_path instead.
Both stores are shared across threads, so a copy there would outlive the
incognito thread and its expiry sweep.

Verified with tests/test_incognito_durable_writes.py plus the memory and
tool-output suites; the marker is an exact server boolean, so a persisted
"true" string cannot unlock the write paths.
The workspace needs to know whether incognito chats are allowed and how long
an idle chat lives. GET /api/features now reports incognito.enabled and
incognito.idle_ttl_seconds from the live configuration, so the sidebar entry
can hide when an operator disables the feature and the temporary-chat frame
can state the actual deletion window instead of a hard-coded default.

The fake configs in the feature-router tests gain the block, and the exact
response assertions list the new field.
The workspace gets an incognito entry beside New chat, shown only when the
Gateway reports incognito chats enabled. The new-chat identity scope now
includes the incognito query, so switching between the ordinary and incognito
entry points mints a fresh thread instead of carrying a pre-created row (and
its in-flight submission) across modes.

An incognito chat pre-creates its row before the first run, because admission
can pin the server-owned marker only on an existing thread; the seeded
metadata keeps the frame stable when the URL later becomes the bare thread
route. The chat shows a dark frame below the header with the two notices —
what the chat never enters, and the idle lifetime read from the live
configuration — plus a dashed composer border. The × control sends the end
request with keepalive and leaves immediately; an already-deleted thread
counts as ended, and a failed request still expires on the idle lifetime.

The incognito surface uses dedicated tokens that stay dark in both themes,
since the temporary-chat mode is meant to read distinctly from a raised
card. Tests cover the feature mapping, lifetime formatting, entry gating,
identity re-mint, the API contract and the frame renders.
Delegated runs rebuilt their runtime context without the admission-pinned
incognito marker, so the shared durable-write gates (blob externalization,
view_image) failed open inside a subagent and an incognito research run left
oversized tool output and viewed images in the content-addressed blob store
that thread purge never deletes. The task tool and the durable batch spec now
carry the marker to the executor, which writes it into the child runtime
context; only the exact boolean True propagates.

Batch rows also survived a purge: suppress_thread_continuations only fences
in-flight continuations, leaving each item's prompt text and the
execution_spec readable. SubagentBatchRepository.delete_by_thread removes the
batch, item and dependency rows dependency-first, so the result does not rely
on ondelete=CASCADE, and purge_thread_data calls it for both a user delete and
the incognito sweep.
A scheduled task is a durable user-level object: its prompt and schedule
outlive the conversation and surface on the tasks page. Binding the
scheduler capability is what makes schedule_task callable at all, so an
incognito thread now binds none; the tool returns its existing
scheduler_tools_disabled 503 and the model tells the user it cannot
create tasks here. The verdict reads the thread row that admission
already fetches, so it costs no extra store call, and the reuse_thread
422 stays as the REST and race backstop.
A side chat is a persistent thread of its own, so an incognito chat must
not create one. The provider takes a disabled flag: it skips the restore
query, drops an adopted side thread, and every open path becomes a no-op,
which also keeps the header trigger unmounted. The selection toolbar
keeps "Add to conversation" because a quote only rides the main composer
and dies with the thread, but hides "Ask in side chat".
A branch copies the conversation into a new persistent thread, which is
exactly the durable derivative an incognito chat must not leave behind.
The chat page hands the message list no branch handler, so the action is
not rendered at all; the backend already rejects a branch of an incognito
thread with 409 for direct API callers.
API.md gains the incognito thread section: create and end, the browser-
session-only restriction, the REST backstops (branch, project move,
share, scheduled-task reuse), and the /api/features incognito block.
The user guide now lists the entries an incognito chat does not offer
(scheduled tasks, side chat, branch) and the edges outside the promise:
external side effects, MCP OAuth credentials, and DeerMem retrieval
bookkeeping.
The sidebar menu item is gone: an incognito chat starts from the ghost
entry in the chat header, and while it is open the workspace sidebar is
not rendered at all. The chat shows a dark top bar around a framed
conversation area, with the centered title, a dashed composer and the
two notices under it. Focusing the composer thickens the dashed border
and turns it blue instead of drawing a solid ring. The welcome
suggestions and the AI disclaimer are not part of this surface.
- Accept metadata.incognito as the SDK's implicit-create hint so the first send no longer conflicts with the REST pre-create.
- Offer the ghost entry only on a blank new chat.
- State the storage boundary in the lead and subagent prompts, keep memory writes read-only, and anchor the Chinese term 无痕模式.
- re-verify the pinned incognito verdict at run admission and refuse a
  thread that expired or disappeared meanwhile
- make the tombstone terminal: late status/title writes and renewals
  cannot revive a thread whose deadline already passed
- keep durable subagent batches out of incognito runs, and count batch
  and read-marker cleanup toward the strict purge contract
- refuse direct DELETE on an incognito thread, hide incognito ids from
  the activity feed, and stop the memory store from overwriting a
  tombstone
- end a pre-created incognito row from the frontend even while the URL
  still calls the chat new
The idle window could be set to one minute, which renews only on runs, so a chat could expire while the user was still writing or right after a long run finished. Require at least one hour and keep the idle window at or below the absolute lifetime; cap the lifetime at one year so the deadline arithmetic stays inside datetime's range.

Route creation, renewal and an explicit end through one deadline helper, so every path stops at the absolute lifetime instead of only renewals doing it.

Render the notice in hours up to 72 hours and days (plus hours) above that, marking a window the units cannot express exactly, and document the ranges and the reason for them in config.example.yaml.
The prompt described the Chinese interface name and asked the model to
use that term when explaining it, so English replies could gloss
"incognito chat (无痕模式)". State a per-language selection rule
instead: Chinese replies use the terms exactly as written, and replies
in any other language must not include them.

The rule stays positive: requiring the exact terms already excludes
alternate translations, without an open-ended blacklist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants