← Back to Pull requests

demo_agent: an app update keeps the session's lane; restore-lane repairs a moved one (beta.19 P1, goatai#1885) #143

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 04, 2026 01:23 UTC
Author

Claude-PC: P1 for beta.19. An app update with MT5 open moved a customer terminal into the owner demo lane. This PR makes install-build keep the session's lane and adds restore-lane to repair terminals that an older update already moved. The desktop half is algogoat/goatai#2222. Coordination is on goatai#1885 (Claude-Mac agreed in comment 5975155476).

Root cause (proven on Terminal 3, 2026-10-04 00:25Z)

The desktop's suite.updatePlan probes the terminal. With MT5 open, the probe throws and the plan takes the demo path (demoResumeLogin). suite.applyUpdate then runs the bundled demo_agent.py install-build --require-running --linked-login --bundle-version --agent-guide-path. DemoAgent._adopt_installed_binary rebinds session.json to the new receipt, and it also wrote authority_kind = 'demo_direct' on every session:

if session.get('authority_kind') != 'demo_direct' or session.get('installation_sha256') != sha(checked):
    session['authority_kind'] = 'demo_direct'

That line is the owner's way to enroll a terminal ("its commands refuse to drive Studio until install-build has converted the selected session"). The desktop update reuses install-build, so it enrolled every terminal it updated with MT5 open. T3's evidence:

  • demo-agent/backups/session-ea5a19fb….json, written just before the rewrite: authority_kind: native_human_control. The current session.json reads demo_direct.

  • actions.jsonl: before_close, binary_replaced, local_identity_verified (00:25:45), relaunch verified, then bundle_identity_verified.

  • The receipt gained demo_installed_at.

  • The next studio close-terminal (Desktop suite.closeTerminal) refused in studio_research_authority.authority(): Demo mutation requires the broker-verified agent tool.
  • Fix

  • install-build rebinds installation_sha256 and keeps authority_kind:

  • - A customer session stays native_human_control.
    - An owner session stays demo_direct.
    - A legacy session keeps no kind.
  • Only --enter-demo-lane writes demo_direct. That flag is the owner explicitly enrolling one of GOAT's own demo terminals. It refuses together with the app's --bundle-version/--agent-guide-path, so an app update can never change a lane. The desktop never passes it.

  • For an update with identical bytes, a customer session now takes the existing "verify where it runs" path, the same one demo_direct already used, instead of closing MT5 again. Enrollment still takes the full path.

  • local_identity_verified rows now log authority_kind and previous_authority_kind.

  • Owner demo_direct terminals behave exactly as before. Build verification, the DLL-carrying relaunch, the readback, "pairing needed" and the receipt write are all unchanged.
  • Behaviour change for the owner: enrolling a new GOAT demo terminal now needs install-build ... --enter-demo-lane. DEMO-AGENT-TOOLS.md says so. Terminals already on demo_direct (Banker, T2) need nothing.

    Repair for terminals an older update moved: restore-lane

    & $goat demo --installation $receipt restore-lane          # read-only review
    & $goat demo --installation $receipt restore-lane --apply  # back to native_human_control
    

    --apply rewrites only session.json's authority_kind and keeps the current installation_sha256. The demo_direct bytes are saved to demo-agent/backups/ and the change is logged as restore_lane. MT5, the EA, the receipt and studio.sqlite are untouched.

    Every proof below must hold, or restore-lane refuses:

  • The session is demo_direct and bound to the current receipt.

  • demo-agent/backups/ holds this tool's own backup of this exact session on native_human_control, and its content matches its name.

  • The store still holds the binding's native_human_control authority.

  • There is no research-authority.json.

  • actions.jsonl has an install_build identity row and only update steps: install_build, launch_terminal, readback_refresh, recover_orphan, restore_lane.

  • There is no owner STOP, active native batch, live driver, or seed/catch-up run.
  • So an owner terminal that has run demo research always refuses. I scanned this PC read-only: Banker has 17 kinds of owner operations in its log and T2 has 14, so both would refuse. T3 has none.

    Not run on T3. I ran only the review against T3's real files, with this branch's code and a G: build Python. It returned ready_to_restore, with evidence backups/session-ea5a19fb….json. Every file in T3's state was hashed before and after (session, receipt, studio.sqlite, demo-agent/*) and all were byte-identical. --apply was not run.

    Tests

    New controller/test_demo_update_keeps_lane.py (8 tests, fixtures only, no MT5):

    | Test | Proves |
    |---|---|
    | customer update with MT5 open | The exact desktop args install, verify and relaunch. The session stays native_human_control, rebound to the new receipt. Then the real dispatch() CLI choke point plus close_terminal() (Desktop suite.closeTerminal) close MT5 (Claude-Mac's required test). |
    | same-bytes customer update | Metadata-only update: verified in place, process.close never called, lane kept. |
    | owner demo_direct update | Stays demo_direct; ready_for_batch after readback; raw studio close-terminal still refuses as before (regression test). |
    | explicit enrollment | --enter-demo-lane with bundle metadata refuses before any close; alone it enrolls. |
    | restore-lane end to end | Replays the beta.18 flip. close-terminal refuses (the T3 bug), the review writes nothing, --apply restores, close-terminal works, and a second run returns already_customer_lane. |
    | restore-lane refusals | Owner demo work in the log; missing or tampered backup; STOP; typed continuation; active batch; store without the customer authority. |
    | restore-lane CLI | Review by default, --apply writes. |

    Mutation check: with the old always-enroll behaviour patched back in, both customer-update tests fail ('demo_direct' != 'native_human_control').

    Fixtures that used _adopt_installed_binary as an implicit enrollment now pass enter_demo_lane=True: test_demo_agent, test_demo_reservation_release, test_studio_t2_r3_fixes. Two desktop-shaped install tests now start from an owner demo_direct session, because they assert ready_for_batch.

    Run locally (PowerShell, bundled Python 3.13.15, worktree controller first on sys.path, module sources verified): the 15 demo, guide, setup, authority, rebind and self-repair modules pass (259 tests, including the 8 new ones and RecoveryGuidanceTests/test_studio_customer_skills for the guide). The full discovery run is still in progress locally, and the "Controller Windows tests" CI on this PR runs the full suite.

    Docs

  • DEMO-AGENT-TOOLS.md: the lane rule, --enter-demo-lane, and the restore-lane contract.

  • AGENT-START-HERE.md: one sentence. Updating keeps native_human_control. If a customer terminal reads demo_direct after an older update, the agent tells the user that GOAT support can restore it. The agent still never switches to goat demo.
  • Not verified

  • No native MT5 run of the fixed install-build on a customer terminal. That needs a beta.19 candidate on T3 after restore-lane --apply.

  • Batch start on a customer lane after a lane-keeping update is not exercised natively. The fixture covers the CLI authority and close paths.
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: chatgpt-codex-connector[bot] Review duration: 8m
    All Vouch review confidence checks passed
    Residual risk 0.42 = Change Risk (0.57) × (1 − Review Confidence (0.26)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 49% · Reviewer familiarity: 35%
    25%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #143"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 25.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 25.8% · Lower = rushed or shallow review
    25.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 42.3% · Moderate risk
    42.3%