Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/mutation-affected.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jobs:
report:
name: Affected decision-kernel mutants
needs: [select, mutants]
if: always() && needs.select.result == 'success'
if: ${{ !cancelled() && needs.select.result == 'success' }}
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 15
steps:
Expand Down
5 changes: 3 additions & 2 deletions packages/daemon-contracts/src/daemon-registration-owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ export function createOwnedReplayStateDir(): OwnedReplayStateDir {
}

/**
* Tightens a state path an older launcher left at the umask default. The repair never decides
* whether the daemon starts: a path another user owns, or a mount without chmod, keeps its mode.
* Forces a pre-existing state path to the private mode, whatever mode it had. The repair never
* decides whether the daemon starts: a path another user owns, or a mount without chmod, keeps
* its mode.
Comment thread
thymikee marked this conversation as resolved.
Resolved
*/
function repairStateMode(target: string, mode: number): void {
try {
Expand Down
44 changes: 8 additions & 36 deletions packages/daemon/src/core/session-action-recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ function applySessionEchoProtection(
const literals = session.recordedFillLiterals;
if (!literals || literals.size === 0) return { entry, echoedNames: [] };

const result = parameterizeRecordedResultEcho(entry.result, literals);
const { payload: result, insertedPlaceholders } = parameterizeRecordedResultEcho(
entry.result,
literals,
);
const evidenceMode = entry.targetEvidenceMode ?? 'action';
const targetEvidence =
evidenceMode === 'landmark'
Expand All @@ -250,44 +253,13 @@ function applySessionEchoProtection(

return {
entry: { ...entry, result, targetEvidence, targetEvidences },
echoedNames: readSubstitutedNames(entry.result, result, literals),
// Annotations are never interpolated, so only the result's placeholders are live.
echoedNames: [...insertedPlaceholders].flatMap(
(placeholder) => readRecordedInputVariableName(placeholder) ?? [],
),
};
}

/**
* The variables whose placeholders echo protection wrote into the result: the placeholders that
* occur more often after it than before. Annotations are never interpolated, so only the result
* counts toward the live script placeholders.
*/
function readSubstitutedNames(
before: RecordActionEntry['result'],
after: RecordActionEntry['result'],
literals: ReadonlyMap<string, string>,
): string[] {
const beforeTexts = collectStrings(before);
const afterTexts = collectStrings(after);
const names: string[] = [];
for (const placeholder of new Set(literals.values())) {
if (countOccurrences(afterTexts, placeholder) <= countOccurrences(beforeTexts, placeholder)) {
continue;
}
const name = readRecordedInputVariableName(placeholder);
if (name) names.push(name);
}
return names;
}

function countOccurrences(texts: readonly string[], needle: string): number {
return texts.reduce((count, text) => count + text.split(needle).length - 1, 0);
}

function collectStrings(value: unknown): string[] {
if (typeof value === 'string') return [value];
if (Array.isArray(value)) return value.flatMap(collectStrings);
if (value && typeof value === 'object') return Object.values(value).flatMap(collectStrings);
return [];
}

/**
* #1398: a landmark-mode echo is treated exactly like #1349's existing
* identity-empty case — record NO annotation rather than a placeholder that
Expand Down
8 changes: 4 additions & 4 deletions packages/platform-linux/src/__tests__/tool-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ test('local Linux desktop provider reports nothing for a launched app that exits
// An injected executor owns process execution, so the type refuses one without its own launcher:
// the host-local detached runner must never stand in beside it. The directive fails typecheck if
// the refusal goes away.
test('a Linux provider that injects runCommand must also inject launchDetached', () => {
function compileTimeInjectedExecutorNeedsLauncherProof(): void {
const runCommand: LinuxToolCommandExecutor = async () => ({
exitCode: 0,
stdout: '',
Expand All @@ -302,9 +302,9 @@ test('a Linux provider that injects runCommand must also inject launchDetached',
// @ts-expect-error runCommand without launchDetached
const withoutLauncher: LinuxToolProviderOverrides = { runCommand };
const withLauncher: LinuxToolProviderOverrides = { runCommand, launchDetached: launchesNoApp };
assert.equal(withoutLauncher.launchDetached, undefined);
assert.equal(withLauncher.launchDetached, launchesNoApp);
});
void [withoutLauncher, withLauncher];
}
void compileTimeInjectedExecutorNeedsLauncherProof;

test('local Linux desktop provider falls back to pkill when wmctrl is unavailable', async () => {
const commands: Array<[string, string[], boolean | undefined]> = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/platform-web/src/agent-browser-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ test('agent-browser provider keeps typed text out of argv and error details when
for (const [attempt, command, hint] of [
[async () => await provider.fillRef?.('@e9', secret), 'fill', /snapshot -i/],
[() => provider.typeText(secret), 'keyboard type', /Focus the field again/],
[() => provider.fill(11, 22, secret), 'keyboard type', /Focus the field again/],
[() => provider.fill(11, 22, secret), 'keyboard type', /snapshot -i/],
] as const) {
await assert.rejects(attempt, (error: unknown) => {
assert.ok(error instanceof AppError);
Expand Down
17 changes: 11 additions & 6 deletions packages/platform-web/src/agent-browser-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ export function createAgentBrowserWebProvider(options: AgentBrowserProviderOptio
await sends.send(['press', 'Backspace']);
return;
}
await sendTextEntry(sends.send, ['keyboard', 'type', text]);
await sendTextEntry(sends.send, 'fill', ['keyboard', 'type', text]);
} catch (error) {
throw sends.discloseDispatch(error);
}
},
async fillRef(ref, text) {
await sendTextEntry(runJson, ['fill', browserRefSelector(ref), text]);
await sendTextEntry(runJson, 'fill', ['fill', browserRefSelector(ref), text]);
},
async typeText(text) {
await sendTextEntry(runJson, ['keyboard', 'type', text]);
await sendTextEntry(runJson, 'type', ['keyboard', 'type', text]);
},
async scroll(direction, scrollOptions) {
await runPacedScroll(runJson, direction, scrollOptions);
Expand Down Expand Up @@ -207,9 +207,14 @@ function createAgentBrowserSendLedger(runJson: AgentBrowserRunJson): {
* from stdin. The text is often a password, so it must stay out of the backend's argv, which every
* host user can read from the process table, and out of `details.args` on a failure. The backend
* exits non-zero for a failed entry and still prints the entry list, so the entry's own `success`
* verdict decides the outcome.
* verdict decides the outcome. `userCommand` names the agent-device command the user ran, which
* the failure hint tells them to retry: a coordinate `fill` sends `keyboard type` underneath.
*/
async function sendTextEntry(send: AgentBrowserRunJson, command: readonly string[]): Promise<void> {
async function sendTextEntry(
send: AgentBrowserRunJson,
userCommand: 'fill' | 'type',
command: readonly string[],
): Promise<void> {
const commandName = command[0] ?? 'batch';
const label = `agent-browser ${command.slice(0, commandName === 'keyboard' ? 2 : 1).join(' ')}`;
const data = await send(['batch'], {
Expand All @@ -236,7 +241,7 @@ async function sendTextEntry(send: AgentBrowserRunJson, command: readonly string
reason: 'text-entry-failed',
// The backend ran and refused this entry, so its install is not the suspect.
hint:
commandName === 'fill'
userCommand === 'fill'
? 'The page refused this text entry: the field may have changed or gone. Run snapshot -i again and retry fill with the ref it reports.'
: 'The page refused this text entry: the focused field may have changed or gone. Focus the field again (click it) and retry type.',
});
Expand Down
20 changes: 15 additions & 5 deletions packages/selectors/src/parameterized-recorded-fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,24 @@ export function parameterizeRecordedFillPayload<
* before anything is rewritten. Delegates to `parameterizeAgainstLiteralMap`
* for the actual substitution, so redacting one literal can never corrupt a
* placeholder another literal (or an earlier stage) already inserted.
* `insertedPlaceholders` holds each placeholder this pass wrote in place of a
* literal; a placeholder the payload already carried is not counted.
*/
export function parameterizeRecordedResultEcho<
TPayload extends Record<string, unknown> | undefined,
>(payload: TPayload, literals: ReadonlyMap<string, string>): TPayload {
if (!payload) return payload;
>(
payload: TPayload,
literals: ReadonlyMap<string, string>,
): { payload: TPayload; insertedPlaceholders: ReadonlySet<string> } {
const insertedPlaceholders = new Set<string>();
if (!payload) return { payload, insertedPlaceholders };
const pairs = sortedLiteralPairs(literals);
return parameterizeBackendOutput(
const redacted = parameterizeBackendOutput(
payload,
(value) => parameterizeAgainstLiteralMap(value, pairs),
(value) => parameterizeAgainstLiteralMap(value, pairs, insertedPlaceholders),
(candidate) => selectorCandidateCarriesAnyLiteral(candidate, literals),
) as TPayload;
return { payload: redacted, insertedPlaceholders };
}

/**
Expand Down Expand Up @@ -482,11 +489,13 @@ function sortedLiteralPairs(
* `pairs` must already be sorted longest-literal-first (`sortedLiteralPairs`)
* — this is the hot leaf-level primitive, invoked once per string field
* during a payload/evidence walk, so the sort happens once at the caller
* rather than being repeated on every leaf.
* rather than being repeated on every leaf. When given, `inserted` receives
* each placeholder the pass writes in place of a literal.
*/
function parameterizeAgainstLiteralMap(
value: string,
pairs: readonly (readonly [string, string])[],
inserted?: Set<string>,
): string {
if (!value || pairs.length === 0) return value;

Expand All @@ -496,6 +505,7 @@ function parameterizeAgainstLiteralMap(
for (const [literal, placeholder] of pairs) {
if (value.startsWith(literal, index)) {
result += placeholder;
inserted?.add(placeholder);
index += literal.length;
continue scan;
}
Expand Down
Loading