Skip to content

fix(planner): inject current user into scoped queries - #787

Merged
vladimirrott merged 3 commits into
lacs-project:mainfrom
dannyward630:fix/671-query-user-injection
Nov 17, 2026
Merged

vladimirrott merged 3 commits into
lacs-project:mainfrom
dannyward630:fix/671-query-user-injection

Conversation

@dannyward630

@dannyward630 dannyward630 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Inject the planner's current user into the five read-only query actions whose daemon specs require a username, keeping identity out of the model-facing tool schemas.
  • Skip dispatch and return a query error if the current user cannot be determined.
  • Add planner-to-executor regression coverage and update the measured workspace test baseline.

Related Issue

Fixes #671

Validation

  • Tests added or updated.

  • Security impact considered; the daemon remains the only privileged executor.

  • Trust boundary preserved; the planner supplies identity without exposing it in model-facing schemas.

  • All hosted checks pass on current head 1411c74: CI, CodeQL, container, secret-scan, cflite, and e2e.

  • Every commit is signed off.

  • UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh — 2,129 passed, 8 skipped in WSL Ubuntu. DAC override was dropped so the permission test exercised EACCES.

  • cargo fmt --all -- --check — passed.

  • cargo clippy --workspace --all-features --all-targets --locked -- -D warnings — passed in hosted CI.

  • git diff --check — passed.

No user-facing documentation changes were needed; the model-facing schemas remain unchanged.

Assisted by Codex (GPT-6).

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed at 60a48bd. The code is ready. One mechanical step, a merge with main, stands between it and landing, and that is the only reason this review asks for changes.

You put the daemon in the test as the judge. user_scoped_query_tools_inject_current_user_for_daemon_specs drives the real planner and then hands every captured param set to sysknife_daemon::executor::build_action_spec, so the test fails on what the daemon refuses rather than on a list it keeps itself. That is the cross-crate check #671 asked for. Resolving current_user() once per turn with get_or_insert_with and leaving username out of the tool schemas were both right too.

I ran three mutants in a container:

pristine                                         daemon test ok, host_secrets_are_redacted_... ok
M1 injection line -> `let _ = username;`         user_scoped_query_tools_inject_current_user_for_daemon_specs ... FAILED
M2 "query_toolboxes" dropped from the list       user_scoped_..._daemon_specs FAILED, host_secrets_are_redacted_... FAILED
M3 `continue;` removed from the unknown-user arm  host_secrets_are_redacted_... FAILED
restored, pristine again                         both ok

M3 matters most to me: it proves the planner test you adjusted is what stops a query going out with no user, so that adjustment carries weight.

Blocking (mechanical): I merged #744 a few minutes ago, and it touches the same lines of planner.rs, so this branch now conflicts. The conflict is two let lines side by side; keep both:

                    let mut proposed_plan = None;
                    let mut current_user: Option<Result<String, String>> = None;

I built that resolution myself to check it: the daemon test passes (1 test), cargo test -p sysknife-brain --test planner passes 83 of 83, and M1 still goes red on the merged tree. After merging main, please re-run UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh; main now records 2114, so the file should read 2115. Both conflicts come from my merge order, not from anything you did.

Optional: the test names the five user-scoped tools twice, once in the input table and once in the matches!. A loop over every tool query_tool_to_action maps, sending each through build_action_spec, would also catch a sixth user-scoped query that someone adds later without touching query_tool_needs_current_user. Fine to leave for later.

@dannyward630
dannyward630 force-pushed the fix/671-query-user-injection branch from d22c39a to 1411c74 Compare November 17, 2026 05:47
@dannyward630

Copy link
Copy Markdown
Contributor Author

Merged latest main (b3eb865), preserved both planner states through the conflict, and refreshed the baseline from the Linux run. The head is 1411c74, the 2,129-test suite passes, and all hosted checks are green. Please re-review/approve the resolved mechanical blocker when convenient.

vladimirrott
vladimirrott previously approved these changes Nov 17, 2026

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved at 1411c74. Thanks for the merge and for keeping both let lines.

I rebuilt main plus the head from my last review (60a48bd) with git merge-tree. Against that tree your merge differs in two places: tests/evidence/workspace-tests.json, which now reads 2129 (main's 2128 plus your one test), and the planner.rs conflict block, where you kept both sides:

                     let mut proposed_plan = None;
                     let mut current_user: Option<Result<String, String>> = None;

That is the resolution I asked for. The merge gate re-ran your daemon-backed test at this head in a container, with the injection line mutated:

maintainer-merge verify 787 1411c74c208abed8232e607d1250892e92c47500 user_scoped_query_tools_inject_current_user_for_daemon_specs 's/params\["username"\] = username.clone().into();/let _ = username;/'
  rust suite: evidence of 1 executed unit(s), passing unmutated
  receipt recorded for #787 at 1411c74c (observed: clean pass, mutated fail)

The fix is ready. One thing is out of your hands: #785, #788 and #791 also record the test baseline, so whichever of them lands before this one will put the evidence file in conflict again. When that happens I'll say so here, and it's one more UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh after merging main. That churn comes from how I order merges, not from your branch.

@vladimirrott

Copy link
Copy Markdown
Member

As I said in the review, it happened: I merged #785 a few minutes later, and main's evidence file now reads 2132. git merge-tree --write-tree --name-only origin/main 1411c74c reports CONFLICT (content): Merge conflict in tests/evidence/workspace-tests.json and nothing else.

After merging main, UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh should record 2133 (2132 plus your one test). My approval stands for the code; I'll re-check the merge the same way and land it.

Merge origin/main into the branch and set tests/evidence/workspace-tests.json to main's count plus the 1 test(s) this branch adds.

Signed-off-by: Vladimir Rotariu <[email protected]>

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-approving at ecb7572.

After #785 and #796 landed, the branch conflicted with main on tests/evidence/workspace-tests.json. I merged main into it and set the baseline to 2133: 2132 on main plus the one test this PR adds. The diff against main is the same five files as the head I approved, 1411c74, and nothing else.

The gate receipt is recorded at this head: maintainer-merge verify 787 ecb7572d... user_scoped_query_tools_inject_current_user_for_daemon_specs, with params["username"] = username.clone().into(); replaced by let _ = username;, printed receipt recorded for #787 at ecb7572d (observed: clean pass, mutated fail). All 15 checks are green on this head.

Thank you for the patient rebases. Merging now.

@vladimirrott
vladimirrott merged commit 3d6e23d into lacs-project:main Nov 17, 2026
15 checks passed
vladimirrott added a commit that referenced this pull request Nov 17, 2026
…790 (#805)

Eight merged pull requests had no Unreleased entry.

Signed-off-by: Vladimir Rotariu <[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.

Five planner query tools can never succeed: they send no username to actions that require one

2 participants