Skip to content

fix(scoring): mask shadowed environment secrets via knownSecrets - #1380

Merged
SaulMoro merged 1 commit into
Tencent:mainfrom
aryansinha1908:issue#1362
Oct 25, 2026
Merged

SaulMoro merged 1 commit into
Tencent:mainfrom
aryansinha1908:issue#1362

Conversation

@aryansinha1908

@aryansinha1908 aryansinha1908 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Scoring built its mask set as { ...collectEnvSecrets(), ...await collectTeamSecrets(config) }, so when the environment and the team both had a value for the same secret name and the two differed, the team value replaced the environment's and the member's own value went out unmasked: into the judge evidence (buildEvidence), and into the First prompt: log, the judge prompt and the judged transcript (scoreSession, and the session read in session-work.ts). All three call sites now use knownSecrets(config), the set the workflow engine already masks with, which keeps the shadowed value as <KEY> (environment).

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

  • npx tsc --noEmit passes
  • npm run lint passes
  • npx vitest run passes. The affected files pass (workflow-scoring-evidence.test.ts, session-scoring.test.ts, session-work.test.ts: 101/101). The full suite has 11 failures locally, all in files that import none of the scoring modules, each caused by this machine:
    • env-loader.test.ts (5): Ubuntu's /etc/bash.bashrc prints its sudo hint into the bash output the tests read
    • cursor-*.test.ts (3): the sqlite3 CLI is not installed
    • submodule-checkout.test.ts (2): local Git is 2.43, and the tests expect config-based hooks (Git 2.54+)
    • git-discovery.test.ts (1): most likely the same Git version
  • Added/updated tests for the change

New tests, one per scoring path. In each, env/secrets.yaml declares DEPLOY_HOOK, the team store holds team-token-value-1362, and the environment holds personal-token-value-1362:

  • workflow-scoring-evidence.test.ts: masks both the environment value of a secret and the different value the team gives it. The team value is in a repo file and the personal value in the session; neither appears in any evidence file.
  • session-scoring.test.ts: …in the scorer's prompt, the evidence and the first prompt. The personal value is in the scorer's prompt and the session's first prompt; neither value appears in the judge prompt, the judged transcript, the reasoning file, or the printed output.

With the old spread restored, both tests fail on the personal value (expected [ 'prompt.md', 'transcripts/write#1.md' ] to deeply equal [], and expected 'Judge the session. Never print person…' not to contain 'personal-token-value-1362'). With the fix, both pass.

Real-CLI verification

At cd2ceaca, after npm run build, with the built CLI (node dist/index.js) against a local bare team repo (--provider git) in a temp HOME. The team repo declares DEPLOY_HOOK in env/secrets.yaml and has a scorer whose body reads Never print personal-hook-1362 or team-hook-1362.. A finished Claude session in the app directory has the first prompt Deploy with personal-hook-1362. The judge is a fake claude on PATH that keeps copies of the prompt and transcript it is given.

$ teamai init https://github.com/acme/team.git --provider git --agent claude --scope user --force && teamai pull
$ printf team-hook-1362 | teamai env set DEPLOY_HOOK --stdin
✔ Set DEPLOY_HOOK for this team (…/home/.teamai/secrets/teams/fac8a5de….json).
$ export DEPLOY_HOOK=personal-hook-1362
$ teamai score --scorer review-quality --session 7c1e0000-0000-4000-8000-000000000001 --source claude-code
  ℹ First prompt: Deploy with <REDACTED:DEPLOY_HOOK (environment)>
  ℹ review-quality: thorough (score 1, passed). Reasoning: …/home/.teamai/scores/reasoning/c9c10b5b….md
$ grep 'Never print' <prompt the judge got>
  Judge the review. Never print <REDACTED:DEPLOY_HOOK (environment)> or <REDACTED:DEPLOY_HOOK>.
$ grep 'Deploy with' <transcript the judge got>
  Deploy with <REDACTED:DEPLOY_HOOK (environment)>
$ grep -lF -e personal-hook-1362 -e team-hook-1362 <judge prompt> <judge transcript> <reasoning file> <CLI output>
  (no matches)

The same script on a build with the old spread restored prints First prompt: Deploy with personal-hook-1362 and Never print personal-hook-1362 or <REDACTED:DEPLOY_HOOK>, and the final grep matches all four files.

Workflow scoring (teamai score --next) is covered by the unit test above, not by this run: workflow start refuses a scorer that holds a secret's value (invalid_inputs), so a real run can't put the value in the scorer prompt. Other agents and the gitlab/github providers are left to CI.

Related Issues

Closes #1362

