Skip to content

[Bug]: cloneContextWith drops the isFile probe — one permission grant changes bash classification for the rest of the session #151

Closed

Description

@KevinBarrus

Description

cloneContextWith drops the isFile probe when cloning a ToolPermissionContext. After any permission rule update (i.e. any "always allow"/"always deny" decision or managed rule change during a session), the resulting context has isFile === undefined, which silently changes downstream bash permission behavior for the rest of the session.

Source evidence

Audited against the 0.4.12 source preview (release/extraction.json sourceRevision 9b9885e42a3cf1a3df1cfa52a46e4fdb034cfcee); line numbers refer to that revision.

  • isFile is part of the context and set at creation: packages/agent-modules/permission/src/context.ts:157.
  • cloneContextWith copies mode, rules, sandbox flags, paths, dirs, agent/session fields — but not isFile: packages/agent-modules/permission/src/context.ts:210-232.
  • Every applyPermissionUpdate (addRules/replaceRules/removeRules, context.ts:190-204) produces the clone, so the field is lost on the first rule mutation.
  • Consumer: packages/agent-modules/permission/src/tools/bash-permission.ts:579 — if (!bashCtx.isFile?.(resolved)) return false;. Once isFile is undefined, this local-script relaxation check permanently returns false, so a single permission grant mid-session changes how later bash commands are classified.

Expected behavior

Cloning a context preserves all probe callbacks; permission behavior should not change as a side effect of granting or revoking a rule.

Suggested fix

Add isFile: ctx.isFile to the object returned by cloneContextWith (packages/agent-modules/permission/src/context.ts:214-231). Consider a type-level guard so future context fields cannot be silently dropped again (e.g. satisfies over a Pick of the mutable fields plus an exhaustiveness check).

Environment

Found by source audit; not runtime-reproduced yet.

Activity

  1. KevinBarrus commented on Sep 18, 2026

    @KevinBarrus
    Author

    Closing for now to keep this batch of reports smaller — I kept the two highest-impact findings open (#150 permission enforcement, #152 context compaction trigger). Happy to reopen or refile if maintainers find this one useful; the analysis in the body stays valid against the cited revision.

  2. KevinBarrus commented on Sep 18, 2026

    @KevinBarrus
    Author

    Reopening — closing them added nothing since closed issues stay fully visible. Keeping all five open for triage.

  3. hetaoBackend commented on Sep 18, 2026

    @hetaoBackend
    Collaborator

    Thanks for the report. Fixed and merged in #167 (commit e3724a13d72d61c9bdc68a1a72b5c020f065ba26).

    cloneContextWith now preserves the host-owned isFile callback. Regression tests exercise addRules, replaceRules, and removeRules through the actual bash permission checker and verify that local-script classification remains unchanged after the update.

    Validation: all 106 new regression cases pass; the full local verification profile passed on macOS arm64, and Linux/macOS/Windows CI plus the source audit passed on the PR head. Built-CLI smoke/startup and offline BYOK runtime tests also passed. This is a source fix on main; it does not imply a new package release.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions