Skip to content

fix(brain-orb): post-voice processing as observable execution + write→select hardening (trinity-enterprise#102, #103) - #1494

Merged
dolho merged 1 commit into
devfrom
feature/102-103-brain-orb-voice-postprocess
Jul 7, 2026
Merged

dolho merged 1 commit into
devfrom
feature/102-103-brain-orb-voice-postprocess

Conversation

@vybe

@vybe vybe commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the two Brain Orb voice bugs from live testing (both P2, epic trinity-enterprise#57):

  • trinity-enterprise#102 — the post-voice-session run was a detached claude -p forked by the agent hook: invisible to the platform (a billing error silently became the "processed" note's content) and reaped by the agent-server's 30s cgroup orphan sweep (bug: Runaway subprocess after task failure makes agent-server unresponsive, triggering persistent CB cascade #817). The platform now owns the trigger: the action route strips capture_transcript's process flag before the hook call and the new services/brain_orb_postprocess.py dispatches the agent's configured prompt (perf: Backend CPU saturation at 45% with ~30 agents due to WebSocket churn and polling storms #73 — config stays agent-owned, Invariant security: implement safe tar extraction with symlink/hardlink validation #8) via execute_task(triggered_by="voice") — sweep-safe, visible under Executions, cost-tracked, failures land as FAILED rows with the diagnostic. process_transcript dispatches the same way and never reaches the hook. Every outcome is surfaced in the orb (saved / started / skipped+reason / failed / agent offline), and voice.js always relays the session end so "no dialogue" is distinguishable from a broken pipeline.
  • trinity-enterprise#103 — "add a note, then show it" failed invisibly: real exporters title inbox nodes by file stem, so auto-select/navigate searching the H1 title missed (normTitle kept hyphens); postAction swallowed FastAPI detail errors (a stopped agent read as a silent no-op); navigate_to_note awaited a minutes-long reindex inside the voice tile's 8s tool timeout. Fixed: pending auto-select tracks title and path stem + hyphen folding; refreshGraph joins in-flight runs and queues one follow-up; a refresh that doesn't surface the note briefly polls /data (async/net-zero exporters); navigate waits a bounded ~6s then answers honestly and auto-selects on completion; creation/failure and broker errors toast loudly.

Root-cause analyses documented on the issues: 102, 103.

Changes

  • src/backend/services/brain_orb_postprocess.py (new) — config read (fail-closed) + framed-message dispatch through execute_task, execution row pre-created (scheduler pattern), fail-soft (a dispatch problem never loses a saved transcript)
  • src/backend/routers/agent_brain_orb.py — process strip + dispatch merge into the capture_transcript snapshot (idempotency-complete after merge so replays carry the execution id); process_transcript intercepted → dispatch; shared _require_running_agent gate; audit gains postprocess_dispatched/postprocess_execution_id
  • src/frontend/public/brain-orb/orb.js — outcome toasts for the whole transcript chain; postAction/refreshGraph error surfacing (detail → toast); multi-key pending focus + normTitle hyphen folding; in-flight join + queued refresh; bounded /data poll; bounded navigate wait
  • src/frontend/public/brain-orb/voice/voice.js — always relay session end (guarded on a session having started)
  • src/frontend/src/components/BrainPanel.vue — copy: runs appear under Executions
  • docker/base-image/agent_server/routers/brain_orb.py — contract docstring (no behavior change)
  • Docs: architecture.md Brain Orb section, feature-flows/brain-orb.md Phase 4b + refresh-loop sections
  • Tests: 8 new router tests + new tests/unit/test_brain_orb_postprocess.py (10 tests)

Test Plan

  • pytest tests/unit/test_brain_orb.py tests/unit/test_brain_orb_postprocess.py tests/unit/test_85_brain_orb_settings.py — 134 passed
  • Live localhost (both hook generations — real cornelius-e2e hooks + template hooks): capture_transcript {process:true} → transcript saved + execution row (triggered_by=voice) → reaches agent → terminal status with precise diagnostic (previously swallowed: "You've hit your weekly limit…" now on the FAILED row)
  • Idempotent replay (session-id key): X-Idempotent-Replay: true, same execution id, one transcript file, no double dispatch
  • Playwright UI: capture → "integrating…" → "graph updated · +5 notes" → auto-select of the stem-titled node (the exact feat: Telegram Bot Integration for Agents (TGRAM-001) #103 repro); voice-transcript toast chain; no-dialogue toast; stopped-agent errors surfaced ("Agent is not running")
  • Post-process SUCCESS terminal — blocked externally on this box (no Claude auth has quota: platform key out of credits, subscription weekly-limited until Jul 8); the pipeline runs claude and captures its terminal either way

Refs abilityai/trinity-enterprise#102, abilityai/trinity-enterprise#103 (private-tracker issues — closed manually at release; cross-repo keywords don't auto-close)

🤖 Generated with Claude Code

…→select loop hardening (trinity-enterprise#102, #103)

#102 — the post-session run was a DETACHED claude -p forked by the agent's
action hook: invisible to the platform (no execution row/cost/failure surface
— a billing error silently became the "processed" note) and reaped by the
agent-server's 30s cgroup orphan sweep (#817). The platform now owns the
trigger: the action route strips capture_transcript's `process` flag before
the hook call and services/brain_orb_postprocess dispatches the agent's
configured prompt (#73, still agent-owned — Invariant #8) via
execute_task(triggered_by="voice") — sweep-safe, visible under Executions,
failures land as FAILED rows. process_transcript dispatches the same way and
never reaches the hook. Every outcome is surfaced in the orb (saved / started
/ skipped+reason / failed / agent offline), and voice.js always relays the
session end so "no dialogue" is distinguishable from a broken pipeline.

#103 — "add a note, then show it" over voice failed invisibly: real exporters
title inbox nodes by file stem, so the auto-select/navigate searching the H1
title missed (normTitle kept hyphens); postAction swallowed FastAPI `detail`
errors (a stopped agent read as a silent no-op); navigate_to_note awaited a
minutes-long reindex inside the voice tile's 8s tool timeout. Fixes: pending
auto-select tracks title AND path stem, normTitle folds hyphens; refreshGraph
joins an in-flight run and queues one follow-up instead of dropping; a refresh
that doesn't surface the note polls /data briefly (async/net-zero exporters)
instead of declaring "up to date"; navigate waits a bounded ~6s then answers
honestly and auto-selects on completion; capture success/failure and broker
errors (503 "Agent is not running") toast loudly.

Validated live on localhost against both hook generations (real cornelius-e2e
hooks + template hooks): dispatch → execution row → agent → terminal status
with precise diagnostics; idempotent replay returns the same execution with no
double dispatch; the previously-failing stem-titled auto-select now lands.

Co-Authored-By: Claude Fable 5 <[email protected]>
@dolho

dolho commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review — the code looks solid; the one red check is not yours.

CI: the failing lint (sys.modules pollution check) is pre-existing dev breakage, not this PR

It flags tests/unit/test_fork_to_own.py (3 bare del sys.modules[...] at lines 499/520/798) — a file this PR doesn't touch. Those lines landed on dev via a different PR (fc0e904f, fork-to-own #93) without updating tests/lint_sys_modules_baseline.txt, so dev itself is red on this gate; #1494 (dev + 1 unrelated commit) just inherits it. git rev-list --left-right --count origin/dev...HEAD = 0 1, so it isn't a stale-branch issue either.

Fix belongs in a small dev-hygiene commit (convert those three to monkeypatch.delitem(sys.modules, ..., raising=False), or python tests/lint_sys_modules.py --regenerate-baseline) — ideally not folded into this PR. Worth pinging #93's author. It does block merge until dev is green.

Backend — looks correct, verified two risks

  • services/brain_orb_postprocess.py follows the VoIP _dispatch_post_call precedent cleanly: fail-closed config read, fail-soft dispatch (never raises → a saved transcript is never lost), strong-ref background set (dodges the weak-ref GC footgun), and an observable execution row so the run is sweep-safe + cost-tracked. This directly addresses the Refactor db/agents.py - Split into focused modules #102 root cause (detached claude -p reaped by the bug: Runaway subprocess after task failure makes agent-server unresponsive, triggering persistent CB cascade #817 orphan sweep).
  • Verified the pre-create + execute_task(execution_id=…) handoff does not double-create: execute_task only calls create_task_execution when execution_id is falsy (docstring: "If execution_id is provided the caller has already created the [row]").
  • Verified triggered_by="voice" is a real analytics trigger (db/schedules.py:55 → "Voice" bucket), not an "Other" fallthrough.
  • Router: stripping process before the hook call correctly stops an older hook from also forking, and merging postprocess into the snapshot before completing the idempotency claim means a replay carries the same execution id (no double dispatch). Nice.

Minor

  • Per your own checklist, the SUCCESS terminal path wasn't observed locally (Claude quota exhausted on the box). The dispatch/terminal-capture machinery is exercised, but the happy-path "processed note written" end-to-end hasn't been seen green — worth a follow-up confirmation once quota is back.

Net: approve on the code once dev's lint baseline is fixed (separately). Nice work making the post-voice run a first-class, observable execution.

@dolho
dolho merged commit dd9c673 into dev Jul 7, 2026
19 of 20 checks passed
vybe added a commit that referenced this pull request Sep 7, 2026
…or below the state card (#2538, #2539) (#2546)

* fix(brain-orb): latch wheel routing per gesture so momentum never zooms (#2538)

The single window-level `wheel` listener in public/brain-orb/orb.js decided
zoom-vs-scroll PER EVENT via panelCanScroll(), with no gesture memory. On a
macOS trackpad one flick keeps emitting `wheel` at frame cadence long after
the fingers lift, so the inertia tail that arrived after a panel reached its
edge was routed to camTargetDist and the camera zoomed out.

- Gesture latch: a run of wheel events with inter-event gaps <= 150 ms
  (WHEEL_GAP_MS — the top of the issue's 120-150 ms range) is one gesture.
  Its first vertical event decides the route from the scroll container under
  the pointer; every later event keeps it. Panel-latched events that can
  scroll nothing are swallowed (preventDefault), never zoomed. A fresh
  gesture (gap > 150 ms) over an already-edged panel still zooms, so the
  deliberate "scroll to the end, then keep going to zoom out" chaining is
  preserved.
- Clock is e.timeStamp (input time) with a performance.now() fallback.
  Chromium coalesces events queued behind a stalled frame into one, so a
  stall > 150 ms still ends the gesture — bounded to one re-decided step.
- deltaY === 0 (pure-horizontal) events never start a latch; they refresh
  the clock and otherwise behave exactly as before. deltaX handling stays
  deferred, as the issue itself defers it.
- Allowlist gone: panelCanScroll() walks the target's ancestors up to <body>
  and asks computed style, so the CSS is the single source of truth.
  #scopePanel (overflow-y:auto all along) scrolls under the wheel at last.
- The ctrlKey pinch branch and the Safari gesture* listeners are untouched.
- index.html: orb.js is un-hashed under prod nginx's 1y-immutable cache, so
  the <script> tag now carries ?v=2026-09-06 (comment says: bump BOTH).

Proof: e2e/brain-orb-wheel-latch.spec.js (@smoke; standalone
/brain-orb/index.html FALLBACK graph — no agent, no auth; skips without
WebGL, fails loudly on a boot error). Red before the fix at A2+A3
(camTargetDist 330 -> 473.9 across a 25-event tail), A4 ([true,false]) and
A5 (#scopePanel wheel zoomed, defaultPrevented true); 9 passed after. A1
scrolls #inspContent into the inspector's visible box and asserts the aim
point before firing its one trusted wheel, so a mis-aim can never read as
a routing failure.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(brain-orb): floor the inspector below the state card (#2539)

#stateBox (top:26px, 174px tall) and #inspector (top:50%; translateY(-50%);
max-height:82vh) are both right-anchored .panels at z-index 10 with nothing
reserving vertical space, so a tall inspector rose into the state card and,
being later in DOM order, painted over "STATE / Idle" — measured overlap
128 / 119 / 103 px at 1280×800 / 1440×900 / 1920×1080 (132 px on the real
1280×756 iframe viewport).

CSS only — exactly two values on #inspector change:
- transform: translateY(max(-50%, calc(224px - 50vh))) keeps the centring
  while the box is short and floors its TOP edge at 224px (26 + 174 card +
  24 gap) once it is tall — continuous, no jump. The 174px premise holds
  for every STATES desc and the boot-time "reflecting last run" string
  (<=3 lines at 26ch); spec B1 asserts it rather than trusting it.
- max-height: min(82vh, calc(100vh - 224px - 26px)) keeps the BOTTOM edge
  26px inside the viewport.
No fallback pairs: the sheet already relies on min() unguarded. No JS:
makeDraggable/restorePanels set inline right:auto + transform:none, so a
dragged or restored inspector keeps its user-chosen spot (spec B3).

Cost, stated so nobody raises the cap later: on the real iframe a
full-height inspector shrinks from 82vh to 100vh-250px (~549 -> 420 px at a
1280×800 window). Out of scope, follow-ups: the #controls legend under a
full-height inspector, #scopePanel's own gutter collision, and — surfaced
by spec B1 — the top-centred #dock covering the state value at <=760px.

index.html: styles.css now carries the shared ?v=2026-09-06 token (the
orb.js tag got it in the previous commit; bump BOTH on every edit).

Proof: e2e/brain-orb-inspector-layout.spec.js (@smoke; standalone FALLBACK
page, no agent/auth). Red against the previous styles.css at all five
viewports — "inspector.top 72|81|97|68|81 vs stateBox.bottom 199.86,
Expected >= 215.86" — 8 passed after. The shared helper gains a
`paragraphText` option so B2's short note sits inside the centring band
(h <= 100vh - 448) instead of on its edge.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(brain-orb): state the ?v= cache-bust convention in the feature flow (#2538, #2539)

The "Known limitations" bullet said the orb was frozen (verbatim) and that a
future orb update "needs a cache-bust" — both false once #2538/#2539 edit
orb.js and styles.css and index.html carries the shared ?v=2026-09-06
token. Rewrite that one bullet to state the convention (bump BOTH tokens on
every edit) and its residual (/brain-orb/index.html itself is heuristically
cached by prod nginx — the \.html$ no-store rule is a paired follow-up),
and list the two Playwright HUD specs + helper in the file map. Nothing
else in the flow changes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(brain-orb): name the symmetric latch at the zoom branch so nobody re-decides per event (#2538)

The block comment above panelCanScroll() states the gesture rule ("every
later event of the gesture keeps that route"), but the line a future reader
would actually edit — the zoom branch that runs while `can` is true for a
zoom-latched gesture — only said "zoom-latched". That is exactly where an
`if(wheelMode==='zoom' && can) return;` "improvement" would land and quietly
turn a zoom flick into an inspector scroll (the reported bug's mirror
image). Say it at that line: the latch is symmetric by design, the first
event decides, and spec A4 pins it. Comment only — no behaviour change;
spec A re-run green (9 passed).

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(brain-orb): the ?v= bullet — first orb edits since v0.8.0, not since vendoring (#2538, #2539)

"the first edits to the orb since it was vendored" is false: `git log --all
-- src/frontend/public/brain-orb/orb.js` shows the Phase 2–4 PRs (#1395,
#1407, #1494 and their hardening follow-ups) editing orb.js in-repo after
#1389 vendored it. What IS true, and what the cache-bust convention hinges
on, is that #2538/#2539 are the first orb edits to reach `dev` since the
v0.8.0 release merge (the only commit touching these files on origin/dev).
Say that instead.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Eugene Vyborov <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
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