Notes for Reviewers

  • The tests use DEPLOY_HOOK, a name that doesn't look secret, on purpose. AgentSession.find already scrubs transcripts against the raw environment (scrubSession), so a value under a secret-looking name like GH_TOKEN is masked before scoring's own mask runs and could not show the bug. A declared secret with an ordinary name only goes through scoring's mask, and that mask leaked.
  • The now-unused collectTeamSecrets / collectEnvSecrets imports are removed from the three files. No docs or skill-data/ changes: scoring now masks what the docs already say it masks.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Broken regression-test assertion — src/__tests__/workflow-scoring-evidence.test.ts:270: .some(...) returns a boolean, so calling .toContain(...) on it fails type checking and throws at runtime when the filter visits a file. Read each file, check whether its contents contain either secret, and assert that the matching-file list is empty.

  • [P2 non-blocking] Fixture does not exercise shadowing — src/__tests__/workflow-scoring-evidence.test.ts:259: personal and team have identical values. The old spread also masks this case, so even after repairing the assertion, the test cannot detect the reported bug. Use distinct values and verify that neither appears in the evidence.

  • [P1 blocking] Missing real-CLI verification record — The PR description’s “Real-CLI verification” section contains only an HTML-comment instruction, not an executed verification record. This runtime-changing diff violates the Code Review Rules requirement for end-to-end / real-CLI verification. Document one representative run after npm run build, including the observed masked output.

Review limited to the specified diff and supplied PR description; no PR code was run, built, or installed.

@github-actions

Copy link
Copy Markdown

All three earlier findings remain unresolved in the specified diff:

  • [P1 blocking] Broken regression-test assertion — src/__tests__/workflow-scoring-evidence.test.ts:270: .some(...) returns a boolean, so .toContain(...) fails type checking and throws when evaluated. The outer expect(...) also has no matcher. Read each enumerated file, check for either secret, and assert that the matching-file list is empty.
  • [P2 non-blocking] Fixture does not exercise shadowing — src/__tests__/workflow-scoring-evidence.test.ts:259: personal and team still have identical values, so the fixture cannot detect the overwrite bug. Use distinct values and verify that neither appears in evidence.
  • [P1 blocking] Missing real-CLI verification record — The PR description’s “Real-CLI verification” section still contains only an HTML-comment instruction, not an executed record. This violates the first Code Review Rules item for runtime-changing PRs. Document one representative run after npm run build, including observed masked output.

Reviewed only the specified diff against the trusted base rules and supplied description. No PR code was run, built, or installed.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Missing real-CLI verification record — The PR description’s “Real-CLI verification” section still contains only an HTML-comment instruction, not an executed record. This violates the first Code Review Rules item for runtime-changing PRs. Document one representative run after npm run build, including the observed masked output.

Resolved earlier findings:

  • Broken regression-test assertion: the matching-file list now uses .includes(...) and is asserted with .toEqual([]).
  • Identical fixture values: personal and team secrets now differ.

The shallow checkout prevents triple-dot resolution; commit metadata identifies 13c891e0… as both commits’ parent, so I reviewed its diff to the specified head. No PR code was run, built, or installed.

@aryansinha1908

Copy link
Copy Markdown
Contributor Author

I hope that clears all the checks.
@SaulMoro Please review my PR and let me know if I need to change anything.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This was generated by AI during triage.

@aryansinha1908 Approving at cd2ceac. We reran your setup with the built CLI on a local bare team repo, with an isolated HOME. The setup: DEPLOY_HOOK declared in env/secrets.yaml, team-hook-1362 set through teamai env set, personal-hook-1362 exported in the environment, and a finished session whose first prompt contains the personal value. On the merge-base and on current main (744d982), score prints First prompt: Deploy with personal-hook-1362. This head prints First prompt: Deploy with <REDACTED:DEPLOY_HOOK (environment)>. tsc, lint, the three affected unit files (101 tests) and the score e2e files pass. Both new tests fail on the base for the right reason.

Non-blocking notes:

  • [P2 non-blocking] The session-work.ts call site has no test of its own. With only that file reverted, all 101 tests still pass. The issue names the other two sites, and each has its new test. A case for the session read in session-work.ts would keep the third site from regressing.
  • [P2 non-blocking] collectTeamSecrets (src/env-resolution.ts) no longer has any caller, and its doc comment still describes the old path. Please remove it here, or say why it stays.
  • [P3 nit] { 'recursive': true } in workflow-scoring-evidence.test.ts quotes the key, unlike the rest of the test files.

Not run through the real CLI: the workflow evidence path and the score --next queue path. The unit tests cover the first; the second stays covered only by reading the code.

The CI review's earlier findings were real, and they are fixed at this head. Its last comment, which calls the real-CLI record missing, was posted before the body was edited. The record is there now, and it reproduces. All CI jobs pass; the GitHub-provider e2e job is skipped by the fork policy.

@SaulMoro
SaulMoro merged commit fbd0798 into Tencent:main Oct 25, 2026
17 checks passed
@aryansinha1908
aryansinha1908 deleted the issue#1362 branch October 26, 2026 03:50
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
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.

Scoring drops the environment value of a secret when the team value differs

3 participants