Repository navigation
feat(fs): path-escape posture relax — Wave 1 (allow path + child/glob guards) - #322
Merged
Merged
Conversation
JAORMX
force-pushed
the
acc/path-escape-posture
branch
from
July 29, 2026 12:42
bdb26c7 to
267f866
Compare
Co-Authored-By: mecatl <[email protected]>
…in-progress Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
…rio 1) Land the composition-layer escapeClassifier (internal/app) answering "is this FS-tool call an out-of-root escape?" as a pure classification over the call name + args, reusing BOTH osfs algorithms so it can never disagree with the tool body: resolveInRoot's canonicalize-then-reject for the in-root/escape verdict and allowedReadRoot's lexical match for the read-root third state. Pseudo-filesystem paths (/proc, /sys, /dev) classify as a distinct never-relaxed category (AC1.5): an in-process FS read of /proc/self/environ would return the server's raw, unscrubbed environment, a channel the envscrub-scrubbed Bash parity path does not provide. No behaviour change in this wave: a later wave's root-aware wrapping port.PermissionPolicy consumes the classifier; here it only needs to exist and be proven correct against the tool body. The classifier is COMPOSITION, not domain — engine/tool keeps FileSystem/Workspace (the port<->tool cycle gotcha) and the osfs containment is untouched (ADR-0047). New osfs exports (adapter-side, no *os.Root opened, no I/O beyond resolveInRoot's own stat syscalls): Canonicalize (the resolveInRoot/ resolveRoot ancestor-resolution algorithm), LocalizeInRoot (the lexical relative-path gate), and MatchReadRoot (allowedReadRoot's lexical match). ACs pinned (docs/acceptance/path-escape-posture.md Scenario 1): - AC1.1 TestPathEscapePosture_Scenario1_ClassifierMatchesResolveInRoot - AC1.2 TestPathEscapePosture_Scenario1_ReadRootClassification - AC1.3 TestPathEscapePosture_Scenario1_SymlinkEscapeIsEscape - AC1.4 inspection (shared stat-based ancestor resolution, no root opened) - AC1.5 TestPathEscapePosture_Scenario1_PseudoFsClassification Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
…nario 2)
Wire the relaxed-READ path: at posture yolo and auto an out-of-root
absolute-path Read/Stat succeeds through the FS tool instead of failing with
ErrPathEscape. This is the honesty fix — at those postures Bash already reads
the same bytes, so the FS read boundary was cosmetic and only pushed the model
to a worse-audited `cat`. The relax flows through the ordinary
authorize → preHook + execute tail, so audit (ToolCallRecorder), EvToolResult,
and PostToolUse hooks fire identically to an in-root read.
The decision lives in a root-aware wrapping port.PermissionPolicy
(internal/app/escapepolicy.go, a permpolicy sibling) that DELEGATES TO THE
INNER POLICY FIRST and only relaxes a non-deny — it never overrides an inner
Deny (deny-dominance). It classifies per session root (via the task-01
escapeClassifier, keyed off the ws the loop hands Evaluate) and:
- pseudo-fs (/proc, /sys, /dev) → hard Deny at EVERY posture (an in-process
Read of /proc/self/environ would return the SERVER's raw, unscrubbed
environment — a channel the envscrub-scrubbed Bash parity path does not
provide);
- an out-of-root READ escape at auto/yolo → Allow (Bash parity);
- everything else → the inner decision verbatim (strict/trusted unchanged
this wave; the strict/trusted Ask is Scenario 4).
osfs gains the WithRelaxedReads construction option (DEFAULT OFF — the
zero-value workspace stays deny). Read/Stat serve an out-of-root absolute path
only under it, opening a FRESH *os.Root on the target's LEXICAL parent and
serving the leaf through it (never a bare os.Open). Containment survives the
relax two ways: the serving root refuses a symlink inside the target dir that
escapes further, and a vet (the resolveInRoot ancestor walk, comparison inside
the loop) refuses a path whose canonical resolution jumps above the verbatim
prefix — EvalSymlinks alone would launder the escape. Write/Edit/Glob/Grep
stay workspace-confined.
The relaxed option is wired into the MAIN session's workspace construction
ONLY (osfsWorkspaceFactory, posture-derived), never into newForkWorkspace or
any child engine. The SAME factory is the create-time AND the rehydration
workspace source (the run-entry seam rebuilds from the persisted root through
Workspaces), so a restarted relaxed session rehydrates the SAME relaxed
workspace via Service.rehydrateSession — the AC2.7 restart path needs no new
label (the relax derives from posture + persisted workspace root, both stable
across restart).
Plan mode still permits the read (reads are not mutations).
ACs pinned (docs/acceptance/path-escape-posture.md Scenario 2):
- AC2.1 yolo read escape allowed
- AC2.2 auto read escape allowed (Bash parity)
- AC2.3 audit parity (ToolCallRecorder verbatim + EvToolResult)
- AC2.4 strict unchanged (still ErrPathEscape)
- AC2.5 /proc/self/environ pseudo-fs hard-deny at yolo
- AC2.6 nested symlink escape refused by the serving *os.Root
- AC2.7 restart rehydrates the relaxed workspace
Each named pinning test was driven red-first (the relax/vet/containment
removed) before landing green.
Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
… Scenario 3) Wire the relaxed-WRITE path: under yolo an out-of-root Write/Edit succeeds; under auto (no guardrail knob) a write escape resolves Ask — never a silent un-asked mutation below yolo. - escapePolicy: a write escape resolves Allow at yolo, Ask at auto, delegated to the inner policy FIRST (deny-dominance + the configured-Ask floor hold: a configured Deny wins, a configured Ask is never suppressed). Escape asks are allow-once only — Learn never records an out-of-root rule. - osfs WithRelaxedWrites (default off): Write/Edit serve a canonicalized out-of-root absolute path through a FRESH *os.Root on the target's vetted parent — never a bare os.WriteFile — so a symlinked component that escapes further is refused (ADR-0047 containment survives). Read-only roots stay read-only; the leaf-only rule never mkdirs out-of-root ancestors. - The Edit read-ledger keys out-of-root paths by their canonical absolute form (a `..`-carrying alias matches the canonical path), without regressing in-root cross-form matching. - The escape Ask rides the ordinary surfaceAsk spine (mint askID → PauseForApproval → EvPermissionAsk) — no new ask channel. - The option is wired into the MAIN session's workspace factory only; child engines never see it. Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
…h-escape-posture Scenario 5) Guard tests for the path-escape-posture Scenario 5 acceptance criteria (docs/acceptance/path-escape-posture.md). The out-of-root relax is scoped to the MAIN session's workspace construction only — a SCOPE boundary, not a trust boundary, holding at every posture. - AC5.1 TestPathEscapePosture_Scenario5_ChildReadEscapeDenied: a read-only Subagent child's out-of-root Read is denied at yolo/auto even while the relaxed main session's identical read succeeds (proved non-vacuous by asserting the parent read succeeds first). - AC5.2 TestPathEscapePosture_Scenario5_GlobGrepConfined: Glob/Grep never serve out-of-root matches at any posture incl. yolo (patterns are not paths, ADR-0047 point 5); positive control proves it is not vacuously green. - AC5.3 TestPathEscapePosture_Scenario5_ChildEnginesNeverRelaxed: structural proof that forking the relaxed main workspace through the shared newForkWorkspace constructor (Subagent worktree / team-member force-copy / Parallel branch) yields a child workspace that denies the out-of-root read. - AC5.4 TestPathEscapePosture_DefaultConstructionDeniesEscape: the zero-value osfs workspace (no relaxed option) denies the out-of-root read/stat at every posture — the default stays deny. Each negative guard was verified RED by planting the violation (relaxed options into newForkWorkspace; a naive unconfined filepath.Glob), then green after revert. Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
…ress Co-Authored-By: mecatl <[email protected]>
…space (path-escape-posture Scenario 5 AC5.1b) Task 04 surfaced a real leak: when Bash is disabled (nil runner) the Subagent tool wires NO forker, so the read-only child runs directly against the PARENT's base workspace — and at auto/yolo that base is the escapeWorkspace-wrapped relaxed osfs (WithRelaxedReads/WithRelaxedWrites), handing the shell-less child the main session's out-of-root reach and defeating the child-never-relaxes boundary AC5.1 pins for the forker path. The mode:"read-write" direct-write child (ADR 0041) shares the base the same way. Fix: a new agent.WithSharedChildWorkspace option, consulted only on the nil-forker (base-sharing) branch of forkChildWorkspace, re-views the shared base through the NON-relaxed construction — the SAME root and per-skill read-only roots via newForkWorkspace, NO relaxed options. buildSubagentTool wires it at auto/yolo (inert below); the forked child (worktree/force-copy) never consults it and the main session's own relaxed workspace is untouched. Pinned by TestPathEscapePosture_Scenario5_SharedWorkspaceChildNotRelaxed (read half, at yolo+auto over both shell-less triggers: --no-bash and the untrusted gate) and TestPathEscapePosture_Scenario5_SharedWorkspaceChildWriteDenied (the writable direct-write half at yolo). AC5.1c holds: the forker-path TestPathEscapePosture_Scenario5_ChildReadEscapeDenied stays green unchanged. Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
…axed base (path-escape-posture Scenario 5 AC5.1d/5.1e) Task 05 closed the Subagent nil-forker leak but left the sibling: a base-sharing (shell-less) read-only TEAM MEMBER. The supervisor's base-share fallback (selectMemberWorkspace's default branch) handed the member s.base VERBATIM — and at auto/yolo that base is the escapeWorkspace-wrapped relaxed osfs (WithRelaxedReads/WithRelaxedWrites), giving the shell-less member the main session's out-of-root reach: the same child-never-relaxes leak, through the supervisor rather than the Subagent nil-forker path. Fix mirrors task 05: a new agent.WithTeamSharedBaseWorkspace supervisor option (plus agent.WithTeamToolSharedBaseWorkspace the in-loop Team tool threads through), consulted ONLY on the base-share fallback, re-views the shared base through the NON-relaxed construction — the SAME root and per-skill read-only roots via newForkWorkspace, NO relaxed options. buildTeamWiring produces the re-view at auto/yolo (inert below); both consumers wire it (registerTeamTools -> WithTeamToolSharedBaseWorkspace; applyTeamConfig -> server.Config.SharedBaseWorkspace -> CreateTeam). The two FORKED tiers (worktree IsolateReadOnly, Mutating force-copy) never consult it and the main session's own relaxed workspace is untouched. Pinned by TestPathEscapePosture_Scenario5_BaseSharingMemberNotRelaxed (full Build; gRPC CreateTeam over the relaxed Workspaces factory with a shell-less roster; verified red by disabling the supervisor consult) and TestPathEscapePosture_Scenario5_IsolatedMembersUnchanged (both isolated tiers still deny the escape; the main session still relaxes). Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
…ow-ups Panel review (0 ship-blockers): correct the stale osfs.ClassifyPath doc references to the actual helpers (Canonicalize/LocalizeInRoot/MatchReadRoot/ ResolveRoot), and record the deferred wave-2 follow-ups (Edit-ledger fingerprint pseudo-fs asymmetry, vetRelaxedParent->Canonicalize, the escapePolicy classifier cache, and the IMPLEMENTATION-NOTES/user-docs deliverables). Co-Authored-By: mecatl <[email protected]>
JAORMX
force-pushed
the
acc/path-escape-posture
branch
from
July 30, 2026 10:21
267f866 to
0064853
Compare
JAORMX
added a commit
that referenced
this pull request
Jul 30, 2026
The path-escape-posture Scenario 5 tests (landed on main in #322) read the child's ok/error outcome from subagent.tool events keyed on ToolName alone. ADR 0079's widened projection also emits tool.call previews (IsError=false) and message/result text previews for the same tool, so the outcome must be read from the tool.RESULT projection (InnerKind == EvToolResult). Co-Authored-By: mecatl <[email protected]>
JAORMX
added a commit
that referenced
this pull request
Jul 30, 2026
…llel (ADR 0079) (#327) * docs(acceptance): delegation observability convergence plan + ADR 0079 Acceptance plan for issue #323: converge the delegation observability surface on two tiers — bounded previews for Subagent/Parallel, Team-unique structures stay Team-only. Co-Authored-By: mecatl <[email protected]> * docs(acceptance): flip delegation-observability-convergence to in-progress Co-Authored-By: mecatl <[email protected]> * feat(session): widen delegation payloads with bounded preview fields Add Text/Detail/InnerKind to SubagentPayload and ParallelPayload, mirroring TeamPayload's bounded-preview shape per ADR 0079: Text is a clamped preview of child message text, Detail a clamped preview of a child tool call's args or tool result body, InnerKind discriminates the projected inner event kind. Redaction doc-comments rewritten from metadata-only to the bounded-preview contract (clampPreview scrub + rune cap, permission.ask never forwarded, client-only — gauntlet #7 unchanged); TRIP-WIRE comment updated to note the now-shared preview fields. Fields are declared but not yet populated (task 02 wires the chokepoint). task api:check drift is expected; the api snapshots and CHANGELOG note are reconciled on the accumulator. Pins AC1.1 via TestDelegationObservability_Scenario1_PayloadsCarryPreviewFields. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(agent): project bounded previews through the delegation chokepoint ADR 0079: drainChildObserved now projects clampPreview-bounded previews (tool.call args / tool.result body -> Detail, message.delta / result text -> Text, tagged by InnerKind) for all three delegation families; the Parallel branchTool re-tag copies them. The permission.ask drop and gauntlet-#7 conversation isolation are unchanged. Sentinel tests re-shaped from 'no content fields' to 'content fields provably bounded + scrubbed': canary suites assert no VERBATIM carriage, Subagent gains the structural sentinel Parallel had. Co-Authored-By: mecatl <[email protected]> * feat(server): carry delegation bounded previews over the wire Add text/detail/inner_kind to the proto Subagent (14-16) and Parallel (22-24) messages and copy them verbatim in toProtoSubagent/toProtoParallel, mirroring toProtoTeam's Text/Detail/InnerKind shape (inner_kind a STRING passthrough). The HTTP/SSE relay reuses toProto, so both wire surfaces carry the ADR 0079 bounded previews already clamped upstream in engine/agent. Mapper table tests assert the new fields round-trip for both preview shapes (tool Detail / message Text). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * feat(mecatui): render delegation bounded previews (converge on the Team trace) Thread the ADR-0079 bounded previews through the mecatui client + conversation model, and converge the Subagent/Parallel renderers on the Team trace format. - client: add Text/Detail/InnerKind to SubagentMsg/ParallelMsg and populate them in the subagentMsg/parallelMsg translators. - conversation: replace the name+isError subToolChip with the shared teamTrace shape (kind/text/name/detail/isError) across the subagent inline card, the fleet lane, and the parallel branch lane; one routeTraceEvent projection routes the inner kinds (tool.call/tool.result/message.delta) into chips with bounded previews + coalesced capped message lines for all three families. - renderers: the collapsed Subagent card now names the live current tool (`subagent · <tool> · ↑in ↓out · N tools · ctrl+t trace`, no ticker — AC3.1); the expanded card, the Subagent focus, and the Parallel group focus render the Team-format interleaved trace (glyph chips with bounded previews + capped message lines), double-truncated by the TUI caps (maxTraceDetailLen=80, maxTraceMessageLen=200) on top of the engine clamp (AC3.2/AC3.3). The parallel group focus renders each branch's trace below its roster line, height-bounded. - honesty notes: every "args/results hidden" string becomes the accurate "bounded previews" framing (AC3.4); a source-level sweep fails on any re-introduction. - Team-unique structures (task board, findings ledger, dispositions, mutating cue, context meter) stay Team-only (AC3.5). The prior collapsed-card assertion (the tool name must NOT appear) is deliberately inverted per ADR 0079. Goldens refreshed via task test:golden. Pins: - TestDelegationObservability_Scenario3_CollapsedCardShowsCurrentTool (AC3.1) - TestDelegationObservability_Scenario3_ExpandedCardShowsBoundedPreviews (AC3.2) - TestDelegationObservability_Scenario3_ParallelViewsShowBoundedPreviews (AC3.3) - TestDelegationObservability_Scenario3_HonestyNoteIsBoundedPreviews (AC3.4) - TestDelegationObservability_Scenario3_TeamUniqueStructuresStayTeamOnly (AC3.5) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs: tell the ADR-0079 two-tier delegation observability story The living docs described Subagent and Parallel observability as metadata-only, with Team the only family forwarding bounded previews. ADR 0079 converged all three families on tier-1 bounded previews (clamped + control-byte-scrubbed, client-only) through the shared drainChildObserved chokepoint; the task board, findings ledger, dispositions, mutating cue, and context meter stay Team-unique. - docs/architecture/domain-model.md: delegation-families note rewritten to the two-tier model; event table rows updated. - docs/design/IMPLEMENTATION-NOTES.md: parallel.* section + the log redaction-boundary + team structural-guard notes updated; TRIP-WIRE kept intact. - docs/architecture/subagents-and-teams.md, parallelism.md, docs/tui.md, docs/usage/grpc-api.md: same stale phrasing replaced. - AGENTS.md: the three-families gotcha states the bounded-preview contract; the rest of the gotcha is unchanged. - user-docs: short bounded-previews note on the delegation page plus a mecatui card note (operator-visible TUI behavior). llms.txt regeneration and task docs are left to the orchestrator's aggregate gate. Co-Authored-By: mecatl <[email protected]> * chore(engine): api snapshot + CHANGELOG for the ADR-0079 payload widening Co-Authored-By: mecatl <[email protected]> * docs: regenerate llms.txt for the ADR-0079 docs update Co-Authored-By: mecatl <[email protected]> * docs(acceptance): flip delegation-observability-convergence to landed Co-Authored-By: mecatl <[email protected]> * perf(agent): single-pass clampPreview + skip dropped-event payload alloc The ADR-0079 projection widening cost +62 allocs/op on background_subagents (perf gate 1.02x). Recover 40% of it: clampPreview is now a single-pass strings.Builder walk (zero-alloc on a clean short string; the rune cap is enforced as it fills, so an overlong input allocates only the cap-sized prefix, never the full scrubbed copy), and drainChildObserved skips the payload alloc for events it will drop (turn.start, hooks, compaction, asks). The residual +33/op is the intrinsic cost of the feature (4 projected events x payload+send per child, the same per-event cost Team already pays) — recorded as accepted in ADR 0079. Co-Authored-By: mecatl <[email protected]> * test(app): attribute child tool outcome on the tool.result projection The path-escape-posture Scenario 5 tests (landed on main in #322) read the child's ok/error outcome from subagent.tool events keyed on ToolName alone. ADR 0079's widened projection also emits tool.call previews (IsError=false) and message/result text previews for the same tool, so the outcome must be read from the tool.RESULT projection (InnerKind == EvToolResult). Co-Authored-By: mecatl <[email protected]> * docs(acceptance): restore the path-escape README entry the rebase dropped The rebase's --theirs resolution on docs/acceptance/README.md took our side and dropped main's path-escape-posture index entry (making that plan unreachable — the matlatl gate). Restore both entries and our plan's landed status; regenerate llms.txt per the don't-hand-merge rule. Co-Authored-By: mecatl <[email protected]> * perf(agent): zero-alloc fast path in clampPreview (perf-gate fix) The delegation-observability widening tripped the perf gate (background_subagents 1482 vs 1449 baseline, ratio 1.0228 > 1.02). A kimi-k3 architect+perf team found the real cause: clampPreview (made single-pass in da52a81) is too complex to inline (gc cost 271 > budget 80), so its strings.Builder escaped to heap on EVERY call — even on the clean path that returns the input verbatim (~15/op of recoverable waste, carried by BOTH delegation families). Fix: an inlinable isCleanASCII byte loop short-circuits the common ASCII-short path to a zero-alloc verbatim return; the rune-aware slow path is unchanged. Result: 1507/op, ratio 1.012 — under the gate. The residual +20/op is the irreducible feature cost (4 projected events x payload+send per child, the same per-event cost Team pays); ADR 0079's perf section updated to match. Co-Authored-By: mecatl <[email protected]> --------- Co-authored-by: mecatl <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Wave 1 of the path-escape posture relax (acceptance plan): the osfs out-of-root FS rejection stops being a silent
ErrPathEscapedead-end and becomes a posture-appropriate decision.yoloautostrict/trusted/proc,/sys,/dev)Rationale: at
auto/yolo, Bash already reads/writes outside the workspace unconditionally, so the FS-tool boundary there was cosmetic — it only pushed the model into a worse-auditedcat/sedworkaround and lost the FS tools' invariants (read-before-edit, exact match) and clean audit shape. This makes the relax honest and keeps the real boundaries.How
port.PermissionPolicy(internal/app/escapepolicy.go) resolves the escape by posture, delegating to the inner policy first (deny-dominance + configured-Ask floor preserved). osfs serves a canonicalized out-of-root path through a fresh*os.Rooton the target's parent — never a directoscall — so symlink containment (ADR-0047) survives.internal/app/escapeclassifier.go) reuses osfs's ownCanonicalize/LocalizeInRoot/MatchReadRootso the decision and the tool body can never disagree about what is an escape.Read /proc/self/environwould leak the server's raw unscrubbed env — a channel Bash parity does not provide.newForkWorkspace; base-sharing children (Subagent nil-forker, writable direct-write, team base-share member) are re-viewed through newWithSharedChildWorkspace/WithTeamSharedBaseWorkspaceoptions wired to the non-relaxed constructor. Glob/Grep stay confined at every posture.Acceptance criteria (Wave 1: Scenarios 1–3 + 5)
26 ACs, all with named
verify:tests — classifier↔tool-body agreement, yolo/auto read+write, audit parity, pseudo-fs deny, nested-symlink containment, restart rehydration, Edit-ledger canonical keys, mutate-serial, deny-dominance, child/base-sharing/glob confinement. Scenario 4 (thestrict/trustedask path) + guardrail routing are Wave 2, tracked in the plan's deferred decisions.Verification
task lint,task test(both modules,-race, engine-standalone),task docs(matlatl strict),task api:check— all green on the assembled branch.task ac-trace-strict— planin-progress(report-only); all 25 Wave-1 test-verified ACs resolve; the 4 outstanding are Wave-2 Scenario 4.WithSharedChildWorkspace,WithTeamSharedBaseWorkspace,WithTeamToolSharedBaseWorkspace) classified Added/minor inengine/CHANGELOG.md;task api:updatecommitted.go run ./cmd/mecademofull offline session green.Panel review — 0 ship-blockers
Three-axis panel (Spec / Standards / Domain: secure-code, software-architect, library-reuse, code-duplication). No Critical/High. Mechanical fix applied (phantom
osfs.ClassifyPathdoc refs). Deferred follow-ups logged in the plan: Edit-ledgerfingerprintpseudo-fs asymmetry (latent, not live),vetRelaxedParent→Canonicalizecollapse, theescapePolicyclassifier-cache resource decision, and the IMPLEMENTATION-NOTES/user-docs deliverables — all Wave 2.Notes for the reviewer