Skip to content

refactor(settings): Make director_settings uncallable before harness::attach - #1816

Merged
omesser merged 5 commits into
mainfrom
cursor/director-settings-type-safety-30c0
Oct 24, 2026
Merged

omesser merged 5 commits into
mainfrom
cursor/director-settings-type-safety-30c0

Conversation

@omesser

@omesser omesser commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

What

Make director_settings and config_from require an Attached witness that proves harness::attach was called. The wrong ordering no longer compiles - no runtime checks.

Why

director_settings and config_from both have ordering dependencies on harness::attach, but nothing enforced them. A Harness launch must not read a key it never sends. The witness flows by value from attach through SettingsState, SettingsSession, and SettingsOp::Retarget to both functions, making incorrect ordering a compile error.

How to test

cd src-tauri
cargo test --bin fidget -- settings::tests model::tests harness::tests
cargo check
cargo clippy --all-targets -- -D warnings

All tests pass and the code typechecks.

Closes #1659

— Cursor agent (P. Coder), on @omesser's behalf.

Open in Web Open in Cursor 

cursoragent and others added 3 commits October 24, 2026 10:42
Add Attached witness type that proves harness::attach was called.
Require director_settings to take this witness, making the wrong
ordering a compile error.

Closes #1659

Co-authored-by: Oded Messer <odedmesser@gmail.com>
Make retarget_payload use test_token() in test builds and attached_token()
in production builds. Mark attached_token as cfg(not(test)) to avoid
dead code warnings.

Tests that call retarget_payload directly don't call attach first, so
they need test_token.

Co-authored-by: Oded Messer <odedmesser@gmail.com>
Thread the Attached witness from attach through SettingsState and
SettingsSession to director_settings and retarget_payload. Remove
attached_token() runtime panic and the Option<Attached> field. The
witness now flows entirely at compile time.

- Make Attached Copy so it can be stored in SettingsState
- Pass attached from main to SettingsState to SettingsSession
- Thread it to retarget_off_the_settings_lock and retarget_payload
- Remove attached_token() - no runtime checks
- Add test_attached() constructor for tests
- Remove all cfg(test) branches from production code

Co-authored-by: Oded Messer <odedmesser@gmail.com>
omesser

This comment was marked as outdated.

@omesser

omesser commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Fix in progress for the Architect review at 01382d69: adding a one-line note at config_from that it reads the attachment and so runs after harness::attach, plus a doc line on the new attached field in SettingsState. Staying draft until re-cleared.

— Cursor agent (P. Coder), on @omesser's behalf.

Add doc line to config_from noting it reads the attachment and must run
after harness::attach. Add doc line to SettingsState.attached field
noting it proves harness::attach ran.

Addresses P. Architect review feedback.

Co-authored-by: Oded Messer <odedmesser@gmail.com>
omesser

This comment was marked as outdated.

@omesser
omesser marked this pull request as ready for review October 24, 2026 11:15

@omesser omesser left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Soft Open

Tip: 88a4be51

What changed

  • Attached witness: harness::attach now returns Attached, and director_settings takes it, so calling it before attach no longer compiles.
  • Threading: The witness moves through SettingsState, SettingsSession, retarget_off_the_settings_lock and retarget_payload.
  • Comments: The ordering sentences on director_settings and in main are gone.

What is wrong

  • config_from still has an unenforced ordering: It reads harness::attached to decide configured, and the PR adds the comment "must run after harness::attach" to it. That is the same kind of comment #1659 asked to replace with a type. model::resolve builds a DirectorSettings with no witness, and the store-error path in SettingsSession feeds that straight into config_from, so nothing stops an early call.

Soft-FIX

  • Gate config_from too: Make it take Attached like director_settings, with test_attached in the model and completer tests, and drop the new comment.

Non-blocking

  • Keep the reason: The doc on Attached says only that attach ran. One line saying a Harness launch must not read a key it never sends would keep the why that the deleted comments carried.
  • Title: Other PRs use a conventional prefix, for example refactor(settings):.

Verified on the tip: the harness and settings unit tests pass, 403 of 403, and a grep of every config_from caller.

— Cursor agent (Architect), on @omesser's behalf.

@omesser
omesser marked this pull request as draft October 24, 2026 11:21
@omesser

omesser commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Fix in progress for the Architect review at 88a4be51: making config_from take Attached like director_settings (with test_attached in the model and completer tests) and dropping the ordering comment, plus a one-line why on Attached and a refactor(settings): title. Back to draft until re-cleared.

— Cursor agent (P. Coder), on @omesser's behalf.

Thread Attached through config_from to enforce ordering at compile time.
Pass witness through SettingsOp::Retarget to frame loop. Update all
call sites to use test_attached() in tests.

- Add Attached parameter to config_from
- Add attached field to SettingsOp::Retarget
- Thread witness through main.rs error path
- Thread witness through all test calls
- Add Debug to Attached (required by SettingsOp)
- Document why Attached exists

Co-authored-by: Oded Messer <odedmesser@gmail.com>
@cursor

cursor Bot commented Oct 24, 2026

Copy link
Copy Markdown

Addressed review feedback at a5e920f:

  1. Added Attached witness to config_from: config_from now takes the witness parameter, making the ordering requirement compile-time enforced. Threaded it through all callers including main.rs, settings.rs (retarget_payload and error path), frame_loop.rs, and all tests. Added the witness to SettingsOp::Retarget so the frame loop receives it. Removed the "must run after" doc line since the type enforces it.

  2. Added why doc to Attached: Added one-line doc explaining a Harness launch must not read a key it never sends.

  3. Updated PR title: Changed to refactor(settings): Make director_settings uncallable before harness::attach with conventional prefix.

— Cursor agent (P. Coder), on @omesser's behalf.

@cursor cursor Bot changed the title Make director_settings uncallable before harness::attach refactor(settings): Make director_settings uncallable before harness::attach Oct 24, 2026

@omesser omesser left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Soft+Hard — tip a5e920fb — Cleared

Axis Verdict
Soft Pass
Hard Pass
Spec (#1659) Pass
CI build, cargo-audit, npm-audit, trufflehog pass; checks (ubuntu, macos), windows, renderer, detect-secrets still pending at gate time. Reported, not a merge condition.

Prior items

  • My 88a4be51 fix (the ordering note at config_from) is superseded in a better way: the note is gone and config_from now takes Attached itself.
  • The 88a4be51 review from Oded's other account asked to gate config_from too. Done: every caller (main, retarget_payload, the store-error path in SettingsSession, the frame loop) passes a real witness, and SettingsOp::Retarget carries it to the frame loop. The one-line reason on Attached is in.

Checked on this tip

  • A grep of config_from( and Attached(()) on the tip shows only attach and the #[cfg(test)] test_attached build the witness. The field is private, so no code outside harness can make one.
  • cargo test --bin fidget -- settings:: model:: harness:: completer:: gives 513 passed and 2 failed. The two failures (settings::form::tests::launch_row_is_frozen, no_other_frozen_checkboxes) fail the same way on main 16fa72b1 in this environment, so they don't come from this PR.
  • cargo clippy --all-targets -- -D warnings is clean.

Fix list empty.

Non-blocking: the title still has no conventional prefix (for example refactor(settings):). P. Coder's comment said it would add one.

— Cursor agent (subagent of P. Architect), on @omesser's behalf.

@omesser
omesser marked this pull request as ready for review October 24, 2026 11:32
@omesser
omesser merged commit f4cb071 into main Oct 24, 2026
10 checks passed
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.

Make director_settings uncallable before harness::attach

2 participants