The user wants 2000 tasks, most of them ones Qwen cannot solve. New batch tasks are now measured on their branch first (3 Qwen trials each), and only HARD or MEDIUM tasks reach main; ROUTINE ones stay on the batch branches. A session cut by context_limit or output_limit counts as a failure for difficulty (user decision 2026-11-03); the trajectory stays incomplete. - Batch 26 (route D, real upstream fixes in embedded open-source projects): 7 HARD of 20 (coreJSON, littlefs, CANopen, coreMQTT, LwM2M, Zephyr ring, lwIP SNTP). Most failures are Qwen exhausting its context in the larger workspaces. - Batch 25 (HWE mutation repairs): 1 HARD and 1 MEDIUM of 56. - Batch 27 (spec-dense implementation tasks): 2 MEDIUM of the first 10. Each task comes from the exact commit Qwen measured, and its digest matches the measured one. Failure reasons are not yet reviewed, so difficulty is the automatic label. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
135 lines
3.7 KiB
C++
135 lines
3.7 KiB
C++
#ifndef SENSOR_SESSION_HPP
|
|
#define SENSOR_SESSION_HPP
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <csignal>
|
|
#include <string>
|
|
#include <vector>
|
|
namespace sensor {
|
|
enum class Code : int { Ok=0, Invalid=1, Busy=2, State=3, Io=4, Protocol=5 };
|
|
enum class State : int { Idle=0, Running=1, Stopped=2, Ended=3, Fault=4 };
|
|
struct Config {
|
|
int block=4;
|
|
int channel=1;
|
|
int limit=0;
|
|
};
|
|
struct IoResult {
|
|
int count=0;
|
|
int error=0;
|
|
};
|
|
class Runtime {
|
|
public:
|
|
virtual ~Runtime()=default;
|
|
virtual IoResult read(std::uint64_t offset, std::uint8_t* data, std::size_t size)=0;
|
|
virtual IoResult write(std::uint64_t offset, const std::uint8_t* data, std::size_t size)=0;
|
|
virtual void log(const std::string& text)=0;
|
|
virtual void reserve(std::size_t size)=0;
|
|
virtual void release()=0;
|
|
};
|
|
class Mailbox {
|
|
volatile std::sig_atomic_t pending_=0;
|
|
public:
|
|
void publish(int reason) noexcept;
|
|
int peek() const noexcept;
|
|
int take() noexcept;
|
|
void clear() noexcept;
|
|
};
|
|
struct Snapshot {
|
|
State state=State::Idle;
|
|
Config config;
|
|
std::uint32_t epoch=0;
|
|
std::uint32_t sequence=0;
|
|
int stop=0;
|
|
int pending=0;
|
|
int error=0;
|
|
std::uint64_t input=0;
|
|
std::uint64_t output=0;
|
|
std::uint64_t records=0;
|
|
std::uint64_t reads=0;
|
|
std::uint64_t writes=0;
|
|
std::uint64_t interrupts=0;
|
|
std::uint64_t discarded=0;
|
|
std::size_t buffered=0;
|
|
std::size_t remaining=0;
|
|
bool owned=false;
|
|
};
|
|
struct Frame {
|
|
std::uint8_t channel=0;
|
|
std::uint32_t epoch=0;
|
|
std::uint32_t sequence=0;
|
|
std::vector<std::uint8_t> payload;
|
|
};
|
|
Code validate(const Config& config) noexcept;
|
|
std::vector<std::uint8_t> encode(const Frame& frame);
|
|
Code decode(const std::vector<std::uint8_t>& bytes, Frame& frame);
|
|
std::string hex(const std::vector<std::uint8_t>& bytes);
|
|
Code unhex(const std::string& text, std::vector<std::uint8_t>& bytes);
|
|
std::string describe(const Snapshot& snapshot);
|
|
|
|
struct Entry {
|
|
std::uint32_t epoch=0;
|
|
std::uint32_t next=0;
|
|
std::uint64_t records=0;
|
|
std::uint64_t bytes=0;
|
|
std::uint64_t sum=0;
|
|
};
|
|
class Catalogue {
|
|
std::array<Entry,256> entries_{};
|
|
std::array<bool,256> present_{};
|
|
public:
|
|
Code accept(const std::vector<std::uint8_t>& bytes);
|
|
Code accept_stream(const std::vector<std::uint8_t>& bytes);
|
|
Code merge(const Catalogue& other);
|
|
std::string summary() const;
|
|
bool contains(int channel) const;
|
|
Code lookup(int channel,Entry& entry) const;
|
|
Code erase(int channel);
|
|
void clear();
|
|
std::size_t size() const;
|
|
std::uint64_t records() const;
|
|
std::uint64_t bytes() const;
|
|
std::vector<int> channels() const;
|
|
};
|
|
class Session {
|
|
Runtime& runtime_;
|
|
Config config_;
|
|
State state_=State::Idle;
|
|
Mailbox mailbox_;
|
|
std::uint32_t epoch_=0;
|
|
std::uint32_t sequence_=0;
|
|
int stop_=0;
|
|
int error_=0;
|
|
bool owned_=false;
|
|
bool eof_=false;
|
|
std::array<std::uint8_t,32> input_{};
|
|
std::size_t used_=0;
|
|
std::vector<std::uint8_t> frame_;
|
|
std::size_t sent_=0;
|
|
std::uint64_t input_count_=0;
|
|
std::uint64_t output_count_=0;
|
|
std::uint64_t records_=0;
|
|
std::uint64_t reads_=0;
|
|
std::uint64_t writes_=0;
|
|
std::uint64_t interrupts_=0;
|
|
std::uint64_t discarded_=0;
|
|
void clear_progress();
|
|
void close_resource();
|
|
bool collect_stop();
|
|
void end_stream();
|
|
Code fail(Code code,int error);
|
|
Code read_piece(bool& paused);
|
|
Code write_piece(bool& paused,bool& complete);
|
|
void prepare_frame();
|
|
public:
|
|
explicit Session(Runtime& runtime);
|
|
Code configure(const Config& config);
|
|
Code start(std::uint32_t epoch);
|
|
void notify(int reason) noexcept;
|
|
Code pump(int quota);
|
|
Code reset();
|
|
Snapshot snapshot() const;
|
|
};
|
|
}
|
|
#endif
|