Skip to content

M0 Foundations (v0.3.0 milestone 0): non-vacuous security guards, crash log, dead-thread banner, beta channel, N-client harness, agent.rs - #3

Merged
ayushap18 merged 1 commit into
mainfrom
m0-foundations
Sep 22, 2026

Conversation

@ayushap18

Copy link
Copy Markdown
Owner

Milestone 0 of the v0.3.0 plan. Foundations only — no feature, no behaviour change. Ships to everyone as v0.2.10.

183 backend tests (was 177) · 49 frontend · zero warnings. generate_handler! byte-identical to v0.2.9.

Unit What
STAB-1 Security grep tests could pass with the guarded code deleted. Each now asserts a floor over a shared list spanning lib.rs + agent.rs; proven by deleting a guarded site and watching it go red.
STAB-4 Panic hook → crash.log (64 KB cap, never networked) + /crash.
STAB-5 A dead PTY reader or painter thread now emits an event and the UI shows a banner instead of freezing silently.
STAB-6 Beta channel verified: -beta tags are --prerelease, never --latest, so the updater cannot serve a beta to stable copies.
STAB-2 N-client harness against the real MCP listener: 8 simultaneous → 1 reaches the backend, 7 refused; a race test proves agent_claim admits exactly one of 8 threads.
STAB-3 Sign-off item. Agent code moved to agent.rs. Every moved body verified byte-identical to v0.2.9 modulo pub(crate); the only non-move lines are use super::*; and one re-export.

Also fixes a rare ETXTBSY flake in the two fake-shell tests (serialised).

Not verified

The dead-thread banner and /crash have not been seen in the running app.

…le thread death, a beta channel, an N-client harness, and agent.rs

Foundations for the v0.3.0 multi-agent hub. No feature, no behaviour change:
generate_handler! is byte-identical to v0.2.9 and every function moved into
agent.rs is byte-identical apart from pub(crate) visibility (verified by
extracting each body from v0.2.9 and comparing).

STAB-1 Several source-grep security tests would have PASSED with the guarded
code deleted — a grep for zero bad occurrences passes on an empty file. Each
now asserts a floor (commands > 20, callers == 3) over one shared GREPPED list
that spans lib.rs and agent.rs, and evals/rust-source.mjs takes a file list.
Proven by deleting a #[tauri::command] and a pty_write_internal( site and
watching the guard go red.

STAB-4 A panic hook writes "version ts payload" to config_dir()/crash.log,
truncated past 64 KB, never over the network. /crash prints the tail.

STAB-5 An EmitOnDrop guard at the top of the PTY reader and painter threads:
a dead reader emits pty-exit, a dead painter emits paint-dead and the frontend
paints a banner, so a hung terminal says so instead of freezing silently.

STAB-6 The prerelease channel verified and documented: a -beta tag is
--prerelease and never --latest, so the updater endpoint (releases/latest)
cannot serve a beta to a stable copy. release.test.mjs pins the shape.

STAB-2 An N-client harness drives the real listener with a Stub backend:
8 simultaneous run_command -> exactly one reaches the backend, seven get
isError; 8 sequential -> peak concurrency 1; a panicking holder frees the
slot. A separate race test throws 8 threads at agent_claim on one AgentState
and proves exactly one wins — and goes red if the swap becomes load-then-store.

STAB-3 agent.rs: AgentState, agent_claim/decide/abort, MIN_REVIEW,
decision_stands, agent_propose, AgentRunGuard, agent_loop, AI_AGENT,
render_tools, parse_agent_reply moved out of lib.rs. Task, is_dangerous,
one_line and ai_call stay. Marked SIGN-OFF #2 in the plan: the only non-move
lines are `use super::*;` and one pub(crate) re-export of SeqCst.

Also: the two fake-shell tests could flake under a parallel run (ETXTBSY on a
just-written script); they now serialise on a mutex.

177 -> 183 backend tests.
@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 833904db-deda-429a-a06c-89981b5af860


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Harden crash diagnostics, security guards, and agent concurrency

✨ Enhancement 🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Add local crash diagnostics and visible PTY thread-failure banners.
• Make security guards non-vacuous and test single-client terminal ownership under races.
• Extract agent orchestration and verify prerelease channel isolation.
Diagram

graph TD
  Drivers["Agent Drivers"] --> Approval["Approval Slot"] --> Pty["PTY Runtime"] --> Events["Death Events"] --> UI["Terminal UI"]
  Hook["Panic Hook"] --> Log[("Crash Log")] --> Slash["Crash Command"] --> UI
Loading
High-Level Assessment

The current approach fits the milestone: extracting agent orchestration preserves behavior, an atomic fail-fast claim enforces single-driver semantics, and a small local panic hook avoids introducing telemetry or crash-reporting dependencies. Queueing concurrent agents would weaken explicit ownership, while an external crash service would conflict with the local-only privacy requirement.

Files changed (9) +951 / -469

Enhancement (2) +217 / -452
lib.rsAdd capped crash logging and visible PTY thread-failure events +213/-449

Add capped crash logging and visible PTY thread-failure events

• Installs a chained panic hook that writes sanitized entries to a private, capped 'crash.log', and exposes its tail through '/crash'. Adds drop guards for PTY reader and painter termination, strengthens source-based security checks with shared non-vacuous scan floors, and serializes flaky fake-shell tests.

src-tauri/src/lib.rs

complete.rsExpose '/crash' in slash-command completion +4/-3

Expose '/crash' in slash-command completion

• Adds the crash-log command to completion metadata and updates the backend/frontend command-surface consistency expectations.

ui/src/complete.rs

Bug fix (1) +9 / -4
terminal.rsShow a banner when the terminal painter dies +9/-4

Show a banner when the terminal painter dies

• Generalizes the PTY exit listener to handle both process exit and painter-thread death. A failed painter now leaves a visible restart message instead of presenting a silently frozen terminal.

ui/src/terminal.rs

Refactor (1) +435 / -0
agent.rsExtract built-in agent orchestration into a dedicated module +435/-0

Extract built-in agent orchestration into a dedicated module

• Moves the agent prompt, tool rendering, response parsing, approval state, claim logic, and execution loop out of 'lib.rs'. Exposes the required items within the crate while preserving the shared fail-closed approval slot used by MCP.

src-tauri/src/agent.rs

Documentation (2) +24 / -0
CONTRIBUTING.mdDocument the beta release procedure and stable-channel safeguards +23/-0

Document the beta release procedure and stable-channel safeguards

• Adds the end-to-end beta tagging, version synchronization, artifact naming, publication, and retirement procedure. Explains why prereleases must never be marked as the latest GitHub release.

CONTRIBUTING.md

README.mdDocument the local crash-log command +1/-0

Document the local crash-log command

• Adds '/crash' to the user-facing slash-command reference and states that panic data remains local.

README.md

Other (3) +266 / -13
rust-source.mjsScan agent and library sources for evaluation inputs +7/-3

Scan agent and library sources for evaluation inputs

• Builds evaluation source text from both 'lib.rs' and 'agent.rs', preventing extraction checks from silently missing code moved into the new module. Error messages now identify every scanned path.

evals/rust-source.mjs

release.test.mjsVerify prerelease artifact naming and channel isolation +53/-3

Verify prerelease artifact naming and channel isolation

• Adds beta-tag fixtures covering installer names, checksums, updater URLs, release notes, and workflow prerelease/latest guards. Extends README version parsing to retain semantic prerelease suffixes.

scripts/release.test.mjs

mcp_server.rsAdd real-listener multi-client ownership tests +206/-7

Add real-listener multi-client ownership tests

• Expands the test backend to use the production 'agent_claim' state and track concurrent terminal access. Adds atomic claim races plus simultaneous, sequential, and panicking-client tests proving only one driver enters and that unwinding releases the slot.

src-tauri/src/mcp_server.rs

@qodo-code-review

qodo-code-review Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (4) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Crash logs can exceed their disk cap 🐞 Bug ☼ Reliability
Description
crash_line passes the complete sanitized one_line(payload) to append_crash, which checks only
the pre-write file size before appending the unbounded entry and does not serialize concurrent
writers. An oversized panic payload or simultaneous panics can push crash.log far beyond 64 KiB,
and /crash then reads the entire oversized file before selecting its tail.
Code

src-tauri/src/lib.rs[R2041-2042]

