Repository navigation
fix(ptc): teach the session scope every PTC program shares - #869
WeiLinCool wants to merge 1 commit into
Conversation
658b72f to
828d42b
Compare
|
Coordination note from #982 (P2, staging lineage |
828d42b to
171b87d
Compare
|
Thanks — the trim landed on On your two notes:
Nothing in the section needs to survive a merge verbatim: it does not depend on any text the trim removed. The rebased basis, the updated diff (8 files, +178/−7) and the current probe numbers are in the update section at the bottom of the description. |
A state-retaining PTC runtime keeps a program's top-level `const`, `let`, `class` and `function` while the runtime lives, so a second declaration of that name is a SyntaxError at compile time and the whole program is discarded before its first line runs, tool calls included. A failed program may already have run calls and keeps its names, so a retry has to check the effects and rename before it can succeed. Measured on one 127-program ops-ptc session: 11 of 17 failed programs were this exact error, two of them retries of a program that had already failed, with names declared on turn 1 still colliding on turn 6. Four of the five shipped examples are still not safe to copy twice, because a top-level `const` outlives the program that declared it (bench/probes/probe-scope-guidance.mjs; the fifth uses top-level await, which that probe cannot evaluate). The lesson adds one short section with the three rules and the two matching rows in the mistake table, and Step 3 now separates a name that is spent from a value that may not survive. Examples, steps, the four trajectories and 0.5.6's sandbox section are unchanged. Revision 9; no behaviour changes.
171b87d to
d4d8ecd
Compare
|
Reviewed this branch against
Two things worth stating rather than fixing:
Validation on the rebased head: |
Closes #868
What was wrong
PTC can evaluate a program in a runtime that retains state, so a top-level
const/let/class/functionoutlives the program that declared it. A second declaration of that name is aSyntaxErrorat compile time and the whole program is discarded before its first line runs, tool calls included. A program that throws keeps its names as well — bindings are instantiated before evaluation — so a failed program cannot be retried verbatim: the retry dies on a name, not on its arguments. The name is never reclaimable: there is no way to delete a lexical binding, andconstis not acontextproperty, soObject.keyscannot even enumerate it.In the session that filed #868 (127
run_codeprograms) this was 11 of 17 failures (65% of failures, 8.7% of programs). Two were retries of a program that had already failed. Names declared on turn 1 (q1,e1) still collided on turn 6, and failed programs left ~70 permanently unusable names.The shipped guidance taught the pattern: its Step 3 example is
const [load, head] = await Promise.all([...]), and the model copiedloadinto the next program, dying on program two.The change
release/0.5.5rewrote the same file. This branch is rebased onto the currentmaster(which contains 0.5.5), so the diff against the 0.5.5 text is 15 lines:## One session, one scope— a top-level name can outlive its program, a second one is a compile-time error that discards the whole program, a failed program keeps its names, so each program owns its names and a retry renames.BATCHING_GUIDANCE_REVISION→'5'(0.5.5 already used 4).What this deliberately does not do: wrap the examples in
{ }. That was the first shape of this PR and it is incompatible with 0.5.5:test/batching-examples.test.mjscompiles and executes every shipped example through anAsyncFunctionand asserts the returned summary, so an example has toreturn, andreturncannot live inside a bare block. Switching the examples toconsole.logsilently removed them from that test's coverage — I reverted it for that reason.The stronger alternative, if maintainers prefer 0% over 5%: wrap each example body in
return await (async () => { ... })(). It keeps the returned value, keepsbatching-examplesgreen, and makes the names local, at the cost of turning every example into an IIFE. Say the word and I will send it as a follow-up.Validation
A. Model-driven A/B over one audit task in a retained REPL — same model, same task, same
run_codecontract, only--guidancediffers, 4 runs per arm, 14-program budget:B. Why the examples are not the vehicle —
bench/probes/probe-scope-guidance.mjsruns every fenced example twice in one retained REPL. Both texts score 6 of 7 redeclared, because the examples are unchanged; that is the measurement that says this fix has to be the rule, not the shape.C. Suite —
npm run verifyon this branch (darwin-arm64): 247 of 248 suites pass, 7 skipped. The one failure ispreset-fragment, which compares the shippedpresets/ops-ptc.patch.ymlchecksum against the locally installed host checkout; that checkout is at a newer commit (838665e0…vs the recordedce02148b…), and this branch does not touchpresets/. It passes in CI, where the host is installed from the pinned range.D.
CI required— green on the rebased head: https://github.com/T-Auto/dsh-ops/actions/runs/43458558329An earlier run of the same content was red twice for infrastructure reasons, not for this change:
validate (darwin-arm64)was cancelled with zero steps and no runner assigned, andvalidate (darwin-x64)failed once ontest/native-guidance.test.mjs:59, which waits for the Native reader to be published and then asserts the officialreadis already hidden — publication and hiding are two steps, so a loaded runner can lose that race. Both legs pass on the current head.Update 2026-11-21 — rebased onto v0.5.6
The branch now sits on
v0.5.6(8545d446); the previous head (171b87d2) was based on the 18-card release. Diff against 0.5.6: 8 files, +184/−8. Where the text above disagrees, this section is the accurate one.What 0.5.6 changed under this branch
## Sandbox permissionsin the same slot (between Core rules and Step 0) and took revision 8 for it. This branch keeps both sections — sandbox first, then## One session, one scope— so nothing is displaced, and the revision becomes 9.test/batching-guidance.test.mjsgained a 9,000-character bound and a sandbox-section pin; this branch updates the revision/byte pins and adds a guard that a full surface carries both sections.Two wording fixes from the review
ops_write_file/ops_edit_fileand then throw. It now says "A failed program may already have run calls: check their effects, then rename before retrying", and the mistake row says "Check what it already ran, then rename and retry".Evidence status
Validation on v0.5.6
Wording that must survive the merge: none. The trim (#982) and the sandbox lesson both landed before this branch; the section is additive.