Skip to content

fix(test): record the DACL lockdown spy only on the test's own thread - #39055

Open
aniruddhaadak80 wants to merge 1 commit into
kirodotdev:mainfrom
aniruddhaadak80:fix/dacl-spy-same-thread
Open

aniruddhaadak80 wants to merge 1 commit into
kirodotdev:mainfrom
aniruddhaadak80:fix/dacl-spy-same-thread

Conversation

@aniruddhaadak80

@aniruddhaadak80 aniruddhaadak80 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Scope test_secret_file_owner_dacl.py's restrict_to_owner spy to the test's own thread, so the SEL writer thread can no longer fail an exact-list assertion in a test that has nothing to do with it.

The file's seen fixture swaps the process-global platform_compat.restrict_to_owner for a spy that records every call from every thread. Three of its tests then assert the exact list, its length, or that it is empty (test_telemetry_salt_is_restricted, test_log_append_is_restricted_on_windows, test_log_append_leaves_posix_to_the_creation_mode). The SEL writer is a daemon thread (sel-writer) that re-locks its non-empty audit log through that same symbol on every append (src/kiro_crew/sel_append.py:255). When it flushes events an earlier test on the same worker queued, its call lands in seen and the test fails on a change that has nothing to do with it. #33300 was this failure on macOS CI. The file landed (via #31288) after #33379's sites were swept, so its seen fixture never got the thread scope the other spies got.

Why it matters

Any backend PR can hit one of these reds, pay a rerun, and sit blocked on PR Readiness for a defect that is not in its diff — the same cost #35491 is removing for the nineteen remaining spies in fourteen other files. This file is the one site that issue's sweep did not cover, and it asserts on the exact list three times.

Not a goal

  • No product code change: every writer these tests drive locks its file down on the calling thread (swept below), so a thread scope drops none of their calls.
  • No change to the SEL writer thread or to sel_append.py: the issue asks for the tmp_path filter only for a writer that locks down on a worker thread; none of these writers does.
  • No change to the membership-only spies or the two _deny spies the issue marks unaffected.
  • No assertion loosened: the three tests keep asserting the exact list, its length and emptiness.

What changed (motivation -> approach -> change)

  • Symptom: an intermittent red in test_secret_file_owner_dacl.py's exact-list assertions on CI, caused by a lockdown from a thread the test never touched.
  • Root cause: the seen fixture recorded calls from every thread, while the process-global symbol it replaced is also the one the sel-writer daemon calls on each audit-log append (src/kiro_crew/sel_append.py:255).
  • Change: the fixture captures threading.get_ident() when it installs and its recorder appends only when the calling thread is that thread. The docstring records why the scope exists (Flaky risk: test_secret_file_owner_dacl's restrict_to_owner spy also records the SEL writer thread's calls #37631, the Flaky risk: restrict_to_owner spies in tests also record the SEL writer thread's calls #33379 exposure) and the writer sweep behind it: open_log_for_append_owner_only / restrict_file_to_owner_soft, _get_telemetry_salt, write_queue_atomic, _save_locked and _save_colours all run on the calling thread, so every lockdown these tests expect is made on the test's own thread. A writer that ever moves to a worker thread then fails here loudly (the expected call is missing) instead of silently passing on a stale count.
  • Verification: the issue's own proof — a throwaway pytest plugin firing restrict_to_owner from a thread named sel-writer right after the spy installs and after each tempfile.mkstemp — turns the three remaining named tests red with the fixture reverted and leaves all twelve green with it in place. (The issue's fourth site, test_redaction_allow_list_is_restricted, no longer exists on main; the file changed since the issue was filed.)

Backwards compatibility

Compatible: test-only change — no product code, no public surface, nothing main accepts today stops working.

Tests

  • test/test_secret_file_owner_dacl.py — 12/12 pass with the change in place; black --check, isort --check-only and flake8 are clean on the file.
  • Red/green proof, run locally with the issue's throwaway plugin: with the fixture change reverted, test_telemetry_salt_is_restricted, test_log_append_is_restricted_on_windows and test_log_append_leaves_posix_to_the_creation_mode fail on the foreign thread's call in seen; with the change in place, all twelve pass under the same plugin.
  • Proof: not provable -- test-only change

Manual verification

N/A — unit coverage sufficient: the change is confined to one test fixture, the proof drives it through the same spy the CI flake hits, and no product or frontend surface changes.

Related Issues

Fixes #37631

Sibling sweep

Swept: rg -n "restrict_to_owner" test --glob "*.py" — every test that monkeypatches the symbol the SEL writer calls, each checked for an exact-list, length or emptiness assertion.

Pattern harvest

Rule candidate: review-prompt
Pattern: a test fixture replaces a process-global function with a recording spy and asserts the exact list, its length or emptiness, while a background daemon thread calls the same symbol — scope the spy to the test's own thread at install time.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

kirodotdev#37631: the `seen` fixture swaps the process-global
platform_compat.restrict_to_owner for a spy that records every thread's
calls, and three of its tests assert the exact list, its length or that it
is empty. The SEL writer daemon re-locks its audit log through that same
symbol on every append (src/kiro_crew/sel_append.py:255), so a flush of
events an earlier test queued lands in `seen` and fails a test whose code
is fine.

Scope the spy to the fixture's own thread: record a call only when it is
made on the thread that installed the fixture. Every writer these tests
drive locks down on the calling thread, so none of their calls is
dropped; a writer that ever moves to a worker thread fails here loudly
(the expected call is missing) instead of passing on a stale count.
@aniruddhaadak80
aniruddhaadak80 requested review from iamwhatever and a balanced review from Copilot November 18, 2026 09:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Nov 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky risk: test_secret_file_owner_dacl's restrict_to_owner spy also records the SEL writer thread's calls

2 participants