+    if std::fs::metadata(path).is_ok_and(|m| m.len() > CRASH_LOG_CAP) {
+        let _ = std::fs::remove_file(path);
Evidence
The formatter sanitizes the panic payload but never truncates it, and append_crash removes the
file only when its existing size is already above the cap before writing the complete new line. The
added test explicitly permits growth to CRASH_LOG_CAP + line.len(), confirming that projected
post-write size is not bounded, while the slash command reads the complete resulting file.

src-tauri/src/lib.rs[2017-2032]
src-tauri/src/lib.rs[2034-2052]
src-tauri/src/lib.rs[2854-2860]
src-tauri/src/lib.rs[1436-1463]
src-tauri/src/lib.rs[2017-2053]
src-tauri/src/lib.rs[2056-2082]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The crash logger checks the existing file size but does not bound the incoming formatted entry or serialize concurrent panic hooks, so a single large payload or concurrent writes can exceed the advertised 64 KiB cap and leave `/crash` reading an oversized file.

## Fix Focus Areas
- src-tauri/src/lib.rs[2017-2052]
- src-tauri/src/lib.rs[2839-2861]

## Recommended Fix
Serialize the size-check and append operation, and bound each formatted crash entry while accounting for the version, timestamp, and newline. Reset or truncate the file based on the projected post-write size so both oversized and normal entries preserve `CRASH_LOG_CAP`, keep `/crash` operating on the bounded file, and extend the tests with an oversized entry and concurrent writers that assert the resulting file never exceeds the cap.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Thread-failure warnings can disappear 🐞 Bug ☼ Reliability
Description
The new paint-dead listeners call fill_text directly on the canvas without storing the warning
in terminal state or reserving a row that redraw preserves. If the painter dies before the
mount-time full repaint arrives, a grid-damage event is delivered later, or the window is resized or
refitted, the canvas is redrawn only from buffered terminal cells and the sole indication that the
still-frozen backend is dead is removed.
Code

ui/src/terminal.rs[R732-743]

+    for (event, text) in [
+        ("pty-exit", "[process exited]"),
+        ("paint-dead", "[tachyon] repaint thread died — the screen is frozen; restart tachyon"),
+    ] {
        let term = term.clone();
-        listen("pty-exit", move |_| {
+        listen(event, move |_| {
            let t = term.borrow();
            let row = (t.cursor.line + 1).min(t.rows.saturating_sub(1));
            let (x, y, _, _) = t.cell_px(0, row);
            t.ctx.set_font(&format!("{}px {}", t.font_px, t.font_family));
            t.ctx.set_fill_style_str(crate::theme::tokens(&settings_theme()).err);
-            let _ = t.ctx.fill_text("[process exited]", x, y);
+            let _ = t.ctx.fill_text(text, x, y);
Evidence
The event handler draws the warning directly with fill_text without updating Term.buf or
maintaining persistent banner state. Grid-damage events repaint the same canvas, setup requests a
full grid repaint after the PTY spawn call returns, and fit clears the backing canvas before
refit redraws only the terminal model, showing that event delivery or a normal resize can
overwrite the unmanaged warning.

ui/src/terminal.rs[717-725]
ui/src/terminal.rs[729-745]
ui/src/terminal.rs[746-776]
src-tauri/src/lib.rs[737-740]
ui/src/terminal.rs[265-283]
ui/src/terminal.rs[426-429]
ui/src/terminal.rs[630-641]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Dead-thread warnings exist only as transient canvas pixels, so later full or damaged redraws—including mount-time repaint, grid damage, resize, and refit—can remove the warning while the backend remains dead.

## Fix Focus Areas
- ui/src/terminal.rs[265-283]
- ui/src/terminal.rs[426-429]
- ui/src/terminal.rs[630-641]
- ui/src/terminal.rs[729-745]
- ui/src/terminal.rs[769-776]

## Recommended Fix
Store the active backend-thread failure banner in terminal UI state and render it as an overlay after every full or damaged redraw. Have the event listener update that state before requesting a redraw instead of calling `fill_text` as a one-off operation, and keep the banner visible until the terminal is restarted or a new PTY lifecycle explicitly clears it.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. One command module escapes the guard 🐞 Bug ⚙ Maintainability
Description
GREPPED omits local_models.rs even though that module defines a command registered in the
application handler list. Moving or adding a Task argument there would evade
task_is_never_an_ipc_argument, while the coarse command-count floor would still pass using
commands from the listed files.
Code

src-tauri/src/lib.rs[R2412-2415]

+    const GREPPED: &[(&str, &str)] = &[
+        ("lib.rs", include_str!("lib.rs")),
+        ("agent.rs", include_str!("agent.rs")),
+        ("mcp_server.rs", include_str!("mcp_server.rs")),
Evidence
The changed guard iterates only lib.rs, agent.rs, and mcp_server.rs, then considers any count
above twenty non-vacuous. local_discover is a Tauri command in local_models.rs and is explicitly
registered in generate_handler!, but its source is absent from that scan.

src-tauri/src/lib.rs[2412-2425]
src-tauri/src/lib.rs[2362-2397]
src-tauri/src/lib.rs[4296-4313]
src-tauri/src/local_models.rs[225-228]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The generalized command security scan omits a module that already contains a registered bridge command, leaving the guard incomplete despite its non-vacuity floor.

## Fix Focus Areas
- src-tauri/src/lib.rs[2412-2416]
- src-tauri/src/lib.rs[2362-2397]
- src-tauri/src/lib.rs[4296-4313]
- src-tauri/src/local_models.rs[225-228]

## Recommended Fix
Add `local_models.rs` to the scanned source list and make the guard verify coverage against the commands registered in `generate_handler!`, rather than relying only on a total-count floor that cannot detect an omitted module.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Valid beta versions fail release checks 🐞 Bug ≡ Correctness
Description
NAMED_IN_README permits dots and alphanumeric characters after the first prerelease hyphen but
stops when another hyphen appears. A version accepted by both production release gates, such as
0.3.0-beta-rc.1, is therefore captured as 0.3.0-beta and fails the README version assertion
before release.
Code

scripts/release.test.mjs[167]

+const NAMED_IN_README = /Tachyon_(\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?)_/g;
Evidence
The new README regex uses [0-9A-Za-z.]+, whereas both release gates use [\u0000w.-]+, which
accepts additional hyphens in the suffix. The release script then preserves the entire accepted
version in installer filenames.

scripts/release.test.mjs[164-175]
scripts/release.mjs[5-18]
.github/workflows/release.yml[43-51]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The README filename parser rejects prerelease suffixes containing more than one hyphen even though the release workflow and script accept them.

## Fix Focus Areas
- scripts/release.test.mjs[164-175]
- scripts/release.mjs[5-9]
- .github/workflows/release.yml[43-48]

## Recommended Fix
Allow hyphens throughout the prerelease capture while preserving the filename delimiter, and add a test using a version such as `0.3.0-beta-rc.1`. Keep the accepted version grammar aligned with the workflow and release script.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: 🧠 Deep: This broad, security- and concurrency-sensitive PR adds substantial logic across agent execution, MCP client coordination, crash handling, release behavior, and UI threading, creating many independent defect opportunities.

Grey Divider

Tip of the day
💡 Did you know, you can route each action level your way: inline, summary, both, or drop

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread src-tauri/src/lib.rs
Comment on lines +2041 to +2042
if std::fs::metadata(path).is_ok_and(|m| m.len() > CRASH_LOG_CAP) {
let _ = std::fs::remove_file(path);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Crash logs can exceed their disk cap 🐞 Bug ☼ Reliability

crash_line passes the complete sanitized one_line(payload) to append_crash, which checks only
the pre-write file size before appending the unbounded entry and does not serialize concurrent
writers. An oversized panic payload or simultaneous panics can push crash.log far beyond 64 KiB,
and /crash then reads the entire oversized file before selecting its tail.
Agent Prompt
## Issue description
The crash logger checks the existing file size but does not bound the incoming formatted entry or serialize concurrent panic hooks, so a single large payload or concurrent writes can exceed the advertised 64 KiB cap and leave `/crash` reading an oversized file.

## Fix Focus Areas
- src-tauri/src/lib.rs[2017-2052]
- src-tauri/src/lib.rs[2839-2861]

## Recommended Fix
Serialize the size-check and append operation, and bound each formatted crash entry while accounting for the version, timestamp, and newline. Reset or truncate the file based on the projected post-write size so both oversized and normal entries preserve `CRASH_LOG_CAP`, keep `/crash` operating on the bounded file, and extend the tests with an oversized entry and concurrent writers that assert the resulting file never exceeds the cap.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread scripts/release.test.mjs
// `[0-9.]+` stopped at the hyphen, so on a prerelease version it captured nothing at all and
// this test failed with an empty list however the README was written — it could not be
// satisfied by a beta. The suffix is part of the filename, so it is part of the capture.
const NAMED_IN_README = /Tachyon_(\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?)_/g;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

2. Valid beta versions fail release checks 🐞 Bug ≡ Correctness

NAMED_IN_README permits dots and alphanumeric characters after the first prerelease hyphen but
stops when another hyphen appears. A version accepted by both production release gates, such as
0.3.0-beta-rc.1, is therefore captured as 0.3.0-beta and fails the README version assertion
before release.
Agent Prompt
## Issue description
The README filename parser rejects prerelease suffixes containing more than one hyphen even though the release workflow and script accept them.

## Fix Focus Areas
- scripts/release.test.mjs[164-175]
- scripts/release.mjs[5-9]
- .github/workflows/release.yml[43-48]

## Recommended Fix
Allow hyphens throughout the prerelease capture while preserving the filename delimiter, and add a test using a version such as `0.3.0-beta-rc.1`. Keep the accepted version grammar aligned with the workflow and release script.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread src-tauri/src/lib.rs
Comment on lines +2412 to +2415
const GREPPED: &[(&str, &str)] = &[
("lib.rs", include_str!("lib.rs")),
("agent.rs", include_str!("agent.rs")),
("mcp_server.rs", include_str!("mcp_server.rs")),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

3. One command module escapes the guard 🐞 Bug ⚙ Maintainability

GREPPED omits local_models.rs even though that module defines a command registered in the
application handler list. Moving or adding a Task argument there would evade
task_is_never_an_ipc_argument, while the coarse command-count floor would still pass using
commands from the listed files.
Agent Prompt
## Issue description
The generalized command security scan omits a module that already contains a registered bridge command, leaving the guard incomplete despite its non-vacuity floor.

## Fix Focus Areas
- src-tauri/src/lib.rs[2412-2416]
- src-tauri/src/lib.rs[2362-2397]
- src-tauri/src/lib.rs[4296-4313]
- src-tauri/src/local_models.rs[225-228]

## Recommended Fix
Add `local_models.rs` to the scanned source list and make the guard verify coverage against the commands registered in `generate_handler!`, rather than relying only on a total-count floor that cannot detect an omitted module.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread ui/src/terminal.rs
Comment on lines +732 to +743
for (event, text) in [
("pty-exit", "[process exited]"),
("paint-dead", "[tachyon] repaint thread died — the screen is frozen; restart tachyon"),
] {
let term = term.clone();
listen("pty-exit", move |_| {
listen(event, move |_| {
let t = term.borrow();
let row = (t.cursor.line + 1).min(t.rows.saturating_sub(1));
let (x, y, _, _) = t.cell_px(0, row);
t.ctx.set_font(&format!("{}px {}", t.font_px, t.font_family));
t.ctx.set_fill_style_str(crate::theme::tokens(&settings_theme()).err);
let _ = t.ctx.fill_text("[process exited]", x, y);
let _ = t.ctx.fill_text(text, x, y);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

4. Thread-failure warnings can disappear 🐞 Bug ☼ Reliability

The new paint-dead listeners call fill_text directly on the canvas without storing the warning
in terminal state or reserving a row that redraw preserves. If the painter dies before the
mount-time full repaint arrives, a grid-damage event is delivered later, or the window is resized or
refitted, the canvas is redrawn only from buffered terminal cells and the sole indication that the
still-frozen backend is dead is removed.
Agent Prompt
## Issue description
Dead-thread warnings exist only as transient canvas pixels, so later full or damaged redraws—including mount-time repaint, grid damage, resize, and refit—can remove the warning while the backend remains dead.

## Fix Focus Areas
- ui/src/terminal.rs[265-283]
- ui/src/terminal.rs[426-429]
- ui/src/terminal.rs[630-641]
- ui/src/terminal.rs[729-745]
- ui/src/terminal.rs[769-776]

## Recommended Fix
Store the active backend-thread failure banner in terminal UI state and render it as an overlay after every full or damaged redraw. Have the event listener update that state before requesting a redraw instead of calling `fill_text` as a one-off operation, and keep the banner visible until the terminal is restarted or a new PTY lifecycle explicitly clears it.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@ayushap18
ayushap18 merged commit 8683174 into main Sep 22, 2026
3 checks passed
@ayushap18
ayushap18 deleted the m0-foundations branch September 22, 2026 12:44
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.

1 participant