Commit 70640ce
Harden tools, compaction, and prompt layers for long-horizon autonomous runs (#118)
* fix(agent): harden tools, compaction, and prompt for long-horizon runs
Audit of jcode vs Claude Code and codex (32 findings, tracked with
per-case status in internal-doc/tooling-audit.md); all confirmed cases
fixed with TDD across four waves:
Tools
- execute: head+tail truncation with dropped-bytes marker, full output
spilled to ~/.jcode/tasks and the path returned to the model
- exec lifecycle: process-group kill via new internal/procutil (Setpgid
+ Kill(-pid)), WaitDelay=2s with ErrWaitDelay folded to success,
SSH SIGTERM->SIGKILL grace, Docker in-container pidfile tree kill
- read: 200KB output budget with offset continuation + 2000-byte
per-line truncation (UTF-8 safe)
- glob: find -name replaced with cd+rg --files --glob --sortr=modified
(fixes silently-broken ** recursion, adds deterministic mtime order)
- grep: global (not per-file) content limit via streaming early-stop,
honest capped footer, output_mode enum validation
- edit/write: read-before-edit enforced (ConflictNeverRead; FileTracker
now actually wired in NewEnv), atomic writes (temp+fsync+rename, SSH
base64+mv -f), multi-edit overlap/ambiguity guards + per-op
replace_all, item schemas for edits/todos arrays
- background tasks: head+tail truncation, task log always written and
its path surfaced to the model
- errors: Fatal/IsFatal layer aborts runs on dead container/SSH,
subagent safe middleware (panic recovery + error folding + parent
propagation, async panic no longer crashes the process), ToolError
hints on high-frequency failures
Compaction
- occupancy reminder now uses last-call total (GetLastTotal) instead of
the cumulative ledger — fixes permanently >100% "wrap up" pressure
after any compaction
- crude 500-char threshold strategy demoted to fallback-only behind the
eino summarizer; compact failure fuse (3 strikes, fail-open)
- output-reserve headroom (EffectiveContextLimit) for trigger math
- compaction persists the kept tail; TUI resume no longer loses it
- reduction config single-sourced (BuildReductionConfig) across
TUI/ACP/Web, calibrated token estimator (ASCII/3.6 + CJK-aware + EMA
self-calibration from provider usage) replaces len/4, per-turn
aggregate tool-result budget (150k chars, copy-on-write)
Prompt
- env/git drift re-collected every 5 iterations and injected as a diff
(includes date rollover); AGENTS.md hot-reloaded on mtime+hash change;
externally-modified files reported with a re-read instruction
- system.md: parallel tool-call batching directive + Verification
discipline section
Verified by ~90 new TDD tests (red first), full-repo go test -count=1,
-race on tools/agent, GOOS=windows build, and a new agent-eval ACP e2e
(robust_huge_output: seq 1 200000 truncated to marker+tail, session
survives, oracle-checked answer) passing against a live model.
Generated with Jack AI bot
* chore: resolve golangci-lint findings in new code
errcheck on discarded Count returns, De Morgan simplification,
embedded-field selector cleanup, and two unparam removals
(execLocal constant timeout, buildRgArgs unused maxResults).
Generated with Jack AI bot
* fix(git): scrub inherited GIT_* env from every git subprocess
git exports an absolute GIT_DIR to hook subprocesses when pushing from a
linked worktree. jcode's git calls (envinfo, web git API, session
baseline/diff stats) and the web test helper inherited it, silently
operating on the outer repository instead of the -C/cwd-selected one —
the web suite's `git init` in a temp dir re-initialized the pushing repo
as bare when run under the pre-push hook.
Add util.ScrubbedGitEnv() (drops GIT_DIR/GIT_WORK_TREE/GIT_INDEX_FILE/
GIT_COMMON_DIR and friends), apply it at all production git call sites,
and pin GIT_DIR/GIT_WORK_TREE to the temp repo in the web test helper.
Regression-tested by running the web suite under a hostile GIT_DIR
against a victim repo (stays non-bare) plus unit tests for the scrubber
and for gitCommand under an inherited GIT_DIR.
Recorded as finding #33 in internal-doc/tooling-audit.md.
Generated with Jack AI bot
* fix(agent): address review findings — live-env reminders, calibration recovery, docker fatal coverage
- reminder: read remote-ness from the live *tools.Env each round (switch_env
mutates it in place without an agent rebuild on ACP/web); pause the
env-drift / AGENTS.md / external-file sweeps while remote so local-host
state is never reported as drift of the remote machine, and resume with
the same baselines after switching back
- token estimate: a sustained streak of below-peak counts adopts the shrunk
window as the new full baseline, so calibration resumes after compaction
instead of freezing on the stale peak
- docker exec: route stream-copy and inspect errors through wrapDockerRunErr
so a container removed mid-exec is classified Fatal like create/attach
- glob: resolve a relative search path against the tool workspace instead of
the process cwd; make the mtime-order test deterministic via os.Chtimes
- compaction: refuse to apply an empty strategy result (counts toward the
fuse instead of wiping the conversation)
Generated with Jack AI bot
---------
Co-authored-by: t <t@example.com>1 parent 7b89f16 commit 70640ce
72 files changed
Lines changed: 6146 additions & 328 deletions
File tree
- agent-eval/suite
- internal-doc
- internal
- agent
- command
- hooks
- model
- procutil
- prompts
- session
- tools
- util
- web
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1007 | 1007 | | |
1008 | 1008 | | |
1009 | 1009 | | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
1010 | 1027 | | |
1011 | 1028 | | |
1012 | 1029 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | | - | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
| |||
125 | 127 | | |
126 | 128 | | |
127 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
128 | 136 | | |
129 | 137 | | |
130 | 138 | | |
131 | 139 | | |
132 | 140 | | |
133 | 141 | | |
134 | | - | |
135 | 142 | | |
136 | 143 | | |
137 | 144 | | |
| |||
157 | 164 | | |
158 | 165 | | |
159 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
160 | 170 | | |
161 | 171 | | |
162 | 172 | | |
| |||
193 | 203 | | |
194 | 204 | | |
195 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
196 | 218 | | |
197 | 219 | | |
198 | 220 | | |
| |||
206 | 228 | | |
207 | 229 | | |
208 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
209 | 242 | | |
210 | 243 | | |
211 | 244 | | |
212 | 245 | | |
213 | 246 | | |
214 | 247 | | |
215 | | - | |
216 | 248 | | |
217 | 249 | | |
218 | 250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| |||
0 commit comments