14 Commits
Author SHA1 Message Date
Teknium 599a749ae9 fix(agent): side-question forks release clients only, never close the shared session
/btw and ctx.side_question tore their cache-parity fork down with
shutdown_memory_provider() + close(). The fork shares the live session's
id, and CLI/gateway key a session's terminal sandbox, browser and file
read stamps by that id (run_conversation(task_id=session_id)), so
close() -> _close_task_resources(session_id) -> cleanup_vm/cleanup_browser
tore down the parent session's live tool state after every side question.

Background review already releases only clients for exactly this reason
(_release_fork_clients). Lift that into one shared teardown,
background_review.release_cache_parity_fork(parent, fork, task=...):
attribute usage to the parent under `task`, then release_clients(). Both
one-shot fork callers use it; /btw usage is now recorded under its own
task name, side_question, instead of background_review.

Tests: a parent-session terminal env survives a plugin side question and
a real /btw fork (both red before); the side request runs under the
turn's profile and secret scope when redeemed from a fresh thread.
2026-10-24 19:56:21 -07:00
Teknium f17a567ac9 fix(gateway): let profile retirement stop a running /btw
GW-15 counts /btw as owner work, but its _spawn passed no holder, so
stop_authority_work could not reach its fork while join_authority_work
waited for it. A slow side question (the one-shot fallback allows 180 s)
held retirement for the whole settle window, then the profile kept its
reservation ("workers did not stop; ownership retained").

answer_side_question now publishes its cache-parity fork through
on_fork, and /btw passes a holder (_SideQuestionStop) that interrupts it.
Once stopped, the one-shot fallback is skipped; one already in flight is
an uncancellable, read-only aux call, so a stopped /btw with no fork left
stops counting as owner work and publishes no late answer.

Review finding by @kshitijk4poor on #140967
Refs #134889 (GW-15)
Refs #140719
2026-10-18 03:24:13 -07:00
Maciej Lisiewski d76cce4f11 ci: apply all automatic linter fixes available 2026-10-08 17:22:54 +02:00
Teknium ca90cea815 refactor(agent/side_question,review_*,thinking_timeout_guidance): flatten call sites, drop section banners 2026-09-02 19:19:44 -07:00
Teknium c8d71d9546 refactor(agent/G_small): tighten provider ABC, ssl_guard, tracker formatting, summaries predicate 2026-09-02 19:18:18 -07:00
Teknium 270128294e refactor(agent/G_small): single-line signatures/calls, github effort fallback table, any() slot scan 2026-09-02 19:08:38 -07:00
Teknium 2ccf295128 refactor(agent/review_engine,side_question,thinking_timeout_guidance): reflow prompt literals to 118 cols (bytes identical) 2026-09-02 19:04:35 -07:00
Teknium c1ae5349ba refactor(agent/G_small): rewrap adjacent string-literal fragments (bytes identical, parity corpus) 2026-09-02 19:01:42 -07:00
Teknium ca5f9f342a refactor(agent/G_small): hoist echo-family import, dataclass pending item, adopt_credits_state helper 2026-09-02 18:58:29 -07:00
Teknium d038249b12 refactor(agent/G_small): second code pass — merged guards, table-driven compact display, joined wrapped calls 2026-09-02 18:51:24 -07:00
Teknium a5eb266bd5 refactor(agent/review_*,side_question): hoist review goal constant, single-lock pending stamp, compact docstrings 2026-09-02 18:27:34 -07:00
Teknium c408601937 refactor(agent/review): simplify curator, background_review, verify, insights, title and learning modules (-22% LOC)
Cluster: agent/{curator,curator_backup,background_review,review_engine,
review_idle_queue,insights,learning_graph,learning_graph_render,
learning_mutations,learn_prompt,verification_evidence,verification_stop,
verify_hooks,side_question,title_generator,turn_summary,
manual_compression_feedback,trajectory,moa_trace,trace_upload,verify/*}.
13662 -> 10693 LOC (-2969, -21.7%), behavior-neutral.

- Dead code: 27 private helpers with zero references removed
  (_auto_title_session, _resolve_review_model, _parse_make_targets,
  _filter_verifiable_paths, _find_subsequence, _is_under_root/_temp_dir,
  _merge_runs, learning_graph_render bucket/period/node helpers,
  _memories_dir/_memory_local_index/_node_detail, _cron_jobs_file,
  _retention_cutoff, _scope_for_args, _clean_token, _count_diff_lines,
  _ordered_verbs, _hermes_meta, _iter_skill_files).
- Unified helpers: _read_config_section (curator + curator_backup),
  _write_file/_write_json (4 curator report writers), _msg_text
  (background_review <- side_question), _report_failure/_notify_title
  (title_generator instant/auto paths), _is_under (verification_evidence),
  _scoped SQL pair builder + _query (insights), _optional_lock
  (background_review), verify.recipes table-driven detection.
- if/elif routing -> dict dispatch: side_question role labels,
  curator_backup summary bits, learning_graph_render buckets, insights
  section rendering, verify recipe pickers.
- Redundant defensive layers, single-use wrappers and verbose narrative
  comments collapsed; every non-obvious WHY/invariant kept in compact form.

Verification: parity.py (all REMOVED symbols zero-ref), import smoke for
every module + cli/run_agent/gateway.run/hermes_cli.main/
agent.conversation_loop/tui_gateway.server, old-vs-new fuzz parity on all
shared pure functions, SQL trace parity for insights and
verification_evidence, cluster tests 1354 passed / 0 failed (46 files).
2026-09-02 13:30:25 -07:00
Teknium 578f85cfb0 feat: /btw rides the background-review cache-parity fork for full-context answers
The initial /btw implementation (#97937) answered from a rendered
plain-text transcript digest — truncated context, cold-written tokens on
every question. Teknium's call: reuse the self-improvement review fork
instead, which keeps the entire prompt cache stable for the fork and
gives it the complete conversation for very cheap.

- agent/background_review.py: extract the review-fork construction into
  build_cache_parity_fork() — same runtime/credentials as the parent,
  byte-identical system prompt / tools[] / reasoning config on the
  same-model path, shared session_id for prefix warmth, full persistence
  detachment (no state.db writes, no rotation, no external memory,
  in-place-only compaction). The review thread now calls the helper;
  behavior unchanged (full review test suite green).
- agent/side_question.py: /btw prefers the fork when a live parent
  AIAgent exists — replays the untruncated snapshot as warm cache reads,
  denies every tool at dispatch via an empty thread whitelist (tools[]
  stays byte-identical for cache parity), attributes usage to the parent,
  and trims a mid-turn snapshot tail so role alternation holds. The
  one-shot digest remains as fallback (no live agent = cold cache anyway,
  and any fork failure degrades gracefully).
- CLI passes self.agent, TUI passes the session agent, gateway looks up
  the chat's cached agent (parity with how turns reuse it).

Live-verified: /btw on the worktree runs the fork path (agent.log shows
the side question as a forked conversation turn on the parent session_id
with the full history replayed), answers correctly from context.
2026-08-29 08:23:47 -07:00
Teknium 74a95a3ddf feat: /btw now answers side questions with conversation context; /background renamed to /bg
/bg (formerly /background, which is retired) keeps the existing semantics:
spawn a fresh, independent agent session in the background.

/btw is now its own command matching the convention other harnesses use:
ask a quick side question ABOUT the current conversation without
interrupting it. A one-shot auxiliary LLM call (main model by default,
overridable via auxiliary.side_question.* in config.yaml) answers from a
read-only transcript snapshot — the live session's history, role
alternation, and prompt cache are untouched, and the current turn keeps
running.

Surfaces wired: CLI (inline mid-run dispatch), gateway (all messengers,
busy-dispatch table + idle dispatch, i18n across all 17 locales), TUI
(prompt.btw RPC + btw.complete event), Discord native slash, relay
command manifest, desktop exec routing, docs (EN + zh-Hans).
2026-08-29 07:25:17 -07:00